functionalscript 0.3.7 → 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 +1 -1
- package/crypto/prime_field/module.f.js +1 -1
- package/crypto/secp/module.f.d.ts +1 -1
- package/crypto/secp/module.f.js +2 -2
- 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/js/tokenizer/module.f.d.ts +1 -1
- package/js/tokenizer/module.f.js +1 -1
- 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/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/bigfloat/module.f.js +1 -1
- package/types/bigint/module.f.d.ts +17 -5
- package/types/bigint/module.f.js +19 -4
- 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/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/dev/test.f.js
CHANGED
package/djs/module.f.d.ts
CHANGED
package/djs/module.f.js
CHANGED
|
@@ -2,7 +2,6 @@ import * as list from "../types/list/module.f.js";
|
|
|
2
2
|
const { flat, map } = list;
|
|
3
3
|
import * as string from "../types/string/module.f.js";
|
|
4
4
|
const { concat } = string;
|
|
5
|
-
import * as O from "../types/object/module.f.js";
|
|
6
5
|
import * as f from "../types/function/module.f.js";
|
|
7
6
|
const { compose, fn } = f;
|
|
8
7
|
const { entries } = Object;
|
package/djs/parser/module.f.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as result from '../../types/result/module.f.ts';
|
|
2
2
|
import { type List } from '../../types/list/module.f.ts';
|
|
3
|
-
import * as tokenizerT from '../tokenizer/module.f.ts';
|
|
3
|
+
import type * as tokenizerT from '../tokenizer/module.f.ts';
|
|
4
4
|
export type DjsModule = [readonly string[], readonly DjsConst[]];
|
|
5
5
|
export type DjsConst = boolean | string | number | null | bigint | undefined | DjsModuleRef | DjsArray | DjsObject;
|
|
6
6
|
type DjsModuleRef = ['aref' | 'cref', number];
|
package/djs/parser/module.f.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import * as result from "../../types/result/module.f.js";
|
|
2
2
|
import { fold, first, drop, toArray, length, concat } from "../../types/list/module.f.js";
|
|
3
|
-
import * as Operator from "../../types/function/operator/module.f.js";
|
|
4
|
-
import * as tokenizerT from "../tokenizer/module.f.js";
|
|
5
3
|
import { setReplace, at } from "../../types/map/module.f.js";
|
|
6
4
|
import * as o from "../../types/object/module.f.js";
|
|
7
5
|
const { fromMap } = o;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as list from '../../types/list/module.f.ts';
|
|
2
|
-
import * as O from '../../types/object/module.f.ts';
|
|
3
|
-
import * as DjsParser from '../parser/module.f.ts';
|
|
2
|
+
import type * as O from '../../types/object/module.f.ts';
|
|
3
|
+
import type * as DjsParser from '../parser/module.f.ts';
|
|
4
4
|
export declare const undefinedSerialize: string[];
|
|
5
5
|
type Entry = O.Entry<DjsParser.DjsConst>;
|
|
6
6
|
type Entries = list.List<Entry>;
|
|
@@ -2,7 +2,6 @@ import * as list from "../../types/list/module.f.js";
|
|
|
2
2
|
const { flat, map, entries: listEntries, concat: listConcat, flatMap } = list;
|
|
3
3
|
import * as string from "../../types/string/module.f.js";
|
|
4
4
|
const { concat } = string;
|
|
5
|
-
import * as O from "../../types/object/module.f.js";
|
|
6
5
|
import * as f from "../../types/function/module.f.js";
|
|
7
6
|
const { compose, fn } = f;
|
|
8
7
|
const { entries } = Object;
|
|
@@ -10,7 +9,6 @@ import * as bi from "../../types/bigint/module.f.js";
|
|
|
10
9
|
const { serialize: bigintSerialize } = bi;
|
|
11
10
|
import * as j from "../../json/serializer/module.f.js";
|
|
12
11
|
const { objectWrap, arrayWrap, stringSerialize, numberSerialize, nullSerialize, boolSerialize } = j;
|
|
13
|
-
import * as DjsParser from "../parser/module.f.js";
|
|
14
12
|
const colon = [':'];
|
|
15
13
|
export const undefinedSerialize = ['undefined'];
|
|
16
14
|
const djsConstSerialize = sort => {
|
package/fsc/test.f.js
CHANGED
|
@@ -81,6 +81,6 @@ export type CommentToken = {
|
|
|
81
81
|
};
|
|
82
82
|
export type JsToken = KeywordToken | TrueToken | FalseToken | NullToken | WhitespaceToken | NewLineToken | StringToken | NumberToken | ErrorToken | IdToken | BigIntToken | UndefinedToken | OperatorToken | CommentToken;
|
|
83
83
|
type ErrorMessage = '" are missing' | 'unescaped character' | 'invalid hex value' | 'unexpected character' | 'invalid number' | 'invalid token' | '*\/ expected' | 'unterminated string literal' | 'eof';
|
|
84
|
-
export declare const isKeywordToken: (token: JsToken) =>
|
|
84
|
+
export declare const isKeywordToken: (token: JsToken) => boolean;
|
|
85
85
|
export declare const tokenize: (input: list.List<number>) => list.List<JsToken>;
|
|
86
86
|
export {};
|
package/js/tokenizer/module.f.js
CHANGED
|
@@ -485,8 +485,8 @@ const tokenizeEofOp = state => {
|
|
|
485
485
|
case 'e':
|
|
486
486
|
case 'e+':
|
|
487
487
|
case 'e-': return [[{ kind: 'error', message: 'invalid number' }], { kind: 'eof', }];
|
|
488
|
-
default: return [[bufferToNumberToken(state)], { kind: 'eof' }];
|
|
489
488
|
}
|
|
489
|
+
return [[bufferToNumberToken(state)], { kind: 'eof' }];
|
|
490
490
|
case 'op': return [[getOperatorToken(state.value)], { kind: 'eof' }];
|
|
491
491
|
case '//': return [[{ kind: '//', value: state.value }], { kind: 'eof' }];
|
|
492
492
|
case '/*':
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as result from '../../types/result/module.f.ts';
|
|
2
2
|
import * as list from '../../types/list/module.f.ts';
|
|
3
|
-
import * as Tokenizer from '../tokenizer/module.f.ts';
|
|
4
|
-
import * as Json from '../module.f.ts';
|
|
3
|
+
import type * as Tokenizer from '../tokenizer/module.f.ts';
|
|
4
|
+
import type * as Json from '../module.f.ts';
|
|
5
5
|
export declare const parse: (tokenList: list.List<Tokenizer.JsonToken>) => result.Result<Json.Unknown, string>;
|
package/json/parser/module.f.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import * as result from "../../types/result/module.f.js";
|
|
2
2
|
import * as list from "../../types/list/module.f.js";
|
|
3
3
|
const { fold, first, drop, toArray } = list;
|
|
4
|
-
import * as Operator from "../../types/function/operator/module.f.js";
|
|
5
|
-
import * as Tokenizer from "../tokenizer/module.f.js";
|
|
6
4
|
import * as map from "../../types/map/module.f.js";
|
|
7
5
|
const { setReplace } = map;
|
|
8
|
-
import * as Json from "../module.f.js";
|
|
9
6
|
import * as o from "../../types/object/module.f.js";
|
|
10
7
|
const { fromMap } = o;
|
|
11
8
|
const addKeyToObject = obj => key => ({ kind: 'object', values: obj.values, key: key });
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import * as list from "../../types/list/module.f.js";
|
|
2
2
|
const { flat, reduce, empty } = list;
|
|
3
|
-
import * as O from "../../types/object/module.f.js";
|
|
4
|
-
import * as Operator from "../../types/function/operator/module.f.js";
|
|
5
3
|
const jsonStringify = JSON.stringify;
|
|
6
4
|
export const stringSerialize = input => [jsonStringify(input)];
|
|
7
5
|
export const numberSerialize = input => [jsonStringify(input)];
|
package/package.json
CHANGED
package/text/ascii/module.f.d.ts
CHANGED
package/text/ascii/module.f.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const at = s => i => {
|
|
1
|
+
const at = (s) => (i) => {
|
|
3
2
|
const r = s.codePointAt(i);
|
|
4
3
|
if (r === void 0) {
|
|
5
4
|
throw s;
|
|
@@ -7,7 +6,7 @@ const at = s => i => {
|
|
|
7
6
|
return r;
|
|
8
7
|
};
|
|
9
8
|
export const one = (s) => at(s)(0);
|
|
10
|
-
export const range = s => {
|
|
9
|
+
export const range = (s) => {
|
|
11
10
|
const f = at(s);
|
|
12
11
|
const f0 = f(0);
|
|
13
12
|
if (s.length === 1) {
|
package/text/ascii/test.f.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
const { range } = _;
|
|
1
|
+
import { range } from "./module.f.js";
|
|
3
2
|
import * as json from "../../json/module.f.js";
|
|
4
|
-
import
|
|
5
|
-
const { sort } = o;
|
|
3
|
+
import { sort } from "../../types/object/module.f.js";
|
|
6
4
|
const stringify = json.stringify(sort);
|
|
7
5
|
export default {
|
|
8
6
|
range: () => {
|
package/text/module.f.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Vec } from "../types/bit_vec/module.f.ts";
|
|
2
|
+
import { type List } from '../types/list/module.f.ts';
|
|
2
3
|
export type Block = ItemThunk | ItemArray;
|
|
3
4
|
type ItemArray = readonly Item[];
|
|
4
|
-
type ItemThunk = () =>
|
|
5
|
+
type ItemThunk = () => List<Item>;
|
|
5
6
|
export type Item = string | ItemArray | ItemThunk;
|
|
6
|
-
export declare const flat: (indent: string) => (text: Block) =>
|
|
7
|
+
export declare const flat: (indent: string) => (text: Block) => List<string>;
|
|
7
8
|
export declare const curly: (type: string) => (name: string) => (body: Block) => Block;
|
|
9
|
+
/**
|
|
10
|
+
* Converts a string to an UTF-8, represented as an MSB first bit vector.
|
|
11
|
+
*
|
|
12
|
+
* @param s The input string to be converted.
|
|
13
|
+
* @returns The resulting UTF-8 bit vector, MSB first.
|
|
14
|
+
*/
|
|
15
|
+
export declare const msbUtf8: (s: string) => Vec;
|
|
16
|
+
/**
|
|
17
|
+
* Converts a UTF-8 bit vector with MSB first encoding to a string.
|
|
18
|
+
*
|
|
19
|
+
* @param msbV - The UTF-8 bit vector with MSB first encoding.
|
|
20
|
+
* @returns The resulting string.
|
|
21
|
+
*/
|
|
22
|
+
export declare const msbUtf8ToString: (msbV: Vec) => string;
|
|
8
23
|
export {};
|
package/text/module.f.js
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { msb, u8List, u8ListToVec } from "../types/bit_vec/module.f.js";
|
|
2
|
+
import { flatMap } from "../types/list/module.f.js";
|
|
3
|
+
import * as utf8 from "./utf8/module.f.js";
|
|
4
|
+
import * as utf16 from "./utf16/module.f.js";
|
|
5
|
+
export const flat = (indent) => {
|
|
6
|
+
const f = (prefix) => {
|
|
7
|
+
const g = (item) => typeof (item) === 'string' ? [`${prefix}${item}`] : f(`${prefix}${indent}`)(item);
|
|
6
8
|
return flatMap(g);
|
|
7
9
|
};
|
|
8
10
|
return f('');
|
|
9
11
|
};
|
|
10
|
-
export const curly = type => name => body => [`${type} ${name}`, '{', body, '}'];
|
|
12
|
+
export const curly = (type) => (name) => (body) => [`${type} ${name}`, '{', body, '}'];
|
|
13
|
+
/**
|
|
14
|
+
* Converts a string to an UTF-8, represented as an MSB first bit vector.
|
|
15
|
+
*
|
|
16
|
+
* @param s The input string to be converted.
|
|
17
|
+
* @returns The resulting UTF-8 bit vector, MSB first.
|
|
18
|
+
*/
|
|
19
|
+
export const msbUtf8 = (s) => u8ListToVec(msb)(utf8.fromCodePointList(utf16.toCodePointList(utf16.stringToList(s))));
|
|
20
|
+
/**
|
|
21
|
+
* Converts a UTF-8 bit vector with MSB first encoding to a string.
|
|
22
|
+
*
|
|
23
|
+
* @param msbV - The UTF-8 bit vector with MSB first encoding.
|
|
24
|
+
* @returns The resulting string.
|
|
25
|
+
*/
|
|
26
|
+
export const msbUtf8ToString = (msbV) => utf16.listToString(utf16.fromCodePointList(utf8.toCodePointList(u8List(msb)(msbV))));
|
package/text/sgr/module.f.js
CHANGED
package/text/test.f.d.ts
CHANGED
package/text/test.f.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { flat, msbUtf8, msbUtf8ToString } from "./module.f.js";
|
|
2
|
+
import { join } from "../types/string/module.f.js";
|
|
3
|
+
export default {
|
|
4
|
+
block: () => {
|
|
5
|
+
const text = [
|
|
6
|
+
'a',
|
|
7
|
+
'b',
|
|
8
|
+
() => [
|
|
9
|
+
'c',
|
|
10
|
+
() => ['d'],
|
|
11
|
+
],
|
|
12
|
+
'e',
|
|
13
|
+
];
|
|
14
|
+
const result = join('\n')(flat(':')(text));
|
|
15
|
+
if (result !== 'a\nb\n:c\n::d\ne') {
|
|
16
|
+
throw result;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
encoding: () => {
|
|
20
|
+
const v = msbUtf8('Hello world!');
|
|
21
|
+
const r = msbUtf8ToString(v);
|
|
22
|
+
if (r !== 'Hello world!') {
|
|
23
|
+
throw r;
|
|
24
|
+
}
|
|
17
25
|
}
|
|
18
26
|
};
|
package/text/utf16/module.f.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type List, type Thunk } from '../../types/list/module.f.ts';
|
|
2
|
-
type
|
|
3
|
-
type
|
|
2
|
+
type U16 = number;
|
|
3
|
+
type I32 = number;
|
|
4
4
|
export declare const fromCodePointList: (input: List<number>) => Thunk<number>;
|
|
5
|
-
declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const listToString: (input: List<u16>) => string;
|
|
5
|
+
export declare const toCodePointList: (input: List<U16>) => List<I32>;
|
|
6
|
+
export declare const stringToList: (s: string) => List<U16>;
|
|
7
|
+
export declare const listToString: (input: List<U16>) => string;
|
|
9
8
|
export {};
|
package/text/utf16/module.f.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { map, flat, stateScan, reduce, flatMap, empty, } from "../../types/list/module.f.js";
|
|
2
|
-
import
|
|
2
|
+
import { concat } from "../../types/function/operator/module.f.js";
|
|
3
3
|
import { contains } from "../../types/range/module.f.js";
|
|
4
|
-
import
|
|
5
|
-
const { fn } = f;
|
|
4
|
+
import { fn } from "../../types/function/module.f.js";
|
|
6
5
|
const lowBmp = contains([0x0000, 0xd7ff]);
|
|
7
6
|
const highBmp = contains([0xe000, 0xffff]);
|
|
8
|
-
const isBmpCodePoint = codePoint => lowBmp(codePoint) || highBmp(codePoint);
|
|
7
|
+
const isBmpCodePoint = (codePoint) => lowBmp(codePoint) || highBmp(codePoint);
|
|
9
8
|
const isHighSurrogate = contains([0xd800, 0xdbff]);
|
|
10
9
|
const isLowSurrogate = contains([0xdc00, 0xdfff]);
|
|
11
10
|
const errorMask = 0b1000_0000_0000_0000_0000_0000_0000_0000;
|
|
12
11
|
const isSupplementaryPlane = contains([0x01_0000, 0x10_ffff]);
|
|
13
|
-
const codePointToUtf16 = codePoint => {
|
|
12
|
+
const codePointToUtf16 = (codePoint) => {
|
|
14
13
|
if (isBmpCodePoint(codePoint)) {
|
|
15
14
|
return [codePoint];
|
|
16
15
|
}
|
|
@@ -50,17 +49,17 @@ const utf16ByteToCodePointOp = state => word => {
|
|
|
50
49
|
}
|
|
51
50
|
return [[state | errorMask, word | errorMask], null];
|
|
52
51
|
};
|
|
53
|
-
const utf16EofToCodePointOp = state => [state === null ? empty : [state | errorMask], null];
|
|
52
|
+
const utf16EofToCodePointOp = (state) => [state === null ? empty : [state | errorMask], null];
|
|
54
53
|
const utf16ByteOrEofToCodePointOp = state => input => input === null ? utf16EofToCodePointOp(state) : utf16ByteToCodePointOp(state)(input);
|
|
55
54
|
const eofList = [null];
|
|
56
|
-
export const toCodePointList = input => flat(stateScan(utf16ByteOrEofToCodePointOp)(null)(flat([input, eofList])));
|
|
57
|
-
export const stringToList = s => {
|
|
58
|
-
const at = i => {
|
|
55
|
+
export const toCodePointList = (input) => flat(stateScan(utf16ByteOrEofToCodePointOp)(null)(flat([input, eofList])));
|
|
56
|
+
export const stringToList = (s) => {
|
|
57
|
+
const at = (i) => {
|
|
59
58
|
const first = s.charCodeAt(i);
|
|
60
59
|
return isNaN(first) ? empty : { first, tail: () => at(i + 1) };
|
|
61
60
|
};
|
|
62
61
|
return at(0);
|
|
63
62
|
};
|
|
64
63
|
export const listToString = fn(map(String.fromCharCode))
|
|
65
|
-
.then(reduce(
|
|
64
|
+
.then(reduce(concat)(''))
|
|
66
65
|
.result;
|
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])));
|