@e280/stz 0.0.0-3 → 0.0.0-30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/README.md +170 -0
  2. package/package.json +14 -7
  3. package/s/clone/clone.test.ts +123 -123
  4. package/s/coalesce.ts +1 -0
  5. package/s/data/base-x.ts +170 -0
  6. package/s/data/base58.ts +15 -5
  7. package/s/data/base64.ts +15 -6
  8. package/s/data/base64url.ts +15 -6
  9. package/s/data/bytename/bytename.test.ts +49 -0
  10. package/s/data/{barname/barname.ts → bytename/bytename.ts} +38 -10
  11. package/s/data/bytename/index.ts +4 -0
  12. package/s/data/bytename/thumbprint.test.ts +53 -0
  13. package/s/data/bytename/thumbprint.ts +112 -0
  14. package/s/data/bytes.ts +12 -2
  15. package/s/data/data.test.ts +98 -0
  16. package/s/data/hex.ts +15 -5
  17. package/s/data/txt.ts +14 -4
  18. package/s/deadline.ts +1 -0
  19. package/s/debounce/debounce.test.ts +73 -73
  20. package/s/deep/deep.test.ts +8 -8
  21. package/s/deep/parts/equal.test.ts +123 -124
  22. package/s/{defer-promise.ts → defer.ts} +2 -2
  23. package/s/drill.ts +2 -4
  24. package/s/ev.ts +20 -0
  25. package/s/id-counter.ts +9 -0
  26. package/s/index.ts +16 -2
  27. package/s/is.ts +10 -4
  28. package/s/loopy.ts +12 -0
  29. package/s/map-g.ts +2 -2
  30. package/s/nap.ts +1 -0
  31. package/s/once.ts +14 -0
  32. package/s/pubsub.ts +24 -6
  33. package/s/queue/queue.test.ts +67 -0
  34. package/s/queue/queue.ts +21 -0
  35. package/s/repeat.ts +25 -0
  36. package/s/tests.test.ts +21 -0
  37. package/s/time.ts +22 -0
  38. package/x/clone/clone.test.d.ts +15 -1
  39. package/x/clone/clone.test.js +106 -124
  40. package/x/clone/clone.test.js.map +1 -1
  41. package/x/coalesce.d.ts +1 -0
  42. package/x/coalesce.js +1 -0
  43. package/x/coalesce.js.map +1 -1
  44. package/x/data/base-x.d.ts +47 -0
  45. package/x/data/base-x.js +147 -0
  46. package/x/data/base-x.js.map +1 -0
  47. package/x/data/base58.d.ts +5 -1
  48. package/x/data/base58.js +13 -5
  49. package/x/data/base58.js.map +1 -1
  50. package/x/data/base64.d.ts +7 -3
  51. package/x/data/base64.js +13 -5
  52. package/x/data/base64.js.map +1 -1
  53. package/x/data/base64url.d.ts +5 -1
  54. package/x/data/base64url.js +13 -5
  55. package/x/data/base64url.js.map +1 -1
  56. package/x/data/bytename/bytename.d.ts +19 -0
  57. package/x/data/{barname/barname.js → bytename/bytename.js} +27 -11
  58. package/x/data/bytename/bytename.js.map +1 -0
  59. package/x/data/bytename/bytename.test.d.ts +17 -0
  60. package/x/data/bytename/bytename.test.js +41 -0
  61. package/x/data/bytename/bytename.test.js.map +1 -0
  62. package/x/data/bytename/index.d.ts +2 -0
  63. package/x/data/bytename/index.js +3 -0
  64. package/x/data/bytename/index.js.map +1 -0
  65. package/x/data/bytename/thumbprint.d.ts +36 -0
  66. package/x/data/bytename/thumbprint.js +79 -0
  67. package/x/data/bytename/thumbprint.js.map +1 -0
  68. package/x/data/bytename/thumbprint.test.d.ts +24 -0
  69. package/x/data/bytename/thumbprint.test.js +45 -0
  70. package/x/data/bytename/thumbprint.test.js.map +1 -0
  71. package/x/data/bytename/utils/prefixes.js.map +1 -0
  72. package/x/data/bytename/utils/suffixes.js.map +1 -0
  73. package/x/data/bytes.d.ts +3 -2
  74. package/x/data/bytes.js +11 -2
  75. package/x/data/bytes.js.map +1 -1
  76. package/x/data/data.test.d.ts +69 -0
  77. package/x/data/data.test.js +77 -0
  78. package/x/data/data.test.js.map +1 -0
  79. package/x/data/hex.d.ts +8 -4
  80. package/x/data/hex.js +13 -5
  81. package/x/data/hex.js.map +1 -1
  82. package/x/data/txt.d.ts +6 -2
  83. package/x/data/txt.js +12 -4
  84. package/x/data/txt.js.map +1 -1
  85. package/x/debounce/debounce.test.d.ts +8 -1
  86. package/x/debounce/debounce.test.js +70 -74
  87. package/x/debounce/debounce.test.js.map +1 -1
  88. package/x/deep/deep.test.d.ts +21 -1
  89. package/x/deep/deep.test.js +5 -9
  90. package/x/deep/deep.test.js.map +1 -1
  91. package/x/deep/parts/equal.test.d.ts +19 -1
  92. package/x/deep/parts/equal.test.js +107 -125
  93. package/x/deep/parts/equal.test.js.map +1 -1
  94. package/x/{defer-promise.d.ts → defer.d.ts} +2 -2
  95. package/x/{defer-promise.js → defer.js} +2 -2
  96. package/x/defer.js.map +1 -0
  97. package/x/drill.d.ts +1 -3
  98. package/x/drill.js +2 -4
  99. package/x/drill.js.map +1 -1
  100. package/x/ev.d.ts +6 -0
  101. package/x/ev.js +10 -0
  102. package/x/ev.js.map +1 -0
  103. package/x/id-counter.d.ts +5 -0
  104. package/x/id-counter.js +10 -0
  105. package/x/id-counter.js.map +1 -0
  106. package/x/index.d.ts +13 -2
  107. package/x/index.js +13 -2
  108. package/x/index.js.map +1 -1
  109. package/x/is.d.ts +6 -4
  110. package/x/is.js +6 -4
  111. package/x/is.js.map +1 -1
  112. package/x/loopy.d.ts +2 -0
  113. package/x/loopy.js +10 -0
  114. package/x/loopy.js.map +1 -0
  115. package/x/map-g.d.ts +3 -3
  116. package/x/map-g.js +1 -1
  117. package/x/map-g.js.map +1 -1
  118. package/x/nap.d.ts +1 -0
  119. package/x/nap.js +1 -0
  120. package/x/nap.js.map +1 -1
  121. package/x/once.d.ts +1 -0
  122. package/x/once.js +12 -0
  123. package/x/once.js.map +1 -0
  124. package/x/pubsub.d.ts +12 -1
  125. package/x/pubsub.js +7 -5
  126. package/x/pubsub.js.map +1 -1
  127. package/x/queue/queue.d.ts +4 -0
  128. package/x/queue/queue.js +14 -0
  129. package/x/queue/queue.js.map +1 -0
  130. package/x/queue/queue.test.d.ts +8 -0
  131. package/x/queue/queue.test.js +57 -0
  132. package/x/queue/queue.test.js.map +1 -0
  133. package/x/repeat.d.ts +5 -0
  134. package/x/repeat.js +23 -0
  135. package/x/repeat.js.map +1 -0
  136. package/x/tests.test.js +18 -0
  137. package/x/tests.test.js.map +1 -0
  138. package/x/time.d.ts +18 -0
  139. package/x/time.js +19 -0
  140. package/x/time.js.map +1 -0
  141. package/readme.md +0 -85
  142. package/s/data/anka.ts +0 -66
  143. package/s/data/barname/badge.ts +0 -78
  144. package/s/data/barname/demo.ts +0 -49
  145. package/s/data/barname/index.ts +0 -4
  146. package/x/data/anka.d.ts +0 -5
  147. package/x/data/anka.js +0 -53
  148. package/x/data/anka.js.map +0 -1
  149. package/x/data/barname/badge.d.ts +0 -25
  150. package/x/data/barname/badge.js +0 -64
  151. package/x/data/barname/badge.js.map +0 -1
  152. package/x/data/barname/barname.d.ts +0 -7
  153. package/x/data/barname/barname.js.map +0 -1
  154. package/x/data/barname/demo.js +0 -45
  155. package/x/data/barname/demo.js.map +0 -1
  156. package/x/data/barname/index.d.ts +0 -2
  157. package/x/data/barname/index.js +0 -3
  158. package/x/data/barname/index.js.map +0 -1
  159. package/x/data/barname/utils/prefixes.js.map +0 -1
  160. package/x/data/barname/utils/suffixes.js.map +0 -1
  161. package/x/defer-promise.js.map +0 -1
  162. /package/{license → LICENSE} +0 -0
  163. /package/s/data/{barname → bytename}/utils/prefixes.ts +0 -0
  164. /package/s/data/{barname → bytename}/utils/suffixes.ts +0 -0
  165. /package/x/data/{barname → bytename}/utils/prefixes.d.ts +0 -0
  166. /package/x/data/{barname → bytename}/utils/prefixes.js +0 -0
  167. /package/x/data/{barname → bytename}/utils/suffixes.d.ts +0 -0
  168. /package/x/data/{barname → bytename}/utils/suffixes.js +0 -0
  169. /package/x/{data/barname/demo.d.ts → tests.test.d.ts} +0 -0
@@ -1,73 +1,73 @@
1
- //
2
- // import {nap} from "../nap.js"
3
- // import {Suite, expect} from "cynic"
4
- // import {debounce as debounce} from "./debounce.js"
5
- //
6
- // export default <Suite>{
7
- // async "reduces many calls into one"() {
8
- // let count = 0
9
- // const increment = debounce(100, () => {
10
- // count += 1
11
- // })
12
- // increment()
13
- // increment()
14
- // increment()
15
- // await nap(200)
16
- // expect(count).equals(1)
17
- // },
18
- // async "timer gets reset on each call"() {
19
- // let count = 0
20
- // const increment = debounce(100, () => {
21
- // count += 1
22
- // })
23
- // increment()
24
- // await nap(50)
25
- // increment()
26
- // await nap(50)
27
- // increment()
28
- // await nap(50)
29
- // increment()
30
- // await nap(50)
31
- // increment()
32
- // expect(count).equals(0)
33
- // await nap(101)
34
- // expect(count).equals(1)
35
- // },
36
- // async "provides a promise that resolves when done"() {
37
- // let count = 0
38
- // const increment = debounce(100, () => {
39
- // count += 1
40
- // })
41
- // let done = false
42
- // increment()
43
- // .then(() => done = true)
44
- // await nap(50)
45
- // increment()
46
- // await nap(50)
47
- // increment()
48
- // await nap(50)
49
- // increment()
50
- // await nap(50)
51
- // increment()
52
- // expect(done).equals(false)
53
- // await nap(201)
54
- // expect(done).equals(true)
55
- // },
56
- // async "can wait multiple rounds"() {
57
- // let count = 0
58
- // const increment = debounce(100, () => {
59
- // count += 1
60
- // })
61
- // await increment()
62
- // expect(count).equals(1)
63
- // await increment()
64
- // expect(count).equals(2)
65
- // },
66
- // async "errors are passed into promise chain"() {
67
- // const err = debounce(1, () => {
68
- // throw new Error()
69
- // })
70
- // await expect(async() => err()).throws()
71
- // },
72
- // }
73
- //
1
+
2
+ import {nap} from "../nap.js"
3
+ import {Science, expect} from "@e280/science"
4
+ import {debounce as debounce} from "./debounce.js"
5
+
6
+ export default Science.suite({
7
+ async "reduces many calls into one"() {
8
+ let count = 0
9
+ const increment = debounce(100, () => {
10
+ count += 1
11
+ })
12
+ increment()
13
+ increment()
14
+ increment()
15
+ await nap(200)
16
+ expect(count).is(1)
17
+ },
18
+ async "timer gets reset on each call"() {
19
+ let count = 0
20
+ const increment = debounce(100, () => {
21
+ count += 1
22
+ })
23
+ increment()
24
+ await nap(50)
25
+ increment()
26
+ await nap(50)
27
+ increment()
28
+ await nap(50)
29
+ increment()
30
+ await nap(50)
31
+ increment()
32
+ expect(count).is(0)
33
+ await nap(101)
34
+ expect(count).is(1)
35
+ },
36
+ async "provides a promise that resolves when done"() {
37
+ let count = 0
38
+ const increment = debounce(100, () => {
39
+ count += 1
40
+ })
41
+ let done = false
42
+ increment()
43
+ .then(() => done = true)
44
+ await nap(50)
45
+ increment()
46
+ await nap(50)
47
+ increment()
48
+ await nap(50)
49
+ increment()
50
+ await nap(50)
51
+ increment()
52
+ expect(done).is(false)
53
+ await nap(201)
54
+ expect(done).is(true)
55
+ },
56
+ async "can wait multiple rounds"() {
57
+ let count = 0
58
+ const increment = debounce(100, () => {
59
+ count += 1
60
+ })
61
+ await increment()
62
+ expect(count).is(1)
63
+ await increment()
64
+ expect(count).is(2)
65
+ },
66
+ async "errors are passed into promise chain"() {
67
+ const err = debounce(1, () => {
68
+ throw new Error()
69
+ })
70
+ await expect(async() => err()).throwsAsync()
71
+ },
72
+ })
73
+
@@ -1,8 +1,8 @@
1
- //
2
- // import {Suite} from "cynic"
3
- // import deepEqual from "./parts/equal.test.js"
4
- //
5
- // export default <Suite>{
6
- // deepEqual,
7
- // }
8
- //
1
+
2
+ import {Science} from "@e280/science"
3
+ import deepEqual from "./parts/equal.test.js"
4
+
5
+ export default Science.suite({
6
+ deepEqual,
7
+ })
8
+
@@ -1,124 +1,123 @@
1
- //
2
- // import {Suite, expect} from "cynic"
3
- // import {deepEqual} from "./equal.js"
4
- //
5
- // export default <Suite>{
6
- //
7
- // async "compare primitive types"() {
8
- // expect(deepEqual(123, 123)).equals(true)
9
- // expect(deepEqual("abc", "abc")).equals(true)
10
- // expect(deepEqual(true, true)).equals(true)
11
- // expect(deepEqual(123, "123")).equals(false)
12
- // expect(deepEqual(true, 1)).equals(false)
13
- // },
14
- //
15
- // async "compare arrays"() {
16
- // const array1 = [1, 2, 3]
17
- // const array2 = [1, 2, 3]
18
- // const array3 = [1, 2, 4]
19
- // expect(deepEqual(array1, array2)).equals(true)
20
- // expect(deepEqual(array1, array3)).equals(false)
21
- // },
22
- //
23
- // async "compare plain objects"() {
24
- // const obj1 = { foo: "bar", baz: 123 }
25
- // const obj2 = { foo: "bar", baz: 123 }
26
- // const obj3 = { foo: "bar", baz: 124 }
27
- // expect(deepEqual(obj1, obj2)).equals(true)
28
- // expect(deepEqual(obj1, obj3)).equals(false)
29
- // },
30
- //
31
- // async "compare nested objects"() {
32
- // const obj1 = { foo: "bar", inner: { baz: 123, deeper: { qux: true }}}
33
- // const obj2 = { foo: "bar", inner: { baz: 123, deeper: { qux: true }}}
34
- // const obj3 = { foo: "bar", inner: { baz: 124, deeper: { qux: true }}}
35
- // expect(deepEqual(obj1, obj2)).equals(true)
36
- // expect(deepEqual(obj1, obj3)).equals(false)
37
- // },
38
- //
39
- // async "compare array of objects"() {
40
- // const arr1 = [{ foo: "bar" }, { baz: 123 }, { qux: true }]
41
- // const arr2 = [{ foo: "bar" }, { baz: 123 }, { qux: true }]
42
- // const arr3 = [{ foo: "bar" }, { baz: 123 }, { qux: false }]
43
- // expect(deepEqual(arr1, arr2)).equals(true)
44
- // expect(deepEqual(arr1, arr3)).equals(false)
45
- // },
46
- //
47
- // async "compare null and undefined"() {
48
- // expect(deepEqual(null, null)).equals(true)
49
- // expect(deepEqual(undefined, undefined)).equals(true)
50
- // expect(deepEqual(null, undefined)).equals(false)
51
- // },
52
- //
53
- // async "compare with nested arrays"() {
54
- // const obj1 = { foo: "bar", array: [1, 2, [3, 4]] }
55
- // const obj2 = { foo: "bar", array: [1, 2, [3, 4]] }
56
- // const obj3 = { foo: "bar", array: [1, 2, [3, 5]] }
57
- // expect(deepEqual(obj1, obj2)).equals(true)
58
- // expect(deepEqual(obj1, obj3)).equals(false)
59
- // },
60
- //
61
- // async "circularity is forbidden"() {
62
- // const obj1 = {alpha: 1} as any
63
- // const obj2 = {alpha: 1} as any
64
- // obj1.bravo = obj1
65
- // obj2.bravo = obj2
66
- // expect(() => deepEqual(obj1, obj2)).throws()
67
- // },
68
- //
69
- // async "duplicate references are allowed"() {
70
- // const dupe = {a: 123}
71
- // const obj1 = {alpha: 1, dupe}
72
- // const obj2 = {alpha: 1, dupe}
73
- // const obj3 = {alpha: 1, dupe: {a: 0}}
74
- // expect(deepEqual(obj1, obj2)).equals(true)
75
- // expect(deepEqual(obj1, obj3)).equals(false)
76
- // },
77
- //
78
- // "maps and sets": {
79
- // async "compare maps"() {
80
- // const map1 = new Map([['key1', 'value1'], ['key2', 'value2']])
81
- // const map2 = new Map([['key1', 'value1'], ['key2', 'value2']])
82
- // const map3 = new Map([['key1', 'value1'], ['key2', 'value3']])
83
- // expect(deepEqual(map1, map2)).equals(true)
84
- // expect(deepEqual(map1, map3)).equals(false)
85
- // },
86
- //
87
- // async "compare sets"() {
88
- // const set1 = new Set([1, 2, 3])
89
- // const set2 = new Set([1, 2, 3])
90
- // const set3 = new Set([1, 2, 4])
91
- // expect(deepEqual(set1, set2)).equals(true)
92
- // expect(deepEqual(set1, set3)).equals(false)
93
- // },
94
- //
95
- // async "compare nested maps and sets"() {
96
- // const obj1 = { map: new Map([['key', new Set([1, 2, 3])]]) }
97
- // const obj2 = { map: new Map([['key', new Set([1, 2, 3])]]) }
98
- // const obj3 = { map: new Map([['key', new Set([1, 2, 4])]]) }
99
- // expect(deepEqual(obj1, obj2)).equals(true)
100
- // expect(deepEqual(obj1, obj3)).equals(false)
101
- // },
102
- //
103
- // async "compare complex structures"() {
104
- // const map1 = new Map([['set', new Set([{ a: 1 }, { b: 2 }])]])
105
- // const map2 = new Map([['set', new Set([{ a: 1 }, { b: 2 }])]])
106
- // const map3 = new Map([['set', new Set([{ a: 1 }, { b: 3 }])]])
107
- // expect(deepEqual(map1, map2)).equals(true)
108
- // expect(deepEqual(map1, map3)).equals(false)
109
- // },
110
- //
111
- // async "compare edge cases"() {
112
- // const emptyMap1 = new Map()
113
- // const emptyMap2 = new Map()
114
- // const emptySet1 = new Set()
115
- // const emptySet2 = new Set()
116
- // const mixedMap1 = new Map([['b', 2], ['a', 1]])
117
- // const mixedMap2 = new Map([['a', 1], ['b', 2]])
118
- // expect(deepEqual(emptyMap1, emptyMap2)).equals(true)
119
- // expect(deepEqual(emptySet1, emptySet2)).equals(true)
120
- // expect(deepEqual(mixedMap1, mixedMap2)).equals(true)
121
- // },
122
- // },
123
- // }
124
- //
1
+
2
+ import {deepEqual} from "./equal.js"
3
+ import {Science, expect} from "@e280/science"
4
+
5
+ export default Science.suite({
6
+ async "compare primitive types"() {
7
+ expect(deepEqual(123, 123)).is(true)
8
+ expect(deepEqual("abc", "abc")).is(true)
9
+ expect(deepEqual(true, true)).is(true)
10
+ expect(deepEqual(123, "123")).is(false)
11
+ expect(deepEqual(true, 1)).is(false)
12
+ },
13
+
14
+ async "compare arrays"() {
15
+ const array1 = [1, 2, 3]
16
+ const array2 = [1, 2, 3]
17
+ const array3 = [1, 2, 4]
18
+ expect(deepEqual(array1, array2)).is(true)
19
+ expect(deepEqual(array1, array3)).is(false)
20
+ },
21
+
22
+ async "compare plain objects"() {
23
+ const obj1 = { foo: "bar", baz: 123 }
24
+ const obj2 = { foo: "bar", baz: 123 }
25
+ const obj3 = { foo: "bar", baz: 124 }
26
+ expect(deepEqual(obj1, obj2)).is(true)
27
+ expect(deepEqual(obj1, obj3)).is(false)
28
+ },
29
+
30
+ async "compare nested objects"() {
31
+ const obj1 = { foo: "bar", inner: { baz: 123, deeper: { qux: true }}}
32
+ const obj2 = { foo: "bar", inner: { baz: 123, deeper: { qux: true }}}
33
+ const obj3 = { foo: "bar", inner: { baz: 124, deeper: { qux: true }}}
34
+ expect(deepEqual(obj1, obj2)).is(true)
35
+ expect(deepEqual(obj1, obj3)).is(false)
36
+ },
37
+
38
+ async "compare array of objects"() {
39
+ const arr1 = [{ foo: "bar" }, { baz: 123 }, { qux: true }]
40
+ const arr2 = [{ foo: "bar" }, { baz: 123 }, { qux: true }]
41
+ const arr3 = [{ foo: "bar" }, { baz: 123 }, { qux: false }]
42
+ expect(deepEqual(arr1, arr2)).is(true)
43
+ expect(deepEqual(arr1, arr3)).is(false)
44
+ },
45
+
46
+ async "compare null and undefined"() {
47
+ expect(deepEqual(null, null)).is(true)
48
+ expect(deepEqual(undefined, undefined)).is(true)
49
+ expect(deepEqual(null, undefined)).is(false)
50
+ },
51
+
52
+ async "compare with nested arrays"() {
53
+ const obj1 = { foo: "bar", array: [1, 2, [3, 4]] }
54
+ const obj2 = { foo: "bar", array: [1, 2, [3, 4]] }
55
+ const obj3 = { foo: "bar", array: [1, 2, [3, 5]] }
56
+ expect(deepEqual(obj1, obj2)).is(true)
57
+ expect(deepEqual(obj1, obj3)).is(false)
58
+ },
59
+
60
+ async "circularity is forbidden"() {
61
+ const obj1 = {alpha: 1} as any
62
+ const obj2 = {alpha: 1} as any
63
+ obj1.bravo = obj1
64
+ obj2.bravo = obj2
65
+ expect(() => deepEqual(obj1, obj2)).throws()
66
+ },
67
+
68
+ async "duplicate references are allowed"() {
69
+ const dupe = {a: 123}
70
+ const obj1 = {alpha: 1, dupe}
71
+ const obj2 = {alpha: 1, dupe}
72
+ const obj3 = {alpha: 1, dupe: {a: 0}}
73
+ expect(deepEqual(obj1, obj2)).is(true)
74
+ expect(deepEqual(obj1, obj3)).is(false)
75
+ },
76
+
77
+ "maps and sets": {
78
+ async "compare maps"() {
79
+ const map1 = new Map([['key1', 'value1'], ['key2', 'value2']])
80
+ const map2 = new Map([['key1', 'value1'], ['key2', 'value2']])
81
+ const map3 = new Map([['key1', 'value1'], ['key2', 'value3']])
82
+ expect(deepEqual(map1, map2)).is(true)
83
+ expect(deepEqual(map1, map3)).is(false)
84
+ },
85
+
86
+ async "compare sets"() {
87
+ const set1 = new Set([1, 2, 3])
88
+ const set2 = new Set([1, 2, 3])
89
+ const set3 = new Set([1, 2, 4])
90
+ expect(deepEqual(set1, set2)).is(true)
91
+ expect(deepEqual(set1, set3)).is(false)
92
+ },
93
+
94
+ async "compare nested maps and sets"() {
95
+ const obj1 = { map: new Map([['key', new Set([1, 2, 3])]]) }
96
+ const obj2 = { map: new Map([['key', new Set([1, 2, 3])]]) }
97
+ const obj3 = { map: new Map([['key', new Set([1, 2, 4])]]) }
98
+ expect(deepEqual(obj1, obj2)).is(true)
99
+ expect(deepEqual(obj1, obj3)).is(false)
100
+ },
101
+
102
+ async "compare complex structures"() {
103
+ const map1 = new Map([['set', new Set([{ a: 1 }, { b: 2 }])]])
104
+ const map2 = new Map([['set', new Set([{ a: 1 }, { b: 2 }])]])
105
+ const map3 = new Map([['set', new Set([{ a: 1 }, { b: 3 }])]])
106
+ expect(deepEqual(map1, map2)).is(true)
107
+ expect(deepEqual(map1, map3)).is(false)
108
+ },
109
+
110
+ async "compare edge cases"() {
111
+ const emptyMap1 = new Map()
112
+ const emptyMap2 = new Map()
113
+ const emptySet1 = new Set()
114
+ const emptySet2 = new Set()
115
+ const mixedMap1 = new Map([['b', 2], ['a', 1]])
116
+ const mixedMap2 = new Map([['a', 1], ['b', 2]])
117
+ expect(deepEqual(emptyMap1, emptyMap2)).is(true)
118
+ expect(deepEqual(emptySet1, emptySet2)).is(true)
119
+ expect(deepEqual(mixedMap1, mixedMap2)).is(true)
120
+ },
121
+ },
122
+ })
123
+
@@ -1,6 +1,6 @@
1
1
 
2
2
  /** a promise which can be resolved from the outside */
3
- export type DeferredPromise<R> = {
3
+ export type Deferred<R = void> = {
4
4
  promise: Promise<R>
5
5
  resolve: (result: R) => void
6
6
  reject: (reason: any) => void
@@ -10,7 +10,7 @@ export type DeferredPromise<R> = {
10
10
  }
11
11
 
12
12
  /** returns a deferred promise with exposed resolve and reject fns */
13
- export function deferPromise<R>(): DeferredPromise<R> {
13
+ export function defer<R = void>(): Deferred<R> {
14
14
  let resolve!: (result: R) => void
15
15
  let reject!: (reason: any) => void
16
16
 
package/s/drill.ts CHANGED
@@ -1,9 +1,7 @@
1
1
 
2
2
  import {is} from "./is.js"
3
3
 
4
- /**
5
- * return a value within an object tree, found at the given path.
6
- */
4
+ /** return a value within an object tree, found at the given path. */
7
5
  export function drill<xResult>(
8
6
  object: {[key: string]: any},
9
7
  path: string[],
@@ -13,7 +11,7 @@ export function drill<xResult>(
13
11
 
14
12
  for (const key of path) {
15
13
  current = current[key]
16
- if (is.unavailable(current))
14
+ if (is.unset(current))
17
15
  break
18
16
  }
19
17
 
package/s/ev.ts ADDED
@@ -0,0 +1,20 @@
1
+
2
+ export type EvFn = (...a: any[]) => void
3
+
4
+ export type EvTarget<N extends string> = {
5
+ addEventListener(name: N, fn: EvFn): void
6
+ removeEventListener(name: N, fn: EvFn): void
7
+ }
8
+
9
+ export function ev<N extends string>(target: EvTarget<N>, fns: Record<N, EvFn>) {
10
+ const entries = Object.entries(fns) as [N, EvFn][]
11
+
12
+ for (const [name, fn] of entries)
13
+ target.addEventListener(name, fn)
14
+
15
+ return () => {
16
+ for (const [name, fn] of entries)
17
+ target.removeEventListener(name, fn)
18
+ }
19
+ }
20
+
@@ -0,0 +1,9 @@
1
+
2
+ export class IdCounter {
3
+ constructor(public count = 0) {}
4
+
5
+ next() {
6
+ return this.count++
7
+ }
8
+ }
9
+
package/s/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
- export * from "./data/barname/index.js"
2
+ export * from "./data/bytename/index.js"
3
+ export * from "./data/base-x.js"
3
4
  export * from "./data/base58.js"
4
5
  export * from "./data/base64.js"
5
6
  export * from "./data/base64url.js"
@@ -7,19 +8,32 @@ export * from "./data/bytes.js"
7
8
  export * from "./data/hex.js"
8
9
  export * from "./data/txt.js"
9
10
 
11
+ export * from "./debounce/debounce.js"
12
+ export * from "./debounce/types.js"
13
+
14
+ export * from "./deep/deep.js"
15
+
16
+ export * from "./queue/queue.js"
17
+
10
18
  export * from "./coalesce.js"
11
19
  export * from "./concurrent.js"
12
20
  export * from "./deadline.js"
13
21
  export * from "./dedupe.js"
14
- export * from "./defer-promise.js"
22
+ export * from "./defer.js"
15
23
  export * from "./drill.js"
16
24
  export * from "./escape-regex.js"
25
+ export * from "./ev.js"
17
26
  export * from "./hat.js"
27
+ export * from "./id-counter.js"
18
28
  export * from "./is.js"
29
+ export * from "./loopy.js"
19
30
  export * from "./map-g.js"
20
31
  export * from "./nap.js"
21
32
  export * from "./ob.js"
33
+ export * from "./once.js"
22
34
  export * from "./pipe.js"
35
+ export * from "./repeat.js"
23
36
  export * from "./pubsub.js"
37
+ export * from "./time.js"
24
38
  export * from "./trash.js"
25
39
 
package/s/is.ts CHANGED
@@ -1,9 +1,9 @@
1
1
 
2
- export const is = {
3
- available: <X>(x: X): x is NonNullable<X> =>
2
+ export const is = Object.freeze({
3
+ set: <X>(x: X): x is NonNullable<X> =>
4
4
  x !== undefined && x !== null,
5
5
 
6
- unavailable: (x: any): x is (undefined | null) =>
6
+ unset: (x: any): x is (undefined | null) =>
7
7
  x === undefined || x === null,
8
8
 
9
9
  boolean: (x: any): x is boolean =>
@@ -23,5 +23,11 @@ export const is = {
23
23
 
24
24
  array: (x: any | any[]): x is any[] =>
25
25
  Array.isArray(x),
26
- }
26
+
27
+ fn: (x: any): x is (...a: any[]) => any =>
28
+ typeof x === "function",
29
+
30
+ symbol: (x: any): x is symbol =>
31
+ typeof x === "symbol",
32
+ })
27
33
 
package/s/loopy.ts ADDED
@@ -0,0 +1,12 @@
1
+
2
+ export function* loop(n: number) {
3
+ for (let i = 0; i < n; i++)
4
+ yield i
5
+ }
6
+
7
+ export function* loop2d([columns, rows]: [number, number]) {
8
+ for (let y = 0; y < rows; y++)
9
+ for (let x = 0; x < columns; x++)
10
+ yield [x, y] as [number, number]
11
+ }
12
+
package/s/map-g.ts CHANGED
@@ -1,11 +1,11 @@
1
1
 
2
- /** js map, but with handy methods like `require` and `guarantee` */
2
+ /** extended js map with handy methods like `require` and `guarantee` */
3
3
  export class MapG<K, V> extends Map<K, V> {
4
4
  static require<K, V>(map: Map<K, V>, key: K) {
5
5
  const value = map.get(key)
6
6
  if (value === undefined)
7
7
  throw new Error(`required key not found: "${key}"`)
8
- return value
8
+ return value as V
9
9
  }
10
10
 
11
11
  static guarantee<K, V>(map: Map<K, V>, key: K, make: () => V) {
package/s/nap.ts CHANGED
@@ -1,4 +1,5 @@
1
1
 
2
+ /** create a promise that waits for a number of milliseconds. */
2
3
  export const nap = (milliseconds: number = 0) => (
3
4
  new Promise<void>(resolve => setTimeout(resolve, milliseconds))
4
5
  )
package/s/once.ts ADDED
@@ -0,0 +1,14 @@
1
+
2
+ export function once<Fn extends (...a: any[]) => any>(fn: Fn) {
3
+ let done = false
4
+ let ret: any
5
+
6
+ return ((...a) => {
7
+ if (!done) {
8
+ done = true
9
+ ret = fn(...a)
10
+ }
11
+ return ret
12
+ }) as Fn
13
+ }
14
+