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,22 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Determines if two sets are equal.
|
4
|
+
*
|
5
|
+
* - Two sets are considered equal if they have exactly the same members.
|
6
|
+
* - Assumes both `set1` and `set2` are sorted in ascending order.
|
7
|
+
* - Uses the provided `compare` function to determine the order and equality of elements.
|
8
|
+
*
|
9
|
+
* @param set1 - The first sorted set.
|
10
|
+
* @param set2 - The second sorted set.
|
11
|
+
* @param compare - A comparison function that takes two elements and returns:
|
12
|
+
* - A negative number if the first element is less than the second.
|
13
|
+
* - 0 if the elements are equal.
|
14
|
+
* - A positive number if the first element is greater than the second.
|
15
|
+
* Default is `defaultCompare`.
|
16
|
+
* @returns `true` if `set1` and `set2` are equal, otherwise `false`.
|
17
|
+
*/
|
18
|
+
export function isEqualset<T>(
|
19
|
+
set1: T[],
|
20
|
+
set2: T[],
|
21
|
+
compare: (a: T, b: T) => number
|
22
|
+
): boolean;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/**
|
2
|
+
* 判断两个集合是否相等(成员完全相同,顺序无关)。
|
3
|
+
* @template T
|
4
|
+
* @param {T[]} set1 - 第一个集合
|
5
|
+
* @param {T[]} set2 - 第二个集合
|
6
|
+
* @param {(a: T, b: T) => number} compare - 比较函数
|
7
|
+
* @returns {boolean} 如果集合相等返回 true,否则返回 false
|
8
|
+
*/
|
9
|
+
export function isEqualset(set1, set2, compare) {
|
10
|
+
/**
|
11
|
+
* @param {T[]} a
|
12
|
+
* @param {T[]} b
|
13
|
+
* @returns {boolean}
|
14
|
+
*/
|
15
|
+
function loop(a, b) {
|
16
|
+
if (a.length === 0 && b.length === 0) {
|
17
|
+
return true
|
18
|
+
}
|
19
|
+
|
20
|
+
if (a.length > 0 && b.length > 0) {
|
21
|
+
let [a0, ...aa] = a
|
22
|
+
let [b0, ...bb] = b
|
23
|
+
if (compare(a0, b0) === 0) {
|
24
|
+
return loop(aa, bb)
|
25
|
+
} else {
|
26
|
+
return false
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
return false
|
31
|
+
}
|
32
|
+
return loop(set1, set2)
|
33
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { compareKeyPath, defaultCompare } from '../comparison'
|
2
|
+
import { isEqualset } from './isEqualset'
|
3
|
+
|
4
|
+
describe('set ops block', () => {
|
5
|
+
test('isEqualset test', () => {
|
6
|
+
let a = [1, 2]
|
7
|
+
let b = [1, 3]
|
8
|
+
let c = [1, 2, 3]
|
9
|
+
|
10
|
+
expect(isEqualset(a, [...a], defaultCompare)).toEqual(true)
|
11
|
+
expect(isEqualset(a, b, defaultCompare)).toEqual(false)
|
12
|
+
expect(isEqualset(a, c, defaultCompare)).toEqual(false)
|
13
|
+
expect(isEqualset(b, c, defaultCompare)).toEqual(false)
|
14
|
+
})
|
15
|
+
|
16
|
+
test('isequal keypath test', () => {
|
17
|
+
let a = [[1, 2], ['a', 'b']]
|
18
|
+
let b = [[1, 2], ['a', 'b']]
|
19
|
+
|
20
|
+
expect(isEqualset(a, b, compareKeyPath)).toEqual(true)
|
21
|
+
})
|
22
|
+
})
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Determines if `set1` is a subset of `set2`.
|
4
|
+
*
|
5
|
+
* - Assumes both `set1` and `set2` are sorted in ascending order.
|
6
|
+
* - Uses the provided `compare` function to determine the order and equality of elements.
|
7
|
+
*
|
8
|
+
* @param set1 - The first sorted set (potential subset).
|
9
|
+
* @param set2 - The second sorted set (potential superset).
|
10
|
+
* @param compare - A comparison function that takes two elements and returns:
|
11
|
+
* - A negative number if the first element is less than the second.
|
12
|
+
* - 0 if the elements are equal.
|
13
|
+
* - A positive number if the first element is greater than the second.
|
14
|
+
* Default is `defaultCompare`.
|
15
|
+
* @returns `true` if `set1` is a subset of `set2`, otherwise `false`.
|
16
|
+
*/
|
17
|
+
export function isSubset<T>(
|
18
|
+
set1: T[],
|
19
|
+
set2: T[],
|
20
|
+
compare?: (a: T, b: T) => number
|
21
|
+
): boolean;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/**
|
2
|
+
* 判断 set1 是否为 set2 的子集(假定已排序)。
|
3
|
+
* @template T
|
4
|
+
* @param {T[]} set1 - 可能为子集的数组
|
5
|
+
* @param {T[]} set2 - 可能为超集的数组
|
6
|
+
* @param {(a: T, b: T) => number} compare - 比较函数
|
7
|
+
* @returns {boolean} 如果 set1 是 set2 的子集返回 true,否则返回 false
|
8
|
+
*/
|
9
|
+
export function isSubset(set1, set2, compare) {
|
10
|
+
/**
|
11
|
+
* @param {T[]} a
|
12
|
+
* @param {T[]} b
|
13
|
+
* @returns {boolean}
|
14
|
+
*/
|
15
|
+
function loop(a, b) {
|
16
|
+
if (a.length === 0) {
|
17
|
+
return true
|
18
|
+
} else if (b.length === 0) {
|
19
|
+
return false
|
20
|
+
} else {
|
21
|
+
switch (Math.sign(compare(a[0], b[0]))) {
|
22
|
+
case -1:
|
23
|
+
return false
|
24
|
+
case 0:
|
25
|
+
return loop(a.slice(1), b.slice(1))
|
26
|
+
case 1:
|
27
|
+
default:
|
28
|
+
return loop(a, b.slice(1))
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
return loop(set1, set2)
|
33
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { isSubset } from './isSubset'
|
2
|
+
import { compareKeyPath, defaultCompare } from '../comparison'
|
3
|
+
|
4
|
+
describe('isSubset block', () => {
|
5
|
+
test('isSubset test', () => {
|
6
|
+
let a = [1, 2]
|
7
|
+
let b = [1, 3]
|
8
|
+
let c = [1, 2, 3]
|
9
|
+
|
10
|
+
expect(isSubset(a, [...a], defaultCompare)).toEqual(true)
|
11
|
+
expect(isSubset(a, b, defaultCompare)).toEqual(false)
|
12
|
+
expect(isSubset(a, c, defaultCompare)).toEqual(true)
|
13
|
+
})
|
14
|
+
|
15
|
+
test('isSubset keypath test', () => {
|
16
|
+
let a = [[1, 2], ['a', 'b']]
|
17
|
+
let b = [[1, 2], ['a', 'b'], [3, 'x']]
|
18
|
+
|
19
|
+
expect(isSubset(a, b, compareKeyPath)).toEqual(true)
|
20
|
+
})
|
21
|
+
})
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Determines if `a` is a superset of `b`.
|
4
|
+
*
|
5
|
+
* - Assumes both `a` and `b` are sorted in ascending order.
|
6
|
+
* - Uses the provided `compare` function to determine the order and equality of elements.
|
7
|
+
*
|
8
|
+
* @param a - The first sorted set (potential superset).
|
9
|
+
* @param b - The second sorted set (potential subset).
|
10
|
+
* @param compare - A comparison function that takes two elements and returns:
|
11
|
+
* - A negative number if the first element is less than the second.
|
12
|
+
* - 0 if the elements are equal.
|
13
|
+
* - A positive number if the first element is greater than the second.
|
14
|
+
* Default is `defaultCompare`.
|
15
|
+
* @returns `true` if `a` is a superset of `b`, otherwise `false`.
|
16
|
+
*/
|
17
|
+
export function isSuperset<T>(
|
18
|
+
a: T[],
|
19
|
+
b: T[],
|
20
|
+
compare?: (a: T, b: T) => number
|
21
|
+
): boolean;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { isSubset } from './isSubset'
|
2
|
+
|
3
|
+
/**
|
4
|
+
* 判断 a 是否为 b 的超集(假定已排序)。
|
5
|
+
* @template T
|
6
|
+
* @param {T[]} a - 可能为超集的数组
|
7
|
+
* @param {T[]} b - 可能为子集的数组
|
8
|
+
* @param {(x: T, y: T) => number} compare - 比较函数
|
9
|
+
* @returns {boolean} 如果 a 是 b 的超集返回 true,否则返回 false
|
10
|
+
*/
|
11
|
+
export function isSuperset(a, b, compare) {
|
12
|
+
return isSubset(b, a, compare)
|
13
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { isSuperset } from './isSuperset'
|
2
|
+
import { compareKeyPath, defaultCompare } from '../comparison'
|
3
|
+
|
4
|
+
describe('isSuperset block', () => {
|
5
|
+
test('isSuperset test', () => {
|
6
|
+
let a = [1, 2]
|
7
|
+
let b = [1, 3]
|
8
|
+
let c = [1, 2, 3]
|
9
|
+
|
10
|
+
expect(isSuperset(a, [...a], defaultCompare)).toEqual(true)
|
11
|
+
expect(isSuperset(a, b, defaultCompare)).toEqual(false)
|
12
|
+
expect(isSuperset(c, a, defaultCompare)).toEqual(true)
|
13
|
+
})
|
14
|
+
|
15
|
+
test('isSuperset keypath test', () => {
|
16
|
+
let a = [[1, 2], ['a', 'b'], [3, 'x']]
|
17
|
+
let b = [[1, 2], ['a', 'b']]
|
18
|
+
|
19
|
+
expect(isSuperset(a, b, compareKeyPath)).toEqual(true)
|
20
|
+
})
|
21
|
+
})
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Removes duplicates from a sorted array.
|
4
|
+
*
|
5
|
+
* - Assumes the input array is sorted in ascending order.
|
6
|
+
* - Throws an error if the array is not sorted correctly.
|
7
|
+
*
|
8
|
+
* @param sortedArray - The input array, which must be sorted in ascending order.
|
9
|
+
* @param compare - A comparison function that takes two elements and returns:
|
10
|
+
* - A negative number if the first element is less than the second.
|
11
|
+
* - 0 if the elements are equal.
|
12
|
+
* - A positive number if the first element is greater than the second.
|
13
|
+
* Default is `defaultCompare`.
|
14
|
+
* @returns A new array with duplicates removed.
|
15
|
+
* @throws Will throw an error if the input array is not sorted in ascending order.
|
16
|
+
*/
|
17
|
+
export function sortedArrayToSet<T>(
|
18
|
+
sortedArray: T[],
|
19
|
+
compare: (a: T, b: T) => number
|
20
|
+
): T[];
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/**
|
2
|
+
* 数组去重,排序好后的数组去重。
|
3
|
+
* @template T
|
4
|
+
* @param {T[]} sortedArray - 已排序的数组
|
5
|
+
* @param {(a: T, b: T) => number} compare - 比较函数
|
6
|
+
* @returns {T[]} 去重后的新数组
|
7
|
+
*/
|
8
|
+
export function sortedArrayToSet(sortedArray, compare) {
|
9
|
+
/**
|
10
|
+
* @param {T[]} acc - 当前结果
|
11
|
+
* @param {T[]} sarray - 剩余待处理的数组
|
12
|
+
* @returns {T[]} 去重后的新数组
|
13
|
+
*/
|
14
|
+
function loop(acc, sarray) {
|
15
|
+
if (sarray.length === 0) {
|
16
|
+
return acc
|
17
|
+
} else {
|
18
|
+
switch (Math.sign(compare(acc[acc.length - 1], sarray[0]))) {
|
19
|
+
case -1:
|
20
|
+
return loop([...acc, sarray[0]], sarray.slice(1))
|
21
|
+
case 0:
|
22
|
+
return loop(acc, sarray.slice(1))
|
23
|
+
case 1:
|
24
|
+
default:
|
25
|
+
throw new Error('sort ascent')
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
if (sortedArray.length === 0) {
|
31
|
+
return []
|
32
|
+
} else {
|
33
|
+
return loop([sortedArray[0]], sortedArray.slice(1))
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { sortedArrayToSet } from './sortedArrayToSet'
|
2
|
+
import { compareKeyPath, defaultCompare } from '../comparison'
|
3
|
+
|
4
|
+
describe('sortedArrayToSet block', () => {
|
5
|
+
test('sortedArrayToSet', () => {
|
6
|
+
//输入数组应该用相同的比较函数先排序一遍
|
7
|
+
let sortedArray = ['A', 'B', 'B', 'C']
|
8
|
+
let y = sortedArrayToSet(sortedArray, defaultCompare)
|
9
|
+
expect(y).toEqual(['A', 'B', 'C'])
|
10
|
+
})
|
11
|
+
})
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Computes the union of two sorted sets.
|
4
|
+
*
|
5
|
+
* - Assumes both `set1` and `set2` are sorted.
|
6
|
+
* - Uses the provided `compare` function to determine the order and equality of elements.
|
7
|
+
*
|
8
|
+
* @param set1 - The first sorted set.
|
9
|
+
* @param set2 - The second sorted set.
|
10
|
+
* @param compare - A comparison function that takes two elements and returns:
|
11
|
+
* - A negative number if the first element is less than the second.
|
12
|
+
* - 0 if the elements are equal.
|
13
|
+
* - A positive number if the first element is greater than the second.
|
14
|
+
* Default is `defaultCompare`.
|
15
|
+
* @returns A new array containing all unique elements from both sets, sorted.
|
16
|
+
*/
|
17
|
+
export function unionSet<T>(
|
18
|
+
set1: T[],
|
19
|
+
set2: T[],
|
20
|
+
compare: (a: T, b: T) => number
|
21
|
+
): T[];
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/**
|
2
|
+
* 计算两个有序数组的并集(去重)。
|
3
|
+
* @template T
|
4
|
+
* @param {T[]} set1 - 第一个已排序的数组
|
5
|
+
* @param {T[]} set2 - 第二个已排序的数组
|
6
|
+
* @param {(a: T, b: T) => number} compare - 比较函数
|
7
|
+
* @returns {T[]} 并集后的新数组
|
8
|
+
*/
|
9
|
+
export function unionSet(set1, set2, compare) {
|
10
|
+
/**
|
11
|
+
* @param {T[]} acc - 当前结果
|
12
|
+
* @param {T[]} a - 剩余的 set1
|
13
|
+
* @param {T[]} b - 剩余的 set2
|
14
|
+
* @returns {T[]} 并集
|
15
|
+
*/
|
16
|
+
function loop(acc, a, b) {
|
17
|
+
if (a.length === 0) {
|
18
|
+
return [...acc, ...b]
|
19
|
+
} else if (b.length === 0) {
|
20
|
+
return [...acc, ...a]
|
21
|
+
} else {
|
22
|
+
switch (Math.sign(compare(a[0], b[0]))) {
|
23
|
+
case -1:
|
24
|
+
return loop([...acc, a[0]], a.slice(1), b)
|
25
|
+
case 0:
|
26
|
+
return loop([...acc, a[0]], a.slice(1), b.slice(1))
|
27
|
+
case 1:
|
28
|
+
default:
|
29
|
+
return loop([...acc, b[0]], a, b.slice(1))
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
return loop([], set1, set2)
|
34
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { unionSet } from './unionSet'
|
2
|
+
import { compareKeyPath, defaultCompare } from '../comparison'
|
3
|
+
|
4
|
+
describe('unionSet block', () => {})
|
5
|
+
|
6
|
+
test('unions two sets', () => {
|
7
|
+
const set1 = ['a', 'b', 'c']
|
8
|
+
const set2 = ['b', 'd', 'wow']
|
9
|
+
const set3 = unionSet(set1, set2, defaultCompare )
|
10
|
+
expect(set3).toEqual(['a', 'b', 'c', 'd', 'wow'])
|
11
|
+
})
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* Compares two dates by their numeric value.
|
3
|
+
*
|
4
|
+
* @param a - The first date to compare.
|
5
|
+
* @param b - The second date to compare.
|
6
|
+
* @returns A negative number if `a` is earlier than `b`, 0 if they are equal, or a positive number if `a` is later than `b`.
|
7
|
+
*/
|
8
|
+
export function compareDate(a: Date, b: Date): number;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* Compares two entries (key-value pairs) based on their key paths.
|
3
|
+
*
|
4
|
+
* - Uses `compareKeyPath` to compare the key paths of the two entries.
|
5
|
+
*
|
6
|
+
* @param entry1 - The first entry, where the key is a key path (array of keys).
|
7
|
+
* @param entry2 - The second entry, where the key is a key path (array of keys).
|
8
|
+
* @returns A negative number if `entry1` is less than `entry2`, 0 if they are equal, or a positive number if `entry1` is greater than `entry2`.
|
9
|
+
*/
|
10
|
+
export function compareEntries(
|
11
|
+
entry1: [(number | string)[], any],
|
12
|
+
entry2: [(number | string)[], any]
|
13
|
+
): number;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { compareKeyPath } from "./compareKeyPath"
|
2
|
+
|
3
|
+
/**
|
4
|
+
* 比较两个 entries(key-value 对)。依据他们的 key path。
|
5
|
+
*
|
6
|
+
* @public
|
7
|
+
* @param {[(number|string)[], any]} entry1 - 第一个 entry,key 为 key path(键路径数组)
|
8
|
+
* @param {[(number|string)[], any]} entry2 - 第二个 entry,key 为 key path(键路径数组)
|
9
|
+
* @returns {number} 若 entry1 < entry2 返回负数,相等返回 0,大于返回正数
|
10
|
+
*/
|
11
|
+
export function compareEntries([keypath1], [keypath2]) {
|
12
|
+
return compareKeyPath(keypath1, keypath2)
|
13
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* Compares two values and returns a number indicating their relative order.
|
3
|
+
*
|
4
|
+
* - If both values are of the same type, it uses `defaultCompare` for comparison.
|
5
|
+
* - Strings are considered greater than numbers.
|
6
|
+
*
|
7
|
+
* @param a - The first value to compare (can be a `number` or `string`).
|
8
|
+
* @param b - The second value to compare (can be a `number` or `string`).
|
9
|
+
* @returns A negative number if `a` is less than `b`, 0 if they are equal, or a positive number if `a` is greater than `b`.
|
10
|
+
*/
|
11
|
+
export function compareKey(a: number | string, b: number | string): number;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { defaultCompare } from './defaultCompare.js'
|
2
|
+
|
3
|
+
/**
|
4
|
+
*
|
5
|
+
* Compares two values and returns a number indicating their relative order.
|
6
|
+
* @param {number|string} a - The first value to compare.
|
7
|
+
* @param {number|string} b - The second value to compare.
|
8
|
+
* @returns {number} -1 if a < b, 1 if a > b, or 0 if they are equal.
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
export function compareKey(a, b) {
|
12
|
+
let type1 = typeof a
|
13
|
+
let type2 = typeof b
|
14
|
+
|
15
|
+
if (type1 === type2) {
|
16
|
+
return defaultCompare(a,b)
|
17
|
+
}
|
18
|
+
|
19
|
+
//string > number
|
20
|
+
if (type1 === 'string') {
|
21
|
+
return 1
|
22
|
+
}
|
23
|
+
|
24
|
+
return -1
|
25
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { compareKey } from './compareKey'
|
2
|
+
|
3
|
+
describe('compare key', () => {
|
4
|
+
test('number compare', () => {
|
5
|
+
expect(compareKey(1, 2)).toEqual(-1)
|
6
|
+
expect(compareKey(2, 2)).toEqual(0)
|
7
|
+
expect(compareKey(2, 1)).toEqual(1)
|
8
|
+
})
|
9
|
+
|
10
|
+
test('string compare', () => {
|
11
|
+
expect(compareKey("80", "9")).toEqual(-1)
|
12
|
+
expect(compareKey('80', '80')).toEqual(0)
|
13
|
+
expect(compareKey('9', '80')).toEqual(1)
|
14
|
+
})
|
15
|
+
|
16
|
+
test('number string compare', () => {
|
17
|
+
expect(compareKey(1, 'x')).toEqual(-1)
|
18
|
+
expect(compareKey('x', 1)).toEqual(1)
|
19
|
+
})
|
20
|
+
|
21
|
+
})
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { compareKey } from './compareKey';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Compares two key paths (arrays of keys) lexicographically.
|
5
|
+
*
|
6
|
+
* - Two empty arrays are considered equal.
|
7
|
+
* - An empty array is considered less than a non-empty array.
|
8
|
+
* - A non-empty array is considered greater than an empty array.
|
9
|
+
* - If the first elements of both arrays are equal, the comparison continues recursively with the remaining elements.
|
10
|
+
*
|
11
|
+
* @param a - The first key path (array of keys) to compare.
|
12
|
+
* @param b - The second key path (array of keys) to compare.
|
13
|
+
* @returns A negative number if `a` is less than `b`, 0 if they are equal, or a positive number if `a` is greater than `b`.
|
14
|
+
*/
|
15
|
+
export function compareKeyPath(a: (number | string)[], b: (number | string)[]): number;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { compareKey } from './compareKey.js'
|
2
|
+
|
3
|
+
/**
|
4
|
+
* 比较两个 key path(键路径数组)。
|
5
|
+
*
|
6
|
+
* @public
|
7
|
+
* @param {(number|string)[]} a - 第一个 key path
|
8
|
+
* @param {(number|string)[]} b - 第二个 key path
|
9
|
+
* @returns {number} 若 a < b 返回负数,相等返回 0,大于返回正数
|
10
|
+
*/
|
11
|
+
export function compareKeyPath(a, b) {
|
12
|
+
//两个空数组相等
|
13
|
+
if (a.length === 0 && b.length === 0) {
|
14
|
+
return 0
|
15
|
+
}
|
16
|
+
|
17
|
+
//空数组小于非空数组。
|
18
|
+
if (a.length === 0) {
|
19
|
+
return -1
|
20
|
+
}
|
21
|
+
|
22
|
+
//非空数组大于空数组。
|
23
|
+
if (b.length === 0) {
|
24
|
+
return 1
|
25
|
+
}
|
26
|
+
|
27
|
+
//两个数组每次从0位出一个元素,进行比较。
|
28
|
+
let [a0, ...aa] = a
|
29
|
+
let [b0, ...bb] = b
|
30
|
+
|
31
|
+
//两个元素相等,递归比较剩余数组。
|
32
|
+
return compareKey(a0, b0) || compareKeyPath(aa, bb)
|
33
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { compareKeyPath } from './compareKeyPath.js'
|
2
|
+
|
3
|
+
describe('compare key path', () => {
|
4
|
+
test('empty array compare', () => {
|
5
|
+
expect(compareKeyPath([], [1])).toEqual(-1)
|
6
|
+
expect(compareKeyPath([], [])).toEqual(0)
|
7
|
+
expect(compareKeyPath([1], [])).toEqual(1)
|
8
|
+
})
|
9
|
+
|
10
|
+
//可比元素不同
|
11
|
+
test('elem different compare', () => {
|
12
|
+
expect(compareKeyPath([0], [1])).toEqual(-1)
|
13
|
+
expect(compareKeyPath([0, 1], [1])).toEqual(-1)
|
14
|
+
expect(compareKeyPath([0], [1, 2])).toEqual(-1)
|
15
|
+
})
|
16
|
+
|
17
|
+
//可比元素相同,长度不同
|
18
|
+
test('elem same compare', () => {
|
19
|
+
expect(compareKeyPath([0], [0])).toEqual(0)
|
20
|
+
expect(compareKeyPath([0, 1], [0])).toEqual(1)
|
21
|
+
expect(compareKeyPath([0], [0, 2])).toEqual(-1)
|
22
|
+
})
|
23
|
+
|
24
|
+
test('example compare', () => {
|
25
|
+
expect(compareKeyPath(['key', 0], ['key', 1])).toEqual(-1)
|
26
|
+
})
|
27
|
+
|
28
|
+
})
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* Compares two numbers or bigints, including special handling for `NaN` and `Infinity`.
|
3
|
+
*
|
4
|
+
* - `NaN` is considered the largest value.
|
5
|
+
* - Supports comparison of `number` and `bigint` types.
|
6
|
+
*
|
7
|
+
* @param a - The first value to compare (can be `number` or `bigint`).
|
8
|
+
* @param b - The second value to compare (can be `number` or `bigint`).
|
9
|
+
* @returns A negative number if `a` is less than `b`, 0 if they are equal, or a positive number if `a` is greater than `b`.
|
10
|
+
*/
|
11
|
+
export function compareNumber(a: number | bigint, b: number | bigint): number;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { defaultCompare } from './defaultCompare'
|
2
|
+
|
3
|
+
/**
|
4
|
+
* 可以比较NaN,Infinity,number,bigint
|
5
|
+
* @param {number|bigint} a
|
6
|
+
* @param {number|bigint} b
|
7
|
+
*/
|
8
|
+
export function compareNumber(a, b) {
|
9
|
+
if (Number.isNaN(a) && Number.isNaN(b)) {
|
10
|
+
return 0
|
11
|
+
}
|
12
|
+
|
13
|
+
//NaN最大
|
14
|
+
if (Number.isNaN(a)) {
|
15
|
+
return 1
|
16
|
+
}
|
17
|
+
|
18
|
+
if (Number.isNaN(b)) {
|
19
|
+
return -1
|
20
|
+
}
|
21
|
+
|
22
|
+
return defaultCompare(a, b)
|
23
|
+
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { compareNumber } from './compareNumber'
|
2
|
+
|
3
|
+
describe('Basic usage', () => {
|
4
|
+
test('nan', () => {
|
5
|
+
expect(compareNumber(NaN, NaN)).toEqual(0)
|
6
|
+
})
|
7
|
+
|
8
|
+
test('nan Infinity', () => {
|
9
|
+
expect(compareNumber(NaN, Infinity)).toEqual(1)
|
10
|
+
expect(compareNumber(NaN, 0n)).toEqual(1)
|
11
|
+
|
12
|
+
})
|
13
|
+
|
14
|
+
test('Infinity bigint', () => {
|
15
|
+
expect(compareNumber(Infinity, 0n)).toEqual(1)
|
16
|
+
expect(compareNumber(-Infinity, 0n)).toEqual(-1)
|
17
|
+
})
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
})
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* Compares two values using the default comparison logic.
|
3
|
+
*
|
4
|
+
* @param a - The first value to compare.
|
5
|
+
* @param b - The second value to compare.
|
6
|
+
* @returns A negative number if `a` is less than `b`, 0 if they are equal, or a positive number if `a` is greater than `b`.
|
7
|
+
*/
|
8
|
+
export function defaultCompare<T>(a: T, b: T): number;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { defaultCompare } from './defaultCompare'
|
2
|
+
|
3
|
+
describe('Basic usage', () => {
|
4
|
+
test('Undefined', () => {
|
5
|
+
expect(defaultCompare(undefined, undefined)).toEqual(0)
|
6
|
+
})
|
7
|
+
|
8
|
+
test('null', () => {
|
9
|
+
expect(defaultCompare(null, null)).toEqual(0)
|
10
|
+
})
|
11
|
+
|
12
|
+
test('nan', () => {
|
13
|
+
expect(defaultCompare(NaN, NaN)).toEqual(0)
|
14
|
+
})
|
15
|
+
|
16
|
+
test('+ Infinity', () => {
|
17
|
+
expect(defaultCompare(Infinity, Infinity)).toEqual(0)
|
18
|
+
})
|
19
|
+
|
20
|
+
test('- Infinity', () => {
|
21
|
+
expect(defaultCompare(- Infinity, - Infinity)).toEqual(0)
|
22
|
+
})
|
23
|
+
|
24
|
+
})
|