functionalscript 0.1.609 → 0.2.0
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.d.mts +4 -8
- package/com/cpp/module.f.mjs +20 -25
- package/com/cpp/testlib.f.mjs +3 -4
- package/com/cs/module.f.d.mts +4 -8
- package/com/cs/module.f.mjs +18 -23
- package/com/cs/testlib.f.mjs +3 -5
- package/com/rust/module.f.d.mts +3 -7
- package/com/rust/module.f.mjs +25 -30
- package/com/rust/testlib.f.mjs +3 -5
- package/com/test/build.f.d.mts +2 -2
- package/com/test/build.f.mjs +2 -2
- package/com/test/build.mjs +4 -4
- package/com/types/module.f.d.mts +5 -10
- package/com/types/module.f.mjs +5 -12
- package/commonjs/build/module.f.d.mts +13 -17
- package/commonjs/build/module.f.mjs +23 -28
- package/commonjs/build/test.f.mjs +4 -4
- package/commonjs/module/function/module.f.d.mts +0 -2
- package/commonjs/module/function/module.f.mjs +0 -2
- package/commonjs/module/module.f.d.mts +16 -21
- package/commonjs/module/module.f.mjs +2 -9
- package/commonjs/module.d.mts +1 -5
- package/commonjs/module.f.d.mts +0 -2
- package/commonjs/module.f.mjs +0 -2
- package/commonjs/module.mjs +2 -7
- package/commonjs/package/dependencies/module.f.d.mts +3 -7
- package/commonjs/package/dependencies/module.f.mjs +5 -10
- package/commonjs/package/dependencies/test.f.mjs +1 -1
- package/commonjs/package/module.f.d.mts +12 -18
- package/commonjs/package/module.f.mjs +6 -13
- package/commonjs/package/test.f.mjs +1 -1
- package/commonjs/path/module.f.d.mts +25 -32
- package/commonjs/path/module.f.mjs +12 -23
- package/commonjs/path/test.f.mjs +11 -11
- package/commonjs/test.mjs +1 -1
- package/dev/module.f.d.mts +1 -4
- package/dev/module.f.mjs +1 -4
- package/dev/test/module.f.d.mts +2 -3
- package/dev/test/module.f.mjs +4 -6
- package/djs/module.f.d.mts +13 -18
- package/djs/module.f.mjs +12 -19
- package/djs/parser/module.f.d.mts +11 -15
- package/djs/parser/module.f.mjs +18 -24
- package/djs/parser/test.f.mjs +9 -9
- package/djs/test.f.mjs +4 -4
- package/djs/tokenizer/module.f.d.mts +6 -10
- package/djs/tokenizer/module.f.mjs +18 -23
- package/djs/tokenizer/test.f.mjs +6 -6
- package/fsc/module.f.d.mts +4 -9
- package/fsc/module.f.mjs +17 -24
- package/fsc/test.f.mjs +3 -3
- package/fsm/module.f.d.mts +13 -20
- package/fsm/module.f.mjs +27 -38
- package/fsm/test.f.mjs +8 -8
- package/html/module.f.d.mts +7 -12
- package/html/module.f.mjs +14 -23
- package/html/test.f.mjs +4 -4
- package/js/tokenizer/module.f.d.mts +10 -15
- package/js/tokenizer/module.f.mjs +55 -62
- package/js/tokenizer/test.f.mjs +6 -6
- package/json/module.f.d.mts +18 -26
- package/json/module.f.mjs +18 -31
- package/json/parser/module.f.d.mts +9 -13
- package/json/parser/module.f.mjs +9 -14
- package/json/parser/test.f.mjs +7 -7
- package/json/serializer/module.f.d.mts +11 -20
- package/json/serializer/module.f.mjs +14 -29
- package/json/serializer/test.f.mjs +2 -2
- package/json/test.f.mjs +3 -3
- package/json/tokenizer/module.f.d.mts +6 -10
- package/json/tokenizer/module.f.mjs +14 -19
- package/json/tokenizer/test.f.mjs +6 -6
- package/jsr.json +1 -1
- package/nodejs/version/main.mjs +1 -1
- package/nodejs/version/module.f.d.mts +4 -9
- package/nodejs/version/module.f.mjs +2 -7
- package/nodejs/version/test.f.mjs +3 -3
- package/package.json +1 -1
- package/prime_field/module.f.d.mts +20 -23
- package/prime_field/module.f.mjs +9 -12
- package/prime_field/test.f.mjs +1 -1
- package/secp/module.f.d.mts +27 -28
- package/secp/module.f.mjs +38 -39
- package/secp/test.f.mjs +4 -4
- package/sha2/module.f.d.mts +8 -16
- package/sha2/module.f.mjs +7 -20
- package/sha2/test.f.mjs +4 -4
- package/text/ascii/module.f.d.mts +69 -72
- package/text/ascii/module.f.mjs +5 -10
- package/text/ascii/test.f.mjs +3 -3
- package/text/module.f.d.mts +9 -14
- package/text/module.f.mjs +7 -14
- package/text/sgr/module.f.d.mts +7 -9
- package/text/sgr/module.f.mjs +2 -4
- package/text/test.f.mjs +3 -3
- package/text/utf16/module.f.d.mts +8 -15
- package/text/utf16/module.f.mjs +17 -28
- package/text/utf16/test.f.mjs +5 -5
- package/text/utf8/module.f.d.mts +4 -9
- package/text/utf8/module.f.mjs +9 -16
- package/text/utf8/test.f.mjs +4 -4
- package/types/array/module.f.d.mts +14 -24
- package/types/array/module.f.mjs +8 -25
- package/types/array/test.f.mjs +3 -3
- package/types/bigfloat/module.f.d.mts +4 -9
- package/types/bigfloat/module.f.mjs +3 -10
- package/types/bigfloat/test.f.mjs +1 -1
- package/types/bigint/module.f.d.mts +16 -64
- package/types/bigint/module.f.mjs +11 -30
- package/types/bigint/test.f.mjs +1 -1
- package/types/btree/find/module.f.d.mts +20 -26
- package/types/btree/find/module.f.mjs +8 -17
- package/types/btree/find/test.f.mjs +7 -7
- package/types/btree/module.f.d.mts +4 -8
- package/types/btree/module.f.mjs +6 -11
- package/types/btree/remove/module.f.d.mts +7 -12
- package/types/btree/remove/module.f.mjs +10 -17
- package/types/btree/remove/test.f.mjs +5 -5
- package/types/btree/set/module.f.d.mts +3 -7
- package/types/btree/set/module.f.mjs +4 -9
- package/types/btree/set/test.f.mjs +4 -4
- package/types/btree/test.f.mjs +9 -9
- package/types/btree/types/module.f.d.mts +0 -2
- package/types/btree/types/module.f.mjs +0 -2
- package/types/byte_set/module.f.d.mts +16 -29
- package/types/byte_set/module.f.mjs +14 -39
- package/types/byte_set/test.f.mjs +5 -5
- package/types/function/compare/module.f.d.mts +9 -15
- package/types/function/compare/module.f.mjs +3 -12
- package/types/function/compare/test.f.mjs +1 -1
- package/types/function/module.f.d.mts +20 -27
- package/types/function/module.f.mjs +4 -15
- package/types/function/operator/module.f.d.mts +28 -43
- package/types/function/operator/module.f.mjs +14 -41
- package/types/function/test.f.mjs +1 -1
- package/types/list/module.f.d.mts +56 -91
- package/types/list/module.f.mjs +45 -114
- package/types/list/test.f.mjs +10 -10
- package/types/map/module.f.d.mts +15 -24
- package/types/map/module.f.mjs +15 -30
- package/types/map/test.f.mjs +2 -2
- package/types/nibble_set/module.f.d.mts +10 -20
- package/types/nibble_set/module.f.mjs +7 -24
- package/types/nibble_set/test.f.mjs +2 -2
- package/types/nullable/module.f.d.mts +3 -8
- package/types/nullable/module.f.mjs +2 -9
- package/types/nullable/test.f.mjs +1 -1
- package/types/number/module.f.d.mts +7 -13
- package/types/number/module.f.mjs +8 -19
- package/types/number/test.f.mjs +1 -1
- package/types/object/module.f.d.mts +11 -18
- package/types/object/module.f.mjs +9 -20
- package/types/object/test.f.mjs +1 -1
- package/types/range/module.f.d.mts +3 -8
- package/types/range/module.f.mjs +2 -9
- package/types/range/test.f.mjs +1 -1
- package/types/range_map/module.f.d.mts +9 -15
- package/types/range_map/module.f.mjs +9 -18
- package/types/range_map/test.f.mjs +32 -32
- package/types/result/module.d.mts +3 -3
- package/types/result/module.f.d.mts +6 -12
- package/types/result/module.f.mjs +3 -12
- package/types/result/module.mjs +2 -2
- package/types/sorted_list/module.f.d.mts +22 -28
- package/types/sorted_list/module.f.mjs +10 -19
- package/types/sorted_list/test.f.mjs +7 -7
- package/types/sorted_set/module.f.d.mts +6 -12
- package/types/sorted_set/module.f.mjs +7 -16
- package/types/sorted_set/test.f.mjs +7 -7
- package/types/string/module.f.d.mts +8 -14
- package/types/string/module.f.mjs +10 -21
- package/types/string/test.f.mjs +2 -2
- package/types/string_set/module.f.d.mts +8 -16
- package/types/string_set/module.f.mjs +12 -27
- package/types/string_set/test.f.mjs +1 -1
package/json/parser/module.f.mjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as result from '../../types/result/module.f.mjs'
|
|
3
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
4
4
|
const { fold, first, drop, toArray } = list
|
|
5
5
|
import * as Operator from '../../types/function/operator/module.f.mjs'
|
|
6
6
|
import * as Tokenizer from '../tokenizer/module.f.mjs'
|
|
7
|
-
import
|
|
7
|
+
import * as map from '../../types/map/module.f.mjs'
|
|
8
8
|
const { setReplace } = map
|
|
9
9
|
import * as Json from '../module.f.mjs'
|
|
10
|
-
import o from '../../types/object/module.f.mjs'
|
|
10
|
+
import * as o from '../../types/object/module.f.mjs'
|
|
11
11
|
const { fromMap } = o
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {{
|
|
16
16
|
* readonly kind: 'object'
|
|
17
|
-
* readonly values:
|
|
17
|
+
* readonly values: map.Map<Json.Unknown>
|
|
18
18
|
* readonly key: string
|
|
19
19
|
* }} JsonObject
|
|
20
20
|
* */
|
|
@@ -22,7 +22,7 @@ const { fromMap } = o
|
|
|
22
22
|
/**
|
|
23
23
|
* @typedef {{
|
|
24
24
|
* readonly kind: 'array'
|
|
25
|
-
* readonly values:
|
|
25
|
+
* readonly values: list.List<Json.Unknown>
|
|
26
26
|
* }} JsonArray
|
|
27
27
|
* */
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ const { fromMap } = o
|
|
|
33
33
|
* } JsonStackElement
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
|
-
/** @typedef {
|
|
36
|
+
/** @typedef {list.List<JsonStackElement>} JsonStack */
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* @typedef {{
|
|
@@ -206,8 +206,8 @@ const foldOp = token => state => {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
/** @type {(tokenList:
|
|
210
|
-
const parse = tokenList => {
|
|
209
|
+
/** @type {(tokenList: list.List<Tokenizer.JsonToken>) => result.Result<Json.Unknown, string>} */
|
|
210
|
+
export const parse = tokenList => {
|
|
211
211
|
const state = fold(foldOp)({ status: '', top: null, stack: null })(tokenList)
|
|
212
212
|
switch (state.status) {
|
|
213
213
|
case 'result': return result.ok(state.value)
|
|
@@ -215,8 +215,3 @@ const parse = tokenList => {
|
|
|
215
215
|
default: return result.error('unexpected end')
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
|
|
219
|
-
export default {
|
|
220
|
-
/** @readonly */
|
|
221
|
-
parse
|
|
222
|
-
}
|
package/json/parser/test.f.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import parser from './module.f.mjs'
|
|
2
|
-
import
|
|
3
|
-
import list from '../../types/list/module.f.mjs'
|
|
1
|
+
import * as parser from './module.f.mjs'
|
|
2
|
+
import * as tokenizer from '../tokenizer/module.f.mjs'
|
|
3
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
4
4
|
const { toArray } = list
|
|
5
|
-
import json from '../module.f.mjs'
|
|
6
|
-
import o from '../../types/object/module.f.mjs'
|
|
5
|
+
import * as json from '../module.f.mjs'
|
|
6
|
+
import * as o from '../../types/object/module.f.mjs'
|
|
7
7
|
const { sort } = o
|
|
8
|
-
import encoding from '../../text/utf16/module.f.mjs'
|
|
8
|
+
import * as encoding from '../../text/utf16/module.f.mjs'
|
|
9
9
|
|
|
10
|
-
/** @type {(s: string) => readonly
|
|
10
|
+
/** @type {(s: string) => readonly tokenizer.JsonToken[]} */
|
|
11
11
|
const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)))
|
|
12
12
|
|
|
13
13
|
const stringify = json.stringify(sort)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
1
|
+
/** @type {(_: string) => list.List<string>} */
|
|
2
|
+
export const stringSerialize: (_: string) => list.List<string>;
|
|
3
|
+
/** @type {(_: number) => list.List<string>} */
|
|
4
|
+
export const numberSerialize: (_: number) => list.List<string>;
|
|
5
|
+
export const nullSerialize: string[];
|
|
6
|
+
/** @type {(_: boolean) => list.List<string>} */
|
|
7
|
+
export const boolSerialize: (_: boolean) => list.List<string>;
|
|
8
|
+
export const objectWrap: (input: list.List<list.List<string>>) => list.List<string>;
|
|
9
|
+
export const arrayWrap: (input: list.List<list.List<string>>) => list.List<string>;
|
|
10
10
|
/**
|
|
11
11
|
* <T>
|
|
12
12
|
*/
|
|
@@ -27,19 +27,10 @@ export type Entry<T> = O.Entry<Unknown<T>>;
|
|
|
27
27
|
/**
|
|
28
28
|
* <T>
|
|
29
29
|
*/
|
|
30
|
-
export type Entries<T> = (
|
|
30
|
+
export type Entries<T> = (list.List<Entry<T>>);
|
|
31
31
|
/**
|
|
32
32
|
* <T>
|
|
33
33
|
*/
|
|
34
34
|
export type MapEntries<T> = (entries: Entries<T>) => Entries<T>;
|
|
35
|
-
|
|
36
|
-
declare const arrayWrap: (input: List.List<List.List<string>>) => List.List<string>;
|
|
37
|
-
/** @type {(_: string) => List.List<string>} */
|
|
38
|
-
declare const stringSerialize: (_: string) => List.List<string>;
|
|
39
|
-
/** @type {(_: number) => List.List<string>} */
|
|
40
|
-
declare const numberSerialize: (_: number) => List.List<string>;
|
|
41
|
-
declare const nullSerialize: string[];
|
|
42
|
-
/** @type {(_: boolean) => List.List<string>} */
|
|
43
|
-
declare const boolSerialize: (_: boolean) => List.List<string>;
|
|
35
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
44
36
|
import * as O from '../../types/object/module.f.mjs';
|
|
45
|
-
import * as List from '../../types/list/module.f.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
-
import
|
|
2
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
3
3
|
const { flat, reduce, empty } = list
|
|
4
4
|
import * as O from '../../types/object/module.f.mjs'
|
|
5
5
|
import * as Operator from '../../types/function/operator/module.f.mjs'
|
|
@@ -37,39 +37,39 @@ import * as Operator from '../../types/function/operator/module.f.mjs'
|
|
|
37
37
|
|
|
38
38
|
const jsonStringify = JSON.stringify
|
|
39
39
|
|
|
40
|
-
/** @type {(_: string) =>
|
|
41
|
-
const stringSerialize = input => [jsonStringify(input)]
|
|
40
|
+
/** @type {(_: string) => list.List<string>} */
|
|
41
|
+
export const stringSerialize = input => [jsonStringify(input)]
|
|
42
42
|
|
|
43
|
-
/** @type {(_: number) =>
|
|
44
|
-
const numberSerialize = input => [jsonStringify(input)]
|
|
43
|
+
/** @type {(_: number) => list.List<string>} */
|
|
44
|
+
export const numberSerialize = input => [jsonStringify(input)]
|
|
45
45
|
|
|
46
|
-
const nullSerialize = ['null']
|
|
46
|
+
export const nullSerialize = ['null']
|
|
47
47
|
|
|
48
48
|
const trueSerialize = ['true']
|
|
49
49
|
|
|
50
50
|
const falseSerialize = ['false']
|
|
51
51
|
|
|
52
|
-
/** @type {(_: boolean) =>
|
|
53
|
-
const boolSerialize = value => value ? trueSerialize : falseSerialize
|
|
52
|
+
/** @type {(_: boolean) => list.List<string>} */
|
|
53
|
+
export const boolSerialize = value => value ? trueSerialize : falseSerialize
|
|
54
54
|
|
|
55
55
|
const comma = [',']
|
|
56
56
|
|
|
57
|
-
/** @type {Operator.Reduce<
|
|
57
|
+
/** @type {Operator.Reduce<list.List<string>>} */
|
|
58
58
|
const joinOp = b => prior => flat([prior, comma, b])
|
|
59
59
|
|
|
60
|
-
/** @type {(input:
|
|
60
|
+
/** @type {(input: list.List<list.List<string>>) => list.List<string>} */
|
|
61
61
|
const join = reduce(joinOp)(empty)
|
|
62
62
|
|
|
63
|
-
/** @type {(open: string) => (close: string) => (input:
|
|
63
|
+
/** @type {(open: string) => (close: string) => (input: list.List<list.List<string>>) => list.List<string>} */
|
|
64
64
|
const wrap = open => close => {
|
|
65
65
|
const seqOpen = [open]
|
|
66
66
|
const seqClose = [close]
|
|
67
67
|
return input => flat([seqOpen, join(input), seqClose])
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const objectWrap = wrap('{')('}')
|
|
70
|
+
export const objectWrap = wrap('{')('}')
|
|
71
71
|
|
|
72
|
-
const arrayWrap = wrap('[')(']')
|
|
72
|
+
export const arrayWrap = wrap('[')(']')
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* @template T
|
|
@@ -78,25 +78,10 @@ const arrayWrap = wrap('[')(']')
|
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* @template T
|
|
81
|
-
* @typedef {(
|
|
81
|
+
* @typedef {(list.List<Entry<T>>)} Entries<T>
|
|
82
82
|
*/
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* @template T
|
|
86
86
|
* @typedef {(entries: Entries<T>) => Entries<T>} MapEntries<T>
|
|
87
87
|
*/
|
|
88
|
-
|
|
89
|
-
export default {
|
|
90
|
-
/** @readonly */
|
|
91
|
-
objectWrap,
|
|
92
|
-
/** @readonly */
|
|
93
|
-
arrayWrap,
|
|
94
|
-
/** @readonly */
|
|
95
|
-
stringSerialize,
|
|
96
|
-
/** @readonly */
|
|
97
|
-
numberSerialize,
|
|
98
|
-
/** @readonly */
|
|
99
|
-
nullSerialize,
|
|
100
|
-
/** @readonly */
|
|
101
|
-
boolSerialize,
|
|
102
|
-
}
|
package/json/test.f.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import json from './module.f.mjs'
|
|
2
|
-
import o from '../types/object/module.f.mjs'
|
|
1
|
+
import * as json from './module.f.mjs'
|
|
2
|
+
import * as o from '../types/object/module.f.mjs'
|
|
3
3
|
const { sort } = o
|
|
4
|
-
import f from '../types/function/module.f.mjs'
|
|
4
|
+
import * as f from '../types/function/module.f.mjs'
|
|
5
5
|
const { identity } = f
|
|
6
6
|
|
|
7
7
|
export default {
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
export default _default;
|
|
1
|
+
/** @type {(input: list.List<number>) => list.List<JsonToken>} */
|
|
2
|
+
export const tokenize: (input: list.List<number>) => list.List<JsonToken>;
|
|
5
3
|
export type JsonToken = {
|
|
6
4
|
readonly kind: "true" | "false" | "null";
|
|
7
5
|
} | {
|
|
8
6
|
readonly kind: "{" | "}" | ":" | "," | "[" | "]";
|
|
9
|
-
} |
|
|
7
|
+
} | jsTokenizer.StringToken | jsTokenizer.NumberToken | jsTokenizer.ErrorToken;
|
|
10
8
|
export type ScanState = {
|
|
11
9
|
readonly kind: "def" | "-";
|
|
12
10
|
};
|
|
13
|
-
export type ScanInput =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import * as JsTokenizer from '../../js/tokenizer/module.f.mjs';
|
|
17
|
-
import * as List from '../../types/list/module.f.mjs';
|
|
11
|
+
export type ScanInput = jsTokenizer.JsToken | null;
|
|
12
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
13
|
+
import * as jsTokenizer from '../../js/tokenizer/module.f.mjs';
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
2
|
import * as Operator from '../../types/function/operator/module.f.mjs'
|
|
3
|
-
import
|
|
3
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
4
4
|
const { empty, flat, stateScan } = list
|
|
5
|
-
import bf from '../../types/bigfloat/module.f.mjs'
|
|
5
|
+
import * as bf from '../../types/bigfloat/module.f.mjs'
|
|
6
6
|
const { multiply } = bf
|
|
7
|
-
import
|
|
7
|
+
import * as jsTokenizer from '../../js/tokenizer/module.f.mjs'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @typedef {|
|
|
11
11
|
* {readonly kind: 'true' | 'false' | 'null' } |
|
|
12
12
|
* {readonly kind: '{' | '}' | ':' | ',' | '[' | ']' } |
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* jsTokenizer.StringToken |
|
|
14
|
+
* jsTokenizer.NumberToken |
|
|
15
|
+
* jsTokenizer.ErrorToken
|
|
16
16
|
* } JsonToken
|
|
17
17
|
*/
|
|
18
18
|
|
|
@@ -24,11 +24,11 @@ import jsTokenizer, * as JsTokenizer from '../../js/tokenizer/module.f.mjs'
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @typedef {|
|
|
27
|
-
*
|
|
27
|
+
* jsTokenizer.JsToken | null
|
|
28
28
|
* } ScanInput
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
/** @type {(input:
|
|
31
|
+
/** @type {(input: jsTokenizer.JsToken) => list.List<JsonToken>} */
|
|
32
32
|
const mapToken = input =>
|
|
33
33
|
{
|
|
34
34
|
switch(input.kind)
|
|
@@ -51,7 +51,7 @@ const mapToken = input =>
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
/** @type {(input: ScanInput) => readonly [
|
|
54
|
+
/** @type {(input: ScanInput) => readonly [list.List<JsonToken>, ScanState]} */
|
|
55
55
|
const parseDefaultState = input =>
|
|
56
56
|
{
|
|
57
57
|
if (input === null) return [empty, { kind: 'def'}]
|
|
@@ -62,7 +62,7 @@ const parseDefaultState = input =>
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/** @type {(input: ScanInput) => readonly [
|
|
65
|
+
/** @type {(input: ScanInput) => readonly [list.List<JsonToken>, ScanState]} */
|
|
66
66
|
const parseMinusState = input =>
|
|
67
67
|
{
|
|
68
68
|
if (input === null) return [[{ kind: 'error', message: 'invalid token' }], { kind: 'def'}]
|
|
@@ -74,7 +74,7 @@ const parseMinusState = input =>
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
/** @type {Operator.StateScan<ScanInput, ScanState,
|
|
77
|
+
/** @type {Operator.StateScan<ScanInput, ScanState, list.List<JsonToken>>} */
|
|
78
78
|
const scanToken = state => input => {
|
|
79
79
|
switch(state.kind)
|
|
80
80
|
{
|
|
@@ -83,15 +83,10 @@ const scanToken = state => input => {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
/** @type {(input:
|
|
87
|
-
const tokenize = input =>
|
|
86
|
+
/** @type {(input: list.List<number>) => list.List<JsonToken>} */
|
|
87
|
+
export const tokenize = input =>
|
|
88
88
|
{
|
|
89
|
-
/** @type {
|
|
89
|
+
/** @type {list.List<ScanInput>} */
|
|
90
90
|
const jsTokens = jsTokenizer.tokenize(input)
|
|
91
91
|
return flat(stateScan(scanToken)({ kind: 'def' })(list.concat(jsTokens)([null])))
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
export default {
|
|
95
|
-
/** @readonly */
|
|
96
|
-
tokenize
|
|
97
|
-
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import list from '../../types/list/module.f.mjs'
|
|
1
|
+
import * as tokenizer from './module.f.mjs'
|
|
2
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
3
3
|
const { toArray } = list
|
|
4
|
-
import djs from '../../djs/module.f.mjs'
|
|
5
|
-
import o from '../../types/object/module.f.mjs'
|
|
4
|
+
import * as djs from '../../djs/module.f.mjs'
|
|
5
|
+
import * as o from '../../types/object/module.f.mjs'
|
|
6
6
|
const { sort } = o
|
|
7
|
-
import encoding from '../../text/utf16/module.f.mjs'
|
|
7
|
+
import * as encoding from '../../text/utf16/module.f.mjs'
|
|
8
8
|
|
|
9
|
-
/** @type {(s: string) => readonly
|
|
9
|
+
/** @type {(s: string) => readonly tokenizer.JsonToken[]} */
|
|
10
10
|
const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)))
|
|
11
11
|
|
|
12
12
|
const stringify = djs.stringify(sort)
|
package/jsr.json
CHANGED
package/nodejs/version/main.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default _default;
|
|
1
|
+
/** @type {<T>(fs: Fs<T>) => string} */
|
|
2
|
+
export const getVersion: <T>(fs: Fs<T>) => string;
|
|
3
|
+
/** @type {<T>(node: Node<T>) => readonly[T, T]} */
|
|
4
|
+
export const updateVersion: <T>(node: Node<T>) => readonly [T, T];
|
|
6
5
|
export type Buffer = {};
|
|
7
6
|
export type Fs<T> = {
|
|
8
7
|
readonly readFileSync: (name: string) => Buffer;
|
|
@@ -11,7 +10,3 @@ export type Fs<T> = {
|
|
|
11
10
|
export type Node<T> = {
|
|
12
11
|
readonly fs: Fs<T>;
|
|
13
12
|
};
|
|
14
|
-
/** @type {<T>(fs: Fs<T>) => string} */
|
|
15
|
-
declare const getVersion: <T>(fs: Fs<T>) => string;
|
|
16
|
-
/** @type {<T>(node: Node<T>) => readonly[T, T]} */
|
|
17
|
-
declare const updateVersion: <T>(node: Node<T>) => readonly [T, T];
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
const { stringify, parse } = JSON
|
|
21
21
|
|
|
22
22
|
/** @type {<T>(fs: Fs<T>) => string} */
|
|
23
|
-
const getVersion = fs => readJson(fs)('package').version
|
|
23
|
+
export const getVersion = fs => readJson(fs)('package').version
|
|
24
24
|
|
|
25
25
|
const jsonFile = (/** @type {string} */jsonFile) => `${jsonFile}.json`
|
|
26
26
|
|
|
@@ -28,7 +28,7 @@ const jsonFile = (/** @type {string} */jsonFile) => `${jsonFile}.json`
|
|
|
28
28
|
const readJson = fs => name => parse(fs.readFileSync(jsonFile(name)).toString())
|
|
29
29
|
|
|
30
30
|
/** @type {<T>(node: Node<T>) => readonly[T, T]} */
|
|
31
|
-
const updateVersion = ({ fs }) => {
|
|
31
|
+
export const updateVersion = ({ fs }) => {
|
|
32
32
|
const f = (/** @type {string} */name) => {
|
|
33
33
|
return fs.writeFileSync(
|
|
34
34
|
jsonFile(name),
|
|
@@ -45,8 +45,3 @@ const updateVersion = ({ fs }) => {
|
|
|
45
45
|
f('jsr')
|
|
46
46
|
]
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
export default {
|
|
50
|
-
getVersion,
|
|
51
|
-
updateVersion,
|
|
52
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _ from './module.f.mjs'
|
|
2
2
|
|
|
3
3
|
const version = '0.3.0'
|
|
4
4
|
|
|
@@ -82,13 +82,13 @@ const e = '{\n' +
|
|
|
82
82
|
' }\n' +
|
|
83
83
|
'}'
|
|
84
84
|
|
|
85
|
-
/** @type {(s: string) =>
|
|
85
|
+
/** @type {(s: string) => _.Buffer} */
|
|
86
86
|
const buffer = s => ({
|
|
87
87
|
toString: () => s
|
|
88
88
|
})
|
|
89
89
|
|
|
90
90
|
export default () => {
|
|
91
|
-
/** @type {
|
|
91
|
+
/** @type {_.Node<string>} */
|
|
92
92
|
const node = {
|
|
93
93
|
fs: {
|
|
94
94
|
readFileSync: n => buffer(JSON.stringify(x[n])),
|
package/package.json
CHANGED
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
declare namespace _default {
|
|
2
|
-
export { prime_field };
|
|
3
|
-
export let sqrt: (f: PrimeField) => (a: bigint) => bigint | null;
|
|
4
|
-
}
|
|
5
|
-
export default _default;
|
|
6
|
-
export type Reduce = Operator.Reduce<bigint>;
|
|
7
|
-
export type Unary = Operator.Unary<bigint, bigint>;
|
|
8
|
-
export type PrimeField = {
|
|
9
|
-
readonly p: bigint;
|
|
10
|
-
readonly middle: bigint;
|
|
11
|
-
readonly max: bigint;
|
|
12
|
-
readonly neg: Unary;
|
|
13
|
-
readonly sub: Reduce;
|
|
14
|
-
readonly add: Reduce;
|
|
15
|
-
readonly abs: Unary;
|
|
16
|
-
readonly mul: Reduce;
|
|
17
|
-
readonly reciprocal: Unary;
|
|
18
|
-
readonly div: Reduce;
|
|
19
|
-
readonly pow: Reduce;
|
|
20
|
-
readonly pow2: Unary;
|
|
21
|
-
readonly pow3: Unary;
|
|
22
|
-
};
|
|
23
1
|
/** @typedef {Operator.Reduce<bigint>} Reduce */
|
|
24
2
|
/** @typedef {Operator.Unary<bigint, bigint>} Unary*/
|
|
25
3
|
/**
|
|
@@ -40,5 +18,24 @@ export type PrimeField = {
|
|
|
40
18
|
* }} PrimeField
|
|
41
19
|
*/
|
|
42
20
|
/** @type {(p: bigint) => PrimeField} */
|
|
43
|
-
|
|
21
|
+
export const prime_field: (p: bigint) => PrimeField;
|
|
22
|
+
/** @type {(f: PrimeField) => (a: bigint) => bigint|null} */
|
|
23
|
+
export const sqrt: (f: PrimeField) => (a: bigint) => bigint | null;
|
|
24
|
+
export type Reduce = Operator.Reduce<bigint>;
|
|
25
|
+
export type Unary = Operator.Unary<bigint, bigint>;
|
|
26
|
+
export type PrimeField = {
|
|
27
|
+
readonly p: bigint;
|
|
28
|
+
readonly middle: bigint;
|
|
29
|
+
readonly max: bigint;
|
|
30
|
+
readonly neg: Unary;
|
|
31
|
+
readonly sub: Reduce;
|
|
32
|
+
readonly add: Reduce;
|
|
33
|
+
readonly abs: Unary;
|
|
34
|
+
readonly mul: Reduce;
|
|
35
|
+
readonly reciprocal: Unary;
|
|
36
|
+
readonly div: Reduce;
|
|
37
|
+
readonly pow: Reduce;
|
|
38
|
+
readonly pow2: Unary;
|
|
39
|
+
readonly pow3: Unary;
|
|
40
|
+
};
|
|
44
41
|
import * as Operator from '../types/function/operator/module.f.mjs';
|
package/prime_field/module.f.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
2
|
import * as Operator from '../types/function/operator/module.f.mjs'
|
|
3
|
-
import bi from '../types/bigint/module.f.mjs'
|
|
3
|
+
import * as bi from '../types/bigint/module.f.mjs'
|
|
4
4
|
const { scalar_mul } = bi
|
|
5
5
|
|
|
6
6
|
/** @typedef {Operator.Reduce<bigint>} Reduce */
|
|
@@ -26,7 +26,7 @@ const { scalar_mul } = bi
|
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
/** @type {(p: bigint) => PrimeField} */
|
|
29
|
-
const prime_field = p => {
|
|
29
|
+
export const prime_field = p => {
|
|
30
30
|
/** @type {Reduce} */
|
|
31
31
|
const sub = a => b => {
|
|
32
32
|
const r = a - b
|
|
@@ -77,15 +77,12 @@ const prime_field = p => {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
return a
|
|
87
|
-
const result = pow(a)(sqrt_k)
|
|
88
|
-
return mul(result)(result) === a ? result : null
|
|
89
|
-
}
|
|
80
|
+
/** @type {(f: PrimeField) => (a: bigint) => bigint|null} */
|
|
81
|
+
export const sqrt = ({p, mul, pow }) => {
|
|
82
|
+
if ((p & 3n) !== 3n) { throw 'sqrt' }
|
|
83
|
+
const sqrt_k = (p + 1n) >> 2n
|
|
84
|
+
return a => {
|
|
85
|
+
const result = pow(a)(sqrt_k)
|
|
86
|
+
return mul(result)(result) === a ? result : null
|
|
90
87
|
}
|
|
91
88
|
}
|
package/prime_field/test.f.mjs
CHANGED
package/secp/module.f.d.mts
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
declare namespace _default {
|
|
2
|
-
export { curve };
|
|
3
|
-
export let eq: (a: Point) => (b: Point) => boolean;
|
|
4
|
-
export let secp256k1: Init;
|
|
5
|
-
export let secp192r1: Init;
|
|
6
|
-
}
|
|
7
|
-
export default _default;
|
|
8
|
-
export type Point2D = readonly [bigint, bigint];
|
|
9
|
-
export type Point = Point2D | null;
|
|
10
|
-
export type Init = {
|
|
11
|
-
readonly p: bigint;
|
|
12
|
-
readonly a: readonly [bigint, bigint];
|
|
13
|
-
readonly g: readonly [bigint, bigint];
|
|
14
|
-
readonly n: bigint;
|
|
15
|
-
};
|
|
16
|
-
export type Curve = {
|
|
17
|
-
readonly pf: Pf.PrimeField;
|
|
18
|
-
readonly nf: Pf.PrimeField;
|
|
19
|
-
readonly y2: (x: bigint) => bigint;
|
|
20
|
-
readonly y: (x: bigint) => bigint | null;
|
|
21
|
-
readonly neg: (a: Point) => Point;
|
|
22
|
-
readonly add: Operator.Reduce<Point>;
|
|
23
|
-
readonly mul: (a: Point) => (n: bigint) => Point;
|
|
24
|
-
};
|
|
25
1
|
/** @typedef {readonly[bigint, bigint]} Point2D */
|
|
26
2
|
/** @typedef {Point2D|null} Point */
|
|
27
3
|
/**
|
|
@@ -34,8 +10,8 @@ export type Curve = {
|
|
|
34
10
|
*/
|
|
35
11
|
/**
|
|
36
12
|
* @typedef {{
|
|
37
|
-
* readonly pf:
|
|
38
|
-
* readonly nf:
|
|
13
|
+
* readonly pf: pf.PrimeField
|
|
14
|
+
* readonly nf: pf.PrimeField
|
|
39
15
|
* readonly y2: (x: bigint) => bigint
|
|
40
16
|
* readonly y: (x: bigint) => bigint|null
|
|
41
17
|
* readonly neg: (a: Point) => Point
|
|
@@ -44,6 +20,29 @@ export type Curve = {
|
|
|
44
20
|
* }} Curve
|
|
45
21
|
*/
|
|
46
22
|
/** @type {(i: Init) => Curve} */
|
|
47
|
-
|
|
48
|
-
|
|
23
|
+
export const curve: (i: Init) => Curve;
|
|
24
|
+
/** @type {(a: Point) => (b: Point) => boolean} */
|
|
25
|
+
export const eq: (a: Point) => (b: Point) => boolean;
|
|
26
|
+
/** @type {Init} */
|
|
27
|
+
export const secp256k1: Init;
|
|
28
|
+
/** @type {Init} */
|
|
29
|
+
export const secp192r1: Init;
|
|
30
|
+
export type Point2D = readonly [bigint, bigint];
|
|
31
|
+
export type Point = Point2D | null;
|
|
32
|
+
export type Init = {
|
|
33
|
+
readonly p: bigint;
|
|
34
|
+
readonly a: readonly [bigint, bigint];
|
|
35
|
+
readonly g: readonly [bigint, bigint];
|
|
36
|
+
readonly n: bigint;
|
|
37
|
+
};
|
|
38
|
+
export type Curve = {
|
|
39
|
+
readonly pf: pf.PrimeField;
|
|
40
|
+
readonly nf: pf.PrimeField;
|
|
41
|
+
readonly y2: (x: bigint) => bigint;
|
|
42
|
+
readonly y: (x: bigint) => bigint | null;
|
|
43
|
+
readonly neg: (a: Point) => Point;
|
|
44
|
+
readonly add: Operator.Reduce<Point>;
|
|
45
|
+
readonly mul: (a: Point) => (n: bigint) => Point;
|
|
46
|
+
};
|
|
47
|
+
import * as pf from '../prime_field/module.f.mjs';
|
|
49
48
|
import * as Operator from '../types/function/operator/module.f.mjs';
|