hyperscript-rxjs 1.3.15 → 1.3.16
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/dist/hyperscript-rxjs.cjs +4114 -0
- package/dist/hyperscript-rxjs.d.ts +1438 -0
- package/package.json +21 -12
- package/src/array/advance.d.ts +0 -9
- package/src/array/advance.js +0 -13
- package/src/array/advance.test.js +0 -12
- package/src/array/arrayInsert.d.ts +0 -8
- package/src/array/arrayInsert.js +0 -13
- package/src/array/arrayInsert.test.js +0 -13
- package/src/array/arrayRemove.d.ts +0 -7
- package/src/array/arrayRemove.js +0 -15
- package/src/array/arrayRemove.test.js +0 -13
- package/src/array/findLastIndex.d.ts +0 -14
- package/src/array/findLastIndex.js +0 -20
- package/src/array/findLastIndex.test.js +0 -41
- package/src/array/index.d.ts +0 -9
- package/src/array/index.js +0 -9
- package/src/array/isRange.d.ts +0 -7
- package/src/array/isRange.js +0 -15
- package/src/array/isRange.test.js +0 -6
- package/src/array/rangeArray.d.ts +0 -7
- package/src/array/rangeArray.js +0 -10
- package/src/array/rangeArray.test.js +0 -11
- package/src/array/unwrapArgs.d.ts +0 -10
- package/src/array/unwrapArgs.js +0 -15
- package/src/array/unwrapArgs.test.js +0 -33
- package/src/array/zipArray.d.ts +0 -11
- package/src/array/zipArray.js +0 -24
- package/src/array/zipArray.test.js +0 -16
- package/src/comparers/Comparer.d.ts +0 -101
- package/src/comparers/Comparer.js +0 -149
- package/src/comparers/comparers.d.ts +0 -21
- package/src/comparers/comparers.js +0 -10
- package/src/comparers/differenceSet.d.ts +0 -20
- package/src/comparers/differenceSet.js +0 -35
- package/src/comparers/differenceSet.test.js +0 -11
- package/src/comparers/distinctArray.d.ts +0 -13
- package/src/comparers/distinctArray.js +0 -30
- package/src/comparers/distinctArray.test.js +0 -10
- package/src/comparers/findIndexInSet.d.ts +0 -20
- package/src/comparers/findIndexInSet.js +0 -27
- package/src/comparers/findIndexInSet.test.js +0 -8
- package/src/comparers/groupArrayBy.d.ts +0 -19
- package/src/comparers/groupArrayBy.js +0 -29
- package/src/comparers/groupArrayBy.test.js +0 -38
- package/src/comparers/groupSortedEntries.d.ts +0 -17
- package/src/comparers/groupSortedEntries.js +0 -38
- package/src/comparers/groupSortedEntries.test.js +0 -46
- package/src/comparers/index.d.ts +0 -14
- package/src/comparers/index.js +0 -14
- package/src/comparers/intersectSet.d.ts +0 -19
- package/src/comparers/intersectSet.js +0 -35
- package/src/comparers/intersectSet.test.js +0 -14
- package/src/comparers/isEqualset.d.ts +0 -22
- package/src/comparers/isEqualset.js +0 -33
- package/src/comparers/isEqualset.test.js +0 -22
- package/src/comparers/isSubset.d.ts +0 -21
- package/src/comparers/isSubset.js +0 -33
- package/src/comparers/isSubset.test.js +0 -21
- package/src/comparers/isSuperset.d.ts +0 -21
- package/src/comparers/isSuperset.js +0 -13
- package/src/comparers/isSuperset.test.js +0 -21
- package/src/comparers/sortedArrayToSet.d.ts +0 -20
- package/src/comparers/sortedArrayToSet.js +0 -35
- package/src/comparers/sortedArrayToSet.test.js +0 -11
- package/src/comparers/unionSet.d.ts +0 -21
- package/src/comparers/unionSet.js +0 -34
- package/src/comparers/unionSet.test.js +0 -11
- package/src/comparison/compareDate.d.ts +0 -8
- package/src/comparison/compareDate.js +0 -11
- package/src/comparison/compareEntries.d.ts +0 -13
- package/src/comparison/compareEntries.js +0 -13
- package/src/comparison/compareKey.d.ts +0 -11
- package/src/comparison/compareKey.js +0 -25
- package/src/comparison/compareKey.test.js +0 -21
- package/src/comparison/compareKeyPath.d.ts +0 -15
- package/src/comparison/compareKeyPath.js +0 -33
- package/src/comparison/compareKeyPath.test.js +0 -28
- package/src/comparison/compareNumber.d.ts +0 -11
- package/src/comparison/compareNumber.js +0 -27
- package/src/comparison/compareNumber.test.js +0 -21
- package/src/comparison/defaultCompare.d.ts +0 -8
- package/src/comparison/defaultCompare.js +0 -12
- package/src/comparison/defaultCompare.test.js +0 -24
- package/src/comparison/index.d.ts +0 -7
- package/src/comparison/index.js +0 -7
- package/src/comparison/infinity.test.js +0 -122
- package/src/comparison/typeof.test.js +0 -64
- package/src/comparison/types.d.ts +0 -5
- package/src/comparison/types.js +0 -11
- package/src/deep/Deep.d.ts +0 -58
- package/src/deep/Deep.js +0 -267
- package/src/deep/Deep.test.js +0 -130
- package/src/deep/deepCombineLatest.test.js +0 -36
- package/src/deep/deepMerge.test.js +0 -34
- package/src/deep/differenceDeep.test.js +0 -31
- package/src/deep/freshValueDeep.test.js +0 -17
- package/src/deep/index.d.ts +0 -1
- package/src/deep/index.js +0 -2
- package/src/deep/intersectDeep.test.js +0 -25
- package/src/deep/intersectEntries.d.ts +0 -13
- package/src/deep/intersectEntries.js +0 -37
- package/src/deep/intersectEntries.test.js +0 -20
- package/src/deep/objectToDeep.test.js +0 -31
- package/src/deep/replaceValueDeep.test.js +0 -21
- package/src/deep/unionDeep.test.js +0 -30
- package/src/deep/zipValueDeep.test.js +0 -21
- package/src/deep-rxjs/ObservableArray.d.ts +0 -55
- package/src/deep-rxjs/ObservableArray.js +0 -94
- package/src/deep-rxjs/ObservableArray.test.js +0 -117
- package/src/deep-rxjs/index.d.ts +0 -2
- package/src/deep-rxjs/index.js +0 -2
- package/src/deep-rxjs/isRxType.d.ts +0 -9
- package/src/deep-rxjs/isRxType.js +0 -15
- package/src/deep-rxjs/isRxType.test.js +0 -43
- package/src/hyperscript-rxjs/HyperscriptExtensions.d.ts +0 -20
- package/src/hyperscript-rxjs/checkbox.d.ts +0 -13
- package/src/hyperscript-rxjs/checkbox.js +0 -47
- package/src/hyperscript-rxjs/checkbox.test.js +0 -68
- package/src/hyperscript-rxjs/choice.d.ts +0 -13
- package/src/hyperscript-rxjs/choice.js +0 -24
- package/src/hyperscript-rxjs/choice.test.js +0 -108
- package/src/hyperscript-rxjs/collapse.d.ts +0 -14
- package/src/hyperscript-rxjs/collapse.js +0 -32
- package/src/hyperscript-rxjs/collapse.test.js +0 -67
- package/src/hyperscript-rxjs/displays/blockLevelFamily.d.ts +0 -5
- package/src/hyperscript-rxjs/displays/blockLevelFamily.js +0 -51
- package/src/hyperscript-rxjs/displays/getDisplay.d.ts +0 -7
- package/src/hyperscript-rxjs/displays/getDisplay.js +0 -51
- package/src/hyperscript-rxjs/displays/getDisplay.test.js +0 -56
- package/src/hyperscript-rxjs/displays/index.d.ts +0 -3
- package/src/hyperscript-rxjs/displays/index.js +0 -3
- package/src/hyperscript-rxjs/displays/inlineFamily.d.ts +0 -5
- package/src/hyperscript-rxjs/displays/inlineFamily.js +0 -73
- package/src/hyperscript-rxjs/flip.d.ts +0 -15
- package/src/hyperscript-rxjs/flip.js +0 -29
- package/src/hyperscript-rxjs/flip.test.js +0 -85
- package/src/hyperscript-rxjs/fragment.d.ts +0 -10
- package/src/hyperscript-rxjs/fragment.js +0 -22
- package/src/hyperscript-rxjs/fragment.test.js +0 -70
- package/src/hyperscript-rxjs/hyperscript.d.ts +0 -15
- package/src/hyperscript-rxjs/hyperscript.js +0 -170
- package/src/hyperscript-rxjs/hyperscript.test.js +0 -75
- package/src/hyperscript-rxjs/index.d.ts +0 -19
- package/src/hyperscript-rxjs/index.js +0 -19
- package/src/hyperscript-rxjs/multiselect.d.ts +0 -18
- package/src/hyperscript-rxjs/multiselect.js +0 -41
- package/src/hyperscript-rxjs/multiselect.test.js +0 -121
- package/src/hyperscript-rxjs/numberbox.d.ts +0 -14
- package/src/hyperscript-rxjs/numberbox.js +0 -73
- package/src/hyperscript-rxjs/numberbox.test.js +0 -84
- package/src/hyperscript-rxjs/radio.d.ts +0 -15
- package/src/hyperscript-rxjs/radio.js +0 -53
- package/src/hyperscript-rxjs/radio.test.js +0 -59
- package/src/hyperscript-rxjs/select.d.ts +0 -28
- package/src/hyperscript-rxjs/select.js +0 -88
- package/src/hyperscript-rxjs/select.test.js +0 -101
- package/src/hyperscript-rxjs/tabControls/bindTabIndex.d.ts +0 -12
- package/src/hyperscript-rxjs/tabControls/bindTabIndex.js +0 -59
- package/src/hyperscript-rxjs/tabControls/index.d.ts +0 -8
- package/src/hyperscript-rxjs/tabControls/index.js +0 -10
- package/src/hyperscript-rxjs/tabControls/tabControl.d.ts +0 -19
- package/src/hyperscript-rxjs/tabControls/tabControl.js +0 -40
- package/src/hyperscript-rxjs/tabControls/tabControl.test.js +0 -98
- package/src/hyperscript-rxjs/tabControls/tabNavItem.d.ts +0 -9
- package/src/hyperscript-rxjs/tabControls/tabNavItem.js +0 -30
- package/src/hyperscript-rxjs/tabControls/tabPanel.d.ts +0 -9
- package/src/hyperscript-rxjs/tabControls/tabPanel.js +0 -21
- package/src/hyperscript-rxjs/tabControls/tabRoot.d.ts +0 -7
- package/src/hyperscript-rxjs/tabControls/tabRoot.js +0 -26
- package/src/hyperscript-rxjs/tags.d.ts +0 -193
- package/src/hyperscript-rxjs/tags.js +0 -751
- package/src/hyperscript-rxjs/tags.test.js +0 -75
- package/src/hyperscript-rxjs/textNode.d.ts +0 -11
- package/src/hyperscript-rxjs/textNode.js +0 -51
- package/src/hyperscript-rxjs/textNode.test.js +0 -56
- package/src/hyperscript-rxjs/textarea.d.ts +0 -17
- package/src/hyperscript-rxjs/textarea.js +0 -45
- package/src/hyperscript-rxjs/textarea.test.js +0 -52
- package/src/hyperscript-rxjs/textbox.d.ts +0 -15
- package/src/hyperscript-rxjs/textbox.js +0 -42
- package/src/hyperscript-rxjs/textbox.test.js +0 -52
- package/src/index.d.ts +0 -19
- package/src/index.js +0 -19
- package/src/nodes/attachSubscriptionToNode.d.ts +0 -13
- package/src/nodes/attachSubscriptionToNode.js +0 -25
- package/src/nodes/attachSubscriptionToNode.test.js +0 -73
- package/src/nodes/index.d.ts +0 -6
- package/src/nodes/index.js +0 -6
- package/src/nodes/normalizeChildNodes.d.ts +0 -9
- package/src/nodes/normalizeChildNodes.js +0 -15
- package/src/nodes/normalizeChildNodes.test.js +0 -55
- package/src/nodes/parseHyperscriptArgs.d.ts +0 -10
- package/src/nodes/parseHyperscriptArgs.js +0 -57
- package/src/nodes/parseHyperscriptArgs.test.js +0 -85
- package/src/nodes/pipeEvent.d.ts +0 -15
- package/src/nodes/pipeEvent.js +0 -49
- package/src/nodes/pipeEvent.test.js +0 -97
- package/src/nodes/subscribeEvent.d.ts +0 -15
- package/src/nodes/subscribeEvent.js +0 -56
- package/src/nodes/subscribeEvent.test.js +0 -88
- package/src/object/index.d.ts +0 -10
- package/src/object/index.js +0 -11
- package/src/object/intersectObject.d.ts +0 -12
- package/src/object/intersectObject.js +0 -23
- package/src/object/intersectObject.test.js +0 -69
- package/src/object/isEmptyObject.d.ts +0 -7
- package/src/object/isEmptyObject.js +0 -13
- package/src/object/isEmptyObject.test.js +0 -33
- package/src/object/isPlainObject.d.ts +0 -11
- package/src/object/isPlainObject.js +0 -18
- package/src/object/nestedCombineLatest.d.ts +0 -11
- package/src/object/nestedCombineLatest.js +0 -18
- package/src/object/nestedCombineLatest.test.js +0 -25
- package/src/object/nestedMerge.d.ts +0 -11
- package/src/object/nestedMerge.js +0 -11
- package/src/object/nestedMerge.test.js +0 -61
- package/src/object/pickBehaviorSubject.d.ts +0 -13
- package/src/object/pickBehaviorSubject.js +0 -81
- package/src/object/pickBehaviorSubject.test.js +0 -88
- package/src/object/pluckProperty.d.ts +0 -13
- package/src/object/pluckProperty.js +0 -24
- package/src/object/pluckProperty.test.js +0 -37
- package/src/object/restore.d.ts +0 -12
- package/src/object/restore.js +0 -69
- package/src/object/restore.test.js +0 -124
- package/src/object/splitObjectByObservable.d.ts +0 -12
- package/src/object/splitObjectByObservable.js +0 -41
- package/src/object/splitObjectByObservable.test.js +0 -78
- package/src/props/getNestedProperty.d.ts +0 -12
- package/src/props/getNestedProperty.js +0 -31
- package/src/props/getNestedProperty.test.js +0 -72
- package/src/props/index.d.ts +0 -7
- package/src/props/index.js +0 -7
- package/src/props/parsePropName.d.ts +0 -13
- package/src/props/parsePropName.js +0 -45
- package/src/props/parsePropName.test.js +0 -67
- package/src/props/setProp.d.ts +0 -16
- package/src/props/setProp.js +0 -42
- package/src/props/setProp.test.js +0 -59
- package/src/props/setProps.d.ts +0 -14
- package/src/props/setProps.js +0 -47
- package/src/props/setProps.test.js +0 -97
- package/src/props/subscribeProp.d.ts +0 -16
- package/src/props/subscribeProp.js +0 -47
- package/src/props/subscribeProp.test.js +0 -81
- package/src/ramda/compose.d.ts +0 -10
- package/src/ramda/compose.js +0 -36
- package/src/ramda/compose.test.js +0 -73
- package/src/ramda/cond.d.ts +0 -12
- package/src/ramda/cond.js +0 -29
- package/src/ramda/cond.test.js +0 -88
- package/src/ramda/fold.d.ts +0 -13
- package/src/ramda/fold.js +0 -20
- package/src/ramda/fold.test.js +0 -51
- package/src/ramda/index.d.ts +0 -6
- package/src/ramda/index.js +0 -6
- package/src/ramda/pipe.d.ts +0 -13
- package/src/ramda/pipe.js +0 -27
- package/src/ramda/pipe.test.js +0 -77
- package/src/ramda/unfold.d.ts +0 -11
- package/src/ramda/unfold.js +0 -20
- package/src/ramda/unfold.test.js +0 -29
- package/src/unquoted-json/ajax.test.js +0 -1074
- package/src/unquoted-json/index.d.ts +0 -13
- package/src/unquoted-json/index.js +0 -12
- package/src/unquoted-json/queryStringify.d.ts +0 -8
- package/src/unquoted-json/queryStringify.js +0 -70
- package/src/unquoted-json/queryStringify.test.js +0 -110
- package/src/unquoted-json/stringifyKey.d.ts +0 -7
- package/src/unquoted-json/stringifyKey.js +0 -16
- package/src/unquoted-json/stringifyKey.test.js +0 -51
- package/src/unquoted-json/stringifyStringValue.d.ts +0 -7
- package/src/unquoted-json/stringifyStringValue.js +0 -17
- package/src/unquoted-json/stringifyStringValue.test.js +0 -52
- package/src/unquoted-json/unquotedJsonStringify.d.ts +0 -7
- package/src/unquoted-json/unquotedJsonStringify.js +0 -39
- package/src/unquoted-json/unquotedJsonStringify.test.js +0 -52
@@ -1,13 +0,0 @@
|
|
1
|
-
// // 工具函数
|
2
|
-
// export * from './peercent-encode/pctEncodeChar'
|
3
|
-
// export * from './peercent-encode/queryPctEncode'
|
4
|
-
// export * from './peercent-encode/toUtf8'
|
5
|
-
|
6
|
-
// 主函数
|
7
|
-
export * from "./queryStringify"
|
8
|
-
|
9
|
-
// export * from "./stringifyKey"
|
10
|
-
// export * from "./stringifyStringValue"
|
11
|
-
|
12
|
-
|
13
|
-
export * from './unquotedJsonStringify'
|
@@ -1,12 +0,0 @@
|
|
1
|
-
// // 工具函数
|
2
|
-
// export * from './peercent-encode/pctEncodeChar'
|
3
|
-
// export * from './peercent-encode/queryPctEncode'
|
4
|
-
// export * from './peercent-encode/toUtf8'
|
5
|
-
// export * from "./stringifyKey"
|
6
|
-
// export * from "./stringifyStringValue"
|
7
|
-
|
8
|
-
|
9
|
-
// 主函数
|
10
|
-
export * from "./queryStringify"
|
11
|
-
export * from './unquotedJsonStringify'
|
12
|
-
|
@@ -1,70 +0,0 @@
|
|
1
|
-
import { unquotedJsonStringify } from './unquotedJsonStringify'
|
2
|
-
import { isPlainObject } from '../object'
|
3
|
-
/**
|
4
|
-
* 将对象序列化为 URL 查询字符串(支持嵌套对象和多类型字段)。
|
5
|
-
*
|
6
|
-
* @public
|
7
|
-
* @param {Object} data - 要序列化的对象
|
8
|
-
* @returns {string} 查询字符串(如 "?a=1&b=2"),无有效字段时返回空字符串
|
9
|
-
*/
|
10
|
-
export function queryStringify(data) {
|
11
|
-
if (!isPlainObject(data)) {
|
12
|
-
throw new Error("input should be a plain object.")
|
13
|
-
}
|
14
|
-
let pairs =
|
15
|
-
Object.entries(data)
|
16
|
-
.filter(([k, v]) =>
|
17
|
-
supportedDataTypes.has(typeof v) && v !== ''
|
18
|
-
)
|
19
|
-
|
20
|
-
if (pairs.length === 0) {
|
21
|
-
return ''
|
22
|
-
}
|
23
|
-
|
24
|
-
// 如果字段是对象,包括数组,则序列化字段值,否则不变。
|
25
|
-
return pairs
|
26
|
-
.map(([k, v]) => {
|
27
|
-
let vv = typeof v === 'object' ? unquotedJsonStringify(v) : String(v)
|
28
|
-
return escape(k) + '=' + escape(vv)
|
29
|
-
})
|
30
|
-
.join('&')
|
31
|
-
|
32
|
-
}
|
33
|
-
|
34
|
-
const supportedDataTypes = new Set([
|
35
|
-
'string',
|
36
|
-
'number',
|
37
|
-
'boolean',
|
38
|
-
'bigint',
|
39
|
-
// 'function',
|
40
|
-
// 'symbol',
|
41
|
-
// 'undefined',
|
42
|
-
'object',
|
43
|
-
])
|
44
|
-
|
45
|
-
/**
|
46
|
-
* 需要编码的ASCII字符及其百分比编码(键为字符本身,用\x或可打印形式)
|
47
|
-
* @type {Map<string, string>}
|
48
|
-
*/
|
49
|
-
const mp = new Map([
|
50
|
-
['\x00', '%00'], ['\x01', '%01'], ['\x02', '%02'], ['\x03', '%03'], ['\x04', '%04'],
|
51
|
-
['\x05', '%05'], ['\x06', '%06'], ['\x07', '%07'], ['\x08', '%08'], ['\t', '%09'],
|
52
|
-
['\n', '%0A'], ['\x0B', '%0B'], ['\x0C', '%0C'], ['\r', '%0D'],
|
53
|
-
['\x0E', '%0E'], ['\x0F', '%0F'], ['\x10', '%10'], ['\x11', '%11'], ['\x12', '%12'],
|
54
|
-
['\x13', '%13'], ['\x14', '%14'], ['\x15', '%15'], ['\x16', '%16'], ['\x17', '%17'],
|
55
|
-
['\x18', '%18'], ['\x19', '%19'], ['\x1A', '%1A'], ['\x1B', '%1B'], ['\x1C', '%1C'],
|
56
|
-
['\x1D', '%1D'], ['\x1E', '%1E'], ['\x1F', '%1F'], ['\x20', '%20'],
|
57
|
-
['#', '%23'],
|
58
|
-
['%', '%25'], //浏览器能识别不是%dd格式的百分号为原义,这里冗余转义为了保险起见。
|
59
|
-
['&', '%26'],
|
60
|
-
['+', '%2B'], // 原义+有时候会被解析为空格
|
61
|
-
['=', '%3D'],
|
62
|
-
['\x7F', '%7F'], // DEL
|
63
|
-
]);
|
64
|
-
|
65
|
-
/**
|
66
|
-
* 这是最小的转义函数,其他一概保持原义。
|
67
|
-
* @param {string} str
|
68
|
-
* @returns {string}
|
69
|
-
*/
|
70
|
-
const escape = str => str.replace(/[\x00-\x20#%&+=\x7F]/g, c => mp.get(c) || c)
|
@@ -1,110 +0,0 @@
|
|
1
|
-
import { queryStringify } from './queryStringify'
|
2
|
-
|
3
|
-
test('queryStringify', () => {
|
4
|
-
let obj = { foo: 'bar', baz: ['qux', 'quux'], corge: '' }
|
5
|
-
let y = queryStringify(obj)
|
6
|
-
expect(y).toEqual("foo=bar&baz=[qux,quux]")
|
7
|
-
})
|
8
|
-
|
9
|
-
describe('queryStringify ignore', () => {
|
10
|
-
test('undefined', () => {
|
11
|
-
let obj = { foo: undefined }
|
12
|
-
let y = queryStringify(obj)
|
13
|
-
expect(y).toEqual('')
|
14
|
-
})
|
15
|
-
|
16
|
-
test('function', () => {
|
17
|
-
let obj = { foo: x => x }
|
18
|
-
let y = queryStringify(obj)
|
19
|
-
expect(y).toEqual('')
|
20
|
-
})
|
21
|
-
|
22
|
-
test('Symbol', () => {
|
23
|
-
let obj = { foo: Symbol() }
|
24
|
-
let y = queryStringify(obj)
|
25
|
-
expect(y).toEqual('')
|
26
|
-
})
|
27
|
-
|
28
|
-
test('empty string', () => {
|
29
|
-
let obj = { foo: '' }
|
30
|
-
let y = queryStringify(obj)
|
31
|
-
expect(y).toEqual('')
|
32
|
-
})
|
33
|
-
})
|
34
|
-
|
35
|
-
describe('queryStringify real', () => {
|
36
|
-
test('null', () => {
|
37
|
-
let obj = { foo: null }
|
38
|
-
let y = queryStringify(obj)
|
39
|
-
expect(y).toEqual("foo=null")
|
40
|
-
})
|
41
|
-
|
42
|
-
test('NaN', () => {
|
43
|
-
let obj = { foo: NaN }
|
44
|
-
let y = queryStringify(obj)
|
45
|
-
expect(y).toEqual("foo=NaN")
|
46
|
-
})
|
47
|
-
|
48
|
-
test('Infinity', () => {
|
49
|
-
let obj = { foo: Infinity, bar: -Infinity }
|
50
|
-
let y = queryStringify(obj)
|
51
|
-
expect(y).toEqual("foo=Infinity&bar=-Infinity")
|
52
|
-
})
|
53
|
-
|
54
|
-
test('boolean', () => {
|
55
|
-
let obj = { foo: true, bar: false }
|
56
|
-
let y = queryStringify(obj)
|
57
|
-
expect(y).toEqual('foo=true&bar=false')
|
58
|
-
})
|
59
|
-
|
60
|
-
// test('bigint', () => {
|
61
|
-
// let obj = { foo: 0n, bar: 1n }
|
62
|
-
// let y = queryStringify(obj)
|
63
|
-
// expect(y).toEqual('?foo=0&bar=1')
|
64
|
-
// })
|
65
|
-
|
66
|
-
test('number 0', () => {
|
67
|
-
let obj = { foo: 1 / Infinity, bar: -1 / Infinity }
|
68
|
-
let y = queryStringify(obj)
|
69
|
-
expect(y).toEqual('foo=0&bar=0')
|
70
|
-
})
|
71
|
-
|
72
|
-
test('string', () => {
|
73
|
-
let obj = { foo: 'test' }
|
74
|
-
let y = queryStringify(obj)
|
75
|
-
expect(y).toEqual('foo=test')
|
76
|
-
})
|
77
|
-
|
78
|
-
test('object', () => {
|
79
|
-
let obj = { foo: {} }
|
80
|
-
let y = queryStringify(obj)
|
81
|
-
expect(y).toEqual('foo={}')
|
82
|
-
})
|
83
|
-
|
84
|
-
test('array', () => {
|
85
|
-
let obj = { foo: [] }
|
86
|
-
let y = queryStringify(obj)
|
87
|
-
expect(y).toEqual('foo=[]')
|
88
|
-
})
|
89
|
-
|
90
|
-
test('encode data', () => {
|
91
|
-
const data = {
|
92
|
-
name: 'this is a test',
|
93
|
-
inlet: {
|
94
|
-
SO2: 4273.11,
|
95
|
-
SO3: 45.35924,
|
96
|
-
'CaSO4*(1/2)H2O': 49.79,
|
97
|
-
HF: 38.48,
|
98
|
-
ash: 'NO',
|
99
|
-
},
|
100
|
-
effect: [96, 30, 95, 95, 85],
|
101
|
-
'CaSO4*(1/2)H2O': -1,
|
102
|
-
cleanLeakage: -1,
|
103
|
-
}
|
104
|
-
|
105
|
-
let res = queryStringify(data)
|
106
|
-
expect(res).toBe("name=this%20is%20a%20test&inlet={SO2:4273.11,SO3:45.35924,CaSO4*(1/2)H2O:49.79,HF:38.48,ash:NO}&effect=[96,30,95,95,85]&CaSO4*(1/2)H2O=-1&cleanLeakage=-1")
|
107
|
-
})
|
108
|
-
|
109
|
-
})
|
110
|
-
|
@@ -1,16 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* 将键名字符串化,必要时加引号(如包含特殊字符或空字符串)。
|
3
|
-
*
|
4
|
-
* @public
|
5
|
-
* @param {string} x - 要处理的键名
|
6
|
-
* @returns {string} 处理后的键名
|
7
|
-
*/
|
8
|
-
export const stringifyKey = x => {
|
9
|
-
if (
|
10
|
-
x === "" ||
|
11
|
-
/(^\u0020)|[,:{}[\]"\u0000-\u001F\u007F]|(\u0020$)/.test(x)
|
12
|
-
)
|
13
|
-
return JSON.stringify(x)
|
14
|
-
else
|
15
|
-
return x
|
16
|
-
}
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import { stringifyKey } from './stringifyKey'
|
2
|
-
|
3
|
-
test("stringifyKey empty", () => {
|
4
|
-
let x = ""
|
5
|
-
let y = stringifyKey(x)
|
6
|
-
let e = '""'
|
7
|
-
expect(y).toEqual(e)
|
8
|
-
})
|
9
|
-
|
10
|
-
test("stringifyKey control char", () => {
|
11
|
-
let x = "\u0000"
|
12
|
-
let y = stringifyKey(x)
|
13
|
-
let e = '"\\u0000"'
|
14
|
-
expect(y).toEqual(e)
|
15
|
-
})
|
16
|
-
|
17
|
-
test("stringifyKey space", () => {
|
18
|
-
let x = " x"
|
19
|
-
let y = stringifyKey(x)
|
20
|
-
let e = '" x"'
|
21
|
-
expect(y).toEqual(e)
|
22
|
-
})
|
23
|
-
|
24
|
-
test("stringifyKey keyword", () => {
|
25
|
-
let x = "]"
|
26
|
-
let y = stringifyKey(x)
|
27
|
-
let e = '"]"'
|
28
|
-
expect(y).toEqual(e)
|
29
|
-
})
|
30
|
-
|
31
|
-
test("stringifyKey normal", () => {
|
32
|
-
let x = "abc"
|
33
|
-
let y = stringifyKey(x)
|
34
|
-
let e = x
|
35
|
-
expect(y).toEqual(e)
|
36
|
-
})
|
37
|
-
|
38
|
-
test("stringifyKey null", () => {
|
39
|
-
let x = "null"
|
40
|
-
let y = stringifyKey(x)
|
41
|
-
let e = x
|
42
|
-
expect(y).toEqual(e)
|
43
|
-
})
|
44
|
-
|
45
|
-
test("stringifyKey 123", () => {
|
46
|
-
let x = "-123.45"
|
47
|
-
let y = stringifyKey(x)
|
48
|
-
let e = x
|
49
|
-
expect(y).toEqual(e)
|
50
|
-
})
|
51
|
-
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { stringifyKey } from './stringifyKey'
|
2
|
-
|
3
|
-
/**
|
4
|
-
* 将字符串值序列化为 JSON 字符串,必要时加引号(如布尔/null/数字字面量或特殊字符)。
|
5
|
-
*
|
6
|
-
* @public
|
7
|
-
* @param {string} x - 要处理的字符串值
|
8
|
-
* @returns {string} 处理后的字符串
|
9
|
-
*/
|
10
|
-
export const stringifyStringValue = x => {
|
11
|
-
if (x === "true" || x === "false" || x === "null")
|
12
|
-
return JSON.stringify(x)
|
13
|
-
else if (/^[-+]?\d+(\.\d+)?([eE][-+]?\d+)?$/.test(x))
|
14
|
-
return JSON.stringify(x)
|
15
|
-
else
|
16
|
-
return stringifyKey(x)
|
17
|
-
}
|
@@ -1,52 +0,0 @@
|
|
1
|
-
import { stringifyStringValue } from './stringifyStringValue'
|
2
|
-
|
3
|
-
test("stringifyStringValue empty", () => {
|
4
|
-
let x = ""
|
5
|
-
let y = stringifyStringValue(x)
|
6
|
-
let e = '""'
|
7
|
-
expect(y).toEqual(e)
|
8
|
-
})
|
9
|
-
|
10
|
-
test("stringifyStringValue control char", () => {
|
11
|
-
let x = "\u0000"
|
12
|
-
let y = stringifyStringValue(x)
|
13
|
-
let e = '"\\u0000"'
|
14
|
-
expect(y).toEqual(e)
|
15
|
-
})
|
16
|
-
|
17
|
-
test("stringifyStringValue space", () => {
|
18
|
-
let x = " x"
|
19
|
-
let y = stringifyStringValue(x)
|
20
|
-
let e = '" x"'
|
21
|
-
expect(y).toEqual(e)
|
22
|
-
})
|
23
|
-
|
24
|
-
test("stringifyStringValue keyword", () => {
|
25
|
-
let x = "]"
|
26
|
-
let y = stringifyStringValue(x)
|
27
|
-
let e = '"]"'
|
28
|
-
expect(y).toEqual(e)
|
29
|
-
})
|
30
|
-
|
31
|
-
test("stringifyStringValue normal", () => {
|
32
|
-
let x = "abc"
|
33
|
-
let y = stringifyStringValue(x)
|
34
|
-
let e = x
|
35
|
-
expect(y).toEqual(e)
|
36
|
-
})
|
37
|
-
|
38
|
-
test("stringifyStringValue null", () => {
|
39
|
-
let x = "null"
|
40
|
-
let y = stringifyStringValue(x)
|
41
|
-
let e = '"null"'
|
42
|
-
expect(y).toEqual(e)
|
43
|
-
})
|
44
|
-
|
45
|
-
test("stringifyStringValue 123", () => {
|
46
|
-
let x = "-123.45"
|
47
|
-
let y = stringifyStringValue(x)
|
48
|
-
let e = '"-123.45"'
|
49
|
-
expect(y).toEqual(e)
|
50
|
-
})
|
51
|
-
|
52
|
-
|
@@ -1,39 +0,0 @@
|
|
1
|
-
import { stringifyKey } from './stringifyKey'
|
2
|
-
import { stringifyStringValue } from './stringifyStringValue'
|
3
|
-
|
4
|
-
/**
|
5
|
-
* 将任意 JS 值序列化为“无引号 JSON”字符串(仅对键名和部分字符串值去引号)。
|
6
|
-
*
|
7
|
-
* @public
|
8
|
-
* @param {*} value - 要序列化的值
|
9
|
-
* @returns {string} 序列化后的字符串
|
10
|
-
*/
|
11
|
-
export function unquotedJsonStringify(value) {
|
12
|
-
if (value === null) {
|
13
|
-
return 'null'
|
14
|
-
} else if (typeof value === 'string') {
|
15
|
-
return stringifyStringValue(value)
|
16
|
-
} else if (typeof value === 'number') {
|
17
|
-
return isFinite(value) ? value.toString() : 'null'
|
18
|
-
} else if (typeof value === 'boolean') {
|
19
|
-
return value ? 'true' : 'false'
|
20
|
-
} else if (typeof value === 'bigint') {
|
21
|
-
return value.toString()
|
22
|
-
} else if (Array.isArray(value)) {
|
23
|
-
let elems = value.map(e => unquotedJsonStringify(e)).join(',')
|
24
|
-
return '[' + elems + ']'
|
25
|
-
} else if (typeof value === 'object') {
|
26
|
-
let fields = Object.entries(value)
|
27
|
-
.map(([k, v]) => stringifyKey(k) + ':' + unquotedJsonStringify(v))
|
28
|
-
.join(',')
|
29
|
-
return '{' + fields + '}'
|
30
|
-
} else if (typeof value === 'undefined') {
|
31
|
-
return 'null'
|
32
|
-
} else if (typeof value === 'function') {
|
33
|
-
return 'null'
|
34
|
-
} else if (typeof value === 'symbol') {
|
35
|
-
return 'null'
|
36
|
-
} else {
|
37
|
-
return 'null'
|
38
|
-
}
|
39
|
-
}
|
@@ -1,52 +0,0 @@
|
|
1
|
-
import { unquotedJsonStringify } from './unquotedJsonStringify'
|
2
|
-
|
3
|
-
test("null", () => {
|
4
|
-
let x = null
|
5
|
-
let y = unquotedJsonStringify(x)
|
6
|
-
let e = 'null'
|
7
|
-
expect(y).toEqual(e)
|
8
|
-
})
|
9
|
-
|
10
|
-
test("string unquoted", () => {
|
11
|
-
let x = "string"
|
12
|
-
let y = unquotedJsonStringify(x)
|
13
|
-
let e = x
|
14
|
-
expect(y).toEqual(e)
|
15
|
-
})
|
16
|
-
|
17
|
-
test("string quoted", () => {
|
18
|
-
let x = "true"
|
19
|
-
let y = unquotedJsonStringify(x)
|
20
|
-
let e = '"true"'
|
21
|
-
expect(y).toEqual(e)
|
22
|
-
})
|
23
|
-
|
24
|
-
|
25
|
-
test("number", () => {
|
26
|
-
let x = -123
|
27
|
-
let y = unquotedJsonStringify(x)
|
28
|
-
let e = '-123'
|
29
|
-
expect(y).toEqual(e)
|
30
|
-
})
|
31
|
-
|
32
|
-
test("boolean", () => {
|
33
|
-
let x = true
|
34
|
-
let y = unquotedJsonStringify(x)
|
35
|
-
let e = 'true'
|
36
|
-
expect(y).toEqual(e)
|
37
|
-
})
|
38
|
-
|
39
|
-
test("array", () => {
|
40
|
-
let x = []
|
41
|
-
let y = unquotedJsonStringify(x)
|
42
|
-
let e = '[]'
|
43
|
-
expect(y).toEqual(e)
|
44
|
-
})
|
45
|
-
|
46
|
-
test("obj", () => {
|
47
|
-
let x = {}
|
48
|
-
let y = unquotedJsonStringify(x)
|
49
|
-
let e = '{}'
|
50
|
-
expect(y).toEqual(e)
|
51
|
-
})
|
52
|
-
|