-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.js
1913 lines (1505 loc) · 39.6 KB
/
base.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
class StandardObject {
constructor(store) {
this.store = store || {}
}
get keys() { return Object.keys(this.store) }
get values() { return Object.values(this.store) }
get entries() { return Object.entries(this.store) }
has(key) { return this.store.hasOwnProperty(key) }
reset() {
this.store = {}
}
}
function dreplace(s, dict, regexTemplate = '\\b(?:$1)\\b', flags = 'g') {
let escape
if (flags.includes('e')) {
escape = true
flags = flags.replace('e', '')
}
const regex = ncg(regexTemplate, dict, escape)
function fix(x) {
if (x.startsWith('\\')) return '\\' + x
return x
}
const parser = hasCaptureGroup(regexTemplate) ? (_, x) => dict[fix(x)] : (x) => dict[fix(x)]
return replace(regex, parser, s, flags)
}
function ncg(template, ref, escape) {
if (template === '') template = '(?:$1)'
if (!ref && isIterable(template)) {
return '\\b(?:' + ncgRunner(template, escape) + ')\\b'
}
else if (!isPrimitive(ref) && ref[0] && !isPrimitive(ref[0])) {
return templater(template, ref.map((el) => ncgRunner(el, escape)))
}
else {
return templater(template, ncgRunner(ref, escape))
}
}
function isIterable(x) {
return isArray(x) || isObject(x)
}
function isArray(a) {
return Array.isArray(a)
}
function isObject(x) {
return type(x) == 'Object'
}
function type(x) {
return search(/object (\w+)/, Object.prototype.toString.call(x))
}
function search(regex, s, flags = '') {
if (isString(regex)) regex = RegExp(regex, flags)
const match = s.match(regex)
return matchgetter(match)
}
function isString(s) {
return typeof s === 'string'
}
function matchgetter(match) {
return !match ?
null :
match.length == 1 ?
match[0] :
match.length == 2 ?
match[1] :
match.slice(1)
}
function ncgRunner(ref, escape) {
return escape ? prepareIterable(ref, 'keys').map(rescape).join('|') :
prepareIterable(ref, 'keys').join('|')
}
function prepareIterable(data, mode) {
if (isNumber(data)) {
return range(1, data)
}
if (isString(data)) {
return [data]
}
if (isObject(data)) {
if (mode == Array) mode == 'values'
if (mode == Object) mode == 'entries'
return Object[mode](data)
}
return data
}
function isNumber(s) {
return typeof s == 'number' || test('^-?\\d+(?:\\.\\d+)?$', s)
}
function test(regex, s, flags = '') {
return RegExp(regex, flags).test(s)
}
function range(...args) {
let a
let b
let c
if (!isPrimitive(args[args.length - 1])) {
c = args.pop()
}
if (args.length == 1) {
b = args[0]
a = 1
}
else {
;[a, b] = args
}
if (isArray(b)) {
b = b.length - 1
a = 0
}
const store = []
for (let i = a; i <= b ; i++) {
if (c) {
if (c.toString() == [].toString()) store.push([])
else if (c.toString() == {}.toString()) store.push({})
}
else {
store.push(i)
}
}
return store
}
function isPrimitive(value) {
return (
typeof value === 'string' ||
typeof value === 'number' ||
typeof value === 'symbol' ||
typeof value === 'boolean'
)
}
function rescape(s) {
const rescapeRE = /[.\\[*+?()|^${}\[\]]/g
return s.replace(rescapeRE, '\\$&')
}
function templater(s, ref) {
if (!s.includes('$')) return s
let regex = /\$(\w)/g
if (isPrimitive(ref)) {
ref = [ref]
}
else {
regex = /\$(\w+)/g
}
return s.replace(regex, (_, x) => {
return isArray(ref) ? ref[Number(x) - 1] : ref[x]
})
}
function hasCaptureGroup(s) {
return test(/[^\\]\((?!\?)/, s)
}
function replace(regex, replacement, s, flags = 'gm') {
if (isString(regex)) regex = RegExp(regex, flags)
return s.replace(regex, replacement)
}
function argsplit(s, ref, regex = '($1)(\\w+)') {
let match = search(ncg(regex, ref), s)
return match ? match : [null, null]
}
function coinflip(n = 0.5) {
return Math.random() > 1 - n
}
function merge(...args) {
let first = args[0]
if (isObject(first)) {
const store = {}
for (let arg of args) {
Object.assign(store, arg)
}
return store
}
if (isArray(first)) {
const store = []
for (let arg of args) {
store.push(...arg)
}
return store
}
if (isString(first)) {
if (first.includes('\n')) return args.join('\n')
if (first.includes(' ')) return args.join(' ')
return args.join('\n')
}
if (isNumber(first)) {
return sum(args.map(Number))
}
}
function getLast(arr, n = -1) {
return arr[arr.length + n]
}
function tryval(s) {
try {
return {
input: s,
value: eval(s)
}
}
catch(e) {
return {
input: s,
error: e.toString()
}
}
}
function abbreviate(s) {
let start = test(/[A-Z]/, s[0]) ? '' : s[0]
let abrev = start + s.replace(/[\da-z]+/g, '').toLowerCase()
return abrev
}
const catpics = [
//'dancing.jpg',
'fist on chin.jpg',
'flying.jpg',
'like a boss.jpg',
'ocean sunset.jpg',
'pose f.jpg',
]
function counted(regex, s, flags = 'g') {
if (isString(s)) {
if (isString(regex)) {
regex = rescape(regex)
if (isWord(regex)) regex = '\\b' + regex + '\\b'
regex = RegExp(regex, flags)
}
const matches = s.match(regex)
return matches ? matches.length : 0
}
else if (isArray(s)) {
return s.filter(regex).length
}
}
function hasMultipleVariables(s) {
return counted(/\b[abcde]\b/g, s) > 1
}
function shuffle(arr) {
const ref = Array.from(arr)
let m = arr.length
while (m) {
let i = ~~(Math.random() * m--)
let t = ref[m]
ref[m] = ref[i]
ref[i] = t
}
return ref
}
function isBoolean(x) {
return x === true || x === false
}
class Clock {
constructor(options) {
this.increment = 1000
this.speed = 1
if (isObject(options)) {
if (options.duration) this.duration = options.duration
if (options.increment) this.increment = options.increment
if (options.steps) this.increment = this.duration / options.steps
}
else {
this.duration = options
}
}
async start(duration) {
if (duration) this.duration = duration
if (this.duration <= 10) this.duration *= 1000
this.count = 0
this._stop = false
await this.runner()
}
stop() {
this._stop = true
}
pause() {
this.stop()
}
async resume() {
this._stop = false
await this.runner()
}
runner() {
if (this._onTick) this._onTick()
return new Promise((resolve) => {
const runner = () => {
if (this.isDone()) {
clearTimeout(this.timerID)
if (this._onFinish) this._onFinish()
resolve()
}
else {
this.count += this.increment
this.timerID = setTimeout(() => {
if (this._onTick) this._onTick()
runner()
}, Math.floor(this.increment / this.speed))
}
}
runner()
})
}
at(n, fn) {
let current = this._onTick
this._onTick = () => this.count == n * this.increment ? this.handle(fn()) : current()
}
set onTick(fn) {
this._onTick = () => this.handle(fn(this.timeLeft, this.count, this.duration))
}
set onFinish(fn) {
this._onFinish = () => fn(this.timeLeft, this.count, this.duration)
}
isDone() { return this.count >= this.duration || this._stop }
get timeLeft() {
//console.log(this.duration)
//console.log(this.count)
//console.log(this.increment)
return Math.round((this.duration - this.count) / this.increment)
}
handle(result) {
if (result === true) this._stop = true
else if (isNumber(result)) this.duration += result
}
}
function isFirst(key, state = $$) {
if (!state[key]) {
state[key] = true
return true
}
return false
}
function coerceError(arg) {
if (!exists(arg)) throw new Error('coercing error')
}
function toArgument(s) {
s = s.trim()
if (isNumber(s)) return Number(s)
if (s == 'false') return false
if (s == 'true') return true
if (s == 'null') return null
if (s == 'Number') return Number
if (s == 'String') return String
return s
}
function randomPick(items) {
if(!isArray(items)) return items
return items[Math.floor(Math.random() * items.length)]
}
function isWord(s) {
return test(/^[a-zA-Z]+$/, s)
}
function createConfig(s) {
if (isWord(s)) return s
if (s == '') return s
const regex = /(.*?) *[:=] *(.*?)(?:$|, ?| )/g
return reduce(findall(regex, s), (k,v) => [k.trim(), v ? toArgument(v) : true])
}
function isPromise(x) {
return x.constructor.name == 'Promise'
}
function getExtension(file) {
return search(/\.(\w+)$/, file)
}
function rng(min = 2, max = 10, negative = null, boundary = null) {
if (isFunction(min)) {
while (true) {
let n = negative ? rng(max, negative) : rng()
if (min(n)) return n
}
}
if (isArray(min)) {
return randomPick(min)
}
min = Math.ceil(min)
max = Math.floor(max)
let value = Math.floor(Math.random() * (max - min + 1)) + min
if (negative) value = Math.abs(value) * -1
if (boundary) value = roundToNearest(value, boundary) + boundary
return value
}
function sorted(items, fn, reverse = false) {
const defaultObjectSort = (s) => s[1]
const defaultNumberSort = (s) => s
if (items.store) {
items = Object.entries(items.store)
} else if (isObject(items)) {
items = Object.entries(items)
}
if (!fn) fn = isDoubleIterable(items) ?
defaultObjectSort :
isNumber(items[0]) ?
defaultNumberSort :
char2n
function runner(a, b) {
if (reverse) return Number(fn(b)) - Number(fn(a))
return Number(fn(a)) - Number(fn(b))
}
items.sort(runner)
return items
}
function isDoubleIterable(items) {
return isObject(items) || isNestedArray(items)
}
function isNestedArray(x) {
return isArray(x) && isArray(x[0])
}
function char2n(ch) {
return ch.toLowerCase().charCodeAt(0) - 97
}
function datestamp(date) {
const [m, d, y] = getMDY(date)
return m.toString().padStart(2, 0) + '-' + d.toString().padStart(2, 0) + '-' + y
}
function getMDY(date) {
if (!date) date = new Date()
else if (isString(date)) {
date = new Date(date)
}
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return [month, day, year]
}
function newlineIndent(s, n) {
return '\n' + indent(isArray(s) ? s.join('\n') : s, n) + '\n'
}
function indent(s, n = 4) {
return replace('^', toSpaces(n), s, 'gm')
}
function toSpaces(n = 4) {
return isNumber(n) ? ' '.repeat(n) : n
}
function iterate(items, fn, ...args) {
const store = []
if (isNumber(items)) {
items = range(1, items)
}
else {
items = toArray(items)
}
for (let i = 0; i < items.length; i++) {
store.push(fn(items[i], ...args))
}
return store
}
function toArray(val) {
return isArray(val) ? val : [val]
}
function sortStorage() {
return reduce(sorted(this.store, zoop(fn)), (k,v) => [k,v])
}
class Storage {
constructor(mode = Array) {
this.store = {};
this._mode = mode
}
delete(k) { delete this.store[k] }
get value() { return this.store }
get keys() { return Object.keys(this.store) }
get values() { return Object.values(this.store) }
get entries() { return Object.entries(this.store) }
get(k) { return this.store[k] }
set(k, v) { this.store[k] = v; return v }
has(k) { return this.store.hasOwnProperty(k) }
forEach(fn) { return Object.entries(this.store).forEach(([k,v]) => fn(k,v)) }
reset(k) {
if (!k) { this.store = {}; return }
switch (this._mode) {
case Array: this.store[k] = []; break;
case Number: this.store[k] = 0; break;
case String: this.store[k] = ''; break;
case Object: this.store[k] = {}; break;
case null: this.store[k] = null; break;
}
}
add(k, v) {
if (k == null) return
switch (this._mode) {
case Array: this.addArray(k, v) ; break;
case Object: this.addObject(k, v); break;
case String: this.addString(k, v); break;
case Number: return this.addNumber(k, v); break;
default: this.set(k, v) ; break;
}
return this.get(k)
}
addNumber(k, v) {
v = v == null ? 1 : Number(v)
return this.store[k] ? (this.store[k] += v) : (this.store[k] = v)
}
addString(k, v, delimiter = '') {
this.store[k] ? (this.store[k] += delimiter + v) : (this.store[k] = v)
}
addArray(k, v) {
if (isArray(v)) {
this.store[k]? this.store[k].push(...v) : this.store[k] = v
} else {
this.store[k]? this.store[k].push(v) : this.store[k] = [v]
}
}
addObject(k, v) {
this.store[k] ?
Object.assign(this.store[k], v) :
this.store[k] = v
}
}
function reduce(items, fn = (k,v) => [k,v]) {
if (!exists(items)) return {}
items = prepareIterable(items, 'entries')
const store = {}
const doublet = isDoubleIterable(items)
for (let i = 0; i < items.length; i++) {
const item = items[i]
const value = doublet ? fn(...item, i) : fn(item, i)
if (!exists(value)) continue
if (isArray(value) && value.length == 2) {
store[value[0]] = value[1]
} else {
if (doublet) store[item[0]] = value
else {
store[item] = value
}
}
}
return store
}
function exists(input) {
if (input == null) return false
if (isString(input)) return input.trim().length > 0
if (isArray(input)) return input.filter(exists).length > 0
if (isObject(input)) return Object.keys(input).length > 0
return true
}
function remove(arr, index) {
return arr.splice(index, 1)[0]
}
function modularIncrement(arr, item, increment = 1) {
if (increment == '+') increment = 1
else if (increment == '-') increment = -1
if (isObject(arr)) {
arr = Object.keys(arr)
}
if (!item) return arr[0]
const i = arr.indexOf(item)
if (i < 0) return arr[0]
let newIndex
if (i + increment < 0) {
newIndex = arr.length - 1
}
else {
newIndex = (i + increment) % arr.length
}
const p = arr[newIndex]
return p
}
function mreplace(regex, replacement, s, flags = 'g', singular = false) {
if (arguments.length == 2) {
replacement = ''
s = arguments[1]
}
if (arguments.length == 3 && arguments[2] == true) {
replacement = ''
s = arguments[1]
singular = arguments[2]
}
const store = []
const sliceBy = hasCaptureGroup(regex) ? 1 : 0
function parser(...args) {
args = args.slice(sliceBy, -2).filter((x) => x != null)
store.push(smallify(args))
return isString(replacement) ? replacement : replacement(...args)
}
const text = replace(regex, parser, s.trim(), flags).replace(/^\n+/, '').trimEnd()
if (singular) return [text, smallify(store)]
return [text, store]
}
function smallify(x) {
return x.length == 0 ?
null :
x.length == 1 ?
x[0] :
x
}
function sleep(delay = 3000) {
if (delay < 100) delay *= 1000
return new Promise((resolve) => setTimeout(resolve, delay))
}
function parens(s) {
return '(' + s + ')'
}
function unique(a, b) {
if (isNestedArray(a)) {
const seen = []
const store = a.filter(x => {
if (seen.includes(x[0])) return false
seen.push(x[0])
return true
})
return store
}
if (b) return a.filter((item) => !b.includes(item))
return isArray(a) && a.length > 1 ? Array.from(new Set(a)) : a
}
function stringify(s) {
return isPrimitive(s) ? s : JSON.stringify(s, null, 2)
}
function getStorage(key, placeholder = null) {
return key in localStorage ? parseJSON(localStorage.getItem(key)) : placeholder
}
function parseJSON(s) {
if (/^[\d/]+$/.test(s)) {
return Number(s)
}
return /^[{\[]/.test(s) ? JSON.parse(s) : s
}
function delta(a, b) {
const p = Math.abs(a - b)
console.log({'delta': p, a, b})
return p
}
function splitonce(s, delimiter = '\\s') {
if (isRegExp(delimiter)) delimiter = delimiter.source
let regex = '^(.*?)' + delimiter + '([^]+)$'
return search(regex, s) || [s, '']
}
function isRegExp(x) {
return x.constructor.name == 'RegExp'
}
function pop(arr, key, fallback) {
if (isObject(arr)) {
let value = arr[key]
delete arr[key]
return value
}
if (isArray(arr)) {
const index = isFunction(key) ?
arr.findIndex(key) :
isNumber(key) ? key : arr.indexOf(key)
if (index < 0) {
if (fallback) {
return pop(arr, fallback)
}
else {
return
}
}
else {
return remove(arr, index)
}
}
}
function isFunction(x) {
return typeof x === 'function'
}
function fill(arr, n) {
while (arr.length <= n) {
arr.push(null)
counter()
}
}
function counter(n) {
if (typeof __count__ == 'undefined') __count__ = 0
__count__++
if (__count__ == 1000) throw ""
if (n && __count__ == n) throw ""
return __count__
}
function joined(arr) {
if (arguments.length > 1) {
arr = Array.from(arguments).filter(exists).map(String)
if (test(/^[ .]$/, getLast(arr))) {
delimiter = arr.pop()
return arr.join(delimiter)
}
}
let s = ''
for (let item of arr) {
s += item
s += item.includes('\n') ? '\n\n' : '\n'
}
return s
}
function assign(obj, key, items) {
if (obj[key] && items) Object.assign(obj[key], items)
else if (items) obj[key] = items
}
function findall(regex, s, flags = 'g', filtered = false) {
if (isString(regex)) regex = RegExp(regex, flags)
let store = []
let match
s = s.trim()
while (exists(match = regex.exec(s))) {
if (match.length == 1) {
store.push(match[0])
}
else if (filtered) {
store.push(smallify(match.slice(1).filter(exists)))
}
else if (match.length == 2) {
store.push(match[1])
}
else {
store.push(match.slice(1))
}
}
return store
}
function divify(tag, attrs, children) {
if (tag == 'img' && isString(attrs)) return divify('img', {class: 'img', src: attrs}, '')
if (children == null) {
console.log(attrs)
throw new Error("")
}
let s = toOpeningTag(tag, attrs)
let indentation = 4
if (isArray(children)) {
s += newlineIndent(children.map(x => {
if (isArray(x)) {
return divify(x)
}
if (!x) {
console.log(children)
throw "ummmmmm not sure but x doesnt exist"
}
if (isObject(x)) {
console.log(children)
throw "ummmmmm not sure why its an object"
}
if (isNumber(x)) x = String(x)
return x.includes('\n') && !x.startsWith('<') ? newlineIndent(x) : x
}), indentation)
}
else if (isDefined(children)) {
if (isNumber(children)) children = String(children)
s += children.includes('\n') ? newlineIndent(children, indentation) : children
}
s += toClosingTag(tag)
return s
}
function toOpeningTag(el, attrs = '', props = '') {
if (el == 'html') return '<!doctype html><html>'
if (attrs) {
if (isString(attrs)) attrs = ' class=' + doublequote(attrs)
else if (isObject(attrs)) {
attrs = Object.entries(attrs).reduce((acc, [a,b]) => acc += ` ${a}="${b}"`, '')
}
}
else {
attrs = ''
}
if (props) attrs = ' ' + props
const suffix = hasHtmlSuffix(el) ? '>' : '/>'
return '<' + el + attrs + suffix
}
function doublequote(s) {
return '"' + s + '"'
}
function hasHtmlSuffix(el) {
const items = ['style', 'pre', 'script', 'body', 'ul', 'li', 'p', 'textarea', 'button', 'section', 'div', 'h1', 'h2', 'h3', 'main', 'blockquote', 'span', 'article', 'body', 'html']
return items.includes(el)
}
function isDefined(x) {
return x != null
}
function toClosingTag(el) {
const noclosers = ['input', 'hr', 'br', 'link', 'img']
if (noclosers.includes(el)) return ''
return '</' + el + '>'
}
function toString(x) {
if (isObject(x)) return JSON.stringify(x, null, 2)
if (isArray(x)) joined(x)
if (isRegExp(x)) return x.source
return x.toString()
}
function split(s, regex = / +/) {
if (isNumber(regex)) return [s.slice(0, regex), s.slice(regex)]
return s.trim().split(regex)
}
function matchall(regex, s) {
const match = s.match(regex, s)
return match ? match : []
}
class AnimationState {
constructor() {
this.store = {}
this.fill = 'forwards'
this.easing = 'linear'
this.iterations = 1
this.delay = 0
this.duration = 750
}
export() {
return {
animate: this.animate.bind(this),
}
}
register(key, options) {
this.store[key] = options
}
animate(element, key) {
const ref = this.store[key]
element.style.background = 'white'
const options = {
fill: ref.fill ? 'forwards' : this.fill,
duration: ref.duration || this.duration,
delay: ref.delay || this.delay,
iterations: ref.iterations || this.iterations,
easing: this.easing,
}
let keyframes
if (ref.background) {