functionalscript 0.3.6 → 0.3.8
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/com/cpp/module.f.js +0 -1
- package/com/cs/module.f.js +5 -6
- package/com/rust/module.f.d.ts +3 -3
- package/com/rust/module.f.js +24 -29
- package/com/test/build.f.js +2 -2
- package/com/types/module.f.d.ts +1 -1
- package/com/types/module.f.js +1 -2
- package/com/types/testlib.f.js +0 -1
- package/commonjs/build/module.f.d.ts +2 -2
- package/commonjs/build/module.f.js +3 -6
- package/commonjs/build/test.f.js +0 -4
- package/commonjs/module/function/module.f.d.ts +1 -1
- package/commonjs/module/function/module.f.js +1 -1
- package/commonjs/module/module.f.d.ts +1 -1
- package/commonjs/module/module.f.js +2 -3
- package/commonjs/path/module.f.d.ts +5 -5
- package/commonjs/path/module.f.js +6 -8
- package/commonjs/path/test.f.js +1 -2
- package/crypto/prime_field/module.f.d.ts +2 -2
- package/crypto/prime_field/module.f.js +3 -4
- package/crypto/secp/module.f.d.ts +2 -2
- package/crypto/secp/module.f.js +4 -5
- package/crypto/sha2/module.f.d.ts +75 -12
- package/crypto/sha2/module.f.js +246 -139
- package/crypto/sha2/test.f.d.ts +22 -3
- package/crypto/sha2/test.f.js +120 -67
- package/dev/test/module.f.d.ts +1 -1
- package/dev/test/module.f.js +4 -5
- package/dev/test.f.js +0 -4
- package/djs/module.f.d.ts +1 -1
- package/djs/module.f.js +0 -1
- package/djs/parser/module.f.d.ts +1 -1
- package/djs/parser/module.f.js +0 -2
- package/djs/serializer/module.f.d.ts +2 -2
- package/djs/serializer/module.f.js +0 -2
- package/djs/tokenizer/module.f.js +0 -1
- package/fsc/test.f.js +0 -1
- package/html/module.f.d.ts +1 -1
- package/html/module.f.js +15 -11
- package/html/test.f.js +7 -7
- package/js/tokenizer/module.f.d.ts +2 -2
- package/js/tokenizer/module.f.js +1 -2
- package/json/parser/module.f.d.ts +2 -2
- package/json/parser/module.f.js +0 -3
- package/json/serializer/module.f.js +0 -2
- package/json/tokenizer/module.f.js +0 -1
- package/nanvm-lib/tests/test.f.d.ts +28 -0
- package/nanvm-lib/tests/test.f.js +45 -0
- package/package.json +1 -1
- package/text/ascii/module.f.d.ts +1 -1
- package/text/ascii/module.f.js +2 -3
- package/text/ascii/test.f.js +2 -4
- package/text/module.f.d.ts +18 -3
- package/text/module.f.js +22 -6
- package/text/sgr/module.f.js +1 -1
- package/text/test.f.d.ts +4 -1
- package/text/test.f.js +24 -16
- package/text/utf16/module.f.d.ts +5 -6
- package/text/utf16/module.f.js +9 -10
- package/text/utf16/test.f.js +29 -30
- package/text/utf8/module.f.d.ts +8 -5
- package/text/utf8/module.f.js +3 -5
- package/text/utf8/test.f.js +34 -35
- package/types/array/module.f.d.ts +12 -9
- package/types/array/module.f.js +10 -11
- package/types/array/test.f.d.ts +1 -0
- package/types/array/test.f.js +18 -17
- package/types/bigfloat/module.f.d.ts +1 -1
- package/types/bigfloat/module.f.js +7 -8
- package/types/bigfloat/test.f.js +1 -2
- package/types/bigint/module.f.d.ts +20 -11
- package/types/bigint/module.f.js +19 -20
- package/types/bigint/test.f.d.ts +1 -0
- package/types/bigint/test.f.js +7 -2
- package/types/bit_vec/module.f.d.ts +103 -83
- package/types/bit_vec/module.f.js +68 -110
- package/types/bit_vec/test.f.d.ts +20 -8
- package/types/bit_vec/test.f.js +110 -117
- package/types/btree/find/test.f.js +3 -4
- package/types/btree/module.f.d.ts +3 -3
- package/types/btree/module.f.js +2 -5
- package/types/btree/remove/test.f.js +2 -3
- package/types/btree/set/test.f.js +3 -6
- package/types/btree/test.f.js +0 -1
- package/types/btree/types/module.f.d.ts +3 -3
- package/types/byte_set/module.f.d.ts +2 -2
- package/types/byte_set/module.f.js +0 -2
- package/types/function/compare/module.f.d.ts +1 -1
- package/types/function/compare/module.f.js +0 -1
- package/types/function/compare/test.f.js +1 -2
- package/types/function/module.f.d.ts +1 -1
- package/types/function/module.f.js +1 -1
- package/types/function/operator/module.f.d.ts +2 -3
- package/types/function/operator/module.f.js +5 -5
- package/types/function/test.f.js +1 -2
- package/types/list/module.f.d.ts +1 -1
- package/types/list/module.f.js +9 -9
- package/types/list/test.f.js +2 -4
- package/types/map/module.f.d.ts +6 -6
- package/types/map/module.f.js +6 -15
- package/types/map/test.f.js +1 -2
- package/types/monoid/module.f.d.ts +73 -0
- package/types/monoid/module.f.js +42 -0
- package/types/monoid/test.f.d.ts +5 -0
- package/types/monoid/test.f.js +27 -0
- package/types/nibble_set/module.f.d.ts +2 -3
- package/types/nibble_set/test.f.js +1 -2
- package/types/number/test.f.js +1 -2
- package/types/object/module.f.d.ts +5 -5
- package/types/object/module.f.js +2 -4
- package/types/range_map/module.f.d.ts +4 -4
- package/types/range_map/module.f.js +3 -9
- package/types/result/module.f.d.ts +2 -3
- package/types/sorted_list/module.f.d.ts +6 -6
- package/types/sorted_list/module.f.js +2 -6
- package/types/sorted_list/test.f.js +4 -9
- package/types/sorted_set/module.f.d.ts +1 -1
- package/types/sorted_set/module.f.js +2 -5
- package/types/sorted_set/test.f.js +4 -9
- package/types/string/module.f.d.ts +3 -3
- package/types/string/module.f.js +1 -2
- package/types/string/test.f.js +2 -4
- package/types/string_set/module.f.d.ts +1 -1
- package/types/string_set/module.f.js +5 -11
package/text/utf16/test.f.js
CHANGED
|
@@ -1,55 +1,54 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { toCodePointList, fromCodePointList, stringToList, listToString } from "./module.f.js";
|
|
2
2
|
import * as json from "../../json/module.f.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const stringify = a => json.stringify(sort)(a);
|
|
3
|
+
import { sort } from "../../types/object/module.f.js";
|
|
4
|
+
import { toArray } from "../../types/list/module.f.js";
|
|
5
|
+
const stringify = (a) => json.stringify(sort)(a);
|
|
7
6
|
export default {
|
|
8
7
|
toCodePointList: [
|
|
9
8
|
() => {
|
|
10
|
-
const result = stringify(
|
|
9
|
+
const result = stringify(toArray(toCodePointList([-1, 65536])));
|
|
11
10
|
if (result !== '[4294967295,4294967295]') {
|
|
12
11
|
throw result;
|
|
13
12
|
}
|
|
14
13
|
},
|
|
15
14
|
() => {
|
|
16
|
-
const result = stringify(
|
|
15
|
+
const result = stringify(toArray(toCodePointList([0, 36, 8364, 55295, 57344, 65535])));
|
|
17
16
|
if (result !== '[0,36,8364,55295,57344,65535]') {
|
|
18
17
|
throw result;
|
|
19
18
|
}
|
|
20
19
|
},
|
|
21
20
|
() => {
|
|
22
|
-
const result = stringify(
|
|
21
|
+
const result = stringify(toArray(toCodePointList([56320, 57343])));
|
|
23
22
|
if (result !== '[-2147427328,-2147426305]') {
|
|
24
23
|
throw result;
|
|
25
24
|
}
|
|
26
25
|
},
|
|
27
26
|
() => {
|
|
28
|
-
const result = stringify(
|
|
27
|
+
const result = stringify(toArray(toCodePointList([55296, 56320, 55297, 56375, 55378, 57186, 56319, 57343])));
|
|
29
28
|
if (result !== '[65536,66615,150370,1114111]') {
|
|
30
29
|
throw result;
|
|
31
30
|
}
|
|
32
31
|
},
|
|
33
32
|
() => {
|
|
34
|
-
const result = stringify(
|
|
33
|
+
const result = stringify(toArray(toCodePointList([55296, 55296])));
|
|
35
34
|
if (result !== '[-2147428352,-2147428352]') {
|
|
36
35
|
throw result;
|
|
37
36
|
}
|
|
38
37
|
},
|
|
39
38
|
() => {
|
|
40
|
-
const result = stringify(
|
|
39
|
+
const result = stringify(toArray(toCodePointList([55296, 0])));
|
|
41
40
|
if (result !== '[-2147428352,0]') {
|
|
42
41
|
throw result;
|
|
43
42
|
}
|
|
44
43
|
},
|
|
45
44
|
() => {
|
|
46
|
-
const result = stringify(
|
|
45
|
+
const result = stringify(toArray(toCodePointList([56320])));
|
|
47
46
|
if (result !== '[-2147427328]') {
|
|
48
47
|
throw result;
|
|
49
48
|
}
|
|
50
49
|
},
|
|
51
50
|
() => {
|
|
52
|
-
const result = stringify(
|
|
51
|
+
const result = stringify(toArray(toCodePointList([56320, 0])));
|
|
53
52
|
if (result !== '[-2147427328,0]') {
|
|
54
53
|
throw result;
|
|
55
54
|
}
|
|
@@ -57,67 +56,67 @@ export default {
|
|
|
57
56
|
],
|
|
58
57
|
fromCodePointList: [
|
|
59
58
|
() => {
|
|
60
|
-
const result = stringify(
|
|
59
|
+
const result = stringify(toArray(fromCodePointList([0])));
|
|
61
60
|
if (result !== '[0]') {
|
|
62
61
|
throw result;
|
|
63
62
|
}
|
|
64
63
|
},
|
|
65
64
|
() => {
|
|
66
|
-
const result = stringify(
|
|
65
|
+
const result = stringify(toArray(fromCodePointList([0x24])));
|
|
67
66
|
if (result !== '[36]') {
|
|
68
67
|
throw result;
|
|
69
68
|
}
|
|
70
69
|
},
|
|
71
70
|
() => {
|
|
72
|
-
const result = stringify(
|
|
71
|
+
const result = stringify(toArray(fromCodePointList([0x20AC])));
|
|
73
72
|
if (result !== '[8364]') {
|
|
74
73
|
throw result;
|
|
75
74
|
}
|
|
76
75
|
},
|
|
77
76
|
() => {
|
|
78
|
-
const result = stringify(
|
|
77
|
+
const result = stringify(toArray(fromCodePointList([0xd7ff])));
|
|
79
78
|
if (result !== '[55295]') {
|
|
80
79
|
throw result;
|
|
81
80
|
}
|
|
82
81
|
},
|
|
83
82
|
() => {
|
|
84
|
-
const result = stringify(
|
|
83
|
+
const result = stringify(toArray(fromCodePointList([0xe000])));
|
|
85
84
|
if (result !== '[57344]') {
|
|
86
85
|
throw result;
|
|
87
86
|
}
|
|
88
87
|
},
|
|
89
88
|
() => {
|
|
90
|
-
const result = stringify(
|
|
89
|
+
const result = stringify(toArray(fromCodePointList([0xffff])));
|
|
91
90
|
if (result !== '[65535]') {
|
|
92
91
|
throw result;
|
|
93
92
|
}
|
|
94
93
|
},
|
|
95
94
|
() => {
|
|
96
|
-
const result = stringify(
|
|
95
|
+
const result = stringify(toArray(fromCodePointList([0x10000])));
|
|
97
96
|
if (result !== '[55296,56320]') {
|
|
98
97
|
throw result;
|
|
99
98
|
}
|
|
100
99
|
},
|
|
101
100
|
() => {
|
|
102
|
-
const result = stringify(
|
|
101
|
+
const result = stringify(toArray(fromCodePointList([0x10437])));
|
|
103
102
|
if (result !== '[55297,56375]') {
|
|
104
103
|
throw result;
|
|
105
104
|
}
|
|
106
105
|
},
|
|
107
106
|
() => {
|
|
108
|
-
const result = stringify(
|
|
107
|
+
const result = stringify(toArray(fromCodePointList([0x24B62])));
|
|
109
108
|
if (result !== '[55378,57186]') {
|
|
110
109
|
throw result;
|
|
111
110
|
}
|
|
112
111
|
},
|
|
113
112
|
() => {
|
|
114
|
-
const result = stringify(
|
|
113
|
+
const result = stringify(toArray(fromCodePointList([0x10ffff])));
|
|
115
114
|
if (result !== '[56319,57343]') {
|
|
116
115
|
throw result;
|
|
117
116
|
}
|
|
118
117
|
},
|
|
119
118
|
() => {
|
|
120
|
-
const result = stringify(
|
|
119
|
+
const result = stringify(toArray(fromCodePointList([-1, 0xd800, 0xdfff, 0x110000])));
|
|
121
120
|
if (result !== '[65535,55296,57343,0]') {
|
|
122
121
|
throw result;
|
|
123
122
|
}
|
|
@@ -125,17 +124,17 @@ export default {
|
|
|
125
124
|
],
|
|
126
125
|
string: [
|
|
127
126
|
() => {
|
|
128
|
-
const utf16List =
|
|
129
|
-
const result =
|
|
127
|
+
const utf16List = stringToList("Hello world!😂🚜🚲");
|
|
128
|
+
const result = listToString(utf16List);
|
|
130
129
|
if (result !== "Hello world!😂🚜🚲") {
|
|
131
130
|
throw result;
|
|
132
131
|
}
|
|
133
132
|
},
|
|
134
133
|
() => {
|
|
135
|
-
const a =
|
|
136
|
-
const b =
|
|
137
|
-
const c =
|
|
138
|
-
const result =
|
|
134
|
+
const a = stringToList("Hello world!😂🚜🚲");
|
|
135
|
+
const b = toCodePointList(a);
|
|
136
|
+
const c = fromCodePointList(b);
|
|
137
|
+
const result = listToString(c);
|
|
139
138
|
if (result !== "Hello world!😂🚜🚲") {
|
|
140
139
|
throw result;
|
|
141
140
|
}
|
package/text/utf8/module.f.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type List, type Thunk } from '../../types/list/module.f.ts';
|
|
2
|
-
type
|
|
3
|
-
type
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
2
|
+
import type { Array1, Array2, Array3 } from '../../types/array/module.f.ts';
|
|
3
|
+
export type ByteOrEof = U8 | null;
|
|
4
|
+
export type Utf8NonEmptyState = Array1<number> | Array2<number> | Array3<number>;
|
|
5
|
+
export type Utf8State = null | Utf8NonEmptyState;
|
|
6
|
+
export type U8 = number;
|
|
7
|
+
export type I32 = number;
|
|
8
|
+
export declare const fromCodePointList: (input: List<number>) => Thunk<U8>;
|
|
9
|
+
export declare const toCodePointList: (input: List<U8>) => List<I32>;
|
package/text/utf8/module.f.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { flatMap, flat, stateScan } from "../../types/list/module.f.js";
|
|
2
|
-
import * as operator from "../../types/function/operator/module.f.js";
|
|
3
|
-
import * as Array from "../../types/array/module.f.js";
|
|
4
2
|
const errorMask = 0b1000_0000_0000_0000_0000_0000_0000_0000;
|
|
5
|
-
const codePointToUtf8 = input => {
|
|
3
|
+
const codePointToUtf8 = (input) => {
|
|
6
4
|
if (input >= 0x0000 && input <= 0x007f) {
|
|
7
5
|
return [input & 0b01111_1111];
|
|
8
6
|
}
|
|
@@ -32,7 +30,7 @@ const codePointToUtf8 = input => {
|
|
|
32
30
|
return [errorMask];
|
|
33
31
|
};
|
|
34
32
|
export const fromCodePointList = flatMap(codePointToUtf8);
|
|
35
|
-
const utf8StateToError = state => {
|
|
33
|
+
const utf8StateToError = (state) => {
|
|
36
34
|
let x;
|
|
37
35
|
switch (state.length) {
|
|
38
36
|
case 1: {
|
|
@@ -106,7 +104,7 @@ const utf8ByteToCodePointOp = state => byte => {
|
|
|
106
104
|
}
|
|
107
105
|
return [[error, byte | errorMask], null];
|
|
108
106
|
};
|
|
109
|
-
const utf8EofToCodePointOp = state => [state === null ? null : [utf8StateToError(state)], null];
|
|
107
|
+
const utf8EofToCodePointOp = (state) => [state === null ? null : [utf8StateToError(state)], null];
|
|
110
108
|
const utf8ByteOrEofToCodePointOp = state => input => input === null ? utf8EofToCodePointOp(state) : utf8ByteToCodePointOp(state)(input);
|
|
111
109
|
const eofList = [null];
|
|
112
110
|
export const toCodePointList = input => flat(stateScan(utf8ByteOrEofToCodePointOp)(null)(flat([input, eofList])));
|
package/text/utf8/test.f.js
CHANGED
|
@@ -1,67 +1,66 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { toCodePointList, fromCodePointList } from "./module.f.js";
|
|
2
2
|
import * as json from "../../json/module.f.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import * as list from "../../types/list/module.f.js";
|
|
3
|
+
import { sort } from "../../types/object/module.f.js";
|
|
4
|
+
import { toArray } from "../../types/list/module.f.js";
|
|
6
5
|
const stringify = json.stringify(sort);
|
|
7
6
|
export default {
|
|
8
7
|
toCodePoint: [
|
|
9
8
|
() => {
|
|
10
|
-
const result = stringify(
|
|
9
|
+
const result = stringify(toArray(toCodePointList([-1, 256])));
|
|
11
10
|
if (result !== '[2147483648,2147483648]') {
|
|
12
11
|
throw result;
|
|
13
12
|
}
|
|
14
13
|
},
|
|
15
14
|
() => {
|
|
16
|
-
const result = stringify(
|
|
15
|
+
const result = stringify(toArray(toCodePointList([128, 193, 245, 255])));
|
|
17
16
|
if (result !== '[-2147483520,-2147483455,-2147483403,-2147483393]') {
|
|
18
17
|
throw result;
|
|
19
18
|
}
|
|
20
19
|
},
|
|
21
20
|
() => {
|
|
22
|
-
const result = stringify(
|
|
21
|
+
const result = stringify(toArray(toCodePointList([0, 1, 127])));
|
|
23
22
|
if (result !== '[0,1,127]') {
|
|
24
23
|
throw result;
|
|
25
24
|
}
|
|
26
25
|
},
|
|
27
26
|
() => {
|
|
28
|
-
const result = stringify(
|
|
27
|
+
const result = stringify(toArray(toCodePointList([194, 128, 194, 169, 223, 191])));
|
|
29
28
|
if (result !== '[128,169,2047]') {
|
|
30
29
|
throw result;
|
|
31
30
|
}
|
|
32
31
|
},
|
|
33
32
|
() => {
|
|
34
|
-
const result = stringify(
|
|
33
|
+
const result = stringify(toArray(toCodePointList([194, 194, 127, 194, 192, 194])));
|
|
35
34
|
if (result !== '[-2147483454,-2147483454,127,-2147483454,-2147483456,-2147483454]') {
|
|
36
35
|
throw result;
|
|
37
36
|
}
|
|
38
37
|
},
|
|
39
38
|
() => {
|
|
40
|
-
const result = stringify(
|
|
39
|
+
const result = stringify(toArray(toCodePointList([224, 160, 128, 224, 160, 129, 239, 191, 191])));
|
|
41
40
|
if (result !== '[2048,2049,65535]') {
|
|
42
41
|
throw result;
|
|
43
42
|
}
|
|
44
43
|
},
|
|
45
44
|
() => {
|
|
46
|
-
const result = stringify(
|
|
45
|
+
const result = stringify(toArray(toCodePointList([224, 224, 160, 127, 239, 191])));
|
|
47
46
|
if (result !== '[-2147483424,-2147482592,127,-2147481601]') {
|
|
48
47
|
throw result;
|
|
49
48
|
}
|
|
50
49
|
},
|
|
51
50
|
() => {
|
|
52
|
-
const result = stringify(
|
|
51
|
+
const result = stringify(toArray(toCodePointList([240, 144, 128, 128, 240, 144, 128, 129, 244, 143, 191, 191])));
|
|
53
52
|
if (result !== '[65536,65537,1114111]') {
|
|
54
53
|
throw result;
|
|
55
54
|
}
|
|
56
55
|
},
|
|
57
56
|
() => {
|
|
58
|
-
const result = stringify(
|
|
57
|
+
const result = stringify(toArray(toCodePointList([240, 240, 160, 127, 244, 191])));
|
|
59
58
|
if (result !== '[-2147483408,-2147483104,127,-2147482817]') {
|
|
60
59
|
throw result;
|
|
61
60
|
}
|
|
62
61
|
},
|
|
63
62
|
() => {
|
|
64
|
-
const result = stringify(
|
|
63
|
+
const result = stringify(toArray(toCodePointList([240, 160, 160, 244, 160, 160])));
|
|
65
64
|
if (result !== '[-2147448800,-2147432416]') {
|
|
66
65
|
throw result;
|
|
67
66
|
}
|
|
@@ -69,67 +68,67 @@ export default {
|
|
|
69
68
|
],
|
|
70
69
|
fromCodePointList: [
|
|
71
70
|
() => {
|
|
72
|
-
const result = stringify(
|
|
71
|
+
const result = stringify(toArray(fromCodePointList([0, 1, 0x7F])));
|
|
73
72
|
if (result !== '[0,1,127]') {
|
|
74
73
|
throw result;
|
|
75
74
|
}
|
|
76
75
|
},
|
|
77
76
|
() => {
|
|
78
|
-
const result = stringify(
|
|
77
|
+
const result = stringify(toArray(fromCodePointList([0x80])));
|
|
79
78
|
if (result !== '[194,128]') {
|
|
80
79
|
throw result;
|
|
81
80
|
}
|
|
82
81
|
},
|
|
83
82
|
() => {
|
|
84
|
-
const result = stringify(
|
|
83
|
+
const result = stringify(toArray(fromCodePointList([0xa9])));
|
|
85
84
|
if (result !== '[194,169]') {
|
|
86
85
|
throw result;
|
|
87
86
|
}
|
|
88
87
|
},
|
|
89
88
|
() => {
|
|
90
|
-
const result = stringify(
|
|
89
|
+
const result = stringify(toArray(fromCodePointList([0x7ff])));
|
|
91
90
|
if (result !== '[223,191]') {
|
|
92
91
|
throw result;
|
|
93
92
|
}
|
|
94
93
|
},
|
|
95
94
|
() => {
|
|
96
|
-
const result = stringify(
|
|
95
|
+
const result = stringify(toArray(fromCodePointList([0x800])));
|
|
97
96
|
if (result !== '[224,160,128]') {
|
|
98
97
|
throw result;
|
|
99
98
|
}
|
|
100
99
|
},
|
|
101
100
|
() => {
|
|
102
|
-
const result = stringify(
|
|
101
|
+
const result = stringify(toArray(fromCodePointList([0x801])));
|
|
103
102
|
if (result !== '[224,160,129]') {
|
|
104
103
|
throw result;
|
|
105
104
|
}
|
|
106
105
|
},
|
|
107
106
|
() => {
|
|
108
|
-
const result = stringify(
|
|
107
|
+
const result = stringify(toArray(fromCodePointList([0xffff])));
|
|
109
108
|
if (result !== '[239,191,191]') {
|
|
110
109
|
throw result;
|
|
111
110
|
}
|
|
112
111
|
},
|
|
113
112
|
() => {
|
|
114
|
-
const result = stringify(
|
|
113
|
+
const result = stringify(toArray(fromCodePointList([0x10000])));
|
|
115
114
|
if (result !== '[240,144,128,128]') {
|
|
116
115
|
throw result;
|
|
117
116
|
}
|
|
118
117
|
},
|
|
119
118
|
() => {
|
|
120
|
-
const result = stringify(
|
|
119
|
+
const result = stringify(toArray(fromCodePointList([0x10001])));
|
|
121
120
|
if (result !== '[240,144,128,129]') {
|
|
122
121
|
throw result;
|
|
123
122
|
}
|
|
124
123
|
},
|
|
125
124
|
() => {
|
|
126
|
-
const result = stringify(
|
|
125
|
+
const result = stringify(toArray(fromCodePointList([0x10FFFF])));
|
|
127
126
|
if (result !== '[244,143,191,191]') {
|
|
128
127
|
throw result;
|
|
129
128
|
}
|
|
130
129
|
},
|
|
131
130
|
() => {
|
|
132
|
-
const result = stringify(
|
|
131
|
+
const result = stringify(toArray(fromCodePointList([0x110000, 2147483648])));
|
|
133
132
|
if (result !== '[2147483648,2147483648]') {
|
|
134
133
|
throw result;
|
|
135
134
|
}
|
|
@@ -137,36 +136,36 @@ export default {
|
|
|
137
136
|
],
|
|
138
137
|
toFrom: [
|
|
139
138
|
() => {
|
|
140
|
-
const codePointList =
|
|
141
|
-
const result = stringify(
|
|
139
|
+
const codePointList = toCodePointList([128, 193, 245, 255]);
|
|
140
|
+
const result = stringify(toArray(fromCodePointList(codePointList)));
|
|
142
141
|
if (result !== '[128,193,245,255]') {
|
|
143
142
|
throw result;
|
|
144
143
|
}
|
|
145
144
|
},
|
|
146
145
|
() => {
|
|
147
|
-
const codePointList =
|
|
148
|
-
const result = stringify(
|
|
146
|
+
const codePointList = toCodePointList([194, 194, 127, 194, 192, 194]);
|
|
147
|
+
const result = stringify(toArray(fromCodePointList(codePointList)));
|
|
149
148
|
if (result !== '[194,194,127,194,192,194]') {
|
|
150
149
|
throw result;
|
|
151
150
|
}
|
|
152
151
|
},
|
|
153
152
|
() => {
|
|
154
|
-
const codePointList =
|
|
155
|
-
const result = stringify(
|
|
153
|
+
const codePointList = toCodePointList([224, 224, 160, 127, 239, 191]);
|
|
154
|
+
const result = stringify(toArray(fromCodePointList(codePointList)));
|
|
156
155
|
if (result !== '[224,224,160,127,239,191]') {
|
|
157
156
|
throw result;
|
|
158
157
|
}
|
|
159
158
|
},
|
|
160
159
|
() => {
|
|
161
|
-
const codePointList =
|
|
162
|
-
const result = stringify(
|
|
160
|
+
const codePointList = toCodePointList([240, 240, 160, 127, 244, 191]);
|
|
161
|
+
const result = stringify(toArray(fromCodePointList(codePointList)));
|
|
163
162
|
if (result !== '[240,240,160,127,244,191]') {
|
|
164
163
|
throw result;
|
|
165
164
|
}
|
|
166
165
|
},
|
|
167
166
|
() => {
|
|
168
|
-
const codePointList =
|
|
169
|
-
const result = stringify(
|
|
167
|
+
const codePointList = toCodePointList([240, 160, 160, 244, 160, 160]);
|
|
168
|
+
const result = stringify(toArray(fromCodePointList(codePointList)));
|
|
170
169
|
if (result !== '[240,160,160,244,160,160]') {
|
|
171
170
|
throw result;
|
|
172
171
|
}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
export type Array1<T> = readonly [T];
|
|
2
|
-
type Index1 = 0;
|
|
2
|
+
export type Index1 = 0;
|
|
3
3
|
export type Array2<T> = readonly [T, T];
|
|
4
|
-
type
|
|
4
|
+
export type Tuple2<T0, T1> = readonly [T0, T1];
|
|
5
|
+
export type Index2 = 0 | 1;
|
|
5
6
|
export type Array3<T> = readonly [T, T, T];
|
|
7
|
+
export type Tuple3<T0, T1, T2> = readonly [T0, T1, T2];
|
|
6
8
|
export type Index3 = 0 | 1 | 2;
|
|
7
9
|
export type Array4<T> = readonly [T, T, T, T];
|
|
8
|
-
type Index4 = 0 | 1 | 2 | 3;
|
|
10
|
+
export type Index4 = 0 | 1 | 2 | 3;
|
|
9
11
|
export type Array5<T> = readonly [T, T, T, T, T];
|
|
10
12
|
export type Array8<T> = readonly [T, T, T, T, T, T, T, T];
|
|
11
13
|
export type Array16<T> = readonly [T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T];
|
|
14
|
+
export type Index16 = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
|
|
15
|
+
export type Array1_5<T> = Array1<T> | Array2<T> | Array3<T> | Array4<T> | Array5<T>;
|
|
12
16
|
export type Index5 = 0 | 1 | 2 | 3 | 4;
|
|
13
17
|
export type KeyOf<T> = T extends Array1<infer _> ? Index1 : T extends Array2<infer _> ? Index2 : T extends Array3<infer _> ? Index3 : T extends Array4<infer _> ? Index4 : T extends Array5<infer _> ? Index5 : T extends readonly (infer _)[] ? number : never;
|
|
14
|
-
export declare const at: (
|
|
18
|
+
export declare const at: (i: number) => <T>(a: readonly T[]) => T | null;
|
|
15
19
|
export declare const first: <T>(_: readonly T[]) => T | null;
|
|
16
|
-
export declare const last: <T>(
|
|
17
|
-
export declare const tail: <T>(
|
|
20
|
+
export declare const last: <T>(a: readonly T[]) => T | null;
|
|
21
|
+
export declare const tail: <T>(a: readonly T[]) => readonly T[] | null;
|
|
18
22
|
export declare const splitFirst: <T>(a: readonly T[]) => readonly [T, readonly T[]] | null;
|
|
19
|
-
export declare const head: <T>(
|
|
20
|
-
export declare const splitLast: <T>(
|
|
21
|
-
export {};
|
|
23
|
+
export declare const head: <T>(a: readonly T[]) => readonly T[] | null;
|
|
24
|
+
export declare const splitLast: <T>(a: readonly T[]) => readonly [readonly T[], T] | null;
|
package/types/array/module.f.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
export const at = i => a => {
|
|
1
|
+
import { map } from "../nullable/module.f.js";
|
|
2
|
+
const uncheckTail = (a) => a.slice(1);
|
|
3
|
+
const uncheckHead = (a) => a.slice(0, -1);
|
|
4
|
+
export const at = (i) => (a) => {
|
|
6
5
|
const r = a[i];
|
|
7
|
-
return r ===
|
|
6
|
+
return r === undefined ? null : r;
|
|
8
7
|
};
|
|
9
8
|
export const first = at(0);
|
|
10
|
-
export const last = a => at(a.length - 1)(a);
|
|
11
|
-
export const tail = a => a.length === 0 ? null : uncheckTail(a);
|
|
9
|
+
export const last = (a) => at(a.length - 1)(a);
|
|
10
|
+
export const tail = (a) => a.length === 0 ? null : uncheckTail(a);
|
|
12
11
|
export const splitFirst = (a) => {
|
|
13
|
-
const split = first => [first, uncheckTail(a)];
|
|
12
|
+
const split = (first) => [first, uncheckTail(a)];
|
|
14
13
|
return map(split)(first(a));
|
|
15
14
|
};
|
|
16
|
-
export const head = a => a.length === 0 ? null : uncheckHead(a);
|
|
17
|
-
export const splitLast = a => {
|
|
15
|
+
export const head = (a) => a.length === 0 ? null : uncheckHead(a);
|
|
16
|
+
export const splitLast = (a) => {
|
|
18
17
|
const lastA = last(a);
|
|
19
18
|
if (lastA === null) {
|
|
20
19
|
return null;
|
package/types/array/test.f.d.ts
CHANGED
package/types/array/test.f.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { at, first, last, head, tail, splitFirst, splitLast } from "./module.f.js";
|
|
2
2
|
import * as json from "../../json/module.f.js";
|
|
3
|
-
import
|
|
4
|
-
const { sort } = o;
|
|
3
|
+
import { sort } from "../object/module.f.js";
|
|
5
4
|
const stringify = json.stringify(sort);
|
|
6
5
|
export default {
|
|
7
6
|
stringify: () => {
|
|
@@ -12,13 +11,13 @@ export default {
|
|
|
12
11
|
},
|
|
13
12
|
at: [
|
|
14
13
|
() => {
|
|
15
|
-
const result =
|
|
14
|
+
const result = at(2)([1, 20, 300]);
|
|
16
15
|
if (result !== 300) {
|
|
17
16
|
throw result;
|
|
18
17
|
}
|
|
19
18
|
},
|
|
20
19
|
() => {
|
|
21
|
-
const result =
|
|
20
|
+
const result = at(3)([1, 20, 300]);
|
|
22
21
|
if (result !== null) {
|
|
23
22
|
throw result;
|
|
24
23
|
}
|
|
@@ -26,13 +25,13 @@ export default {
|
|
|
26
25
|
],
|
|
27
26
|
first: [
|
|
28
27
|
() => {
|
|
29
|
-
const result =
|
|
28
|
+
const result = first([1, 20, 300]);
|
|
30
29
|
if (result !== 1) {
|
|
31
30
|
throw result;
|
|
32
31
|
}
|
|
33
32
|
},
|
|
34
33
|
() => {
|
|
35
|
-
const result =
|
|
34
|
+
const result = first([]);
|
|
36
35
|
if (result !== null) {
|
|
37
36
|
throw result;
|
|
38
37
|
}
|
|
@@ -40,13 +39,13 @@ export default {
|
|
|
40
39
|
],
|
|
41
40
|
last: [
|
|
42
41
|
() => {
|
|
43
|
-
const result =
|
|
42
|
+
const result = last([1, 20, 300]);
|
|
44
43
|
if (result !== 300) {
|
|
45
44
|
throw result;
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
() => {
|
|
49
|
-
const result =
|
|
48
|
+
const result = last([]);
|
|
50
49
|
if (result !== null) {
|
|
51
50
|
throw result;
|
|
52
51
|
}
|
|
@@ -54,7 +53,7 @@ export default {
|
|
|
54
53
|
],
|
|
55
54
|
head: [
|
|
56
55
|
() => {
|
|
57
|
-
const result =
|
|
56
|
+
const result = head([1, 20, 300]);
|
|
58
57
|
if (result === null) {
|
|
59
58
|
throw result;
|
|
60
59
|
}
|
|
@@ -64,7 +63,7 @@ export default {
|
|
|
64
63
|
}
|
|
65
64
|
},
|
|
66
65
|
() => {
|
|
67
|
-
const result =
|
|
66
|
+
const result = head([]);
|
|
68
67
|
if (result !== null) {
|
|
69
68
|
throw result;
|
|
70
69
|
}
|
|
@@ -72,14 +71,14 @@ export default {
|
|
|
72
71
|
],
|
|
73
72
|
tail: [
|
|
74
73
|
() => {
|
|
75
|
-
const result =
|
|
74
|
+
const result = tail([1, 20, 300]);
|
|
76
75
|
const str = stringify(result);
|
|
77
76
|
if (str !== '[20,300]') {
|
|
78
77
|
throw str;
|
|
79
78
|
}
|
|
80
79
|
},
|
|
81
80
|
() => {
|
|
82
|
-
const result =
|
|
81
|
+
const result = tail([]);
|
|
83
82
|
if (result !== null) {
|
|
84
83
|
throw result;
|
|
85
84
|
}
|
|
@@ -87,27 +86,29 @@ export default {
|
|
|
87
86
|
],
|
|
88
87
|
splitFirst: [
|
|
89
88
|
() => {
|
|
90
|
-
const result =
|
|
89
|
+
const result = splitFirst([1, 20, 300]);
|
|
91
90
|
const str = stringify(result);
|
|
92
91
|
if (str !== '[1,[20,300]]') {
|
|
93
92
|
throw str;
|
|
94
93
|
}
|
|
95
94
|
},
|
|
96
95
|
() => {
|
|
97
|
-
const result =
|
|
96
|
+
const result = splitFirst([]);
|
|
98
97
|
if (result !== null) {
|
|
99
98
|
throw result;
|
|
100
99
|
}
|
|
101
100
|
},
|
|
101
|
+
],
|
|
102
|
+
splitLast: [
|
|
102
103
|
() => {
|
|
103
|
-
const result =
|
|
104
|
+
const result = splitLast([1, 20, 300]);
|
|
104
105
|
const str = stringify(result);
|
|
105
106
|
if (str !== '[[1,20],300]') {
|
|
106
107
|
throw str;
|
|
107
108
|
}
|
|
108
109
|
},
|
|
109
110
|
() => {
|
|
110
|
-
const result =
|
|
111
|
+
const result = splitLast([]);
|
|
111
112
|
if (result !== null) {
|
|
112
113
|
throw result;
|
|
113
114
|
}
|