@e280/stz 0.0.0-2 → 0.0.0-21

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 (148) hide show
  1. package/README.md +170 -0
  2. package/package.json +9 -5
  3. package/s/clone/clone.test.ts +123 -123
  4. package/s/coalesce.ts +6 -0
  5. package/s/data/base-x.ts +164 -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 +93 -0
  16. package/s/data/hex.ts +15 -5
  17. package/s/data/txt.ts +14 -4
  18. package/s/deadline.ts +7 -4
  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 +20 -0
  24. package/s/id-counter.ts +9 -0
  25. package/s/index.ts +12 -2
  26. package/s/is.ts +10 -4
  27. package/s/loopy.ts +12 -0
  28. package/s/map-g.ts +2 -2
  29. package/s/nap.ts +1 -0
  30. package/s/pubsub.ts +20 -2
  31. package/s/tests.test.ts +19 -0
  32. package/x/clone/clone.test.d.ts +15 -1
  33. package/x/clone/clone.test.js +106 -124
  34. package/x/clone/clone.test.js.map +1 -1
  35. package/x/coalesce.d.ts +2 -0
  36. package/x/coalesce.js +5 -0
  37. package/x/coalesce.js.map +1 -0
  38. package/x/data/base-x.d.ts +44 -0
  39. package/x/data/base-x.js +142 -0
  40. package/x/data/base-x.js.map +1 -0
  41. package/x/data/base58.d.ts +5 -1
  42. package/x/data/base58.js +13 -5
  43. package/x/data/base58.js.map +1 -1
  44. package/x/data/base64.d.ts +7 -3
  45. package/x/data/base64.js +13 -5
  46. package/x/data/base64.js.map +1 -1
  47. package/x/data/base64url.d.ts +5 -1
  48. package/x/data/base64url.js +13 -5
  49. package/x/data/base64url.js.map +1 -1
  50. package/x/data/bytename/bytename.d.ts +19 -0
  51. package/x/data/{barname/barname.js → bytename/bytename.js} +27 -11
  52. package/x/data/bytename/bytename.js.map +1 -0
  53. package/x/data/bytename/bytename.test.d.ts +17 -0
  54. package/x/data/bytename/bytename.test.js +41 -0
  55. package/x/data/bytename/bytename.test.js.map +1 -0
  56. package/x/data/bytename/index.d.ts +2 -0
  57. package/x/data/bytename/index.js +3 -0
  58. package/x/data/bytename/index.js.map +1 -0
  59. package/x/data/bytename/thumbprint.d.ts +36 -0
  60. package/x/data/bytename/thumbprint.js +79 -0
  61. package/x/data/bytename/thumbprint.js.map +1 -0
  62. package/x/data/bytename/thumbprint.test.d.ts +24 -0
  63. package/x/data/bytename/thumbprint.test.js +45 -0
  64. package/x/data/bytename/thumbprint.test.js.map +1 -0
  65. package/x/data/bytename/utils/prefixes.js.map +1 -0
  66. package/x/data/bytename/utils/suffixes.js.map +1 -0
  67. package/x/data/bytes.d.ts +3 -2
  68. package/x/data/bytes.js +11 -2
  69. package/x/data/bytes.js.map +1 -1
  70. package/x/data/data.test.d.ts +68 -0
  71. package/x/data/data.test.js +72 -0
  72. package/x/data/data.test.js.map +1 -0
  73. package/x/data/hex.d.ts +8 -4
  74. package/x/data/hex.js +13 -5
  75. package/x/data/hex.js.map +1 -1
  76. package/x/data/txt.d.ts +6 -2
  77. package/x/data/txt.js +12 -4
  78. package/x/data/txt.js.map +1 -1
  79. package/x/deadline.d.ts +3 -2
  80. package/x/deadline.js +8 -4
  81. package/x/deadline.js.map +1 -1
  82. package/x/debounce/debounce.test.d.ts +8 -1
  83. package/x/debounce/debounce.test.js +70 -74
  84. package/x/debounce/debounce.test.js.map +1 -1
  85. package/x/deep/deep.test.d.ts +21 -1
  86. package/x/deep/deep.test.js +5 -9
  87. package/x/deep/deep.test.js.map +1 -1
  88. package/x/deep/parts/equal.test.d.ts +19 -1
  89. package/x/deep/parts/equal.test.js +107 -125
  90. package/x/deep/parts/equal.test.js.map +1 -1
  91. package/x/{defer-promise.d.ts → defer.d.ts} +2 -2
  92. package/x/{defer-promise.js → defer.js} +2 -2
  93. package/x/defer.js.map +1 -0
  94. package/x/drill.d.ts +4 -0
  95. package/x/drill.js +12 -0
  96. package/x/drill.js.map +1 -0
  97. package/x/id-counter.d.ts +5 -0
  98. package/x/id-counter.js +10 -0
  99. package/x/id-counter.js.map +1 -0
  100. package/x/index.d.ts +10 -2
  101. package/x/index.js +10 -2
  102. package/x/index.js.map +1 -1
  103. package/x/is.d.ts +6 -4
  104. package/x/is.js +6 -4
  105. package/x/is.js.map +1 -1
  106. package/x/loopy.d.ts +2 -0
  107. package/x/loopy.js +10 -0
  108. package/x/loopy.js.map +1 -0
  109. package/x/map-g.d.ts +3 -3
  110. package/x/map-g.js +1 -1
  111. package/x/map-g.js.map +1 -1
  112. package/x/nap.d.ts +1 -0
  113. package/x/nap.js +1 -0
  114. package/x/nap.js.map +1 -1
  115. package/x/pubsub.d.ts +11 -0
  116. package/x/pubsub.js +4 -2
  117. package/x/pubsub.js.map +1 -1
  118. package/x/tests.test.js +16 -0
  119. package/x/tests.test.js.map +1 -0
  120. package/readme.md +0 -85
  121. package/s/data/anka.ts +0 -66
  122. package/s/data/barname/badge.ts +0 -78
  123. package/s/data/barname/demo.ts +0 -49
  124. package/s/data/barname/index.ts +0 -4
  125. package/x/data/anka.d.ts +0 -5
  126. package/x/data/anka.js +0 -53
  127. package/x/data/anka.js.map +0 -1
  128. package/x/data/barname/badge.d.ts +0 -25
  129. package/x/data/barname/badge.js +0 -64
  130. package/x/data/barname/badge.js.map +0 -1
  131. package/x/data/barname/barname.d.ts +0 -7
  132. package/x/data/barname/barname.js.map +0 -1
  133. package/x/data/barname/demo.js +0 -45
  134. package/x/data/barname/demo.js.map +0 -1
  135. package/x/data/barname/index.d.ts +0 -2
  136. package/x/data/barname/index.js +0 -3
  137. package/x/data/barname/index.js.map +0 -1
  138. package/x/data/barname/utils/prefixes.js.map +0 -1
  139. package/x/data/barname/utils/suffixes.js.map +0 -1
  140. package/x/defer-promise.js.map +0 -1
  141. /package/{license → LICENSE} +0 -0
  142. /package/s/data/{barname → bytename}/utils/prefixes.ts +0 -0
  143. /package/s/data/{barname → bytename}/utils/suffixes.ts +0 -0
  144. /package/x/data/{barname → bytename}/utils/prefixes.d.ts +0 -0
  145. /package/x/data/{barname → bytename}/utils/prefixes.js +0 -0
  146. /package/x/data/{barname → bytename}/utils/suffixes.d.ts +0 -0
  147. /package/x/data/{barname → bytename}/utils/suffixes.js +0 -0
  148. /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> = {
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>(): Deferred<R> {
14
14
  let resolve!: (result: R) => void
15
15
  let reject!: (reason: any) => void
16
16
 
package/s/drill.ts ADDED
@@ -0,0 +1,20 @@
1
+
2
+ import {is} from "./is.js"
3
+
4
+ /** return a value within an object tree, found at the given path. */
5
+ export function drill<xResult>(
6
+ object: {[key: string]: any},
7
+ path: string[],
8
+ ): xResult {
9
+
10
+ let current: any = object
11
+
12
+ for (const key of path) {
13
+ current = current[key]
14
+ if (is.unset(current))
15
+ break
16
+ }
17
+
18
+ return current
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,13 +8,22 @@ 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 "./coalesce.js"
10
17
  export * from "./concurrent.js"
11
18
  export * from "./deadline.js"
12
19
  export * from "./dedupe.js"
13
- export * from "./defer-promise.js"
20
+ export * from "./defer.js"
21
+ export * from "./drill.js"
14
22
  export * from "./escape-regex.js"
15
23
  export * from "./hat.js"
24
+ export * from "./id-counter.js"
16
25
  export * from "./is.js"
26
+ export * from "./loopy.js"
17
27
  export * from "./map-g.js"
18
28
  export * from "./nap.js"
19
29
  export * from "./ob.js"
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/pubsub.ts CHANGED
@@ -1,19 +1,35 @@
1
1
 
2
- import {deferPromise} from "./defer-promise.js"
2
+ import {defer} from "./defer.js"
3
3
 
4
4
  export type Listener<A extends any[]> = (...a: A) => (void | Promise<void>)
5
5
 
6
6
  export interface Xub<A extends any[] = []> {
7
+
8
+ /** publish to all subscribed listeners. */
7
9
  pub(...a: A): Promise<void>
10
+
11
+ /** subscribe a listener function. */
8
12
  sub(fn: Listener<A>): () => void
13
+
14
+ /**
15
+ * subscribe a listener function.
16
+ * @alias sub
17
+ */
18
+ on(fn: Listener<A>): () => void
19
+
20
+ /** subscribe a listener function that unsubscribes itself after being invoked. */
9
21
  once(): Promise<A>
22
+
23
+ /** wipe all listeners attached to this. */
10
24
  clear(): void
11
25
  }
12
26
 
27
+ /** subscriber fn that can be published to. */
13
28
  export interface Sub<A extends any[] = []> extends Xub<A> {
14
29
  (fn: Listener<A>): () => void
15
30
  }
16
31
 
32
+ /** publisher fn that can be published to. */
17
33
  export interface Pub<A extends any[] = []> extends Xub<A> {
18
34
  (...a: A): Promise<void>
19
35
  }
@@ -31,7 +47,7 @@ export function xub<A extends any[] = []>() {
31
47
  }
32
48
 
33
49
  async function once() {
34
- const {promise, resolve} = deferPromise<A>()
50
+ const {promise, resolve} = defer<A>()
35
51
  const unsubscribe = sub((...a) => {
36
52
  resolve(a)
37
53
  unsubscribe()
@@ -45,11 +61,13 @@ export function xub<A extends any[] = []>() {
45
61
 
46
62
  sub.pub = pub
47
63
  sub.sub = sub
64
+ sub.on = sub
48
65
  sub.once = once
49
66
  sub.clear = clear
50
67
 
51
68
  pub.pub = pub
52
69
  pub.sub = sub
70
+ pub.on = sub
53
71
  pub.once = once
54
72
  pub.clear = clear
55
73
 
@@ -0,0 +1,19 @@
1
+
2
+ import {Science} from "@e280/science"
3
+
4
+ import clone from "./clone/clone.test.js"
5
+ import thumbprint from "./data/bytename/thumbprint.test.js"
6
+ import debounce from "./debounce/debounce.test.js"
7
+ import bytename from "./data/bytename/bytename.test.js"
8
+ import deep from "./deep/deep.test.js"
9
+ import data from "./data/data.test.js"
10
+
11
+ await Science.run({
12
+ clone,
13
+ bytename,
14
+ thumbprint,
15
+ debounce,
16
+ deep,
17
+ data,
18
+ })
19
+