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
package/package.json
CHANGED
@@ -3,38 +3,24 @@
|
|
3
3
|
"rxjs": "7.8.2"
|
4
4
|
},
|
5
5
|
"devDependencies": {
|
6
|
-
"@babel/runtime-corejs3": "7.27.6",
|
7
6
|
"@babel/core": "7.27.4",
|
8
|
-
"@babel/plugin-transform-runtime": "7.27.4",
|
9
7
|
"@babel/preset-env": "7.27.2",
|
10
|
-
"@microsoft/api-extractor": "7.52.8",
|
11
8
|
"@types/jest": "30.0.0",
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"jest": "30.0.0",
|
17
|
-
"jest-environment-jsdom": "30.0.0",
|
9
|
+
"babel-jest": "30.0.1",
|
10
|
+
"cross-env": "7.0.3",
|
11
|
+
"jest": "30.0.1",
|
12
|
+
"jest-environment-jsdom": "30.0.1",
|
18
13
|
"jsdom": "26.1.0",
|
19
|
-
"
|
20
|
-
"rxjs": "7.8.2",
|
21
|
-
"tslib": "2.8.1",
|
22
|
-
"typescript": "5.8.3",
|
23
|
-
"webpack": "5.99.9",
|
24
|
-
"webpack-cli": "6.0.1"
|
14
|
+
"typescript": "5.8.3"
|
25
15
|
},
|
26
16
|
"scripts": {
|
27
|
-
"build": "webpack --config webpack.config.js",
|
28
|
-
"test": "jest",
|
29
17
|
"type-check": "tsc --noEmit",
|
30
|
-
"
|
18
|
+
"test": "jest"
|
31
19
|
},
|
32
20
|
"name": "hyperscript-rxjs",
|
33
21
|
"description": "A js UI library that uses rxjs to handle dom directly.",
|
34
|
-
"main": "dist/hyperscript-rxjs.js",
|
35
|
-
"types": "dist/hyperscript-rxjs.d.ts",
|
36
|
-
"version": "1.3.14",
|
37
22
|
"author": "cuishengli<34696643@qq.com>",
|
23
|
+
"version": "1.3.15",
|
38
24
|
"keywords": [
|
39
25
|
"ui",
|
40
26
|
"rxjs",
|
@@ -45,9 +31,14 @@
|
|
45
31
|
"type": "git",
|
46
32
|
"url": "git+https://github.com/xp44mm/hyperscript-rxjs.git"
|
47
33
|
},
|
34
|
+
"main": "src/index.js",
|
35
|
+
"types": "src/index.d.ts",
|
36
|
+
"type": "module",
|
37
|
+
"sideEffects": false,
|
48
38
|
"license": "LGPL-3.0-or-later",
|
49
39
|
"files": [
|
50
|
-
"
|
40
|
+
"src/**/*.js",
|
41
|
+
"src/**/*.d.ts",
|
51
42
|
"README.md"
|
52
43
|
]
|
53
44
|
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* Splits an array into two parts: the first `n` elements (in reverse order) and the remaining elements.
|
3
|
+
*
|
4
|
+
* @param array - The input array to process.
|
5
|
+
* @param n - The number of elements to take from the start of the array.
|
6
|
+
* @returns A tuple where the first element is an array of the first `n` elements (in reverse order),
|
7
|
+
* and the second element is the remaining elements of the array.
|
8
|
+
*/
|
9
|
+
export function advance<T>(array: T[], n: number): [T[], T[]];
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* @template T
|
3
|
+
* @param {Array<T>} array - 要处理的原数组
|
4
|
+
* @param {number} n - 要取出的元素个数
|
5
|
+
* @returns {[Array<T>, Array<T>]} - [已取出的元素数组, 剩余元素数组]
|
6
|
+
*/
|
7
|
+
export function advance(array, n) {
|
8
|
+
let taken = []
|
9
|
+
for (let i = 0; i < n; i++) {
|
10
|
+
taken[n - 1 - i] = array[i]
|
11
|
+
}
|
12
|
+
return [taken, array.slice(n)]
|
13
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* Inserts an element into an array at the specified position in place.
|
3
|
+
*
|
4
|
+
* @param array - The array to modify.
|
5
|
+
* @param item - The element to insert.
|
6
|
+
* @param index - The position at which to insert the element (default is the end of the array).
|
7
|
+
*/
|
8
|
+
export function arrayInsert<T>(array: T[], item: T, index?: number): void;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* insert a element at position in place.
|
3
|
+
* @param {any} array
|
4
|
+
* @param {any} item
|
5
|
+
* @param {any} index
|
6
|
+
*/
|
7
|
+
export function arrayInsert(array, item, index = array.length) {
|
8
|
+
const len = array.length
|
9
|
+
for (let i = len; i > index; i--) {
|
10
|
+
array[i] = array[i - 1]
|
11
|
+
}
|
12
|
+
array[index] = item
|
13
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { arrayInsert } from './arrayInsert'
|
2
|
+
|
3
|
+
describe('arrayInsert block', () => {
|
4
|
+
|
5
|
+
test('arrayInsert test', () => {
|
6
|
+
let array = [0, 1, 2, 3]
|
7
|
+
arrayInsert(array, '1', 1)
|
8
|
+
|
9
|
+
expect(array).toEqual([0, '1', 1, 2, 3])
|
10
|
+
expect(array.length).toEqual(5)
|
11
|
+
})
|
12
|
+
|
13
|
+
})
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* Removes an element from an array at the specified position in place.
|
3
|
+
*
|
4
|
+
* @param array - The array to modify.
|
5
|
+
* @param index - The position of the element to remove (default is the last element).
|
6
|
+
*/
|
7
|
+
export function arrayRemove<T>(array: T[], index?: number): void;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/**
|
2
|
+
* remove a element in place
|
3
|
+
*
|
4
|
+
* @template T
|
5
|
+
* @param {T[]} array
|
6
|
+
* @param {number} index
|
7
|
+
*/
|
8
|
+
export function arrayRemove(array, index = array.length - 1) {
|
9
|
+
const len = array.length
|
10
|
+
for (let i = index; i < len - 1; i++) {
|
11
|
+
array[i] = array[i + 1]
|
12
|
+
}
|
13
|
+
Reflect.deleteProperty(array, len - 1)
|
14
|
+
array.length = len - 1
|
15
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { arrayRemove } from './arrayRemove'
|
2
|
+
|
3
|
+
describe('arrayRemove block', () => {
|
4
|
+
|
5
|
+
test('arrayRemove test', () => {
|
6
|
+
let array = [0, 1, 2, 3]
|
7
|
+
arrayRemove(array, 1)
|
8
|
+
expect(array.length).toEqual(3)
|
9
|
+
expect(array).toEqual([0, 2, 3])
|
10
|
+
|
11
|
+
})
|
12
|
+
|
13
|
+
})
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* Finds the last index in an array where the callback function returns `true`.
|
3
|
+
*
|
4
|
+
* @param array - The array to search.
|
5
|
+
* @param callbackFn - A function that is called for each element in the array.
|
6
|
+
* It should return `true` for the element to match.
|
7
|
+
* @param lastIndex - The starting index for the search (default is the last index of the array).
|
8
|
+
* @returns The index of the last element that satisfies the callback function, or -1 if no such element is found.
|
9
|
+
*/
|
10
|
+
export function findLastIndex<T>(
|
11
|
+
array: T[],
|
12
|
+
callbackFn: (value: T, index: number) => boolean,
|
13
|
+
lastIndex?: number
|
14
|
+
): number;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/**
|
2
|
+
* 查找数组中最后一个满足条件的元素索引。
|
3
|
+
*
|
4
|
+
* @public
|
5
|
+
* @template T
|
6
|
+
* @param {T[]} array - 要查找的数组
|
7
|
+
* @param {(value: T, index: number) => boolean} callbackFn - 判断函数,返回 true 表示找到
|
8
|
+
* @param {number} [lastIndex=array.length-1] - 可选,查找的起始索引(从后往前)
|
9
|
+
* @returns {number} - 最后一个满足条件的元素索引,未找到返回 -1
|
10
|
+
*/
|
11
|
+
export function findLastIndex(array, callbackFn, lastIndex = array.length - 1) {
|
12
|
+
lastIndex = Math.min(lastIndex, array.length - 1)
|
13
|
+
while (lastIndex >= 0) {
|
14
|
+
if (callbackFn(array[lastIndex], lastIndex)) {
|
15
|
+
return lastIndex;
|
16
|
+
}
|
17
|
+
lastIndex--
|
18
|
+
}
|
19
|
+
return -1;
|
20
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { findLastIndex } from './findLastIndex';
|
2
|
+
|
3
|
+
describe('findLastIndex', () => {
|
4
|
+
test('should find last index of matching element', () => {
|
5
|
+
const array = [1, 2, 3, 4, 5, 4, 3];
|
6
|
+
const callback = (item) => item === 4;
|
7
|
+
expect(findLastIndex(array, callback)).toBe(5);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('should return -1 when no element matches', () => {
|
11
|
+
const array = [1, 2, 3];
|
12
|
+
const callback = (item) => item === 5;
|
13
|
+
expect(findLastIndex(array, callback)).toBe(-1);
|
14
|
+
});
|
15
|
+
|
16
|
+
test('should work with empty array', () => {
|
17
|
+
const array = [];
|
18
|
+
const callback = (item) => item === 1;
|
19
|
+
expect(findLastIndex(array, callback)).toBe(-1);
|
20
|
+
});
|
21
|
+
|
22
|
+
test('should find index based on element and index', () => {
|
23
|
+
const array = [10, 20, 30, 20, 10];
|
24
|
+
const callback = (item, index) => item === 20 && index < 3;
|
25
|
+
expect(findLastIndex(array, callback)).toBe(1);
|
26
|
+
});
|
27
|
+
|
28
|
+
test('should start searching from specified index', () => {
|
29
|
+
const array = [1, 2, 3, 4, 3, 2, 1];
|
30
|
+
const callback = (item) => item === 3;
|
31
|
+
expect(findLastIndex(array, callback, 4)).toBe(4);
|
32
|
+
expect(findLastIndex(array, callback, 3)).toBe(2);
|
33
|
+
});
|
34
|
+
|
35
|
+
test('should handle edge cases', () => {
|
36
|
+
const array = [1, 2, 3];
|
37
|
+
// Start index out of bounds
|
38
|
+
expect(findLastIndex(array, () => true, 10)).toBe(2);
|
39
|
+
expect(findLastIndex(array, () => true, -2)).toBe(-1);
|
40
|
+
});
|
41
|
+
});
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* Checks if the input array represents a range of consecutive numbers starting from 0.
|
3
|
+
*
|
4
|
+
* @param keys - An array of strings to check.
|
5
|
+
* @returns `true` if the array represents a range of consecutive numbers starting from 0, otherwise `false`.
|
6
|
+
*/
|
7
|
+
export function isRange(keys: string[]): boolean;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/**
|
2
|
+
* 判断输入的字符串数组是否为从0开始的连续数字区间(如 ['0','1','2',...])。
|
3
|
+
*
|
4
|
+
* @public
|
5
|
+
* @param {string[]} keys - 要检查的字符串数组
|
6
|
+
* @returns {boolean} - 如果是从0开始的连续数字区间返回 true,否则返回 false
|
7
|
+
*/
|
8
|
+
export function isRange(keys) {
|
9
|
+
if (keys.every(key => /^\d+$/.test(key))) {
|
10
|
+
let nums = keys.map(key => parseInt(key))
|
11
|
+
return nums.every((v, i) => v === i)
|
12
|
+
}
|
13
|
+
return false
|
14
|
+
}
|
15
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* unwraps an array of arguments simply. If the array contains a single element that is itself an array,
|
3
|
+
* it unwraps and returns that element. Otherwise, it returns the original array.
|
4
|
+
*
|
5
|
+
* @param args - The array of arguments to process.
|
6
|
+
* @returns The unwrapped array if the input is a single array, otherwise the original array.
|
7
|
+
*/
|
8
|
+
export function unwrapArgs<T>(
|
9
|
+
args: (T|T[])[]
|
10
|
+
): T[];
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/**
|
2
|
+
* 简易unwrap参数数组。如果子节点是单个数组,则解构为子节点,否则返回原数组。
|
3
|
+
*
|
4
|
+
* @template T
|
5
|
+
* @param {(T|T[])[]} args - 子节点数组。
|
6
|
+
* @returns {T[]} - 解构后的子节点数组。
|
7
|
+
*/
|
8
|
+
export function unwrapArgs(args) {
|
9
|
+
return (
|
10
|
+
/** @type{T[]} */
|
11
|
+
(args.length === 1 && Array.isArray(args[0])
|
12
|
+
? args[0]
|
13
|
+
: args
|
14
|
+
));
|
15
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { unwrapArgs } from './unwrapArgs';
|
2
|
+
|
3
|
+
describe('unwrapArgs', () => {
|
4
|
+
test('should unwrap a single nested array', () => {
|
5
|
+
const input = [[1, 2, 3]];
|
6
|
+
const result = unwrapArgs(input);
|
7
|
+
expect(result).toEqual([1, 2, 3]);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('should return the original array if it contains multiple elements', () => {
|
11
|
+
const input = [1, 2, 3];
|
12
|
+
const result = unwrapArgs(input);
|
13
|
+
expect(result).toEqual([1, 2, 3]);
|
14
|
+
});
|
15
|
+
|
16
|
+
test('should return the original array if it is empty', () => {
|
17
|
+
const input = [];
|
18
|
+
const result = unwrapArgs(input);
|
19
|
+
expect(result).toEqual([]);
|
20
|
+
});
|
21
|
+
|
22
|
+
test('should return the original array if it contains a single non-array element', () => {
|
23
|
+
const input = ['hello'];
|
24
|
+
const result = unwrapArgs(input);
|
25
|
+
expect(result).toEqual(['hello']);
|
26
|
+
});
|
27
|
+
|
28
|
+
test('should handle deeply nested arrays by only unwrapping the first level', () => {
|
29
|
+
const input = [[[1, 2, 3]]];
|
30
|
+
const result = unwrapArgs(input);
|
31
|
+
expect(result).toEqual([[1, 2, 3]]);
|
32
|
+
});
|
33
|
+
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* Combines two arrays into an array of tuples.
|
3
|
+
*
|
4
|
+
* - If the arrays have different lengths, the longer array will be truncated to match the length of the shorter array.
|
5
|
+
*
|
6
|
+
* @param a - The first array.
|
7
|
+
* @param b - The second array.
|
8
|
+
* @returns An array of tuples, where each tuple contains one element from `a` and one from `b`.
|
9
|
+
* @throws Will throw an error if either `a` or `b` is not an array.
|
10
|
+
*/
|
11
|
+
export function zipArray<T, U>(a: T[], b: U[]): [T, U][];
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* 合并两个数组为一个元组数组。
|
3
|
+
*
|
4
|
+
* 如果数组长度不同,将以较长的数组为基准,短数组对应位置为 undefined。
|
5
|
+
*
|
6
|
+
* @public
|
7
|
+
* @template T, U
|
8
|
+
* @param {T[]} a - 第一个数组
|
9
|
+
* @param {U[]} b - 第二个数组
|
10
|
+
* @returns {Array<[T, U]>} - 合并后的元组数组
|
11
|
+
* @throws {Error} 如果 a 或 b 不是数组
|
12
|
+
*/
|
13
|
+
export function zipArray(a, b) {
|
14
|
+
if (!Array.isArray(a) || !Array.isArray(b)) {
|
15
|
+
throw new Error("arrayZip(a,b):both a and b should be array")
|
16
|
+
}
|
17
|
+
if (a.length >= b.length) {
|
18
|
+
return a.map((v, i) => [v, b[i]])
|
19
|
+
}
|
20
|
+
else{
|
21
|
+
return b.map((v, i) => [a[i], v])
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { zipArray } from './zipArray'
|
2
|
+
|
3
|
+
describe('zipArray array ops', () => {
|
4
|
+
test('eq test', () => {
|
5
|
+
let a = [1, 2, 3]
|
6
|
+
let b = ['a', 'b', 'c']
|
7
|
+
let e = [[1, 'a'], [2, 'b'], [3, 'c']]
|
8
|
+
expect(zipArray(a, b)).toEqual(e)
|
9
|
+
})
|
10
|
+
test('gt test', () => {
|
11
|
+
expect(zipArray([1, 2, 3, 4], ['a', 'b', 'c'])).toEqual([[1, 'a'], [2, 'b'], [3, 'c'], [4, undefined]])
|
12
|
+
})
|
13
|
+
test('lt test', () => {
|
14
|
+
expect(zipArray([1, 2, 3], ['a', 'b', 'c', 'd'])).toEqual([[1, 'a'], [2, 'b'], [3, 'c'], [undefined, 'd']])
|
15
|
+
})
|
16
|
+
})
|
@@ -0,0 +1,101 @@
|
|
1
|
+
/**
|
2
|
+
* 用于比较和操作数组及集合的工具类。
|
3
|
+
* @template T
|
4
|
+
*/
|
5
|
+
export class Comparer<T> {
|
6
|
+
constructor(compare: (a: T, b: T) => number);
|
7
|
+
|
8
|
+
/**
|
9
|
+
* 使用实例的比较函数对数组进行排序。
|
10
|
+
* @param array - 要排序的数组
|
11
|
+
* @returns 排序后的数组
|
12
|
+
*/
|
13
|
+
sort(array: T[]): T[];
|
14
|
+
|
15
|
+
/**
|
16
|
+
* 移除数组中的重复值。
|
17
|
+
* @param array - 要处理的数组
|
18
|
+
* @returns 去重后的新数组
|
19
|
+
*/
|
20
|
+
distinct(array: T[]): T[];
|
21
|
+
|
22
|
+
/**
|
23
|
+
* 根据 getKey 生成的 key 对数组元素分组。
|
24
|
+
* @template U
|
25
|
+
* @param array - 要分组的数组
|
26
|
+
* @param getKey - 生成分组 key 的函数
|
27
|
+
* @returns 分组后的对象或数组
|
28
|
+
*/
|
29
|
+
groupBy<U>(array: U[], getKey: (item: U) => T): [T, U[]][];
|
30
|
+
|
31
|
+
/**
|
32
|
+
* 对已排序的数组按 key 分组。
|
33
|
+
* @template V
|
34
|
+
* @param array - 已排序的数组
|
35
|
+
* @returns 分组结果
|
36
|
+
*/
|
37
|
+
groupSortedEntries<V>(array: [T, V][]): [T, V[]][];
|
38
|
+
|
39
|
+
/**
|
40
|
+
* 计算两个数组的差集。
|
41
|
+
* @param array1 - 第一个数组
|
42
|
+
* @param array2 - 第二个数组
|
43
|
+
* @returns array1 中有而 array2 中没有的元素
|
44
|
+
*/
|
45
|
+
differenceSet(array1: T[], array2: T[]): T[];
|
46
|
+
|
47
|
+
/**
|
48
|
+
* 在集合(数组)中查找元素的索引。
|
49
|
+
* @param set - 要查找的数组
|
50
|
+
* @param element - 要查找的元素
|
51
|
+
* @returns 元素在集合中的索引,未找到返回 -1
|
52
|
+
*/
|
53
|
+
findIndexInSet(set: T[], element: T): number;
|
54
|
+
|
55
|
+
/**
|
56
|
+
* 计算两个数组的交集。
|
57
|
+
* @param array1 - 第一个数组
|
58
|
+
* @param array2 - 第二个数组
|
59
|
+
* @returns 同时存在于 array1 和 array2 的元素
|
60
|
+
*/
|
61
|
+
intersectSet(array1: T[], array2: T[]): T[];
|
62
|
+
|
63
|
+
/**
|
64
|
+
* 判断两个数组作为集合是否相等。
|
65
|
+
* @param array1 - 第一个数组
|
66
|
+
* @param array2 - 第二个数组
|
67
|
+
* @returns 如果集合相等返回 true,否则返回 false
|
68
|
+
*/
|
69
|
+
isEqualset(array1: T[], array2: T[]): boolean;
|
70
|
+
|
71
|
+
/**
|
72
|
+
* 判断第一个数组是否为第二个数组的子集。
|
73
|
+
* @param array1 - 第一个数组
|
74
|
+
* @param array2 - 第二个数组
|
75
|
+
* @returns 如果 array1 是 array2 的子集返回 true,否则返回 false
|
76
|
+
*/
|
77
|
+
isSubset(array1: T[], array2: T[]): boolean;
|
78
|
+
|
79
|
+
/**
|
80
|
+
* 判断第一个数组是否为第二个数组的超集。
|
81
|
+
* @param array1 - 第一个数组
|
82
|
+
* @param array2 - 第二个数组
|
83
|
+
* @returns 如果 array1 是 array2 的超集返回 true,否则返回 false
|
84
|
+
*/
|
85
|
+
isSuperset(array1: T[], array2: T[]): boolean;
|
86
|
+
|
87
|
+
/**
|
88
|
+
* 计算两个数组的并集(去重)。
|
89
|
+
* @param array1 - 第一个数组
|
90
|
+
* @param array2 - 第二个数组
|
91
|
+
* @returns 两个数组的唯一元素合集
|
92
|
+
*/
|
93
|
+
unionSet(array1: T[], array2: T[]): T[];
|
94
|
+
|
95
|
+
/**
|
96
|
+
* 将已排序的数组转为集合(去重)。
|
97
|
+
* @param array - 已排序的数组
|
98
|
+
* @returns 唯一元素数组
|
99
|
+
*/
|
100
|
+
sortedArrayToSet(array: T[]): T[];
|
101
|
+
}
|