@mirascript/mirascript 0.1.64 → 0.1.65
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/README.md +7 -8
- package/dist/{chunk-ITTCGBBX.js → chunk-MRA5WJ72.js} +385 -402
- package/dist/chunk-MRA5WJ72.js.map +6 -0
- package/dist/{chunk-QN3IOQRQ.js → chunk-X4FUFXO6.js} +3 -1
- package/dist/chunk-X4FUFXO6.js.map +6 -0
- package/dist/compiler/worker.js +1 -1
- package/dist/helpers/utils.d.ts +2 -0
- package/dist/helpers/utils.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/subtle.js +2 -2
- package/dist/vm/lib/global/bit.d.ts.map +1 -1
- package/dist/vm/lib/global/debug.d.ts.map +1 -1
- package/dist/vm/lib/global/json.d.ts.map +1 -1
- package/dist/vm/lib/global/math/arr.d.ts.map +1 -1
- package/dist/vm/lib/global/math/const.d.ts.map +1 -1
- package/dist/vm/lib/global/math/gamma.d.ts.map +1 -1
- package/dist/vm/lib/global/math/index.d.ts.map +1 -1
- package/dist/vm/lib/global/math/round.d.ts.map +1 -1
- package/dist/vm/lib/global/math/unary.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/all-any.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/entries.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/find.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/flatten.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/len.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/map-filter.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/new.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/repeat.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/reverse.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/sort.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/unique.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/with.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/zip.d.ts.map +1 -1
- package/dist/vm/lib/global/string/case.d.ts.map +1 -1
- package/dist/vm/lib/global/string/index.d.ts.map +1 -1
- package/dist/vm/lib/global/string/search.d.ts.map +1 -1
- package/dist/vm/lib/global/string/trim.d.ts.map +1 -1
- package/dist/vm/lib/global/time.d.ts.map +1 -1
- package/dist/vm/lib/global/to-primitive.d.ts.map +1 -1
- package/dist/vm/lib/helpers.d.ts +1 -1
- package/dist/vm/lib/helpers.d.ts.map +1 -1
- package/dist/vm/lib/mod/matrix.d.ts.map +1 -1
- package/dist/vm/types/context.d.ts.map +1 -1
- package/dist/vm/types/function.d.ts +8 -7
- package/dist/vm/types/function.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/helpers/utils.ts +7 -0
- package/src/vm/lib/global/bit.ts +23 -21
- package/src/vm/lib/global/debug.ts +6 -6
- package/src/vm/lib/global/json.ts +7 -6
- package/src/vm/lib/global/math/arr.ts +10 -15
- package/src/vm/lib/global/math/const.ts +0 -10
- package/src/vm/lib/global/math/gamma.ts +4 -6
- package/src/vm/lib/global/math/index.ts +11 -8
- package/src/vm/lib/global/math/round.ts +20 -12
- package/src/vm/lib/global/math/unary.ts +44 -66
- package/src/vm/lib/global/sequence/all-any.ts +14 -10
- package/src/vm/lib/global/sequence/entries.ts +8 -9
- package/src/vm/lib/global/sequence/find.ts +6 -7
- package/src/vm/lib/global/sequence/flatten.ts +5 -3
- package/src/vm/lib/global/sequence/len.ts +2 -3
- package/src/vm/lib/global/sequence/map-filter.ts +18 -21
- package/src/vm/lib/global/sequence/new.ts +13 -6
- package/src/vm/lib/global/sequence/repeat.ts +3 -7
- package/src/vm/lib/global/sequence/reverse.ts +2 -3
- package/src/vm/lib/global/sequence/sort.ts +16 -16
- package/src/vm/lib/global/sequence/unique.ts +16 -16
- package/src/vm/lib/global/sequence/with.ts +6 -7
- package/src/vm/lib/global/sequence/zip.ts +2 -3
- package/src/vm/lib/global/string/case.ts +4 -6
- package/src/vm/lib/global/string/index.ts +18 -12
- package/src/vm/lib/global/string/search.ts +15 -9
- package/src/vm/lib/global/string/trim.ts +6 -9
- package/src/vm/lib/global/time.ts +10 -13
- package/src/vm/lib/global/to-primitive.ts +15 -15
- package/src/vm/lib/helpers.ts +1 -6
- package/src/vm/lib/mod/matrix.ts +48 -39
- package/src/vm/operations/compound.ts +2 -2
- package/src/vm/types/context.ts +17 -20
- package/src/vm/types/function.ts +9 -10
- package/dist/chunk-ITTCGBBX.js.map +0 -6
- package/dist/chunk-QN3IOQRQ.js.map +0 -6
|
@@ -10,136 +10,114 @@ function build(f: (x: number) => number): (x: VmAny) => number {
|
|
|
10
10
|
|
|
11
11
|
export const sign = VmLib(build(Math.sign), {
|
|
12
12
|
summary: '返回数值的符号(正数为 1,负数为 -1,零为 0)',
|
|
13
|
-
params: { x: '要判断符号的数' },
|
|
14
|
-
|
|
15
|
-
returnsType: 'number',
|
|
13
|
+
params: { x: { type: 'number', description: '要判断符号的数' } },
|
|
14
|
+
returns: { type: 'number' },
|
|
16
15
|
});
|
|
17
16
|
export const abs = VmLib(build(Math.abs), {
|
|
18
17
|
summary: '返回数值的绝对值',
|
|
19
|
-
params: { x: '要取绝对值的数' },
|
|
20
|
-
|
|
21
|
-
returnsType: 'number',
|
|
18
|
+
params: { x: { type: 'number', description: '要取绝对值的数' } },
|
|
19
|
+
returns: { type: 'number' },
|
|
22
20
|
});
|
|
23
21
|
|
|
24
22
|
export const acos = VmLib(build(Math.acos), {
|
|
25
23
|
summary: '返回数值的反余弦值(弧度)',
|
|
26
|
-
params: { x: '要计算反余弦的数' },
|
|
27
|
-
|
|
28
|
-
returnsType: 'number',
|
|
24
|
+
params: { x: { type: 'number', description: '要计算反余弦的数' } },
|
|
25
|
+
returns: { type: 'number' },
|
|
29
26
|
});
|
|
30
27
|
export const acosh = VmLib(build(Math.acosh), {
|
|
31
28
|
summary: '返回数值的反双曲余弦值',
|
|
32
|
-
params: { x: '要计算反双曲余弦的数' },
|
|
33
|
-
|
|
34
|
-
returnsType: 'number',
|
|
29
|
+
params: { x: { type: 'number', description: '要计算反双曲余弦的数' } },
|
|
30
|
+
returns: { type: 'number' },
|
|
35
31
|
});
|
|
36
32
|
export const asin = VmLib(build(Math.asin), {
|
|
37
33
|
summary: '返回数值的反正弦值(弧度)',
|
|
38
|
-
params: { x: '要计算反正弦的数' },
|
|
39
|
-
|
|
40
|
-
returnsType: 'number',
|
|
34
|
+
params: { x: { type: 'number', description: '要计算反正弦的数' } },
|
|
35
|
+
returns: { type: 'number' },
|
|
41
36
|
});
|
|
42
37
|
export const asinh = VmLib(build(Math.asinh), {
|
|
43
38
|
summary: '返回数值的反双曲正弦值',
|
|
44
|
-
params: { x: '要计算反双曲正弦的数' },
|
|
45
|
-
|
|
46
|
-
returnsType: 'number',
|
|
39
|
+
params: { x: { type: 'number', description: '要计算反双曲正弦的数' } },
|
|
40
|
+
returns: { type: 'number' },
|
|
47
41
|
});
|
|
48
42
|
export const atan = VmLib(build(Math.atan), {
|
|
49
43
|
summary: '返回数值的反正切值(弧度)',
|
|
50
|
-
params: { x: '要计算反正切的数' },
|
|
51
|
-
|
|
52
|
-
returnsType: 'number',
|
|
44
|
+
params: { x: { type: 'number', description: '要计算反正切的数' } },
|
|
45
|
+
returns: { type: 'number' },
|
|
53
46
|
});
|
|
54
47
|
export const atanh = VmLib(build(Math.atanh), {
|
|
55
48
|
summary: '返回数值的反双曲正切值',
|
|
56
|
-
params: { x: '要计算反双曲正切的数' },
|
|
57
|
-
|
|
58
|
-
returnsType: 'number',
|
|
49
|
+
params: { x: { type: 'number', description: '要计算反双曲正切的数' } },
|
|
50
|
+
returns: { type: 'number' },
|
|
59
51
|
});
|
|
60
52
|
export const cos = VmLib(build(Math.cos), {
|
|
61
53
|
summary: '返回数值的余弦值',
|
|
62
|
-
params: { x: '要计算余弦的数(弧度)' },
|
|
63
|
-
|
|
64
|
-
returnsType: 'number',
|
|
54
|
+
params: { x: { type: 'number', description: '要计算余弦的数(弧度)' } },
|
|
55
|
+
returns: { type: 'number' },
|
|
65
56
|
});
|
|
66
57
|
export const cosh = VmLib(build(Math.cosh), {
|
|
67
58
|
summary: '返回数值的双曲余弦值',
|
|
68
|
-
params: { x: '要计算双曲余弦的数' },
|
|
69
|
-
|
|
70
|
-
returnsType: 'number',
|
|
59
|
+
params: { x: { type: 'number', description: '要计算双曲余弦的数' } },
|
|
60
|
+
returns: { type: 'number' },
|
|
71
61
|
});
|
|
72
62
|
export const sin = VmLib(build(Math.sin), {
|
|
73
63
|
summary: '返回数值的正弦值',
|
|
74
|
-
params: { x: '要计算正弦的数(弧度)' },
|
|
75
|
-
|
|
76
|
-
returnsType: 'number',
|
|
64
|
+
params: { x: { type: 'number', description: '要计算正弦的数(弧度)' } },
|
|
65
|
+
returns: { type: 'number' },
|
|
77
66
|
});
|
|
78
67
|
export const sinh = VmLib(build(Math.sinh), {
|
|
79
68
|
summary: '返回数值的双曲正弦值',
|
|
80
|
-
params: { x: '要计算双曲正弦的数' },
|
|
81
|
-
|
|
82
|
-
returnsType: 'number',
|
|
69
|
+
params: { x: { type: 'number', description: '要计算双曲正弦的数' } },
|
|
70
|
+
returns: { type: 'number' },
|
|
83
71
|
});
|
|
84
72
|
export const tan = VmLib(build(Math.tan), {
|
|
85
73
|
summary: '返回数值的正切值',
|
|
86
|
-
params: { x: '要计算正切的数(弧度)' },
|
|
87
|
-
|
|
88
|
-
returnsType: 'number',
|
|
74
|
+
params: { x: { type: 'number', description: '要计算正切的数(弧度)' } },
|
|
75
|
+
returns: { type: 'number' },
|
|
89
76
|
});
|
|
90
77
|
export const tanh = VmLib(build(Math.tanh), {
|
|
91
78
|
summary: '返回数值的双曲正切值',
|
|
92
|
-
params: { x: '要计算双曲正切的数' },
|
|
93
|
-
|
|
94
|
-
returnsType: 'number',
|
|
79
|
+
params: { x: { type: 'number', description: '要计算双曲正切的数' } },
|
|
80
|
+
returns: { type: 'number' },
|
|
95
81
|
});
|
|
96
82
|
|
|
97
83
|
export const exp = VmLib(build(Math.exp), {
|
|
98
84
|
summary: '返回 e 的指定次幂',
|
|
99
|
-
params: { x: '指数' },
|
|
100
|
-
|
|
101
|
-
returnsType: 'number',
|
|
85
|
+
params: { x: { type: 'number', description: '指数' } },
|
|
86
|
+
returns: { type: 'number' },
|
|
102
87
|
});
|
|
103
88
|
export const expm1 = VmLib(build(Math.expm1), {
|
|
104
89
|
summary: '返回 e 的 x 次幂减 1',
|
|
105
|
-
params: { x: '指数' },
|
|
106
|
-
|
|
107
|
-
returnsType: 'number',
|
|
90
|
+
params: { x: { type: 'number', description: '指数' } },
|
|
91
|
+
returns: { type: 'number' },
|
|
108
92
|
});
|
|
109
93
|
export const log = VmLib(build(Math.log), {
|
|
110
94
|
summary: '返回数值的自然对数(以 e 为底)',
|
|
111
|
-
params: { x: '要取对数的数' },
|
|
112
|
-
|
|
113
|
-
returnsType: 'number',
|
|
95
|
+
params: { x: { type: 'number', description: '要取对数的数' } },
|
|
96
|
+
returns: { type: 'number' },
|
|
114
97
|
});
|
|
115
98
|
export const log10 = VmLib(build(Math.log10), {
|
|
116
99
|
summary: '返回数值的以 10 为底的对数',
|
|
117
|
-
params: { x: '要取对数的数' },
|
|
118
|
-
|
|
119
|
-
returnsType: 'number',
|
|
100
|
+
params: { x: { type: 'number', description: '要取对数的数' } },
|
|
101
|
+
returns: { type: 'number' },
|
|
120
102
|
});
|
|
121
103
|
export const log1p = VmLib(build(Math.log1p), {
|
|
122
104
|
summary: '返回 1 加上数值的自然对数',
|
|
123
|
-
params: { x: '要取对数的数' },
|
|
124
|
-
|
|
125
|
-
returnsType: 'number',
|
|
105
|
+
params: { x: { type: 'number', description: '要取对数的数' } },
|
|
106
|
+
returns: { type: 'number' },
|
|
126
107
|
});
|
|
127
108
|
export const log2 = VmLib(build(Math.log2), {
|
|
128
109
|
summary: '返回数值的以 2 为底的对数',
|
|
129
|
-
params: { x: '要取对数的数' },
|
|
130
|
-
|
|
131
|
-
returnsType: 'number',
|
|
110
|
+
params: { x: { type: 'number', description: '要取对数的数' } },
|
|
111
|
+
returns: { type: 'number' },
|
|
132
112
|
});
|
|
133
113
|
|
|
134
114
|
export const sqrt = VmLib(build(Math.sqrt), {
|
|
135
115
|
summary: '返回数值的平方根',
|
|
136
|
-
params: { x: '要开平方的数' },
|
|
137
|
-
|
|
138
|
-
returnsType: 'number',
|
|
116
|
+
params: { x: { type: 'number', description: '要开平方的数' } },
|
|
117
|
+
returns: { type: 'number' },
|
|
139
118
|
});
|
|
140
119
|
export const cbrt = VmLib(build(Math.cbrt), {
|
|
141
120
|
summary: '返回数值的立方根',
|
|
142
|
-
params: { x: '要计算立方根的数' },
|
|
143
|
-
|
|
144
|
-
returnsType: 'number',
|
|
121
|
+
params: { x: { type: 'number', description: '要计算立方根的数' } },
|
|
122
|
+
returns: { type: 'number' },
|
|
145
123
|
});
|
|
@@ -31,12 +31,14 @@ export const all = VmLib(
|
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
summary: '检查数组或记录中的所有键值对是否都满足条件',
|
|
34
|
-
params: {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
params: {
|
|
35
|
+
data: { type: 'array | record', description: '要检查的数组或记录' },
|
|
36
|
+
predicate: {
|
|
37
|
+
type: 'fn(value: any, key: number | string, input: type(data)) -> boolean',
|
|
38
|
+
description: '用于测试每个键值对的函数',
|
|
39
|
+
},
|
|
38
40
|
},
|
|
39
|
-
|
|
41
|
+
returns: { type: 'boolean' },
|
|
40
42
|
examples: ['all([1, 2, 3], fn { it > 0 }) // true'],
|
|
41
43
|
},
|
|
42
44
|
);
|
|
@@ -67,12 +69,14 @@ export const any = VmLib(
|
|
|
67
69
|
},
|
|
68
70
|
{
|
|
69
71
|
summary: '检查数组或记录中的是否存在满足条件的键值对',
|
|
70
|
-
params: {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
params: {
|
|
73
|
+
data: { type: 'array | record', description: '要检查的数组或记录' },
|
|
74
|
+
predicate: {
|
|
75
|
+
type: 'fn(value: any, key: number | string, input: type(data)) -> boolean',
|
|
76
|
+
description: '用于测试每个键值对的函数',
|
|
77
|
+
},
|
|
74
78
|
},
|
|
75
|
-
|
|
79
|
+
returns: { type: 'boolean' },
|
|
76
80
|
examples: ['any([0, 1, 2], fn { it > 1 }) // true'],
|
|
77
81
|
},
|
|
78
82
|
);
|
|
@@ -20,9 +20,10 @@ export const keys = VmLib(
|
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
summary: '返回数组、记录、外部对象或模块的键列表',
|
|
23
|
-
params: {
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
params: {
|
|
24
|
+
data: { type: 'array | record | extern | module', description: '要获取键的数组、记录、外部对象或模块' },
|
|
25
|
+
},
|
|
26
|
+
returns: { type: 'number[] | string[]' },
|
|
26
27
|
examples: ['keys([10, 20]) // [0, 1]', 'keys((10, 20)) // ["0", "1"]'],
|
|
27
28
|
},
|
|
28
29
|
);
|
|
@@ -39,9 +40,8 @@ export const values = VmLib(
|
|
|
39
40
|
},
|
|
40
41
|
{
|
|
41
42
|
summary: '返回数组或记录的值列表',
|
|
42
|
-
params: { data: '要获取值的数组或记录' },
|
|
43
|
-
|
|
44
|
-
returnsType: 'array',
|
|
43
|
+
params: { data: { type: 'array | record', description: '要获取值的数组或记录' } },
|
|
44
|
+
returns: { type: 'array' },
|
|
45
45
|
examples: ['values((a: 1, b: 2)) // [1, 2]'],
|
|
46
46
|
},
|
|
47
47
|
);
|
|
@@ -61,9 +61,8 @@ export const entries = VmLib(
|
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
63
|
summary: '返回数组或记录的键值对列表',
|
|
64
|
-
params: { data: '要获取键值对的数组或记录' },
|
|
65
|
-
|
|
66
|
-
returnsType: '(number, any)[] | (string, any)[]',
|
|
64
|
+
params: { data: { type: 'array | record', description: '要获取键值对的数组或记录' } },
|
|
65
|
+
returns: { type: '(number, any)[] | (string, any)[]' },
|
|
67
66
|
examples: ['entries([1]) // [(0, 1)]', 'entries((a: 1)) // [("a", 1)]'],
|
|
68
67
|
},
|
|
69
68
|
);
|
|
@@ -39,14 +39,13 @@ export const find = VmLib(
|
|
|
39
39
|
{
|
|
40
40
|
summary: '查找数组或记录中的键值对,返回第一个满足条件的键值对',
|
|
41
41
|
params: {
|
|
42
|
-
data: '要查找的数组或记录',
|
|
43
|
-
predicate:
|
|
42
|
+
data: { type: 'array | record', description: '要查找的数组或记录' },
|
|
43
|
+
predicate: {
|
|
44
|
+
type: '(fn(value: any, key: number | string, input: type(data)) -> boolean) | any',
|
|
45
|
+
description: '用于测试每个键值对的函数,或要查找的值',
|
|
46
|
+
},
|
|
44
47
|
},
|
|
45
|
-
|
|
46
|
-
data: 'array | record',
|
|
47
|
-
predicate: '(fn(value: any, key: number | string, input: type(data)) -> boolean) | any',
|
|
48
|
-
},
|
|
49
|
-
returnsType: '(number | string, any) | nil',
|
|
48
|
+
returns: { type: '(number | string, any) | nil' },
|
|
50
49
|
examples: ['find([3, 5, 8], fn (v) { v % 2 == 0 }) // (2, 8)', `find((x: 1, y: 2, z: 3), 2) // ('y', 2)`],
|
|
51
50
|
},
|
|
52
51
|
);
|
|
@@ -7,9 +7,11 @@ export const flatten = VmLib(
|
|
|
7
7
|
},
|
|
8
8
|
{
|
|
9
9
|
summary: '将数组扁平化',
|
|
10
|
-
params: {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
params: {
|
|
11
|
+
data: { type: 'array', description: '要扁平化的数组' },
|
|
12
|
+
depth: { type: 'number | nil', description: '扁平化的深度,默认为 1' },
|
|
13
|
+
},
|
|
14
|
+
returns: { type: 'array' },
|
|
13
15
|
examples: ['flatten([[1, 2], [3, [4]]], 2) // [1, 2, 3, 4]'],
|
|
14
16
|
},
|
|
15
17
|
);
|
|
@@ -15,9 +15,8 @@ export const len = VmLib(
|
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
summary: '返回数组的长度',
|
|
18
|
-
params: { arr: '要求长度的数组' },
|
|
19
|
-
|
|
20
|
-
returnsType: 'number',
|
|
18
|
+
params: { arr: { type: 'array | extern', description: '要求长度的数组' } },
|
|
19
|
+
returns: { type: 'number' },
|
|
21
20
|
examples: ['len([1, 2, 3]) // 3'],
|
|
22
21
|
},
|
|
23
22
|
);
|
|
@@ -28,14 +28,13 @@ export const map = VmLib(
|
|
|
28
28
|
{
|
|
29
29
|
summary: '对数组或记录中的每个元素应用函数,并返回结果',
|
|
30
30
|
params: {
|
|
31
|
-
data: '要映射的数组或记录',
|
|
32
|
-
f:
|
|
31
|
+
data: { type: 'array | record', description: '要映射的数组或记录' },
|
|
32
|
+
f: {
|
|
33
|
+
type: 'fn(value: any, key: number | string, input: type(data)) -> any',
|
|
34
|
+
description: '应用于每个元素的函数',
|
|
35
|
+
},
|
|
33
36
|
},
|
|
34
|
-
|
|
35
|
-
data: 'array | record',
|
|
36
|
-
f: 'fn(value: any, key: number | string, input: type(data)) -> any',
|
|
37
|
-
},
|
|
38
|
-
returnsType: 'type(data)',
|
|
37
|
+
returns: { type: 'type(data)' },
|
|
39
38
|
examples: ['map([1, 2, 3], fn { it * it }) // [1, 4, 9]'],
|
|
40
39
|
},
|
|
41
40
|
);
|
|
@@ -49,14 +48,13 @@ export const filter = VmLib(
|
|
|
49
48
|
{
|
|
50
49
|
summary: '过滤数组或记录中的元素,返回满足条件的元素',
|
|
51
50
|
params: {
|
|
52
|
-
data: '要过滤的数组或记录',
|
|
53
|
-
predicate:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
predicate: 'fn(value: any, key: number | string, input: type(data)) -> boolean',
|
|
51
|
+
data: { type: 'array | record', description: '要过滤的数组或记录' },
|
|
52
|
+
predicate: {
|
|
53
|
+
type: 'fn(value: any, key: number | string, input: type(data)) -> boolean',
|
|
54
|
+
description: '用于测试每个元素的函数',
|
|
55
|
+
},
|
|
58
56
|
},
|
|
59
|
-
|
|
57
|
+
returns: { type: 'type(data)' },
|
|
60
58
|
examples: ['filter([1, 2, 3, 4], fn { it % 2 == 0 }) // [2, 4]'],
|
|
61
59
|
},
|
|
62
60
|
);
|
|
@@ -70,14 +68,13 @@ export const filter_map = VmLib(
|
|
|
70
68
|
{
|
|
71
69
|
summary: '对数组或记录中的每个元素应用函数,并返回非 `nil` 的结果',
|
|
72
70
|
params: {
|
|
73
|
-
data: '要映射的数组或记录',
|
|
74
|
-
f:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
f: 'fn(value: any, key: number | string, input: type(data)) -> any | nil',
|
|
71
|
+
data: { type: 'array | record', description: '要映射的数组或记录' },
|
|
72
|
+
f: {
|
|
73
|
+
type: 'fn(value: any, key: number | string, input: type(data)) -> any | nil',
|
|
74
|
+
description: '应用于每个元素的函数',
|
|
75
|
+
},
|
|
79
76
|
},
|
|
80
|
-
|
|
77
|
+
returns: { type: 'type(data)' },
|
|
81
78
|
examples: ['filter_map([1, 2, 3], fn {\n if it % 2 == 0 { it * it } else { nil } \n}) // [4]'],
|
|
82
79
|
},
|
|
83
80
|
);
|
|
@@ -21,9 +21,14 @@ export const new_record = VmLib(
|
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
summary: '根据生成器函数创建一个记录',
|
|
24
|
-
params: {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
params: {
|
|
25
|
+
size: { type: 'number', description: '记录的大小' },
|
|
26
|
+
generator: {
|
|
27
|
+
type: 'fn(index: number) -> (string, any) | nil',
|
|
28
|
+
description: '生成器函数,返回键值对或 nil(表示跳过该条目)',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
returns: { type: 'record' },
|
|
27
32
|
examples: ['new_record(3, fn { (it, it * 2) }) // (0, 2, 4)'],
|
|
28
33
|
},
|
|
29
34
|
);
|
|
@@ -40,9 +45,11 @@ export const new_array = VmLib(
|
|
|
40
45
|
},
|
|
41
46
|
{
|
|
42
47
|
summary: '根据生成器函数创建一个数组',
|
|
43
|
-
params: {
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
params: {
|
|
49
|
+
length: { type: 'number', description: '数组的长度' },
|
|
50
|
+
generator: { type: 'fn(index: number) -> any', description: '生成器函数,返回数组元素的值' },
|
|
51
|
+
},
|
|
52
|
+
returns: { type: 'array' },
|
|
46
53
|
examples: ['new_array(5, fn { it * it }) // [0, 1, 4, 9, 16]'],
|
|
47
54
|
},
|
|
48
55
|
);
|
|
@@ -13,14 +13,10 @@ export const repeat = VmLib(
|
|
|
13
13
|
{
|
|
14
14
|
summary: '创建一个包含重复元素的数组',
|
|
15
15
|
params: {
|
|
16
|
-
data: '要重复的元素',
|
|
17
|
-
times: '重复的次数,必须是非负整数',
|
|
16
|
+
data: { type: 'any', description: '要重复的元素' },
|
|
17
|
+
times: { type: 'number', description: '重复的次数,必须是非负整数' },
|
|
18
18
|
},
|
|
19
|
-
|
|
20
|
-
data: 'any',
|
|
21
|
-
times: 'number',
|
|
22
|
-
},
|
|
23
|
-
returnsType: 'type(data)[]',
|
|
19
|
+
returns: { type: 'type(data)[]' },
|
|
24
20
|
examples: ['repeat(0, 5) // [0, 0, 0, 0, 0]', 'repeat("a", 3) // ["a", "a", "a"]'],
|
|
25
21
|
},
|
|
26
22
|
);
|
|
@@ -9,9 +9,8 @@ export const reverse = VmLib(
|
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
summary: '返回数组的反转副本',
|
|
12
|
-
params: { arr: '要反转的数组' },
|
|
13
|
-
|
|
14
|
-
returnsType: 'array',
|
|
12
|
+
params: { arr: { type: 'array', description: '要反转的数组' } },
|
|
13
|
+
returns: { type: 'array' },
|
|
15
14
|
examples: ['reverse([1, 2, 3]) // [3, 2, 1]'],
|
|
16
15
|
},
|
|
17
16
|
);
|
|
@@ -45,14 +45,13 @@ export const sort = VmLib(
|
|
|
45
45
|
{
|
|
46
46
|
summary: '对数组中的元素进行排序,并返回排序后的结果',
|
|
47
47
|
params: {
|
|
48
|
-
data: '要排序的数组',
|
|
49
|
-
comparator:
|
|
48
|
+
data: { type: 'array', description: '要排序的数组' },
|
|
49
|
+
comparator: {
|
|
50
|
+
type: 'fn(a: any, b: any) -> number',
|
|
51
|
+
description: '用于比较两个元素的函数,返回一个数字,表示它们的相对顺序,默认按升序排列',
|
|
52
|
+
},
|
|
50
53
|
},
|
|
51
|
-
|
|
52
|
-
data: 'array',
|
|
53
|
-
comparator: 'fn(a: any, b: any) -> number',
|
|
54
|
-
},
|
|
55
|
-
returnsType: 'array',
|
|
54
|
+
returns: { type: 'array' },
|
|
56
55
|
examples: ['sort(["c", "a", "b"]) // ["a", "b", "c"]'],
|
|
57
56
|
},
|
|
58
57
|
);
|
|
@@ -77,16 +76,17 @@ export const sort_by = VmLib(
|
|
|
77
76
|
{
|
|
78
77
|
summary: '根据键函数对数组中的元素进行排序,并返回排序后的结果',
|
|
79
78
|
params: {
|
|
80
|
-
data: '要排序的数组',
|
|
81
|
-
key:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
data: { type: 'array', description: '要排序的数组' },
|
|
80
|
+
key: {
|
|
81
|
+
type: 'fn(value: any, index: number, arr: type(data)) -> any',
|
|
82
|
+
description: '用于提取排序键的函数,接受一个元素并返回其排序键',
|
|
83
|
+
},
|
|
84
|
+
comparator: {
|
|
85
|
+
type: 'fn(a: any, b: any) -> number',
|
|
86
|
+
description: '用于比较两个排序键的函数,返回一个数字,表示它们的相对顺序,默认按升序排列',
|
|
87
|
+
},
|
|
88
88
|
},
|
|
89
|
-
|
|
89
|
+
returns: { type: 'array' },
|
|
90
90
|
examples: ['sort_by([(0, "x"), (2, "y"), (1, "z")], fn (item) { item[0] }) // [(0, "x"), (1, "z"), (2, "y")]'],
|
|
91
91
|
},
|
|
92
92
|
);
|
|
@@ -39,14 +39,13 @@ export const unique = VmLib(
|
|
|
39
39
|
{
|
|
40
40
|
summary: '对数组中的元素进行去重,并返回去重后的结果',
|
|
41
41
|
params: {
|
|
42
|
-
data: '要去重的数组',
|
|
43
|
-
equal:
|
|
42
|
+
data: { type: 'array', description: '要去重的数组' },
|
|
43
|
+
equal: {
|
|
44
|
+
type: 'fn(a: any, b: any) -> boolean',
|
|
45
|
+
description: '用于判等两个元素的函数,返回一个布尔值,默认使用严格相等比较',
|
|
46
|
+
},
|
|
44
47
|
},
|
|
45
|
-
|
|
46
|
-
data: 'array',
|
|
47
|
-
equal: 'fn(a: any, b: any) -> boolean',
|
|
48
|
-
},
|
|
49
|
-
returnsType: 'array',
|
|
48
|
+
returns: { type: 'array' },
|
|
50
49
|
examples: ['unique([1, 2, 2, 3]) // [1, 2, 3]'],
|
|
51
50
|
},
|
|
52
51
|
);
|
|
@@ -80,16 +79,17 @@ export const unique_by = VmLib(
|
|
|
80
79
|
{
|
|
81
80
|
summary: '根据键函数对数组中的元素进行去重,并返回去重后的结果',
|
|
82
81
|
params: {
|
|
83
|
-
data: '要去重的数组',
|
|
84
|
-
key:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
data: { type: 'array', description: '要去重的数组' },
|
|
83
|
+
key: {
|
|
84
|
+
type: 'fn(value: any, index: number, arr: type(data)) -> any',
|
|
85
|
+
description: '用于提取去重键的函数,接受一个元素并返回其去重键',
|
|
86
|
+
},
|
|
87
|
+
equal: {
|
|
88
|
+
type: 'fn(a: any, b: any) -> boolean',
|
|
89
|
+
description: '用于判同两个元素的函数,返回一个布尔值,默认使用严格相等比较',
|
|
90
|
+
},
|
|
91
91
|
},
|
|
92
|
-
|
|
92
|
+
returns: { type: 'array' },
|
|
93
93
|
examples: ['unique_by(["apple", "banana", "apricot"], fn { chars(it)[0] }) // ["apple", "banana"]'],
|
|
94
94
|
},
|
|
95
95
|
);
|
|
@@ -122,14 +122,13 @@ const _with = VmLib(
|
|
|
122
122
|
{
|
|
123
123
|
summary: '在数组或记录中设置多个键值对',
|
|
124
124
|
params: {
|
|
125
|
-
data: '要设置的数组或记录',
|
|
126
|
-
'..entries':
|
|
125
|
+
data: { type: 'array | record', description: '要设置的数组或记录' },
|
|
126
|
+
'..entries': {
|
|
127
|
+
type: '[..[number | string | (number | string)[], any][]]',
|
|
128
|
+
description: '要设置的键值对,成对出现;键可以是一个值或一个数组(表示嵌套路径)',
|
|
129
|
+
},
|
|
127
130
|
},
|
|
128
|
-
|
|
129
|
-
data: 'array | record',
|
|
130
|
-
'..entries': `[..[number | string | (number | string)[], any][]]`,
|
|
131
|
-
},
|
|
132
|
-
returnsType: 'type(data)',
|
|
131
|
+
returns: { type: 'type(data)' },
|
|
133
132
|
examples: [
|
|
134
133
|
`with([10, 20], 2, 99, 3 ,100) // [10, 20, 99, 100]`,
|
|
135
134
|
`(a: 1)::with(["b", 1], 2) // (a: 1, b: [nil, 2])`,
|
|
@@ -29,9 +29,8 @@ export const zip = VmLib(
|
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
summary: '将数组的数组/记录转换为数组/记录的数组',
|
|
32
|
-
params: { data: '要转换的数组/记录' },
|
|
33
|
-
|
|
34
|
-
returnsType: '(array | record)[]',
|
|
32
|
+
params: { data: { type: 'array | record', description: '要转换的数组/记录' } },
|
|
33
|
+
returns: { type: '(array | record)[]' },
|
|
35
34
|
examples: [
|
|
36
35
|
'zip((x: [1, 2], y: ["a", "b"])) // [(x: 1, y: "a"), (x: 2, y: "b")]',
|
|
37
36
|
`zip([[1, 2], ["a", "b"]]) // [[1, "a"], [2, "b"]]`,
|
|
@@ -6,9 +6,8 @@ export const to_uppercase = VmLib(
|
|
|
6
6
|
},
|
|
7
7
|
{
|
|
8
8
|
summary: '将字符串转换为大写',
|
|
9
|
-
params: { str: '要转换的字符串' },
|
|
10
|
-
|
|
11
|
-
returnsType: 'string',
|
|
9
|
+
params: { str: { type: 'string', description: '要转换的字符串' } },
|
|
10
|
+
returns: { type: 'string' },
|
|
12
11
|
examples: ['to_uppercase("mira") // "MIRA"'],
|
|
13
12
|
},
|
|
14
13
|
);
|
|
@@ -19,9 +18,8 @@ export const to_lowercase = VmLib(
|
|
|
19
18
|
},
|
|
20
19
|
{
|
|
21
20
|
summary: '将字符串转换为小写',
|
|
22
|
-
params: { str: '要转换的字符串' },
|
|
23
|
-
|
|
24
|
-
returnsType: 'string',
|
|
21
|
+
params: { str: { type: 'string', description: '要转换的字符串' } },
|
|
22
|
+
returns: { type: 'string' },
|
|
25
23
|
examples: ['to_lowercase("MIRA") // "mira"'],
|
|
26
24
|
},
|
|
27
25
|
);
|