-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathlocalDataStorage-3.0.0.js
4195 lines (3350 loc) · 188 KB
/
localDataStorage-3.0.0.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
lllllll lllllll DDDDDDDDDDDDD tttt SSSSSSSSSSSSSSS tttt
l:::::l l:::::l D::::::::::::DDD ttt:::t SS:::::::::::::::S ttt:::t
l:::::l l:::::l D:::::::::::::::DD t:::::t S:::::SSSSSS::::::S t:::::t
l:::::l l:::::l DDD:::::DDDDD:::::D t:::::t S:::::S SSSSSSS t:::::t
l::::l ooooooooooo cccccccccccccccc aaaaaaaaaaaaa l::::l D:::::D D:::::D aaaaaaaaaaaaa ttttttt:::::ttttttt aaaaaaaaaaaaa S:::::S ttttttt:::::ttttttt ooooooooooo rrrrr rrrrrrrrr aaaaaaaaaaaaa ggggggggg ggggg eeeeeeeeeeee
l::::l oo:::::::::::oo cc:::::::::::::::c a::::::::::::a l::::l D:::::D D:::::D a::::::::::::a t:::::::::::::::::t a::::::::::::a S:::::S t:::::::::::::::::t oo:::::::::::oo r::::rrr:::::::::r a::::::::::::a g:::::::::ggg::::g ee::::::::::::ee
l::::l o:::::::::::::::o c:::::::::::::::::c aaaaaaaaa:::::a l::::l D:::::D D:::::D aaaaaaaaa:::::at:::::::::::::::::t aaaaaaaaa:::::a S::::SSSS t:::::::::::::::::t o:::::::::::::::or:::::::::::::::::r aaaaaaaaa:::::a g:::::::::::::::::g e::::::eeeee:::::ee
l::::l o:::::ooooo:::::oc:::::::cccccc:::::c a::::a l::::l D:::::D D:::::D a::::atttttt:::::::tttttt a::::a SS::::::SSSSStttttt:::::::tttttt o:::::ooooo:::::orr::::::rrrrr::::::r a::::ag::::::ggggg::::::gge::::::e e:::::e
l::::l o::::o o::::oc::::::c ccccccc aaaaaaa:::::a l::::l D:::::D D:::::D aaaaaaa:::::a t:::::t aaaaaaa:::::a SSS::::::::SS t:::::t o::::o o::::o r:::::r r:::::r aaaaaaa:::::ag:::::g g:::::g e:::::::eeeee::::::e
l::::l o::::o o::::oc:::::c aa::::::::::::a l::::l D:::::D D:::::D aa::::::::::::a t:::::t aa::::::::::::a SSSSSS::::S t:::::t o::::o o::::o r:::::r rrrrrrraa::::::::::::ag:::::g g:::::g e:::::::::::::::::e
l::::l o::::o o::::oc:::::c a::::aaaa::::::a l::::l D:::::D D:::::Da::::aaaa::::::a t:::::t a::::aaaa::::::a S:::::S t:::::t o::::o o::::o r:::::r a::::aaaa::::::ag:::::g g:::::g e::::::eeeeeeeeeee
l::::l o::::o o::::oc::::::c ccccccca::::a a:::::a l::::l D:::::D D:::::Da::::a a:::::a t:::::t tttttta::::a a:::::a S:::::S t:::::t tttttto::::o o::::o r:::::r a::::a a:::::ag::::::g g:::::g e:::::::e
l::::::lo:::::ooooo:::::oc:::::::cccccc:::::ca::::a a:::::a l::::::lDDD:::::DDDDD:::::D a::::a a:::::a t::::::tttt:::::ta::::a a:::::a SSSSSSS S:::::S t::::::tttt:::::to:::::ooooo:::::o r:::::r a::::a a:::::ag:::::::ggggg:::::g e::::::::e
l::::::lo:::::::::::::::o c:::::::::::::::::ca:::::aaaa::::::a l::::::lD:::::::::::::::DD a:::::aaaa::::::a tt::::::::::::::ta:::::aaaa::::::a S::::::SSSSSS:::::S tt::::::::::::::to:::::::::::::::o r:::::r a:::::aaaa::::::a g::::::::::::::::g e::::::::eeeeeeee
l::::::l oo:::::::::::oo cc:::::::::::::::c a::::::::::aa:::al::::::lD::::::::::::DDD a::::::::::aa:::a tt:::::::::::tt a::::::::::aa:::aS:::::::::::::::SS tt:::::::::::tt oo:::::::::::oo r:::::r a::::::::::aa:::a gg::::::::::::::g ee:::::::::::::e
llllllll ooooooooooo cccccccccccccccc aaaaaaaaaa aaaallllllllDDDDDDDDDDDDD aaaaaaaaaa aaaa ttttttttttt aaaaaaaaaa aaaa SSSSSSSSSSSSSSS ttttttttttt ooooooooooo rrrrrrr aaaaaaaaaa aaaa gggggggg::::::g eeeeeeeeeeeeee
g:::::g
gggggg g:::::g
g:::::gg gg:::::g
g::::::ggg:::::::g
gg:::::::::::::g
ggg::::::ggg
gggggg
*/
/*///////////////////////////////////////////////////////////////////////////////////////////////////
localDataStorage 3.0.0
https://cdn.jsdelivr.net/gh/macmcmeans/localDataStorage@master/localDataStorage-3.0.0.js
/////////////////////////////////////////////////////////////////////////////////////////////////////
This version is
Copyright 2017 - 2022 William P. "Mac" McMeans
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/////////////////////////////////////////////////////////////////////////////////////////////////////_setLengthProperty
/////////////////////////////////////////////////////////////////////////////////////////////////////
This version of localDataStorage incorporates aleaPRNG (a pseudo random number generator) by W. McMeans.
/////////////////////////////////////////////////////////////////////////////////////////////////////
aleaPRNG 1.1
//////////////////////////////////////////////////////////////////
https://github.com/macmcmeans/aleaPRNG/blob/master/aleaPRNG-1.1.js
//////////////////////////////////////////////////////////////////
Original work copyright © 2010 Johannes Baagøe, under MIT license
This is a derivative work copyright (c) 2017-2020, W. Mac" McMeans, under BSD license.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
This version of localDataStorage incorporates fisherYatesDurstenfeldKnuthShuffle by W. McMeans.
/////////////////////////////////////////////////////////////////////////////////////////////////////
fisherYatesDurstenfeldKnuthShuffle 1.2
//////////////////////////////////////////////////////////////////
https://github.com/macmcmeans/fisherYatesDurstenfeldKnuthShuffle/blob/master/fisherYatesDurstenfeldKnuthShuffle-1.2.js
//////////////////////////////////////////////////////////////////
Copyright © 2018, 2020, 2021 W. "Mac" McMeans
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
////////////////////////////////////////////////////////////////*/
const localDataStorage = function( _specifiedPrefix, _switches ) {
return( function localDataStore( _storageKeyPrefix, _userswitches ) {
"use strict";
let
// default scramble key
_scrambleKey = { "this":['is'], "not":['cryptographic','strength'] }
// user feedback mode
, _weAreVerbose = 0
// Broadcast Channel API
, _broadcastChannel = 'localDataStorage'
, ourAPIChannel
;
ourAPIChannel = new BroadcastChannel( _broadcastChannel )
const VERSION = '3.0.0'
, ERROR_10 = "𝗡𝗼 𝘀𝗲𝗲𝗱 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_11 = "𝗡𝗼 𝗸𝗲𝘆 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_12 = "𝗡𝗼 𝗸𝗲𝘆 𝘃𝗮𝗹𝘂𝗲 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_13 = "𝗩𝗮𝗹𝘂𝗲 𝗶𝘀 𝗮𝗻 𝘂𝗻𝘀𝘂𝗽𝗽𝗼𝗿𝘁𝗲𝗱 𝘁𝘆𝗽𝗲"
, ERROR_14 = "𝗡𝗼 𝘀𝗰𝗿𝗮𝗺𝗯𝗹𝗲 𝗸𝗲𝘆 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_15 = "𝗞𝗲𝘆 𝗱𝗼𝗲𝘀 𝗻𝗼𝘁 𝗲𝘅𝗶𝘀𝘁"
, ERROR_16 = "𝗞𝗲𝘆 𝗺𝘂𝘀𝘁 𝗯𝗲 𝗮𝗻 𝗔𝗿𝗿𝗮𝘆 𝗞𝗲𝘆"
, ERROR_17 = "𝗨𝗻𝗸𝗻𝗼𝘄𝗻 𝗱𝗮𝘁𝗮 𝘁𝘆𝗽𝗲"
, ERROR_18 = "𝗡𝗼 𝗱𝗮𝘁𝗮 𝘁𝘆𝗽𝗲 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_19 = "𝗡𝗼 𝘃𝗮𝗹𝘂𝗲 𝘁𝗼 𝗰𝗼𝗻𝘃𝗲𝗿𝘁 𝗳𝗿𝗼𝗺"
, ERROR_20 = "𝗡𝗼 𝘃𝗮𝗹𝘂𝗲 𝘁𝗼 𝗰𝗼𝗻𝘃𝗲𝗿𝘁 𝘁𝗼"
, ERROR_21 = "𝗔𝗻 𝗲𝗿𝗿𝗼𝗿 𝗼𝗰𝗰𝘂𝗿𝗿𝗲𝗱 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗳𝗿𝗼𝗺 𝗹𝗼𝗰𝗮𝗹𝗦𝘁𝗼𝗿𝗮𝗴𝗲"
, ERROR_22 = "𝗖𝗮𝗻𝗻𝗼𝘁 𝗮𝘀𝘀𝗶𝗴𝗻 𝘃𝗮𝗹𝘂𝗲 𝗯𝗲𝗰𝗮𝘂𝘀𝗲 𝗹𝗼𝗰𝗮𝗹𝗦𝘁𝗼𝗿𝗮𝗴𝗲 𝗾𝘂𝗼𝘁𝗮 𝗶𝘀 𝗳𝘂𝗹𝗹"
, ERROR_23 = "𝗔𝗻 𝗲𝗿𝗿𝗼𝗿 𝗼𝗰𝗰𝘂𝗿𝗿𝗲𝗱 𝘄𝗿𝗶𝘁𝗶𝗻𝗴 𝘁𝗼 𝗹𝗼𝗰𝗮𝗹𝗦𝘁𝗼𝗿𝗮𝗴𝗲"
, ERROR_24 = "𝗡𝗼 𝗶𝗻𝗱𝗲𝘅 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_25 = "𝗜𝗹𝗹𝗲𝗴𝗮𝗹 𝗶𝗻𝗱𝗲𝘅 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_26 = "𝗨𝗻𝗸𝗻𝗼𝘄𝗻 𝘀𝘁𝗿𝗶𝗻𝗴 𝗶𝗻𝗱𝗲𝘅 𝗸𝗲𝘆𝘄𝗼𝗿𝗱"
, ERROR_27 = "𝗨𝗻𝗸𝗻𝗼𝘄𝗻 𝗻𝘂𝗺𝗲𝗿𝗶𝗰 𝗶𝗻𝗱𝗲𝘅"
, ERROR_28 = "𝗨𝗻𝗸𝗻𝗼𝘄𝗻 𝗶𝗻𝗱𝗲𝘅"
, ERROR_29 = "𝗡𝗼 𝗻𝗲𝘄 𝗸𝗲𝘆 𝗻𝗮𝗺𝗲 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_30 = "𝗖𝗮𝗻𝗻𝗼𝘁 𝗿𝗲𝗻𝗮𝗺𝗲 𝗸𝗲𝘆 𝘁𝗼 𝗶𝘁𝘀 𝗼𝘄𝗻 𝗻𝗮𝗺𝗲"
, ERROR_31 = "𝗗𝗲𝘀𝘁𝗶𝗻𝗮𝘁𝗶𝗼𝗻 𝗸𝗲𝘆 𝗮𝗹𝗿𝗲𝗮𝗱𝘆 𝗲𝘅𝗶𝘀𝘁𝘀"
, ERROR_32 = "𝗡𝗼 𝘀𝘁𝗿𝗶𝗻𝗴 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_33 = "𝗡𝗼 𝘀𝗼𝘂𝗿𝗰𝗲 𝗸𝗲𝘆 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_34 = "𝗡𝗼 𝗱𝗲𝘀𝘁𝗶𝗻𝗮𝘁𝗶𝗼𝗻 𝗸𝗲𝘆 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_35 = "𝗦𝗼𝘂𝗿𝗰𝗲 𝗸𝗲𝘆 𝗱𝗼𝗲𝘀 𝗻𝗼𝘁 𝗲𝘅𝗶𝘀𝘁"
, ERROR_36 = "𝗖𝗮𝗻𝗻𝗼𝘁 𝗼𝘃𝗲𝗿𝘄𝗿𝗶𝘁𝗲 𝗲𝘅𝗶𝘀𝘁𝗶𝗻𝗴 𝗱𝗲𝘀𝘁𝗶𝗻𝗮𝘁𝗶𝗼𝗻 𝗸𝗲𝘆"
, ERROR_37 = "𝗗𝗮𝘁𝗮 𝘁𝘆𝗽𝗲 𝗺𝘂𝘀𝘁 𝗯𝗲 𝘀𝘁𝗿𝗶𝗻𝗴"
, ERROR_38 = "𝗖𝗮𝗻𝗻𝗼𝘁 𝗰𝗼𝗽𝘆 𝗮𝗻 𝗼𝗯𝗳𝘂𝘀𝗰𝗮𝘁𝗲𝗱 𝗸𝗲𝘆"
, ERROR_39 = "𝗞𝗲𝘆 𝗶𝘀 𝗻𝗼𝘁 𝗼𝗯𝗳𝘂𝘀𝗰𝗮𝘁𝗲𝗱"
, ERROR_40 = "𝗕𝗮𝗰𝗸𝘂𝗽 𝗰𝗮𝗻𝗻𝗼𝘁 𝗼𝘃𝗲𝗿𝘄𝗿𝗶𝘁𝗲 𝗲𝘅𝗶𝘀𝘁𝗶𝗻𝗴 𝗹𝗼𝗰𝗮𝗹𝗦𝘁𝗼𝗿𝗮𝗴𝗲 𝗸𝗲𝘆"
, ERROR_41 = "𝗥𝗲𝘀𝘁𝗼𝗿𝗲 𝗰𝗮𝗻𝗻𝗼𝘁 𝗼𝘃𝗲𝗿𝘄𝗿𝗶𝘁𝗲 𝗲𝘅𝗶𝘀𝘁𝗶𝗻𝗴 𝗺𝗲𝗺𝗼𝗿𝘆 𝗸𝗲𝘆"
, ERROR_42 = "𝗦𝗼𝘂𝗿𝗰𝗲 𝗺𝗲𝗺𝗼𝗿𝘆 𝗸𝗲𝘆 𝗱𝗼𝗲𝘀 𝗻𝗼𝘁 𝗲𝘅𝗶𝘀𝘁"
, ERROR_43 = "𝗦𝗼𝘂𝗿𝗰𝗲 𝗹𝗼𝗰𝗮𝗹𝗦𝘁𝗼𝗿𝗮𝗴𝗲 𝗸𝗲𝘆 𝗱𝗼𝗲𝘀 𝗻𝗼𝘁 𝗲𝘅𝗶𝘀𝘁"
, ERROR_44 = "𝗡𝗼 𝗯𝗿𝗼𝗮𝗱𝗰𝗮𝘀𝘁 𝗰𝗵𝗮𝗻𝗻𝗲𝗹 𝘀𝗽𝗲𝗰𝗶𝗳𝗶𝗲𝗱"
, ERROR_45 = "𝗕𝗮𝗰𝗸𝘂𝗽 𝗲𝗿𝗿𝗼𝗿: 𝗰𝗮𝗻𝗻𝗼𝘁 𝗼𝘃𝗲𝗿𝘄𝗿𝗶𝘁𝗲 𝗲𝘅𝗶𝘀𝘁𝗶𝗻𝗴 𝗸𝗲𝘆"
, ERROR_46 = "𝗕𝗮𝗰𝗸𝘂𝗽 𝗲𝗿𝗿𝗼𝗿: 𝗰𝗮𝗻𝗻𝗼𝘁 𝗰𝗿𝗲𝗮𝘁𝗲 𝗻𝗲𝘄 𝗸𝗲𝘆"
, ERROR_47 = "𝗥𝗲𝘀𝘁𝗼𝗿𝗲 𝗲𝗿𝗿𝗼𝗿: 𝗰𝗮𝗻𝗻𝗼𝘁 𝗼𝘃𝗲𝗿𝘄𝗿𝗶𝘁𝗲 𝗲𝘅𝗶𝘀𝘁𝗶𝗻𝗴 𝗸𝗲𝘆"
, ERROR_48 = "𝗥𝗲𝘀𝘁𝗼𝗿𝗲 𝗲𝗿𝗿𝗼𝗿: 𝗰𝗮𝗻𝗻𝗼𝘁 𝗰𝗿𝗲𝗮𝘁𝗲 𝗻𝗲𝘄 𝗸𝗲𝘆"
, SUPPORTED_TYPES = [ 'array', 'bigint', 'boolean', 'date', 'float', 'integer', 'null', 'number', 'object', 'string' ]
// 1 byte overhead per flag (stored using 2 bytes)
//////////////////////////////////////////////////
, SHUFFLE_MARKER = String.fromCodePoint( 1 )
, TYPE_OBFUSCATE = String.fromCodePoint( 2 )
, TYPE_CRUNCH = String.fromCodePoint( 3 )
, TYPE_ARRAY = String.fromCodePoint( 4 )
, TYPE_BIGINT = String.fromCodePoint( 5 )
, TYPE_BOOLEAN = String.fromCodePoint( 6 )
, TYPE_DATE = String.fromCodePoint( 7 )
, TYPE_NUMBER = String.fromCodePoint( 8 )
, TYPE_OBJECT = String.fromCodePoint( 9 )
, TYPE_STRING = String.fromCodePoint( 10 )
//////////////////////////////////////////////////
, STORAGE_TEST = '__storage_test__'
, CRUNCH_TEST = '__crunch_test__'
, STRIP_THE_PREFIX = true
, __prefix = function() {
let _now = new Date();
return _now.getTime() + ':' + ( Math.random() * 100000000 | 0 );
}()
, _prefix = _storageKeyPrefix === ''
? ''
: typeof _storageKeyPrefix === 'undefined'
? __prefix
: _storageKeyPrefix
, _memoryKeyPrefix = '#'
, __isStorageAvailable = function( _type ) {
let storage
, x = STORAGE_TEST
;
try {
storage = window[ _type ]
storage.setItem( x, x );
storage.removeItem( x );
return true;
}
catch( e ) {
return false;
}
}
, _storageIsAvailable = function() {
_housekeeping();
return __isStorageAvailable( 'localStorage' );
}
/*////////////////////////////////////////////////////////////////////
aleaPRNG 1.1
//////////////////////////////////////////////////////////////////////
Copyright (c) 2017-2020, W. "Mac" McMeans
LICENSE: BSD 3-Clause License
https://github.com/macmcmeans/aleaPRNG/blob/master/aleaPRNG-1.1.min.js
////////////////////////////////////////////////////////////////////*/
, _aleaPRNG = function() {
return function(n) {
"use strict";
var a, u, i, c, r, t = new Uint32Array(3), f = "", e = "aleaPRNG 1.1";
function o(n) {
var o, r, t = (o = 4022871197, (r = function(n) {
n = n.toString();
for (var r = 0, t = n.length; r < t; r++) {
var e = .02519603282416938 * (o += n.charCodeAt(r));
e -= o = e >>> 0, o = (e *= o) >>> 0, o += 4294967296 * (e -= o);
}
return 2.3283064365386963e-10 * (o >>> 0);
}).version = "Mash 0.9", r);
a = t(" "), u = t(" "), i = t(" "), c = 1;
for (var e = 0; e < n.length; e++) (a -= t(n[e])) < 0 && (a += 1), (u -= t(n[e])) < 0 && (u += 1),
(i -= t(n[e])) < 0 && (i += 1);
f = t.version, t = null;
}
function l(n) {
return parseInt(n, 10) === n;
}
var s = function() {
var n = 2091639 * a + 2.3283064365386963e-10 * c;
return a = u, u = i, i = n - (c = 0 | n);
};
return s.fract53 = function() {
return s() + 11102230246251565e-32 * (2097152 * s() | 0);
}, s.int32 = function() {
return 4294967296 * s();
}, s.cycle = function(n) {
(n = void 0 === n ? 1 : +n) < 1 && (n = 1);
for (var r = 0; r < n; r++) s();
}, s.range = function() {
var n, r;
return r = 1 === arguments.length ? arguments[n = 0] : (n = arguments[0], arguments[1]),
arguments[0] > arguments[1] && (n = arguments[1], r = arguments[0]), l(n) && l(r) ? Math.floor(s() * (r - n + 1)) + n : s() * (r - n) + n;
}, s.restart = function() {
o(r);
}, s.seed = function() {
o(Array.prototype.slice.call(arguments));
}, s.version = function() {
return e;
}, s.versions = function() {
return e + ", " + f;
}, 0 === n.length && (window.crypto.getRandomValues(t), n = [ t[0], t[1], t[2] ]),
o(r = n), s;
}(Array.prototype.slice.call(arguments));
}
// return boolean true/false testing for array equality and identity
, _arraysAreEqual = function( a1, a2, ) {
let _return = false
, _test = true
;
if( a1.length === a2.length ) {
for( let i = 0; i < a1.length; i++ ) {
_test = a2.indexOf( a1[ i ] ) !== -1;
if( _test !== true ) { break; }
}
_return = _test;
}
return _return;
}
//////////////////////////////////////////////////////////////////////
/*////////////////////////////////////////////////////////////////////
customRadix 1.1.0
//////////////////////////////////////////////////////////////////////
Copyright (c) 2017, W. "Mac" McMeans
LICENSE: BSD 3-Clause License
////////////////////////////////////////////////////////////////////*/
, _customRadix = function() {
"use strict";
const e = "0123456789", r = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", t = "abcdefghijklmnopqrstuvwxyz", n = "+/!#$%&()*,-:;<=>?@[]^_`{|}~\\. '\"", o = e + r + t + n + "¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĆćĈĉĊċČčĜĝĞğĠġĢģĤĥĦħIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŊŋŔŕŖŗŘřŜŝŞşŠšŢţŤťŦŧŲųŴŵŶŷŸŹźŻżŽžΔΛΣΓ", i = "./" + e + r + t, a = function(e) {
return function(e) {
function r(r) {
var a = r;
if (r < 10) throw new Error("Specified seed must be greater than 9");
t = (a += "").length, n = "";
for (var s = 0; s < t; s++) n += a[t - s - 1];
"string" == typeof e && (t = 2 * (t + 1)), o = +("0." + n), i = +("0." + t);
for (var f = 0; f < 20; f++) o = ((i += o) * o + i) % 1;
}
var t, n, o, i, a = new Date().getTime();
r(e || a);
var s = function() {
return o = ((i += o) * o + i) % 1;
};
return s.seed = function(e) {
r(e);
}, s;
}(e);
}, s = function(e) {
var r, t;
if (void 0 === e) r = i; else if ("number" == typeof e) {
if (e < 2) throw new Error("Glyph set must contain at least 2 graphemes");
r = o.slice(0, e);
} else if (e instanceof Array) {
if (e = Number(e[0]), "number" == typeof (t = e) && 0 != t && !t) throw new Error("Array must be number");
if (e < 2) throw new Error("Glyph set must contain at least 2 graphemes");
r = (r = f(o, e)).slice(0, e);
} else if ("BASE64" === e.toUpperCase()) r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; else if ("B64" === e.toUpperCase()) r = i; else if ("UUENCODE" === e.toUpperCase()) r = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"; else if ("XXENCODE" === e.toUpperCase()) r = "+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; else if ("BINHEX" === e.toUpperCase()) r = "!\"#$%&'()*+,-0123456789@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr"; else if ("7BIT" === e.toUpperCase()) r = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/!#$%&()*,-:;<=>?@[]^_`{|}~\\. '\""; else if ("FPN" === e.toUpperCase()) r = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/!#$%&()*,-:;<=>?@[]^_`{|}~\\"; else {
if (e.length < 2) throw new Error("Glyph set must contain at least 2 graphemes");
if (u(e)) throw new Error("Glyph set contains duplicate graphemes");
r = e;
}
return r;
}, f = function(e, r) {
var t, n, o, i;
return i = .059886774281039834 * (o = r), i += 21845.33332824707, i -= o = 0 | i,
o = 0 | (i *= o), t = (o ^= 4294967296 * (i -= o)) >>> 0, n = a(t), function(e, r) {
var t, n = e.length;
for (r = r || function() {
var e = new Uint32Array(2);
return window.crypto.getRandomValues(e), parseFloat("0." + e[0] + e[1]);
}; --n; ) e[t = Math.floor(r() * (n + 1))] = [ e[n], e[n] = e[t] ][0];
}(e = e.split(""), n), e.join("");
}, u = function(e) {
for (var r = e.length, t = 0; t < r; t++) for (var n = e[t], o = t + 1; o <= r - 1; o++) if (n === e[o]) return !0;
return !1;
}, p = function(e, r, t) {
var n, o = s(r), i = o.length, a = Math.floor(e), u = "";
for (void 0 !== t && (o = f(o, t)); n = a % i, u = o.charAt(n) + u, 0 !== (a = Math.floor(a / i)); ) ;
return u;
}, l = function(e, r, t) {
var n = s(r), o = n.length, i = 0;
void 0 !== t && (n = f(n, t));
for (var a = 0; a < e.length; a++) i = i * o + n.indexOf(e[a]);
return i;
};
return {
base10ToRadix: function(e, r, t) {
if (e !== parseInt(e, 10) && "fpn" !== r.toLowerCase()) throw new Error("Number must be positive integer in Base-10");
if (void 0 !== t && "number" != typeof t) throw new Error("Scramble key must be a number");
if ("fpn" === r.toLowerCase() && (e + "").includes(".")) {
let r = (e + "").split("."), n = p(+r[0], "fpn", t), o = p(+r[1], "fpn", t), i = "";
return "0" === (r[1] + "").substr(0, 1) && (i = " "), n + "." + i + o;
}
return p(e, r, t);
},
changeRadix: function(e, r, t, n) {
var o = this.radixToBase10(e, r, n);
return this.base10ToRadix(o, t, n);
},
radixToBase10: function(e, r, t) {
if (void 0 !== t && "number" != typeof t) throw new Error("Scramble key must be a number");
if ("fpn" === r.toLowerCase() && e.includes(".")) {
let r = e.split("."), n = l(r[0], "fpn", t) + "", o = "";
return r[1].includes(" ") ? (r[1] = r[1].replace(" ", ""), o = "0" + l(r[1], "fpn", t)) : o = l(r[1], "fpn", t) + "",
+(n + "." + o);
}
return l(e, r, t);
},
version: function() {
return "customRadix v1.1.0";
}
}
}()
/////////////////////////////////////////////////////////////////////
// compute internal hash (checksum)
, __checksum = function() {
const _mm =
function() {
var r = 4022871197;
return function(n) {
n = n.toString();
for (var t = 0, a = n.length; t < a; t++) {
r += n.charCodeAt(t);
var e = .02519603282416938 * r;
r = e >>> 0, e -= r, e *= r, r = e >>> 0, e -= r, r += 4294967296 * e;
}
return 2.3283064365386963e-10 * (r >>> 0);
};
}
;
let _x1 = localDataStore.toString()
, _x2 = _mm()
, _x3 = _x2( _x1 ) + ''
;
_x3 = _x3.replace( '0.', '' );
_x3 = +_x3;
return _x3;
}()
, _checksum = __checksum
//////////////////////////////////////////////////////////////////////
// convert a localStorage string into its original primitive object (Number, Date, String, etc.) based on embedded flags
// markers are at the end of the value
, _convertFromString = function( _value ) {
let _recovered_value = ''
, _recoveredType
;
const thisIsOurType = function( type ) {
return ( _value.substr( -1, 1 ) === type );
}
, extractTheData = function( val ) {
return val.substr( 0, val.length - 1 );
}
, parseTheData = function( val ) {
return JSON.parse( val, _JSONparser );
}
, anyOfThese = function() {
let tally = arguments.length
, items = Object.values( arguments )
;
let obj = {
areIn( source ) {
for( let i = 0; i < tally; i++ ) { if( items[ i ] === source ) { return true; } }
return false;
}
, total() { return tally; }
};
return obj;
}
;
if( 'undefined' === typeof _value ) { throw new Error( ERROR_19 ); }
// check for embedded flags (at end of string)
if( anyOfThese( TYPE_ARRAY, TYPE_BIGINT, TYPE_BOOLEAN, TYPE_DATE, TYPE_NUMBER, TYPE_OBJECT, TYPE_CRUNCH, TYPE_STRING ).areIn( _value.substr( -1, 1 ) ) ){
if( _recovered_value === '' ) {
_recoveredType = TYPE_CRUNCH;
if( thisIsOurType( _recoveredType ) ) {
_value = extractTheData( _value );
_value = _uncrunch( _value );
_recovered_value = _value;
}
}
if( _recovered_value === '' ) {
_recoveredType = TYPE_STRING;
if( thisIsOurType( _recoveredType ) ) {
_value = extractTheData( _value );
_recovered_value = _value;
}
}
if( _recovered_value === '' ) {
_recoveredType = TYPE_DATE;
if( thisIsOurType( _recoveredType ) ) {
_value = extractTheData( _value );
//_recovered_value = parseTheData( _value );
_recovered_value = _customRadix.radixToBase10( _value, '7BIT' );
_recovered_value = new Date( _recovered_value );
}
}
if( _recovered_value === '' ) {
_recoveredType = TYPE_ARRAY;
if( thisIsOurType( _recoveredType ) ) {
_value = extractTheData( _value );
_recovered_value = parseTheData( _value );
}
}
if( _recovered_value === '' ) {
_recoveredType = TYPE_NUMBER;
if( thisIsOurType( _recoveredType ) ) {
_value = extractTheData( _value );
_recovered_value = _customRadix.radixToBase10( _value, 'FPN' );
//_recovered_value = parseFloat( _recovered_value ); // ints and floats
//_recovered_value = parseFloat( _value ); // ints and floats
}
}
if( _recovered_value === '' ) {
_recoveredType = TYPE_BOOLEAN;
if( thisIsOurType( _recoveredType ) ) {
_value = extractTheData( _value );
_recovered_value = _value === '1' ? true : false;
}
}
if( _recovered_value === '' ) {
_recoveredType = TYPE_BIGINT;
if( thisIsOurType( _recoveredType ) ) {
_value = extractTheData( _value );
_recovered_value = BigInt( _value );
}
}
if( _recovered_value === '' ) {
_recoveredType = TYPE_OBJECT;
if( thisIsOurType( _recoveredType ) ) {
_value = extractTheData( _value );
_recovered_value = parseTheData( _value );
}
}
} else {
if( _getTypeOfKey( 'VALUE_OVERRIDE', _value ) === 'presumed bigint' ) {
_value = _value.substring( 0, _value.length - 1 );
_recovered_value = BigInt( _value );
} else
// assume it's an object, or an array, that has been stringified, if possible
if( _value[ 0 ] === "{" || _value[ 0 ] === "[" ) {
try{
_recovered_value = parseTheData( _value );
} catch( e ) {
_recovered_value = _value;
}
// assume it's a typical localStorage string
} else {
// is it a possible number (int or float)?
if( _value == +_value ) {
_recovered_value = +_value;
// nope, just a regular key value (string)
} else {
_recovered_value = _value;
}
}
}
return _recovered_value;
}
// convert a primitive object (Number, Date, String, etc.) to localStorage string
// embeds data type flags for reconstruction
// marker flags are 1 byte each, adding 2 bytes (actual memory used) overhead for each data type stored
// returns the converted object and its data type
, _convertToString = function( value ) {
let _marker = ''
, _type = ''
, _temp
, cr1
, cr2
;
if( 'undefined' === typeof value ) { throw new Error( ERROR_20 ); }
// strings
if( 'string' === typeof value ) {
_type = 'string';
_marker = TYPE_STRING;
// only try to compress strings
if( _isCrunchable( value ) ) {
_type = 'compressed string';
value = _crunch( value );
//value = TYPE_CRUNCH + value;
_marker = TYPE_CRUNCH;
}
} else
// dates
if( 'object' === typeof value && value instanceof Date ) {
_type = 'date';
_marker = TYPE_DATE;
// integrity check
//_temp = +value;
//cr1 = _customRadix.base10ToRadix( _temp, '7bit' );
//cr2 = _customRadix.radixToBase10( cr1, '7bit' );
//if( cr2 === _temp ) {
// value = _temp;
//} else {
// value = JSON.stringify( value, _JSONstringer );
//}
value = +value;
value = _customRadix.base10ToRadix( value, '7BIT' );
} else
// arrays
if( 'object' === typeof value && value instanceof Array ) {
_type = 'array';
_marker = TYPE_ARRAY;
value = JSON.stringify( value, _JSONstringer );
} else
// numbers
if( 'number' === typeof value ) {
_type = 'integer';
if( ( value + '' ).indexOf( '.' ) !== -1 ) { _type = 'float'; }
_marker = TYPE_NUMBER;
value = _customRadix.base10ToRadix( value, 'FPN' );
//value += '';
} else
// booleans
if( 'boolean' === typeof value ) {
_type = 'boolean';
_marker = TYPE_BOOLEAN;
value = Number( value );
value += '';
} else
// bigints
if( 'bigint' === typeof value ) {
_type = 'bigint';
_marker = TYPE_BIGINT;
value += '';
} else
// all other objects (null etc.)
if( 'object' === typeof value ) {
_type = 'object';
if( value === null ) { _type = 'null'; }
_marker = TYPE_OBJECT;
value = JSON.stringify( value, _JSONstringer );
}
if( _marker !== '' ) {
value += _marker;
}
return [ value, _type ];
}
// compress simple 7-bit ASCII words
, _crunch = function( _text ) {
return _smidge.compress( _text );
}
// wrapper for localStorage removeItem method
, _deleteLocalStorage = function( key ) {
localStorage.removeItem( key );
}
// friendly formatted output
, _describeSize = function( _val, _1k = false ) {
const _units = [ "bytes", "KB", "MB" ];
let _sizeUnit = 0
, k = 1024
;
if( _1k ) { k = 1000; }
while( _val > k ) { _sizeUnit++; _val /= k; }
_val = _val == 1
? '1 byte'
: _val.toFixed( 2 ) + " " + _units[ _sizeUnit ];
_val = _val.replace( '.00 ', ' ' );
return _val;
}
// in-place array shuffle (no copy made)
, _fisherYatesDurstenfeldKnuthShuffle = function(n, r) {
var t, e = n.length;
for (r = r || a; --e; ) t = Math.floor(r() * (e + 1)), n[t] = [ n[e], n[e] = n[t] ][0];
}
// shuffled array is copied to the restored (unshuffled) array
, _fisherYatesDurstenfeldKnuthUnshuffle = function(r, e) {
for (var n, f = new Array(r.length), t = new Array(r.length), a = r.length, h = 0; h < a; h++) t[h] = h;
for (var h = a - 1; h > 0; h--) n = Math.floor(e() * (h + 1)), t[h] = [ t[n], t[n] = t[h] ][0];
for (var h = 0; h < a; h++) f[t[h]] = r[h];
return f;
}
// A fast Hash for integer or float. Returns positive integer.
, _foldFPHash = function(n) {
let r = .059886774281039834 * n;
return r += 21845.33332824707, n = 0 | r, r -= n, r *= n, n = 0 | r, r -= n, (n ^= 4294967296 * r) >>> 0;
}
// return key's primitive value
, _get = function( key ) {
if( 'undefined' === typeof key ) { throw new Error( ERROR_11 ); }
let _value = _readLocalStorage( key );
if( !_value ) {
return undefined;
} else {
return _convertFromString( _value );
}
}
// returns unsorted array of prefixed key names in store, by default
// optionally, prefixes may be stripped
, _getAllKeysThisInstance = function( stripKeyPrefix = false ) {
let _key
, _prefix = _getKeyPrefix()
, _keysThisInstance = new Array()
, _len = localStorage.length
;
// loop through all localStorage keys
for( let i = _len; i--; ) {
_key = localStorage.key( i );
// get the ones prefixed for this instance
if( _key.substr( 0, _prefix.length ) === _prefix ) {
// check if the key prefix should be retained
if( stripKeyPrefix ) {
_key = _stripPrefix( _key );
}
// add keyname to list of keys
_keysThisInstance.push( _key );
}
}
return _keysThisInstance;
}
, _getAllMemoryKeysThisInstance = function( stripKeyPrefix = false ) {
let _memoryKeysThisInstance = new Array();
for( let key in lds ) {
if( key.substr( 0, 1 ) === '#' ) {
// check if the key prefix should be retained
if( stripKeyPrefix ) { key = _stripMemKeyPrefix( key ); }
// add keyname to list of keys
_memoryKeysThisInstance.push( key );
}
}
return _memoryKeysThisInstance;
}
// returns count of bytes in string
, _getByteCount = function( t ) {
t = "" + t;
for (var r = t.length, n = r - 1; n >= 0; n--) {
let e = t.charCodeAt(n);
e > 127 && 2047 >= e ? r++ : e > 2047 && 65535 >= e && (r += 2), e >= 56320 && 57343 >= e && n--;
}
return r;
}
// returns count of codepoints in string
, _getCodePointCount = function( t ) {
return t = "" + t, __ucs2decode( t ).length;
}
// create an object listing duplicate values, their associated keys, and counts
, _getDuplicates = function( _weShouldSortThis ) {
let dupes = _showDupes()
, _keyNamesObj = {}
, _keyNames = {}
, _tempKey = ''
, _len = localStorage.length
;
if( _weShouldSortThis ) { _naturalSort( dupes ); }
if( dupes.length ) {
for( let ii = 0, len = dupes.length; ii < len; ii++ ) {
let _keyNameParts = new Array();
for( let i = _len; i--; ) {
_tempKey = localStorage.key( i );
if( JSON.stringify( _get( _tempKey ), _JSONstringer ) === JSON.stringify( dupes[ ii ], _JSONstringer ) ) {
_tempKey = _stripPrefix( _tempKey );
_keyNameParts.push( _tempKey );
}
}
if( _weShouldSortThis ) { _naturalSort( _keyNameParts ); }
_keyNames[ ii ] = {
'value' : dupes[ ii ]
, 'keys' : _keyNameParts
, 'keycount' : _keyNameParts.length
}
}
}
_keyNamesObj = {
'dupecount' : dupes.length
, 'dupes' : _keyNames
}
return _keyNamesObj;
}
// return a JSON showing library internals
, _getIdentity = function() {
if( !_storageIsAvailable() ) { return false; }
const _internals = {};
_internals.version = lds.version;
_internals.checksum = _checksum;
_internals.prefix = _prefix;
_internals.quota = lds.quota;
_internals.bytes_used = lds.showquotaused( true );
_internals.channel = lds.channel;
return { 'localDataStorage' : _internals };
}
// retrieve the prefix defined when LDS was instantiated
, _getKeyPrefix = function() {
return _prefix + '.';
}
, _getMemoryKeyType = function( key ) {
return _getTypeOfMemoryKey( _readMemoryKey( key ) );
}
// convert input to integer based on value and data type
// returns [ integer, objectString ]
, _getNumberFromObject = function( _input ) {
if( 'undefined' === typeof _input ) { return; }
let _json = typeof _input === 'bigint'
? _input.toString()
: JSON.stringify( _input, _JSONstringer )
, _num = 0
, _type = ''
, _convert = ''
;
const _reverseIt = function( _string ) {
return Array.from( _string ).reverse().join( '' );
}
, _hashCode = function( _string ) {
let _rng = _xmur3a( _string );
return _rng();
}
;
// arrays
if( _input instanceof Array ) {
_type = 'ARRAY1';
} else
// bigints
if( 'bigint' === typeof _input ) {
_type = 'BIGINT2'
} else
// booleans
if( 'boolean' === typeof _input ) {
_type = 'BOOLEAN4';
} else
// dates
if( _input instanceof Date ) {
_type = 'DATE8';
} else
// numbers
if( 'number' === typeof _input ) {
if( ( _input + '' ).includes( '.' ) ) {
_type = 'FLOAT16';
} else {
_type = 'INTEGER32';
}
} else
// strings
if( 'string' === typeof _input ) {
_type = 'STRING64'
// other objects
} else {
_type = 'OBJECT128';
}
// may need canonical JSON stringify in the future (https://github.com/mirkokiefer/canonical-json)
_convert = (
_json +
_json.length +
_type +
_hashCode( _json ) +
_hashCode( _reverseIt( _json ) )
);
for( let i = 0; i < _convert.length; i++ ) {
_num += _convert.codePointAt( i );
}
return [ _num, _convert ];
}
// return key with prefix
, _getPrefixedKey = function( key ) {
return _getKeyPrefix() + key;
}
// find all duplicate key values in _array (strict check; match value and type)
, _getStrictDuplicates = function( _array ) {
let _dupes = new Array()
, _tempDupe = new Array()
, _len = _array.length
;
for( let i = 0; i < _len; i++ ) {
_tempDupe = _array[ i ]; // unconverted localStorage string (much easier to check)
if( ( _array.lastIndexOf( _tempDupe ) !== i ) && ( _dupes.indexOf( _tempDupe ) === -1 ) ) {
_dupes.push( _tempDupe );
}
}
return _dupes;
}
// return the primitive value of the prefixed key
, _getTheKey = function( _key ) {
return _get( _getPrefixedKey( _key ) );
}
// return the data type of value
, _getTypeOf = function( value ) {
return _convertToString( value )[ 1 ];
}
// return the primitive data type of the key's value
// when valueToCheck is supplied, no key lookup is performed
, _getTypeOfKey = function( key, valueToCheck ) {
if( 'undefined' === typeof key ) { throw new Error( ERROR_11 ); }
let _recoveredType = ''
, _value = ''
;
const thisIsOurType = function( type ) {
return _value.includes( type );
}
, anyOfThese = function() {
let tally = arguments.length
, items = Object.values( arguments )
;
let obj = {
areIn( source ) {
for( let i = 0; i < tally; i++ ) { if( items[ i ] === source ) { return true; } }
return false;
}
, total() { return tally; }
};
return obj;
}
;
// check the type from the value of the key
if( 'undefined' === typeof valueToCheck ) {
if( _haskey( key ) ) {
_value = _readLocalStorage( key );
} else {
return undefined;
}
// check the type from the supplied value
} else {
_value = valueToCheck;
}
// check for embedded flags (at end of string)
if( anyOfThese( TYPE_ARRAY, TYPE_BIGINT, TYPE_BOOLEAN, TYPE_DATE, TYPE_NUMBER, TYPE_OBJECT, TYPE_CRUNCH, TYPE_STRING ).areIn( _value.substr( -1, 1 ) ) ) {
if( thisIsOurType( TYPE_CRUNCH ) ) {
_recoveredType = 'compressed string';
}
if( _recoveredType === '' ) {
if( thisIsOurType( TYPE_STRING ) ) {
_recoveredType = 'string';
}
}
if( _recoveredType === '' ) {
if( thisIsOurType( TYPE_DATE ) ) {
_recoveredType = 'date';
}
}
if( _recoveredType === '' ) {
if( thisIsOurType( TYPE_ARRAY ) ) {
_recoveredType = 'array';
}
}
if( _recoveredType === '' ) {
if( thisIsOurType( TYPE_NUMBER ) ) {
_recoveredType = 'number';