hyperscript-rxjs 1.3.14 → 1.3.15
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.
- package/package.json +13 -22
- package/src/array/advance.d.ts +9 -0
- package/src/array/advance.js +13 -0
- package/src/array/advance.test.js +12 -0
- package/src/array/arrayInsert.d.ts +8 -0
- package/src/array/arrayInsert.js +13 -0
- package/src/array/arrayInsert.test.js +13 -0
- package/src/array/arrayRemove.d.ts +7 -0
- package/src/array/arrayRemove.js +15 -0
- package/src/array/arrayRemove.test.js +13 -0
- package/src/array/findLastIndex.d.ts +14 -0
- package/src/array/findLastIndex.js +20 -0
- package/src/array/findLastIndex.test.js +41 -0
- package/src/array/index.d.ts +9 -0
- package/src/array/index.js +9 -0
- package/src/array/isRange.d.ts +7 -0
- package/src/array/isRange.js +15 -0
- package/src/array/isRange.test.js +6 -0
- package/src/array/rangeArray.d.ts +7 -0
- package/src/array/rangeArray.js +10 -0
- package/src/array/rangeArray.test.js +11 -0
- package/src/array/unwrapArgs.d.ts +10 -0
- package/src/array/unwrapArgs.js +15 -0
- package/src/array/unwrapArgs.test.js +33 -0
- package/src/array/zipArray.d.ts +11 -0
- package/src/array/zipArray.js +24 -0
- package/src/array/zipArray.test.js +16 -0
- package/src/comparers/Comparer.d.ts +101 -0
- package/src/comparers/Comparer.js +149 -0
- package/src/comparers/comparers.d.ts +21 -0
- package/src/comparers/comparers.js +10 -0
- package/src/comparers/differenceSet.d.ts +20 -0
- package/src/comparers/differenceSet.js +35 -0
- package/src/comparers/differenceSet.test.js +11 -0
- package/src/comparers/distinctArray.d.ts +13 -0
- package/src/comparers/distinctArray.js +30 -0
- package/src/comparers/distinctArray.test.js +10 -0
- package/src/comparers/findIndexInSet.d.ts +20 -0
- package/src/comparers/findIndexInSet.js +27 -0
- package/src/comparers/findIndexInSet.test.js +8 -0
- package/src/comparers/groupArrayBy.d.ts +19 -0
- package/src/comparers/groupArrayBy.js +29 -0
- package/src/comparers/groupArrayBy.test.js +38 -0
- package/src/comparers/groupSortedEntries.d.ts +17 -0
- package/src/comparers/groupSortedEntries.js +38 -0
- package/src/comparers/groupSortedEntries.test.js +46 -0
- package/src/comparers/index.d.ts +14 -0
- package/src/comparers/index.js +14 -0
- package/src/comparers/intersectSet.d.ts +19 -0
- package/src/comparers/intersectSet.js +35 -0
- package/src/comparers/intersectSet.test.js +14 -0
- package/src/comparers/isEqualset.d.ts +22 -0
- package/src/comparers/isEqualset.js +33 -0
- package/src/comparers/isEqualset.test.js +22 -0
- package/src/comparers/isSubset.d.ts +21 -0
- package/src/comparers/isSubset.js +33 -0
- package/src/comparers/isSubset.test.js +21 -0
- package/src/comparers/isSuperset.d.ts +21 -0
- package/src/comparers/isSuperset.js +13 -0
- package/src/comparers/isSuperset.test.js +21 -0
- package/src/comparers/sortedArrayToSet.d.ts +20 -0
- package/src/comparers/sortedArrayToSet.js +35 -0
- package/src/comparers/sortedArrayToSet.test.js +11 -0
- package/src/comparers/unionSet.d.ts +21 -0
- package/src/comparers/unionSet.js +34 -0
- package/src/comparers/unionSet.test.js +11 -0
- package/src/comparison/compareDate.d.ts +8 -0
- package/src/comparison/compareDate.js +11 -0
- package/src/comparison/compareEntries.d.ts +13 -0
- package/src/comparison/compareEntries.js +13 -0
- package/src/comparison/compareKey.d.ts +11 -0
- package/src/comparison/compareKey.js +25 -0
- package/src/comparison/compareKey.test.js +21 -0
- package/src/comparison/compareKeyPath.d.ts +15 -0
- package/src/comparison/compareKeyPath.js +33 -0
- package/src/comparison/compareKeyPath.test.js +28 -0
- package/src/comparison/compareNumber.d.ts +11 -0
- package/src/comparison/compareNumber.js +27 -0
- package/src/comparison/compareNumber.test.js +21 -0
- package/src/comparison/defaultCompare.d.ts +8 -0
- package/src/comparison/defaultCompare.js +12 -0
- package/src/comparison/defaultCompare.test.js +24 -0
- package/src/comparison/index.d.ts +7 -0
- package/src/comparison/index.js +7 -0
- package/src/comparison/infinity.test.js +122 -0
- package/src/comparison/typeof.test.js +64 -0
- package/src/comparison/types.d.ts +5 -0
- package/src/comparison/types.js +11 -0
- package/src/deep/Deep.d.ts +58 -0
- package/src/deep/Deep.js +267 -0
- package/src/deep/Deep.test.js +130 -0
- package/src/deep/deepCombineLatest.test.js +36 -0
- package/src/deep/deepMerge.test.js +34 -0
- package/src/deep/differenceDeep.test.js +31 -0
- package/src/deep/freshValueDeep.test.js +17 -0
- package/src/deep/index.d.ts +1 -0
- package/src/deep/index.js +2 -0
- package/src/deep/intersectDeep.test.js +25 -0
- package/src/deep/intersectEntries.d.ts +13 -0
- package/src/deep/intersectEntries.js +37 -0
- package/src/deep/intersectEntries.test.js +20 -0
- package/src/deep/objectToDeep.test.js +31 -0
- package/src/deep/replaceValueDeep.test.js +21 -0
- package/src/deep/unionDeep.test.js +30 -0
- package/src/deep/zipValueDeep.test.js +21 -0
- package/src/deep-rxjs/ObservableArray.d.ts +55 -0
- package/src/deep-rxjs/ObservableArray.js +94 -0
- package/src/deep-rxjs/ObservableArray.test.js +117 -0
- package/src/deep-rxjs/index.d.ts +2 -0
- package/src/deep-rxjs/index.js +2 -0
- package/src/deep-rxjs/isRxType.d.ts +9 -0
- package/src/deep-rxjs/isRxType.js +15 -0
- package/src/deep-rxjs/isRxType.test.js +43 -0
- package/src/hyperscript-rxjs/HyperscriptExtensions.d.ts +20 -0
- package/src/hyperscript-rxjs/checkbox.d.ts +13 -0
- package/src/hyperscript-rxjs/checkbox.js +47 -0
- package/src/hyperscript-rxjs/checkbox.test.js +68 -0
- package/src/hyperscript-rxjs/choice.d.ts +13 -0
- package/src/hyperscript-rxjs/choice.js +24 -0
- package/src/hyperscript-rxjs/choice.test.js +108 -0
- package/src/hyperscript-rxjs/collapse.d.ts +14 -0
- package/src/hyperscript-rxjs/collapse.js +32 -0
- package/src/hyperscript-rxjs/collapse.test.js +67 -0
- package/src/hyperscript-rxjs/displays/blockLevelFamily.d.ts +5 -0
- package/src/hyperscript-rxjs/displays/blockLevelFamily.js +51 -0
- package/src/hyperscript-rxjs/displays/getDisplay.d.ts +7 -0
- package/src/hyperscript-rxjs/displays/getDisplay.js +51 -0
- package/src/hyperscript-rxjs/displays/getDisplay.test.js +56 -0
- package/src/hyperscript-rxjs/displays/index.d.ts +3 -0
- package/src/hyperscript-rxjs/displays/index.js +3 -0
- package/src/hyperscript-rxjs/displays/inlineFamily.d.ts +5 -0
- package/src/hyperscript-rxjs/displays/inlineFamily.js +73 -0
- package/src/hyperscript-rxjs/flip.d.ts +15 -0
- package/src/hyperscript-rxjs/flip.js +29 -0
- package/src/hyperscript-rxjs/flip.test.js +85 -0
- package/src/hyperscript-rxjs/fragment.d.ts +10 -0
- package/src/hyperscript-rxjs/fragment.js +22 -0
- package/src/hyperscript-rxjs/fragment.test.js +70 -0
- package/src/hyperscript-rxjs/hyperscript.d.ts +15 -0
- package/src/hyperscript-rxjs/hyperscript.js +170 -0
- package/src/hyperscript-rxjs/hyperscript.test.js +75 -0
- package/src/hyperscript-rxjs/index.d.ts +19 -0
- package/src/hyperscript-rxjs/index.js +19 -0
- package/src/hyperscript-rxjs/multiselect.d.ts +18 -0
- package/src/hyperscript-rxjs/multiselect.js +41 -0
- package/src/hyperscript-rxjs/multiselect.test.js +121 -0
- package/src/hyperscript-rxjs/numberbox.d.ts +14 -0
- package/src/hyperscript-rxjs/numberbox.js +73 -0
- package/src/hyperscript-rxjs/numberbox.test.js +84 -0
- package/src/hyperscript-rxjs/radio.d.ts +15 -0
- package/src/hyperscript-rxjs/radio.js +53 -0
- package/src/hyperscript-rxjs/radio.test.js +59 -0
- package/src/hyperscript-rxjs/select.d.ts +28 -0
- package/src/hyperscript-rxjs/select.js +88 -0
- package/src/hyperscript-rxjs/select.test.js +101 -0
- package/src/hyperscript-rxjs/tabControls/bindTabIndex.d.ts +12 -0
- package/src/hyperscript-rxjs/tabControls/bindTabIndex.js +59 -0
- package/src/hyperscript-rxjs/tabControls/index.d.ts +8 -0
- package/src/hyperscript-rxjs/tabControls/index.js +10 -0
- package/src/hyperscript-rxjs/tabControls/tabControl.d.ts +19 -0
- package/src/hyperscript-rxjs/tabControls/tabControl.js +40 -0
- package/src/hyperscript-rxjs/tabControls/tabControl.test.js +98 -0
- package/src/hyperscript-rxjs/tabControls/tabNavItem.d.ts +9 -0
- package/src/hyperscript-rxjs/tabControls/tabNavItem.js +30 -0
- package/src/hyperscript-rxjs/tabControls/tabPanel.d.ts +9 -0
- package/src/hyperscript-rxjs/tabControls/tabPanel.js +21 -0
- package/src/hyperscript-rxjs/tabControls/tabRoot.d.ts +7 -0
- package/src/hyperscript-rxjs/tabControls/tabRoot.js +26 -0
- package/src/hyperscript-rxjs/tags.d.ts +193 -0
- package/src/hyperscript-rxjs/tags.js +751 -0
- package/src/hyperscript-rxjs/tags.test.js +75 -0
- package/src/hyperscript-rxjs/textNode.d.ts +11 -0
- package/src/hyperscript-rxjs/textNode.js +51 -0
- package/src/hyperscript-rxjs/textNode.test.js +56 -0
- package/src/hyperscript-rxjs/textarea.d.ts +17 -0
- package/src/hyperscript-rxjs/textarea.js +45 -0
- package/src/hyperscript-rxjs/textarea.test.js +52 -0
- package/src/hyperscript-rxjs/textbox.d.ts +15 -0
- package/src/hyperscript-rxjs/textbox.js +42 -0
- package/src/hyperscript-rxjs/textbox.test.js +52 -0
- package/src/index.d.ts +19 -0
- package/src/index.js +19 -0
- package/src/nodes/attachSubscriptionToNode.d.ts +13 -0
- package/src/nodes/attachSubscriptionToNode.js +25 -0
- package/src/nodes/attachSubscriptionToNode.test.js +73 -0
- package/src/nodes/index.d.ts +6 -0
- package/src/nodes/index.js +6 -0
- package/src/nodes/normalizeChildNodes.d.ts +9 -0
- package/src/nodes/normalizeChildNodes.js +15 -0
- package/src/nodes/normalizeChildNodes.test.js +55 -0
- package/src/nodes/parseHyperscriptArgs.d.ts +10 -0
- package/src/nodes/parseHyperscriptArgs.js +57 -0
- package/src/nodes/parseHyperscriptArgs.test.js +85 -0
- package/src/nodes/pipeEvent.d.ts +15 -0
- package/src/nodes/pipeEvent.js +49 -0
- package/src/nodes/pipeEvent.test.js +97 -0
- package/src/nodes/subscribeEvent.d.ts +15 -0
- package/src/nodes/subscribeEvent.js +56 -0
- package/src/nodes/subscribeEvent.test.js +88 -0
- package/src/object/index.d.ts +10 -0
- package/src/object/index.js +11 -0
- package/src/object/intersectObject.d.ts +12 -0
- package/src/object/intersectObject.js +23 -0
- package/src/object/intersectObject.test.js +69 -0
- package/src/object/isEmptyObject.d.ts +7 -0
- package/src/object/isEmptyObject.js +13 -0
- package/src/object/isEmptyObject.test.js +33 -0
- package/src/object/isPlainObject.d.ts +11 -0
- package/src/object/isPlainObject.js +18 -0
- package/src/object/nestedCombineLatest.d.ts +11 -0
- package/src/object/nestedCombineLatest.js +18 -0
- package/src/object/nestedCombineLatest.test.js +25 -0
- package/src/object/nestedMerge.d.ts +11 -0
- package/src/object/nestedMerge.js +11 -0
- package/src/object/nestedMerge.test.js +61 -0
- package/src/object/pickBehaviorSubject.d.ts +13 -0
- package/src/object/pickBehaviorSubject.js +81 -0
- package/src/object/pickBehaviorSubject.test.js +88 -0
- package/src/object/pluckProperty.d.ts +13 -0
- package/src/object/pluckProperty.js +24 -0
- package/src/object/pluckProperty.test.js +37 -0
- package/src/object/restore.d.ts +12 -0
- package/src/object/restore.js +69 -0
- package/src/object/restore.test.js +124 -0
- package/src/object/splitObjectByObservable.d.ts +12 -0
- package/src/object/splitObjectByObservable.js +41 -0
- package/src/object/splitObjectByObservable.test.js +78 -0
- package/src/props/getNestedProperty.d.ts +12 -0
- package/src/props/getNestedProperty.js +31 -0
- package/src/props/getNestedProperty.test.js +72 -0
- package/src/props/index.d.ts +7 -0
- package/src/props/index.js +7 -0
- package/src/props/parsePropName.d.ts +13 -0
- package/src/props/parsePropName.js +45 -0
- package/src/props/parsePropName.test.js +67 -0
- package/src/props/setProp.d.ts +16 -0
- package/src/props/setProp.js +42 -0
- package/src/props/setProp.test.js +59 -0
- package/src/props/setProps.d.ts +14 -0
- package/src/props/setProps.js +47 -0
- package/src/props/setProps.test.js +97 -0
- package/src/props/subscribeProp.d.ts +16 -0
- package/src/props/subscribeProp.js +47 -0
- package/src/props/subscribeProp.test.js +81 -0
- package/src/ramda/compose.d.ts +10 -0
- package/src/ramda/compose.js +36 -0
- package/src/ramda/compose.test.js +73 -0
- package/src/ramda/cond.d.ts +12 -0
- package/src/ramda/cond.js +29 -0
- package/src/ramda/cond.test.js +88 -0
- package/src/ramda/fold.d.ts +13 -0
- package/src/ramda/fold.js +20 -0
- package/src/ramda/fold.test.js +51 -0
- package/src/ramda/index.d.ts +6 -0
- package/src/ramda/index.js +6 -0
- package/src/ramda/pipe.d.ts +13 -0
- package/src/ramda/pipe.js +27 -0
- package/src/ramda/pipe.test.js +77 -0
- package/src/ramda/unfold.d.ts +11 -0
- package/src/ramda/unfold.js +20 -0
- package/src/ramda/unfold.test.js +29 -0
- package/src/unquoted-json/ajax.test.js +1074 -0
- package/src/unquoted-json/index.d.ts +13 -0
- package/src/unquoted-json/index.js +12 -0
- package/src/unquoted-json/queryStringify.d.ts +8 -0
- package/src/unquoted-json/queryStringify.js +70 -0
- package/src/unquoted-json/queryStringify.test.js +110 -0
- package/src/unquoted-json/stringifyKey.d.ts +7 -0
- package/src/unquoted-json/stringifyKey.js +16 -0
- package/src/unquoted-json/stringifyKey.test.js +51 -0
- package/src/unquoted-json/stringifyStringValue.d.ts +7 -0
- package/src/unquoted-json/stringifyStringValue.js +17 -0
- package/src/unquoted-json/stringifyStringValue.test.js +52 -0
- package/src/unquoted-json/unquotedJsonStringify.d.ts +7 -0
- package/src/unquoted-json/unquotedJsonStringify.js +39 -0
- package/src/unquoted-json/unquotedJsonStringify.test.js +52 -0
- package/dist/hyperscript-rxjs.d.ts +0 -1412
- package/dist/hyperscript-rxjs.js +0 -1
- package/dist/tsdoc-metadata.json +0 -11
@@ -0,0 +1,122 @@
|
|
1
|
+
describe('The definition of Infinity', () => {
|
2
|
+
test('typeof', () => {
|
3
|
+
expect(typeof Infinity).toEqual('number')
|
4
|
+
expect(typeof -Infinity).toEqual('number')
|
5
|
+
})
|
6
|
+
|
7
|
+
test('Number', () => {
|
8
|
+
expect(Number.POSITIVE_INFINITY).toEqual(Infinity)
|
9
|
+
expect(Number.NEGATIVE_INFINITY).toEqual(-Infinity)
|
10
|
+
})
|
11
|
+
})
|
12
|
+
|
13
|
+
describe('The properties of Infinity', () => {
|
14
|
+
test('some examples', () => {
|
15
|
+
expect(Infinity).toBeGreaterThan(100)
|
16
|
+
expect(Infinity).toBeGreaterThan(Number.MAX_SAFE_INTEGER)
|
17
|
+
expect(Infinity).toBeGreaterThan(Number.MAX_VALUE)
|
18
|
+
expect(Infinity).toBeGreaterThan(100n)
|
19
|
+
|
20
|
+
|
21
|
+
})
|
22
|
+
|
23
|
+
test('arithmetical operations', () => {
|
24
|
+
expect(Infinity + 1).toEqual(Infinity)
|
25
|
+
expect(Infinity + Infinity).toEqual(Infinity)
|
26
|
+
|
27
|
+
expect(Infinity * 2).toEqual(Infinity)
|
28
|
+
expect(Infinity * Infinity).toEqual(Infinity)
|
29
|
+
|
30
|
+
expect(Infinity / 2).toEqual(Infinity)
|
31
|
+
})
|
32
|
+
|
33
|
+
test('result in finite numbers', () => {
|
34
|
+
expect(10 / Infinity).toEqual(0)
|
35
|
+
})
|
36
|
+
|
37
|
+
test('results in `Infinity`', () => {
|
38
|
+
expect(10 / 0).toEqual(Infinity)
|
39
|
+
})
|
40
|
+
|
41
|
+
test('results in `NaN`', () => {
|
42
|
+
expect(Infinity / Infinity).toBeNaN()
|
43
|
+
expect(Infinity % 2).toEqual(NaN)
|
44
|
+
})
|
45
|
+
})
|
46
|
+
|
47
|
+
describe('the negative infinity', () => {
|
48
|
+
test('some examples', () => {
|
49
|
+
expect(-Infinity).toBeLessThan(100)
|
50
|
+
expect(-Infinity).toBeLessThan(Number.MIN_SAFE_INTEGER)
|
51
|
+
expect(-Infinity).toBeLessThan(Number.MIN_VALUE)
|
52
|
+
expect(-Infinity).toBeLessThan(Infinity)
|
53
|
+
|
54
|
+
})
|
55
|
+
|
56
|
+
test('end up in negative infinity', () => {
|
57
|
+
expect(Infinity * -2).toEqual(-Infinity)
|
58
|
+
expect(Infinity / -1).toEqual(-Infinity)
|
59
|
+
expect(-2 / 0).toEqual(-Infinity)
|
60
|
+
})
|
61
|
+
|
62
|
+
})
|
63
|
+
|
64
|
+
|
65
|
+
describe('Checking for *Infinity*', () => {
|
66
|
+
test('an infinite value equals to an infinite value of the same sign', () => {
|
67
|
+
expect(Infinity).toEqual(Infinity)
|
68
|
+
expect(-Infinity).toEqual(-Infinity)
|
69
|
+
expect(-Infinity).not.toEqual(Infinity)
|
70
|
+
|
71
|
+
})
|
72
|
+
|
73
|
+
test('whether the provided value is finite', () => {
|
74
|
+
expect(Number.isFinite(Infinity)).toEqual(false)
|
75
|
+
expect(Number.isFinite(-Infinity)).toEqual(false)
|
76
|
+
expect(Number.isFinite(999)).toEqual(true)
|
77
|
+
|
78
|
+
})
|
79
|
+
|
80
|
+
})
|
81
|
+
|
82
|
+
describe('*Infinity* use cases', () => {
|
83
|
+
|
84
|
+
})
|
85
|
+
|
86
|
+
describe('Pitfalls of *Infinity*', () => {
|
87
|
+
test('Parsing numbers', () => {
|
88
|
+
expect(parseFloat('Infinity')).toEqual(Infinity)
|
89
|
+
expect(parseInt('Infinity', 10)).toEqual(NaN)
|
90
|
+
})
|
91
|
+
|
92
|
+
test('JSON serialization', () => {
|
93
|
+
const worker = {
|
94
|
+
salary: Infinity
|
95
|
+
};
|
96
|
+
|
97
|
+
let y = JSON.parse(JSON.stringify(worker))
|
98
|
+
let e = { "salary": null }
|
99
|
+
|
100
|
+
expect(y).toEqual(e)
|
101
|
+
})
|
102
|
+
|
103
|
+
test('Max number overflow', () => {
|
104
|
+
|
105
|
+
expect(2 * Number.MAX_VALUE).toEqual(Infinity)
|
106
|
+
expect(Math.pow(10, 1000)).toEqual(Infinity)
|
107
|
+
|
108
|
+
})
|
109
|
+
|
110
|
+
test('Math functions', () => {
|
111
|
+
expect(Math.max()).toEqual(-Infinity)
|
112
|
+
expect(Math.min()).toEqual(Infinity)
|
113
|
+
|
114
|
+
})
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
})
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
describe('Basic usage', () => {
|
2
|
+
test('Number', () => {
|
3
|
+
expect(typeof 37).toEqual('number');
|
4
|
+
expect(typeof 3.14).toEqual('number');
|
5
|
+
expect(typeof (42)).toEqual('number');
|
6
|
+
expect(typeof Math.LN2).toEqual('number');
|
7
|
+
expect(typeof Infinity).toEqual('number');
|
8
|
+
expect(typeof NaN).toEqual('number'); // Despite being "Not-A-Number"
|
9
|
+
expect(typeof Number('1')).toEqual('number'); // Number tries to parse things into numbers
|
10
|
+
expect(typeof Number('shoe')).toEqual('number'); // including values that cannot be type coerced to a number
|
11
|
+
|
12
|
+
expect(typeof 42n).toEqual('bigint');
|
13
|
+
})
|
14
|
+
|
15
|
+
test('String', () => {
|
16
|
+
expect(typeof '').toEqual('string');
|
17
|
+
expect(typeof 'bla').toEqual('string');
|
18
|
+
expect(typeof `template literal`).toEqual('string');
|
19
|
+
expect(typeof '1').toEqual('string'); // note that a number within a string is still typeof string
|
20
|
+
expect(typeof (typeof 1)).toEqual('string'); // typeof always returns a string
|
21
|
+
expect(typeof String(1)).toEqual('string'); // String converts anything into a string, safer than toString
|
22
|
+
})
|
23
|
+
|
24
|
+
test('Boolean', () => {
|
25
|
+
expect(typeof true).toEqual('boolean');
|
26
|
+
expect(typeof false).toEqual('boolean');
|
27
|
+
expect(typeof Boolean(1)).toEqual('boolean'); // Boolean() will convert values based on if they're truthy or falsy
|
28
|
+
expect(typeof !!(1)).toEqual('boolean'); // two calls of the ! (logical NOT) operator are equivalent to Boolean()
|
29
|
+
})
|
30
|
+
|
31
|
+
test('Symbol', () => {
|
32
|
+
expect(typeof Symbol()).toEqual('symbol')
|
33
|
+
expect(typeof Symbol('foo')).toEqual('symbol')
|
34
|
+
expect(typeof Symbol.iterator).toEqual('symbol')
|
35
|
+
})
|
36
|
+
|
37
|
+
test('Undefined', () => {
|
38
|
+
expect(typeof undefined).toEqual('undefined')
|
39
|
+
expect(typeof declaredButUndefinedVariable).toEqual('undefined')
|
40
|
+
expect(typeof undeclaredVariable).toEqual('undefined')
|
41
|
+
})
|
42
|
+
|
43
|
+
test('Object', () => {
|
44
|
+
expect(typeof { a: 1 }).toEqual('object')
|
45
|
+
|
46
|
+
// use Array.isArray or Object.prototype.toString.call
|
47
|
+
// to differentiate regular objects from arrays
|
48
|
+
expect(typeof [1, 2, 4]).toEqual('object')
|
49
|
+
|
50
|
+
expect(typeof new Date()).toEqual('object')
|
51
|
+
expect(typeof /regex/).toEqual('object') // See Regular expressions section for historical results
|
52
|
+
|
53
|
+
// The following are confusing, dangerous, and wasteful. Avoid them.
|
54
|
+
expect(typeof new Boolean(true)).toEqual('object')
|
55
|
+
expect(typeof new Number(1)).toEqual('object')
|
56
|
+
expect(typeof new String('abc')).toEqual('object')
|
57
|
+
})
|
58
|
+
|
59
|
+
test('Function', () => {
|
60
|
+
expect(typeof function () { }).toEqual('function')
|
61
|
+
expect(typeof class C { }).toEqual('function')
|
62
|
+
expect(typeof Math.sin).toEqual('function')
|
63
|
+
})
|
64
|
+
})
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/// 这个字符串数组列举了JavaScript 中所有基本数据类型(primitive types)的名称。typeof 返回值域
|
2
|
+
export const types = [
|
3
|
+
"undefined", // 未定义类型,表示未赋值的变量
|
4
|
+
"object", // 对象类型(包括 null 和所有对象/数组/日期等)
|
5
|
+
"boolean", // 布尔类型(true/false)
|
6
|
+
"number", // 数字类型(包括整数和浮点数)
|
7
|
+
"bigint", // 大整数类型(ES2020 新增,表示任意精度的整数)
|
8
|
+
"string", // 字符串类型
|
9
|
+
"symbol", // Symbol 类型(ES2015 新增,表示唯一标识符)
|
10
|
+
"function" // 函数类型(虽然 typeof 返回 'function',但函数本质是 object 的子类型)
|
11
|
+
]
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { BehaviorSubject, Observable } from 'rxjs';
|
2
|
+
|
3
|
+
export declare class Deep<T> {
|
4
|
+
constructor(entries: [(string | number)[], T][]);
|
5
|
+
|
6
|
+
readonly entries: [(string | number)[], T][];
|
7
|
+
readonly keys: (string | number)[][];
|
8
|
+
getValues(): T[];
|
9
|
+
|
10
|
+
/**
|
11
|
+
* 将深度数据结构转换为普通对象。
|
12
|
+
*
|
13
|
+
* @returns {Record<string|number, any>} 转换后的普通对象。
|
14
|
+
*/
|
15
|
+
toObject(): Record<string | number, any>;
|
16
|
+
|
17
|
+
findIndex(searchKeyPath: (string | number)[]): number;
|
18
|
+
|
19
|
+
structuralEqual(keys: (string | number)[][]): boolean;
|
20
|
+
structuralSubset(keys: (string | number)[][]): boolean;
|
21
|
+
structuralSuperset(keys: (string | number)[][]): boolean;
|
22
|
+
|
23
|
+
intersect(keys: (string | number)[][]): Deep<T>;
|
24
|
+
difference(keys: (string | number)[][]): Deep<T>;
|
25
|
+
/**
|
26
|
+
* 后来者赢(参数赢)
|
27
|
+
* @param entries
|
28
|
+
*/
|
29
|
+
union(entries: [(string | number)[], T][]): Deep<T>;
|
30
|
+
|
31
|
+
map<U>(
|
32
|
+
callbackfn: (value: [(string | number)[], T], index: number, array: [(string | number)[], T][]) => U,
|
33
|
+
thisArg?: any
|
34
|
+
): Deep<U>;
|
35
|
+
filter(
|
36
|
+
predicate: (value: [(string | number)[], T], index: number, array: [(string | number)[], T][]) => boolean,
|
37
|
+
thisArg?: any
|
38
|
+
): Deep<T>;
|
39
|
+
forEach(
|
40
|
+
callbackfn: (value: [(string | number)[], T], index: number, array: [(string | number)[], T][]) => void,
|
41
|
+
thisArg?: any
|
42
|
+
): void;
|
43
|
+
|
44
|
+
freshValue(obj: Record<string | number, any>): Deep<any>;
|
45
|
+
replaceValue<U>(values: U[]): Deep<U>;
|
46
|
+
zipValue<U>(values: U[]): Deep<[T, U]>;
|
47
|
+
|
48
|
+
combineLatest<U>(): Observable<Deep<U>>;
|
49
|
+
merge<U>(): Observable<[(string | number)[], U]>;
|
50
|
+
|
51
|
+
static fromObject(
|
52
|
+
obj: Record<string | number, any>,
|
53
|
+
filter?: (value: any, key: string | number, keyPath: (string | number)[]) => boolean
|
54
|
+
): Deep<any>;
|
55
|
+
static fromBehaviorSubject(obj: Record<string | number, any>): Deep<BehaviorSubject<any>>;
|
56
|
+
static fromObservable(obj: Record<string | number, any>): Deep<Observable<any>>;
|
57
|
+
}
|
58
|
+
|
package/src/deep/Deep.js
ADDED
@@ -0,0 +1,267 @@
|
|
1
|
+
import { BehaviorSubject, isObservable, Observable, combineLatest, from, Subscription } from 'rxjs'
|
2
|
+
import { map, mergeMap } from 'rxjs/operators'
|
3
|
+
|
4
|
+
import { zipArray } from "../array"
|
5
|
+
import { pluckProperty } from '../object'
|
6
|
+
import { keyPathComparer, entryComparer } from '../comparers'
|
7
|
+
import { tojs, flat } from '../structures'
|
8
|
+
import { intersectEntries } from './intersectEntries'
|
9
|
+
|
10
|
+
|
11
|
+
/**
|
12
|
+
* 深度(嵌套)数据结构类,用于处理按键路径排序的键值对集合。
|
13
|
+
* 提供了多种操作方法,包括集合操作、序列操作和数据转换。
|
14
|
+
*
|
15
|
+
* @template T
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
export class Deep {
|
19
|
+
/**
|
20
|
+
* 构造函数。
|
21
|
+
*
|
22
|
+
* @param {[(string|number)[], T][]} entries - 按键路径排序的键值对数组。键值对已经按keypath排序。
|
23
|
+
*/
|
24
|
+
constructor(entries) {
|
25
|
+
this._entries = entries
|
26
|
+
this._keys = this._entries.map(([k]) => k)
|
27
|
+
}
|
28
|
+
|
29
|
+
///基本數據屬性
|
30
|
+
|
31
|
+
get entries() { return this._entries }
|
32
|
+
|
33
|
+
get keys() { return this._keys }
|
34
|
+
|
35
|
+
getValues() {
|
36
|
+
return this.entries.map(([k, v]) => v)
|
37
|
+
}
|
38
|
+
|
39
|
+
///构造正常数据对象
|
40
|
+
/**
|
41
|
+
* 将深度数据结构转换为普通对象。
|
42
|
+
*
|
43
|
+
* @returns {Record<string|number, any>} 转换后的普通对象。
|
44
|
+
*/
|
45
|
+
toObject() {
|
46
|
+
return tojs(this.entries)
|
47
|
+
}
|
48
|
+
|
49
|
+
///單個讀取
|
50
|
+
|
51
|
+
/**
|
52
|
+
*
|
53
|
+
* @param {(string|number)[]} searchKeyPath
|
54
|
+
* @returns
|
55
|
+
*/
|
56
|
+
findIndex(searchKeyPath) {
|
57
|
+
return keyPathComparer.findIndexInSet(this.keys, searchKeyPath)
|
58
|
+
}
|
59
|
+
|
60
|
+
///集合操作
|
61
|
+
|
62
|
+
/**
|
63
|
+
*
|
64
|
+
* @param {(string|number)[][]} keys
|
65
|
+
* @returns
|
66
|
+
*/
|
67
|
+
structuralEqual(keys) {
|
68
|
+
return keyPathComparer.isEqualset(this.keys, keys)
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
*
|
73
|
+
* @param {(string|number)[][]} keys
|
74
|
+
* @returns
|
75
|
+
*/
|
76
|
+
structuralSubset(keys) {
|
77
|
+
return keyPathComparer.isSubset(this.keys, keys)
|
78
|
+
}
|
79
|
+
|
80
|
+
/**
|
81
|
+
*
|
82
|
+
* @param {(string|number)[][]} keys
|
83
|
+
* @returns
|
84
|
+
*/
|
85
|
+
structuralSuperset(keys) {
|
86
|
+
return keyPathComparer.isSuperset(this.keys, keys)
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* @param {(string|number)[][]} keys
|
91
|
+
* @this {Deep<T>}
|
92
|
+
* @returns {Deep<T>}
|
93
|
+
*/
|
94
|
+
intersect(keys) {
|
95
|
+
let entries = intersectEntries(this.entries, keys)
|
96
|
+
return new Deep(entries)
|
97
|
+
}
|
98
|
+
|
99
|
+
/**
|
100
|
+
*
|
101
|
+
* @param {(string|number)[][]} keys
|
102
|
+
* @this {Deep<T>}
|
103
|
+
* @returns {Deep<T>}
|
104
|
+
*/
|
105
|
+
difference(keys) {
|
106
|
+
let newkeys = keyPathComparer.differenceSet(this.keys, keys)
|
107
|
+
return this.intersect(newkeys)
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* 后来者赢(参数赢)
|
112
|
+
* @param {[(string | number)[], T][]} entries
|
113
|
+
* @returns
|
114
|
+
*/
|
115
|
+
union(entries) {
|
116
|
+
let entries2 = entryComparer.sort([...this.entries, ...entries])
|
117
|
+
return new Deep(entries2)
|
118
|
+
}
|
119
|
+
|
120
|
+
|
121
|
+
/// 序列操作符
|
122
|
+
|
123
|
+
/**
|
124
|
+
*
|
125
|
+
* @template U
|
126
|
+
* @param {(value: [(string | number)[], T], index: number, array: [(string | number)[], T][]) => U} callbackfn 返回的是值,而不是键值对,KeyPath保持不变
|
127
|
+
* @param {Deep<T>} [thisArg]
|
128
|
+
* @this {Deep<T>}
|
129
|
+
* @returns {Deep<U>}
|
130
|
+
*
|
131
|
+
*/
|
132
|
+
map(callbackfn, thisArg) {
|
133
|
+
let values = this.entries.map(callbackfn, thisArg)
|
134
|
+
return this.replaceValue(values)
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
*
|
139
|
+
* @param {(value: [(string | number)[], T], index: number, array: [(string | number)[], T][]) => boolean} predicate
|
140
|
+
* @param {Deep<T>} [thisArg]
|
141
|
+
* @returns
|
142
|
+
*/
|
143
|
+
filter(predicate, thisArg) {
|
144
|
+
let entries = this.entries.filter(predicate, thisArg)
|
145
|
+
return new Deep(entries)
|
146
|
+
}
|
147
|
+
|
148
|
+
/**
|
149
|
+
*
|
150
|
+
* @param { (value: [(string | number)[], T], index: number, array: [(string | number)[], T][]) => void} callbackfn
|
151
|
+
* @param {Deep<T>} [thisArg]
|
152
|
+
* @returns
|
153
|
+
*/
|
154
|
+
forEach(callbackfn, thisArg) {
|
155
|
+
this.entries.forEach(callbackfn, thisArg)
|
156
|
+
}
|
157
|
+
|
158
|
+
/// 值操作
|
159
|
+
|
160
|
+
/**
|
161
|
+
* 修改部分个别数值
|
162
|
+
* @param {Record<string|number,any>} obj
|
163
|
+
* @this {Deep<T>}
|
164
|
+
* @returns
|
165
|
+
*/
|
166
|
+
freshValue(obj) {
|
167
|
+
let entries = this.keys.map(
|
168
|
+
/**
|
169
|
+
* @returns {[(string | number)[],any]}
|
170
|
+
*/
|
171
|
+
k => [k, pluckProperty(obj, k)]
|
172
|
+
)
|
173
|
+
return new Deep(entries)
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
/**
|
178
|
+
* 按列替换数值
|
179
|
+
* @template U
|
180
|
+
* @param {U[]} values
|
181
|
+
* @this {Deep<T>}
|
182
|
+
* @returns {Deep<U>}
|
183
|
+
*/
|
184
|
+
replaceValue(values) {
|
185
|
+
let entries = zipArray(this.keys, values)
|
186
|
+
return new Deep(entries)
|
187
|
+
}
|
188
|
+
|
189
|
+
/**
|
190
|
+
* 按列替换数值,保留原有数值
|
191
|
+
* @template U
|
192
|
+
* @param {U[]} values
|
193
|
+
* @this {Deep<T>}
|
194
|
+
* @returns {Deep<[T,U]>}
|
195
|
+
*/
|
196
|
+
zipValue(values) {
|
197
|
+
return this.replaceValue(zipArray(this.getValues(), values))
|
198
|
+
}
|
199
|
+
|
200
|
+
/// rxjs操作符
|
201
|
+
|
202
|
+
/**
|
203
|
+
* 返回Observable of 总体的当前值
|
204
|
+
* @template U
|
205
|
+
* @this {Deep<Observable<U>>}
|
206
|
+
* @returns {Observable<Deep<U>>}
|
207
|
+
*/
|
208
|
+
combineLatest() {
|
209
|
+
let values = this.getValues()
|
210
|
+
return combineLatest(values).pipe(
|
211
|
+
map(values => this.replaceValue(values))
|
212
|
+
)
|
213
|
+
}
|
214
|
+
|
215
|
+
/**
|
216
|
+
* 返回发射消息的那一个成员的路径以及新值。
|
217
|
+
* @template U
|
218
|
+
* @this {Deep<Observable<U>>}
|
219
|
+
* @returns {Observable<[(string|number)[], U]>}
|
220
|
+
*/
|
221
|
+
merge() {
|
222
|
+
return from(this.entries).pipe(
|
223
|
+
mergeMap(([keyPath, value$]) =>
|
224
|
+
value$.pipe(
|
225
|
+
map(
|
226
|
+
/**
|
227
|
+
* @returns {[(string|number)[], U]}
|
228
|
+
*/
|
229
|
+
value => [keyPath, value])
|
230
|
+
)))
|
231
|
+
}
|
232
|
+
|
233
|
+
/// 静态构造方法
|
234
|
+
|
235
|
+
/**
|
236
|
+
*
|
237
|
+
* @param {{[_:string|number]:any}} obj
|
238
|
+
* @param {(value: any, key: string | number, keyPath: (string | number)[]) => boolean} [filter]
|
239
|
+
* @returns
|
240
|
+
*/
|
241
|
+
static fromObject(obj, filter = () => false) {
|
242
|
+
let arr = flat(obj, filter)
|
243
|
+
let entries = entryComparer.sort(arr)
|
244
|
+
return new Deep(entries)
|
245
|
+
}
|
246
|
+
|
247
|
+
/**
|
248
|
+
* @template T
|
249
|
+
* @param {{[_:string|number]:any}} obj
|
250
|
+
* @returns {Deep<BehaviorSubject<T>>}
|
251
|
+
*/
|
252
|
+
static fromBehaviorSubject(obj) {
|
253
|
+
return Deep.fromObject(obj, v => isObservable(v) || v instanceof Subscription)
|
254
|
+
.filter(([k, v]) => v instanceof BehaviorSubject)
|
255
|
+
}
|
256
|
+
|
257
|
+
/**
|
258
|
+
* @template T
|
259
|
+
* @param {{[_:string|number]:any}} obj
|
260
|
+
* @returns
|
261
|
+
*/
|
262
|
+
static fromObservable(obj) {
|
263
|
+
return Deep.fromObject(obj, v => isObservable(v) || v instanceof Subscription)
|
264
|
+
.filter(([k, v]) => isObservable(v))
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
@@ -0,0 +1,130 @@
|
|
1
|
+
import { Deep } from './Deep'
|
2
|
+
|
3
|
+
// let data = {
|
4
|
+
// a: {
|
5
|
+
// a: 0,
|
6
|
+
// b: 1,
|
7
|
+
// },
|
8
|
+
// b: [2, 3],
|
9
|
+
// }
|
10
|
+
|
11
|
+
// let entries = [[['a', 'a'], 0], [['a', 'b'], 1], [['b', 0], 2], [['b', 1], 3]]
|
12
|
+
|
13
|
+
test('constructor entries', () => {
|
14
|
+
let entries = [[['a', 'a'], 0], [['a', 'b'], 1], [['b', 0], 2], [['b', 1], 3]]
|
15
|
+
let deep = new Deep(entries)
|
16
|
+
let y = deep.entries
|
17
|
+
expect(y).toEqual(entries)
|
18
|
+
})
|
19
|
+
|
20
|
+
test('deep keys', () => {
|
21
|
+
let entries = [[['a', 'a'], 0], [['a', 'b'], 1], [['b', 0], 2], [['b', 1], 3]]
|
22
|
+
let deep = new Deep(entries)
|
23
|
+
|
24
|
+
let keys = [['a', 'a'], ['a', 'b'], ['b', 0], ['b', 1]]
|
25
|
+
expect(deep.keys).toEqual(keys)
|
26
|
+
})
|
27
|
+
|
28
|
+
test('deep getValues', () => {
|
29
|
+
let entries = [[['a', 'a'], 0], [['a', 'b'], 1], [['b', 0], 2], [['b', 1], 3]]
|
30
|
+
let deep = new Deep(entries)
|
31
|
+
let values = [0, 1, 2, 3]
|
32
|
+
expect(deep.getValues()).toEqual(values)
|
33
|
+
})
|
34
|
+
|
35
|
+
test('deep toObject', () => {
|
36
|
+
let entries = [[['a', 'a'], 0], [['a', 'b'], 1], [['b', 0], 2], [['b', 1], 3]]
|
37
|
+
let deep = new Deep(entries)
|
38
|
+
let data = {
|
39
|
+
a: {
|
40
|
+
a: 0,
|
41
|
+
b: 1,
|
42
|
+
},
|
43
|
+
b: [2, 3],
|
44
|
+
}
|
45
|
+
expect(deep.toObject()).toEqual(data)
|
46
|
+
})
|
47
|
+
|
48
|
+
test('deep findIndex', () => {
|
49
|
+
let entries = [[['a', 'a'], 0], [['a', 'b'], 1], [['b', 0], 2], [['b', 1], 3]]
|
50
|
+
let deep = new Deep(entries)
|
51
|
+
let keyPath = ['a', 'b']
|
52
|
+
expect(deep.findIndex(keyPath)).toEqual(1)
|
53
|
+
})
|
54
|
+
|
55
|
+
test('keys & values', () => {
|
56
|
+
let entries = [[['a'], 0], [['b'], 1], [['c', 0], 2], [['c', 1], 3], [['c', 2, 'e'], 4]]
|
57
|
+
|
58
|
+
let deep = new Deep(entries)
|
59
|
+
|
60
|
+
let keys = [['a'], ['b'], ['c', 0], ['c', 1], ['c', 2, 'e']]
|
61
|
+
|
62
|
+
expect(deep.keys).toEqual(keys)
|
63
|
+
expect(deep.getValues()).toEqual([0, 1, 2, 3, 4])
|
64
|
+
})
|
65
|
+
|
66
|
+
test('find index', () => {
|
67
|
+
let entries = [[['a'], 0], [['b'], 1], [['c', 0], 2], [['c', 1], 3], [['c', 2, 'e'], 4]]
|
68
|
+
|
69
|
+
let deep = new Deep(entries)
|
70
|
+
|
71
|
+
let i = deep.findIndex(['c', 0])
|
72
|
+
expect(i).toEqual(2)
|
73
|
+
|
74
|
+
let j = deep.findIndex(['no exist', 0])
|
75
|
+
expect(j).toEqual(-1)
|
76
|
+
})
|
77
|
+
|
78
|
+
test('test to object', () => {
|
79
|
+
let entries = [[['a'], 0], [['b'], 1], [['c', 0], 2], [['c', 1], 3], [['c', 2, 'e'], 4]]
|
80
|
+
|
81
|
+
let deep = new Deep(entries)
|
82
|
+
let obj = {
|
83
|
+
a: 0,
|
84
|
+
b: 1,
|
85
|
+
c: [
|
86
|
+
2,
|
87
|
+
3,
|
88
|
+
{
|
89
|
+
e: 4,
|
90
|
+
},
|
91
|
+
],
|
92
|
+
}
|
93
|
+
|
94
|
+
expect(deep.toObject()).toEqual(obj)
|
95
|
+
})
|
96
|
+
|
97
|
+
describe('structural comparison', () => {
|
98
|
+
test('structuralEqual', () => {
|
99
|
+
let deep = new Deep([[['a'], 0], [['b'], 1], [['c', 0], 2], [['c', 1], 3], [['c', 2, 'e'], 4]])
|
100
|
+
let keys = [['a'], ['b'], ['c', 0], ['c', 1], ['c', 2, 'e']]
|
101
|
+
let y = deep.structuralEqual(keys)
|
102
|
+
expect(y).toEqual(true)
|
103
|
+
})
|
104
|
+
|
105
|
+
test('structuralSubset', () => {
|
106
|
+
let deep = new Deep([[['a'], 0], [['c', 0], 2], [['c', 1], 3], [['c', 2, 'e'], 4]])
|
107
|
+
let keys = [
|
108
|
+
['a'],
|
109
|
+
['b'], //*
|
110
|
+
['c', 0],
|
111
|
+
['c', 1],
|
112
|
+
['c', 2, 'e'],
|
113
|
+
]
|
114
|
+
let y = deep.structuralSubset(keys)
|
115
|
+
expect(y).toEqual(true)
|
116
|
+
})
|
117
|
+
|
118
|
+
test('structuralSuperset', () => {
|
119
|
+
let deep = new Deep([[['a'], 0], [['b'], 1], [['c', 0], 2], [['c', 1], 3], [['c', 2, 'e'], 4]])
|
120
|
+
let keys = [
|
121
|
+
['a'],
|
122
|
+
//['b'],
|
123
|
+
['c', 0],
|
124
|
+
['c', 1],
|
125
|
+
['c', 2, 'e'],
|
126
|
+
]
|
127
|
+
let y = deep.structuralSuperset(keys)
|
128
|
+
expect(y).toEqual(true)
|
129
|
+
})
|
130
|
+
})
|