functionalscript 0.4.2 → 0.4.4
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 +1 -1
- package/bnf/data/module.f.d.ts +12 -0
- package/bnf/data/module.f.js +85 -0
- package/bnf/data/test.f.d.ts +4 -0
- package/bnf/data/test.f.js +8 -0
- package/bnf/module.f.d.ts +55 -0
- package/bnf/module.f.js +98 -0
- package/bnf/test.f.d.ts +4 -0
- package/bnf/test.f.js +7 -0
- package/bnf/testlib.f.d.ts +3 -0
- package/bnf/{tag/test.f.js → testlib.f.js} +48 -44
- package/crypto/hmac/module.f.d.ts +28 -0
- package/crypto/hmac/module.f.js +60 -0
- package/crypto/hmac/test.f.d.ts +6 -0
- package/crypto/hmac/test.f.js +24 -0
- package/crypto/secp/module.f.d.ts +8 -0
- package/crypto/secp/module.f.js +30 -0
- package/crypto/secp/test.f.d.ts +3 -0
- package/crypto/secp/test.f.js +67 -3
- package/crypto/sha2/module.f.d.ts +10 -0
- package/crypto/sha2/module.f.js +11 -2
- package/crypto/sha2/test.f.js +28 -21
- package/djs/ast/module.f.d.ts +10 -0
- package/djs/ast/module.f.js +52 -0
- package/djs/ast/test.f.d.ts +8 -0
- package/djs/ast/test.f.js +41 -0
- package/djs/module.f.d.ts +5 -15
- package/djs/module.f.js +1 -62
- package/djs/parser/module.f.d.ts +9 -9
- package/djs/parser/module.f.js +7 -8
- package/djs/parser/test.f.js +97 -97
- package/djs/serializer/module.f.d.ts +8 -4
- package/djs/serializer/module.f.js +9 -27
- package/djs/{test.f.d.ts → serializer/test.f.d.ts} +3 -3
- package/djs/{test.f.js → serializer/test.f.js} +13 -13
- package/djs/tokenizer/test.f.js +2 -2
- package/djs/transpiler/module.f.d.ts +15 -0
- package/djs/transpiler/module.f.js +57 -0
- package/djs/transpiler/test.f.d.ts +8 -0
- package/djs/transpiler/test.f.js +74 -0
- package/io/module.f.d.ts +12 -0
- package/io/virtual-io.f.d.ts +3 -0
- package/io/virtual-io.f.js +10 -0
- package/js/tokenizer/test.f.js +2 -2
- package/json/module.f.d.ts +2 -1
- package/json/tokenizer/test.f.js +2 -2
- package/nanvm-lib/tests/test.f.js +4 -4
- package/package.json +2 -2
- package/path/module.f.d.ts +2 -0
- package/path/module.f.js +34 -0
- package/path/test.f.d.ts +5 -0
- package/path/test.f.js +49 -0
- package/text/sgr/module.f.d.ts +19 -1
- package/text/sgr/module.f.js +26 -1
- package/text/sgr/test.f.d.ts +2 -0
- package/text/sgr/test.f.js +8 -0
- package/text/utf16/module.f.d.ts +116 -0
- package/text/utf16/module.f.js +285 -0
- package/text/utf16/test.f.d.ts +4 -0
- package/text/utf16/test.f.js +28 -0
- package/types/bigint/module.f.d.ts +83 -2
- package/types/bigint/module.f.js +98 -2
- package/types/bigint/test.f.d.ts +4 -0
- package/types/bigint/test.f.js +66 -6
- package/types/bit_vec/module.f.d.ts +1 -1
- package/types/monoid/module.f.d.ts +3 -1
- package/types/monoid/module.f.js +2 -0
- package/types/number/module.f.d.ts +4 -0
- package/types/number/module.f.js +16 -0
- package/types/number/test.f.d.ts +1 -0
- package/types/number/test.f.js +19 -3
- package/types/object/module.f.d.ts +18 -0
- package/types/object/module.f.js +1 -1
- package/bnf/tag/module.f.d.ts +0 -30
- package/bnf/tag/module.f.js +0 -37
- /package/{bnf/tag/test.f.d.ts → io/module.f.js} +0 -0
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import * as list from '../../types/list/module.f.ts';
|
|
2
2
|
import type * as O from '../../types/object/module.f.ts';
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
type Entry = O.Entry<DjsParser.DjsConst>;
|
|
3
|
+
import type { Unknown } from '../module.f.ts';
|
|
4
|
+
type Entry = O.Entry<Unknown>;
|
|
6
5
|
type Entries = list.List<Entry>;
|
|
7
6
|
type MapEntries = (entries: Entries) => Entries;
|
|
8
|
-
export declare const
|
|
7
|
+
export declare const serialize: (mapEntries: MapEntries) => (value: Unknown) => list.List<string>;
|
|
8
|
+
/**
|
|
9
|
+
* The standard `JSON.stringify` rules determined by
|
|
10
|
+
* https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
|
|
11
|
+
*/
|
|
12
|
+
export declare const stringify: (mapEntries: MapEntries) => (value: Unknown) => string;
|
|
9
13
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as list from "../../types/list/module.f.js";
|
|
2
|
-
const { flat, map
|
|
2
|
+
const { flat, map } = list;
|
|
3
3
|
import * as string from "../../types/string/module.f.js";
|
|
4
4
|
const { concat } = string;
|
|
5
5
|
import * as f from "../../types/function/module.f.js";
|
|
@@ -10,8 +10,8 @@ const { serialize: bigintSerialize } = bi;
|
|
|
10
10
|
import * as j from "../../json/serializer/module.f.js";
|
|
11
11
|
const { objectWrap, arrayWrap, stringSerialize, numberSerialize, nullSerialize, boolSerialize } = j;
|
|
12
12
|
const colon = [':'];
|
|
13
|
-
|
|
14
|
-
const
|
|
13
|
+
const undefinedSerialize = ['undefined'];
|
|
14
|
+
export const serialize = sort => {
|
|
15
15
|
const propertySerialize = ([k, v]) => flat([
|
|
16
16
|
stringSerialize(k),
|
|
17
17
|
colon,
|
|
@@ -45,17 +45,7 @@ const djsConstSerialize = sort => {
|
|
|
45
45
|
return undefinedSerialize;
|
|
46
46
|
}
|
|
47
47
|
if (value instanceof Array) {
|
|
48
|
-
|
|
49
|
-
case 'aref': {
|
|
50
|
-
return [`a${value[1]}`];
|
|
51
|
-
}
|
|
52
|
-
case 'cref': {
|
|
53
|
-
return [`c${value[1]}`];
|
|
54
|
-
}
|
|
55
|
-
case 'array': {
|
|
56
|
-
return arraySerialize(value[1]);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
48
|
+
return arraySerialize(value);
|
|
59
49
|
}
|
|
60
50
|
return objectSerialize(value);
|
|
61
51
|
}
|
|
@@ -64,16 +54,8 @@ const djsConstSerialize = sort => {
|
|
|
64
54
|
const arraySerialize = compose(map(f))(arrayWrap);
|
|
65
55
|
return f;
|
|
66
56
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const moduleEntrySerialize = entry => {
|
|
73
|
-
if (entry[0] === len - 1) {
|
|
74
|
-
return listConcat(['export default '])(djsConstSerialize(sort)(entry[1]));
|
|
75
|
-
}
|
|
76
|
-
return flat([['const c'], numberSerialize(entry[0]), [' = '], djsConstSerialize(sort)(entry[1]), ['\n']]);
|
|
77
|
-
};
|
|
78
|
-
return concat(listConcat(flatMap(importSerialize)(importEntries))(flatMap(moduleEntrySerialize)(constEntries)));
|
|
79
|
-
};
|
|
57
|
+
/**
|
|
58
|
+
* The standard `JSON.stringify` rules determined by
|
|
59
|
+
* https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
|
|
60
|
+
*/
|
|
61
|
+
export const stringify = sort => compose(serialize(sort))(concat);
|
|
@@ -2,11 +2,11 @@ declare const _default: {
|
|
|
2
2
|
stringify: ({
|
|
3
3
|
sort: () => void;
|
|
4
4
|
identity: () => void;
|
|
5
|
-
stringify?:
|
|
5
|
+
stringify?: never;
|
|
6
6
|
} | {
|
|
7
7
|
stringify: () => void;
|
|
8
|
-
sort?:
|
|
9
|
-
identity?:
|
|
8
|
+
sort?: never;
|
|
9
|
+
identity?: never;
|
|
10
10
|
})[];
|
|
11
11
|
};
|
|
12
12
|
export default _default;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import * as json from "
|
|
2
|
-
import * as list from "
|
|
1
|
+
import * as json from "../../json/module.f.js";
|
|
2
|
+
import * as list from "../../types/object/module.f.js";
|
|
3
3
|
const { sort } = list;
|
|
4
|
-
import * as f from "
|
|
4
|
+
import * as f from "../../types/function/module.f.js";
|
|
5
5
|
const { identity } = f;
|
|
6
|
-
import * as
|
|
6
|
+
import * as serializer from "./module.f.js";
|
|
7
7
|
export default {
|
|
8
8
|
stringify: [
|
|
9
9
|
{
|
|
10
10
|
sort: () => {
|
|
11
11
|
const r = json.setProperty("Hello")(['a'])({});
|
|
12
|
-
const x =
|
|
12
|
+
const x = serializer.stringify(sort)(r);
|
|
13
13
|
if (x !== '{"a":"Hello"}') {
|
|
14
14
|
throw x;
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
identity: () => {
|
|
18
|
-
const x =
|
|
18
|
+
const x = serializer.stringify(identity)(json.setProperty("Hello")(['a'])({}));
|
|
19
19
|
if (x !== '{"a":"Hello"}') {
|
|
20
20
|
throw x;
|
|
21
21
|
}
|
|
@@ -23,13 +23,13 @@ export default {
|
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
sort: () => {
|
|
26
|
-
const x =
|
|
26
|
+
const x = serializer.stringify(sort)(json.setProperty("Hello")(['a'])({ c: [], b: 12 }));
|
|
27
27
|
if (x !== '{"a":"Hello","b":12,"c":[]}') {
|
|
28
28
|
throw x;
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
identity: () => {
|
|
32
|
-
const x =
|
|
32
|
+
const x = serializer.stringify(identity)(json.setProperty("Hello")(['a'])({ c: [], b: 12 }));
|
|
33
33
|
if (x !== '{"c":[],"b":12,"a":"Hello"}') {
|
|
34
34
|
throw x;
|
|
35
35
|
}
|
|
@@ -39,7 +39,7 @@ export default {
|
|
|
39
39
|
sort: () => {
|
|
40
40
|
const _0 = { a: { y: [24] }, c: [], b: 12 };
|
|
41
41
|
const _1 = json.setProperty("Hello")(['a', 'x'])(_0);
|
|
42
|
-
const _2 =
|
|
42
|
+
const _2 = serializer.stringify(sort)(_1);
|
|
43
43
|
if (_2 !== '{"a":{"x":"Hello","y":[24]},"b":12,"c":[]}') {
|
|
44
44
|
throw _2;
|
|
45
45
|
}
|
|
@@ -47,7 +47,7 @@ export default {
|
|
|
47
47
|
identity: () => {
|
|
48
48
|
const _0 = { a: { y: [24] }, c: [], b: 12 };
|
|
49
49
|
const _1 = json.setProperty("Hello")(['a', 'x'])(_0);
|
|
50
|
-
const _2 =
|
|
50
|
+
const _2 = serializer.stringify(identity)(_1);
|
|
51
51
|
if (_2 !== '{"a":{"y":[24],"x":"Hello"},"c":[],"b":12}') {
|
|
52
52
|
throw _2;
|
|
53
53
|
}
|
|
@@ -56,7 +56,7 @@ export default {
|
|
|
56
56
|
{
|
|
57
57
|
stringify: () => {
|
|
58
58
|
const bi = 1234567890n;
|
|
59
|
-
const result =
|
|
59
|
+
const result = serializer.stringify(sort)(bi);
|
|
60
60
|
if (result !== '1234567890n') {
|
|
61
61
|
throw result;
|
|
62
62
|
}
|
|
@@ -65,7 +65,7 @@ export default {
|
|
|
65
65
|
{
|
|
66
66
|
stringify: () => {
|
|
67
67
|
const arr = [0n, 1, 2n];
|
|
68
|
-
const result =
|
|
68
|
+
const result = serializer.stringify(sort)(arr);
|
|
69
69
|
if (result !== '[0n,1,2n]') {
|
|
70
70
|
throw result;
|
|
71
71
|
}
|
|
@@ -74,7 +74,7 @@ export default {
|
|
|
74
74
|
{
|
|
75
75
|
stringify: () => {
|
|
76
76
|
const obj = { "a": 0n, "b": 1, "c": 2n };
|
|
77
|
-
const result =
|
|
77
|
+
const result = serializer.stringify(sort)(obj);
|
|
78
78
|
if (result !== '{"a":0n,"b":1,"c":2n}') {
|
|
79
79
|
throw result;
|
|
80
80
|
}
|
package/djs/tokenizer/test.f.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as tokenizer from "./module.f.js";
|
|
2
2
|
import * as list from "../../types/list/module.f.js";
|
|
3
3
|
const { toArray } = list;
|
|
4
|
-
import * as
|
|
4
|
+
import * as serializer from "../serializer/module.f.js";
|
|
5
5
|
import * as o from "../../types/object/module.f.js";
|
|
6
6
|
const { sort } = o;
|
|
7
7
|
import * as encoding from "../../text/utf16/module.f.js";
|
|
8
8
|
const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)));
|
|
9
|
-
const stringify =
|
|
9
|
+
const stringify = serializer.stringify(sort);
|
|
10
10
|
export default {
|
|
11
11
|
djs: [
|
|
12
12
|
() => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type * as djs from '../module.f.ts';
|
|
2
|
+
import { type Result } from '../../types/result/module.f.ts';
|
|
3
|
+
import { type List } from '../../types/list/module.f.ts';
|
|
4
|
+
import { type Map } from '../../types/map/module.f.ts';
|
|
5
|
+
import type { Fs } from '../../io/module.f.ts';
|
|
6
|
+
export type ParseContext = {
|
|
7
|
+
readonly fs: Fs;
|
|
8
|
+
readonly complete: Map<djsResult>;
|
|
9
|
+
readonly stack: List<string>;
|
|
10
|
+
readonly error: string | null;
|
|
11
|
+
};
|
|
12
|
+
export type djsResult = {
|
|
13
|
+
djs: djs.Unknown;
|
|
14
|
+
};
|
|
15
|
+
export declare const transpile: (fs: Fs) => (path: string) => Result<djs.Unknown, string>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { error, ok } from "../../types/result/module.f.js";
|
|
2
|
+
import { fold, drop, map as listMap, toArray, includes } from "../../types/list/module.f.js";
|
|
3
|
+
import { tokenize } from "../tokenizer/module.f.js";
|
|
4
|
+
import { setReplace, at } from "../../types/map/module.f.js";
|
|
5
|
+
import { stringToList } from "../../text/utf16/module.f.js";
|
|
6
|
+
import { concat as pathConcat } from "../../path/module.f.js";
|
|
7
|
+
import { parseFromTokens } from "../parser/module.f.js";
|
|
8
|
+
import { run } from "../ast/module.f.js";
|
|
9
|
+
const mapDjs = context => path => {
|
|
10
|
+
const res = at(path)(context.complete);
|
|
11
|
+
if (res === null) {
|
|
12
|
+
throw 'unexpected behaviour';
|
|
13
|
+
}
|
|
14
|
+
return res.djs;
|
|
15
|
+
};
|
|
16
|
+
const transpileWithImports = path => parseModuleResult => context => {
|
|
17
|
+
if (parseModuleResult[0] === 'ok') {
|
|
18
|
+
const pathsCombine = listMap(pathConcat(path))(parseModuleResult[1][0]);
|
|
19
|
+
const contextWithImports = fold(foldNextModuleOp)({ ...context, stack: { first: path, tail: context.stack } })(pathsCombine);
|
|
20
|
+
if (contextWithImports.error !== null) {
|
|
21
|
+
return contextWithImports;
|
|
22
|
+
}
|
|
23
|
+
const args = toArray(listMap(mapDjs(contextWithImports))(pathsCombine));
|
|
24
|
+
const djs = { djs: run(parseModuleResult[1][1])(args) };
|
|
25
|
+
return { ...contextWithImports, stack: drop(1)(contextWithImports.stack), complete: setReplace(path)(djs)(contextWithImports.complete) };
|
|
26
|
+
}
|
|
27
|
+
return { ...context, error: parseModuleResult[1] };
|
|
28
|
+
};
|
|
29
|
+
const parseModule = path => context => {
|
|
30
|
+
const content = context.fs.readFileSync(path, 'utf8');
|
|
31
|
+
if (content === null) {
|
|
32
|
+
return error('file not found');
|
|
33
|
+
}
|
|
34
|
+
const tokens = tokenize(stringToList(content));
|
|
35
|
+
return parseFromTokens(tokens);
|
|
36
|
+
};
|
|
37
|
+
const foldNextModuleOp = path => context => {
|
|
38
|
+
if (context.error !== null) {
|
|
39
|
+
return context;
|
|
40
|
+
}
|
|
41
|
+
if (includes(path)(context.stack)) {
|
|
42
|
+
return { ...context, error: 'circular dependency' };
|
|
43
|
+
}
|
|
44
|
+
if (at(path)(context.complete) !== null) {
|
|
45
|
+
return context;
|
|
46
|
+
}
|
|
47
|
+
const parseModuleResult = parseModule(path)(context);
|
|
48
|
+
return transpileWithImports(path)(parseModuleResult)(context);
|
|
49
|
+
};
|
|
50
|
+
export const transpile = fs => path => {
|
|
51
|
+
const context = foldNextModuleOp(path)({ fs, stack: null, complete: null, error: null });
|
|
52
|
+
if (context.error !== null) {
|
|
53
|
+
return error(context.error);
|
|
54
|
+
}
|
|
55
|
+
const result = at(path)(context.complete)?.djs;
|
|
56
|
+
return ok(result);
|
|
57
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { sort } from "../../types/object/module.f.js";
|
|
2
|
+
import { setReplace } from "../../types/map/module.f.js";
|
|
3
|
+
import { transpile } from "./module.f.js";
|
|
4
|
+
import { stringify } from "../serializer/module.f.js";
|
|
5
|
+
import { createVirtualIo } from "../../io/virtual-io.f.js";
|
|
6
|
+
const virtualFs = map => {
|
|
7
|
+
return createVirtualIo(map).fs;
|
|
8
|
+
};
|
|
9
|
+
export default {
|
|
10
|
+
parse: () => {
|
|
11
|
+
const map = setReplace('a')('export default 1')(null);
|
|
12
|
+
const fs = virtualFs(map);
|
|
13
|
+
const result = transpile(fs)('a');
|
|
14
|
+
if (result[0] === 'error') {
|
|
15
|
+
throw result[1];
|
|
16
|
+
}
|
|
17
|
+
const s = stringify(sort)(result[1]);
|
|
18
|
+
if (s !== '1') {
|
|
19
|
+
throw s;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
parseWithSubModule: () => {
|
|
23
|
+
const map = setReplace('a')('import b from "b"\nexport default b')(null);
|
|
24
|
+
const map2 = setReplace('a/b')('export default 2')(map);
|
|
25
|
+
const fs = virtualFs(map2);
|
|
26
|
+
const result = transpile(fs)('a');
|
|
27
|
+
if (result[0] === 'error') {
|
|
28
|
+
throw result[1];
|
|
29
|
+
}
|
|
30
|
+
const s = stringify(sort)(result[1]);
|
|
31
|
+
if (s !== '2') {
|
|
32
|
+
throw s;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
parseWithSubModules: () => {
|
|
36
|
+
const map = setReplace('a')('import b from "b"\nimport c from "c"\nexport default [b,c,b]')(null);
|
|
37
|
+
const map2 = setReplace('a/b')('import d from "../d"\nexport default [0,d]')(map);
|
|
38
|
+
const map3 = setReplace('a/c')('import d from "../d"\nexport default [1,d]')(map2);
|
|
39
|
+
const map4 = setReplace('a/d')('export default 2')(map3);
|
|
40
|
+
const fs = virtualFs(map4);
|
|
41
|
+
const result = transpile(fs)('a');
|
|
42
|
+
if (result[0] === 'error') {
|
|
43
|
+
throw result[1];
|
|
44
|
+
}
|
|
45
|
+
const s = stringify(sort)(result[1]);
|
|
46
|
+
if (s !== '[[0,2],[1,2],[0,2]]') {
|
|
47
|
+
throw s;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
parseWithFileNotFoundError: () => {
|
|
51
|
+
const map = setReplace('a')('import b from "b"\nexport default b')(null);
|
|
52
|
+
const fs = virtualFs(map);
|
|
53
|
+
const result = transpile(fs)('a');
|
|
54
|
+
if (result[0] !== 'error') {
|
|
55
|
+
throw result;
|
|
56
|
+
}
|
|
57
|
+
if (result[1] !== 'file not found') {
|
|
58
|
+
throw result;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
parseWithCycleError: () => {
|
|
62
|
+
const map = setReplace('a')('import b from "b"\nimport c from "c"\nexport default [b,c,b]')(null);
|
|
63
|
+
const map2 = setReplace('a/b')('import c from "../c"\nexport default c')(map);
|
|
64
|
+
const map3 = setReplace('a/c')('import b from "../b"\nexport default b')(map2);
|
|
65
|
+
const fs = virtualFs(map3);
|
|
66
|
+
const result = transpile(fs)('a');
|
|
67
|
+
if (result[0] !== 'error') {
|
|
68
|
+
throw result;
|
|
69
|
+
}
|
|
70
|
+
if (result[1] !== 'circular dependency') {
|
|
71
|
+
throw result;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
};
|
package/io/module.f.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type BufferEncoding = 'utf8';
|
|
2
|
+
export type Fs = {
|
|
3
|
+
readonly writeFileSync: (file: string, data: string) => void;
|
|
4
|
+
readonly readFileSync: (path: string, options: BufferEncoding) => string | null;
|
|
5
|
+
};
|
|
6
|
+
export type Console = {
|
|
7
|
+
readonly log: (...d: unknown[]) => void;
|
|
8
|
+
};
|
|
9
|
+
export type Io = {
|
|
10
|
+
readonly console: Console;
|
|
11
|
+
readonly fs: Fs;
|
|
12
|
+
};
|
package/js/tokenizer/test.f.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as tokenizer from "./module.f.js";
|
|
2
2
|
import * as list from "../../types/list/module.f.js";
|
|
3
3
|
const { toArray } = list;
|
|
4
|
-
import * as
|
|
4
|
+
import * as serializer from "../../djs/serializer/module.f.js";
|
|
5
5
|
import * as o from "../../types/object/module.f.js";
|
|
6
6
|
const { sort } = o;
|
|
7
7
|
import * as encoding from "../../text/utf16/module.f.js";
|
|
8
8
|
const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)));
|
|
9
|
-
const stringify =
|
|
9
|
+
const stringify = serializer.stringify(sort);
|
|
10
10
|
export default {
|
|
11
11
|
djs: [
|
|
12
12
|
() => {
|
package/json/module.f.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ type Object = {
|
|
|
4
4
|
readonly [k in string]: Unknown;
|
|
5
5
|
};
|
|
6
6
|
type Array = readonly Unknown[];
|
|
7
|
-
export type
|
|
7
|
+
export type Primitive = boolean | string | number | null;
|
|
8
|
+
export type Unknown = Primitive | Object | Array;
|
|
8
9
|
export declare const setProperty: (value: Unknown) => (path: list.List<string>) => (src: Unknown) => Unknown;
|
|
9
10
|
export type Entry = object.Entry<Unknown>;
|
|
10
11
|
type Entries = list.List<Entry>;
|
package/json/tokenizer/test.f.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as tokenizer from "./module.f.js";
|
|
2
2
|
import * as list from "../../types/list/module.f.js";
|
|
3
3
|
const { toArray } = list;
|
|
4
|
-
import * as
|
|
4
|
+
import * as serializer from "../../djs/serializer/module.f.js";
|
|
5
5
|
import * as o from "../../types/object/module.f.js";
|
|
6
6
|
const { sort } = o;
|
|
7
7
|
import * as encoding from "../../text/utf16/module.f.js";
|
|
8
8
|
const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)));
|
|
9
|
-
const stringify =
|
|
9
|
+
const stringify = serializer.stringify(sort);
|
|
10
10
|
export default {
|
|
11
11
|
json: [
|
|
12
12
|
() => {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
const e = a => b => {
|
|
1
|
+
const e = (a) => (b) => {
|
|
2
2
|
if (a === b) { }
|
|
3
3
|
else {
|
|
4
4
|
throw [a, '===', b];
|
|
5
5
|
}
|
|
6
6
|
};
|
|
7
|
-
const n = a => b => {
|
|
7
|
+
const n = (a) => (b) => {
|
|
8
8
|
if (a !== b) { }
|
|
9
9
|
else {
|
|
10
10
|
throw [a, '!==', b];
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
const nan_res = op => n => {
|
|
14
|
-
|
|
13
|
+
const nan_res = (op) => (n) => {
|
|
14
|
+
const result = op(n);
|
|
15
15
|
if (!Number.isNaN(result)) {
|
|
16
16
|
throw result;
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functionalscript",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.f.d.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/functionalscript/functionalscript#readme",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^22.
|
|
41
|
+
"@types/node": "^22.13.4",
|
|
42
42
|
"typescript": "^5.7.3"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/path/module.f.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {} from "../types/function/operator/module.f.js";
|
|
2
|
+
import { fold, last, take, length, concat as listConcat } from "../types/list/module.f.js";
|
|
3
|
+
import { join } from "../types/string/module.f.js";
|
|
4
|
+
import { concat as stringConcat } from "../types/string/module.f.js";
|
|
5
|
+
const foldNormalizeOp = input => state => {
|
|
6
|
+
switch (input) {
|
|
7
|
+
case '': {
|
|
8
|
+
return state;
|
|
9
|
+
}
|
|
10
|
+
case '..': {
|
|
11
|
+
switch (last(undefined)(state)) {
|
|
12
|
+
case undefined:
|
|
13
|
+
case '..': {
|
|
14
|
+
return listConcat(state)([input]);
|
|
15
|
+
}
|
|
16
|
+
default: {
|
|
17
|
+
return take(length(state) - 1)(state);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
default: {
|
|
22
|
+
return listConcat(state)([input]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const normalize = path => {
|
|
27
|
+
const split = path.split('/');
|
|
28
|
+
const foldResult = fold(foldNormalizeOp)([])(split);
|
|
29
|
+
return join('/')(foldResult);
|
|
30
|
+
};
|
|
31
|
+
export const concat = a => b => {
|
|
32
|
+
const s = stringConcat([a, '/', b]);
|
|
33
|
+
return normalize(s);
|
|
34
|
+
};
|
package/path/test.f.d.ts
ADDED
package/path/test.f.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { concat, normalize } from "./module.f.js";
|
|
2
|
+
export default {
|
|
3
|
+
normalize: [
|
|
4
|
+
() => {
|
|
5
|
+
const norm = normalize("dir/file.json");
|
|
6
|
+
if (norm !== "dir/file.json") {
|
|
7
|
+
throw norm;
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
() => {
|
|
11
|
+
const norm = normalize("dir//file.json");
|
|
12
|
+
if (norm !== "dir/file.json") {
|
|
13
|
+
throw norm;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
() => {
|
|
17
|
+
const norm = normalize("../../dir/file.json");
|
|
18
|
+
if (norm !== "../../dir/file.json") {
|
|
19
|
+
throw norm;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
() => {
|
|
23
|
+
const norm = normalize("../../dir/../file.json");
|
|
24
|
+
if (norm !== "../../file.json") {
|
|
25
|
+
throw norm;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
concat: [
|
|
30
|
+
() => {
|
|
31
|
+
const c = concat("a")("b");
|
|
32
|
+
if (c !== "a/b") {
|
|
33
|
+
throw c;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
() => {
|
|
37
|
+
const c = concat("a///b/")("c");
|
|
38
|
+
if (c !== "a/b/c") {
|
|
39
|
+
throw c;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
() => {
|
|
43
|
+
const c = concat("a/../b/..")("c");
|
|
44
|
+
if (c !== "c") {
|
|
45
|
+
throw c;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
]
|
|
49
|
+
};
|
package/text/sgr/module.f.d.ts
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
|
+
export declare const backspace: string;
|
|
2
|
+
type End = 'm';
|
|
3
|
+
type Csi = (code: number | string) => string;
|
|
1
4
|
/**
|
|
5
|
+
* Control Sequence Introducer (CSI) escape sequence.
|
|
6
|
+
* https://en.wikipedia.org/wiki/ANSI_escape_code#Control_Sequence_Introducer_commands
|
|
7
|
+
*
|
|
8
|
+
* @param end - The final character that indicates the type of sequence.
|
|
9
|
+
* @returns A function that takes a code (number or string) and returns the complete ANSI escape sequence.
|
|
10
|
+
*/
|
|
11
|
+
export declare const csi: (end: End) => Csi;
|
|
12
|
+
/**
|
|
13
|
+
* Specialization of CSI for Select Graphic Rendition (SGR) sequences.
|
|
2
14
|
* https://en.wikipedia.org/wiki/ANSI_escape_code#SGR
|
|
3
15
|
*/
|
|
4
|
-
export declare const sgr:
|
|
16
|
+
export declare const sgr: Csi;
|
|
5
17
|
export declare const reset: string;
|
|
6
18
|
export declare const bold: string;
|
|
7
19
|
export declare const fgRed: string;
|
|
8
20
|
export declare const fgGreen: string;
|
|
21
|
+
export type Stdout = {
|
|
22
|
+
readonly write: (s: string) => void;
|
|
23
|
+
};
|
|
24
|
+
export type WriteText = (text: string) => WriteText;
|
|
25
|
+
export declare const createConsoleText: (stdout: Stdout) => WriteText;
|
|
26
|
+
export {};
|
package/text/sgr/module.f.js
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
|
+
// Co control codes
|
|
2
|
+
// https://en.wikipedia.org/wiki/ANSI_escape_code#C0_control_codes
|
|
3
|
+
export const backspace = '\x08';
|
|
1
4
|
/**
|
|
5
|
+
* Control Sequence Introducer (CSI) escape sequence.
|
|
6
|
+
* https://en.wikipedia.org/wiki/ANSI_escape_code#Control_Sequence_Introducer_commands
|
|
7
|
+
*
|
|
8
|
+
* @param end - The final character that indicates the type of sequence.
|
|
9
|
+
* @returns A function that takes a code (number or string) and returns the complete ANSI escape sequence.
|
|
10
|
+
*/
|
|
11
|
+
export const csi = (end) => code => `\x1b[${code.toString()}${end}`;
|
|
12
|
+
/**
|
|
13
|
+
* Specialization of CSI for Select Graphic Rendition (SGR) sequences.
|
|
2
14
|
* https://en.wikipedia.org/wiki/ANSI_escape_code#SGR
|
|
3
15
|
*/
|
|
4
|
-
export const sgr = (
|
|
16
|
+
export const sgr = csi('m');
|
|
5
17
|
export const reset = sgr(0);
|
|
6
18
|
export const bold = sgr(1);
|
|
7
19
|
export const fgRed = sgr(31);
|
|
8
20
|
export const fgGreen = sgr(32);
|
|
21
|
+
const { max } = Math;
|
|
22
|
+
const replace = (old) => (text) => {
|
|
23
|
+
const len = old.length;
|
|
24
|
+
const suffixLength = max(0, len - text.length);
|
|
25
|
+
return backspace.repeat(len) + text + " ".repeat(suffixLength) + backspace.repeat(suffixLength);
|
|
26
|
+
};
|
|
27
|
+
export const createConsoleText = (stdout) => {
|
|
28
|
+
const f = (old) => (text) => {
|
|
29
|
+
stdout.write(replace(old)(text));
|
|
30
|
+
return f(text);
|
|
31
|
+
};
|
|
32
|
+
return f('');
|
|
33
|
+
};
|