functionalscript 0.7.0 → 0.8.1

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.
Files changed (125) hide show
  1. package/LICENSE +21 -661
  2. package/README.md +3 -2
  3. package/bnf/data/module.f.d.ts +16 -6
  4. package/bnf/data/module.f.js +115 -23
  5. package/bnf/data/test.f.d.ts +4 -0
  6. package/bnf/data/test.f.js +389 -14
  7. package/bnf/module.f.d.ts +5 -4
  8. package/bnf/module.f.js +1 -1
  9. package/bnf/testlib.f.js +1 -1
  10. package/ci/module.f.d.ts +3 -0
  11. package/ci/module.f.js +169 -0
  12. package/ci/module.js +3 -0
  13. package/crypto/hmac/module.f.d.ts +5 -4
  14. package/crypto/hmac/module.f.js +9 -18
  15. package/crypto/hmac/test.f.d.ts +1 -0
  16. package/crypto/hmac/test.f.js +16 -8
  17. package/crypto/prime_field/module.f.d.ts +1 -1
  18. package/crypto/prime_field/module.f.js +4 -3
  19. package/crypto/prime_field/test.f.js +13 -13
  20. package/crypto/rfc6979/module.f.d.ts +15 -0
  21. package/crypto/rfc6979/module.f.js +98 -0
  22. package/crypto/rfc6979/test.f.d.ts +10 -0
  23. package/crypto/rfc6979/test.f.js +490 -0
  24. package/crypto/secp/module.f.d.ts +4 -4
  25. package/crypto/secp/module.f.js +1 -1
  26. package/crypto/secp/test.f.js +8 -8
  27. package/crypto/sha2/module.f.d.ts +11 -5
  28. package/crypto/sha2/module.f.js +4 -3
  29. package/crypto/sha2/test.f.d.ts +4 -1
  30. package/crypto/sha2/test.f.js +41 -31
  31. package/crypto/sign/module.f.d.ts +1 -1
  32. package/crypto/sign/module.f.js +3 -2
  33. package/dev/tf/all.test.js +9 -1
  34. package/djs/ast/module.f.d.ts +3 -3
  35. package/djs/ast/test.f.js +7 -8
  36. package/djs/parser/module.f.d.ts +3 -3
  37. package/djs/parser/module.f.js +4 -4
  38. package/djs/parser/test.f.js +76 -77
  39. package/djs/serializer/module.f.d.ts +8 -8
  40. package/djs/serializer/module.f.js +4 -7
  41. package/djs/serializer/test.f.js +8 -9
  42. package/djs/tokenizer/module.f.d.ts +2 -2
  43. package/djs/tokenizer/module.f.js +3 -5
  44. package/djs/tokenizer/test.f.js +8 -10
  45. package/djs/transpiler/module.f.d.ts +3 -3
  46. package/djs/transpiler/module.f.js +2 -0
  47. package/fsc/bnf.f.d.ts +1 -1
  48. package/fsc/bnf.f.js +39 -51
  49. package/fsc/json.f.d.ts +1 -1
  50. package/fsc/json.f.js +56 -81
  51. package/fsc/test.f.d.ts +5 -0
  52. package/fsc/test.f.js +69 -7
  53. package/fsm/module.f.js +3 -3
  54. package/fsm/test.f.js +21 -25
  55. package/html/module.f.js +17 -4
  56. package/html/test.f.d.ts +7 -0
  57. package/html/test.f.js +37 -0
  58. package/issues/031-json.f.d.ts +1 -0
  59. package/js/tokenizer/module.f.d.ts +4 -4
  60. package/js/tokenizer/module.f.js +12 -17
  61. package/js/tokenizer/test.f.js +9 -11
  62. package/json/module.f.d.ts +6 -6
  63. package/json/module.f.js +5 -10
  64. package/json/parser/module.f.d.ts +4 -4
  65. package/json/parser/module.f.js +7 -4
  66. package/json/parser/test.f.js +47 -49
  67. package/json/serializer/module.f.d.ts +6 -6
  68. package/json/serializer/module.f.js +3 -2
  69. package/json/serializer/test.f.js +13 -13
  70. package/json/test.f.js +13 -15
  71. package/json/tokenizer/module.f.d.ts +4 -4
  72. package/json/tokenizer/module.f.js +6 -7
  73. package/json/tokenizer/test.f.js +7 -9
  74. package/nanvm-lib/tests/vm/test.f.d.ts +25 -0
  75. package/nanvm-lib/tests/vm/test.f.js +105 -0
  76. package/package.json +8 -8
  77. package/text/ascii/test.f.js +2 -2
  78. package/text/module.f.d.ts +3 -2
  79. package/text/module.f.js +2 -2
  80. package/text/test.f.js +3 -3
  81. package/text/utf16/test.f.js +2 -2
  82. package/text/utf8/test.f.js +2 -2
  83. package/types/array/test.f.js +2 -2
  84. package/types/bigint/module.f.d.ts +6 -3
  85. package/types/bigint/module.f.js +12 -11
  86. package/types/bigint/test.f.d.ts +2 -0
  87. package/types/bigint/test.f.js +21 -2
  88. package/types/bit_vec/module.f.d.ts +66 -34
  89. package/types/bit_vec/module.f.js +97 -32
  90. package/types/bit_vec/test.f.d.ts +7 -0
  91. package/types/bit_vec/test.f.js +283 -62
  92. package/types/btree/find/test.f.js +9 -8
  93. package/types/btree/remove/test.f.js +4 -4
  94. package/types/btree/set/test.f.js +4 -4
  95. package/types/btree/test.f.js +7 -7
  96. package/types/byte_set/test.f.js +2 -2
  97. package/types/function/compare/module.f.d.ts +15 -1
  98. package/types/function/compare/module.f.js +1 -1
  99. package/types/function/compare/test.f.js +37 -4
  100. package/types/list/test.f.js +93 -93
  101. package/types/monoid/module.f.d.ts +4 -4
  102. package/types/monoid/module.f.js +3 -3
  103. package/types/monoid/test.f.js +3 -3
  104. package/types/nominal/module.f.d.ts +5 -0
  105. package/types/nominal/module.f.js +4 -0
  106. package/types/nominal/test.f.d.ts +5 -0
  107. package/types/nominal/test.f.js +53 -0
  108. package/types/number/module.f.js +2 -2
  109. package/types/range_map/test.f.js +21 -21
  110. package/types/sorted_list/test.f.js +10 -10
  111. package/types/sorted_set/test.f.js +14 -14
  112. package/types/string/module.f.js +2 -2
  113. package/types/string_set/module.f.js +3 -3
  114. package/bnf/djs/module.f.d.ts +0 -77
  115. package/bnf/djs/module.f.js +0 -207
  116. package/bnf/djs/test.f.d.ts +0 -8
  117. package/bnf/djs/test.f.js +0 -277
  118. package/bnf/func/module.f.d.ts +0 -148
  119. package/bnf/func/module.f.js +0 -132
  120. package/bnf/func/test.f.d.ts +0 -12
  121. package/bnf/func/test.f.js +0 -171
  122. package/bnf/func/testlib.f.d.ts +0 -25
  123. package/bnf/func/testlib.f.js +0 -150
  124. /package/{issues/31-json.f.d.ts → ci/module.d.ts} +0 -0
  125. /package/issues/{31-json.f.js → 031-json.f.js} +0 -0
@@ -1,22 +1,22 @@
1
- import * as _ from "./module.f.js";
1
+ import { arrayWrap, boolSerialize, numberSerialize, objectWrap, stringSerialize } from "./module.f.js";
2
2
  import * as list from "../../types/list/module.f.js";
3
3
  const { toArray } = list;
4
4
  export default {
5
5
  arrayWrap: [
6
6
  () => {
7
- const result = JSON.stringify(toArray(_.arrayWrap(null)));
7
+ const result = JSON.stringify(toArray(arrayWrap(null)));
8
8
  if (result !== '["[","]"]') {
9
9
  throw result;
10
10
  }
11
11
  },
12
12
  () => {
13
- const result = JSON.stringify(toArray(_.arrayWrap([['a', 'b']])));
13
+ const result = JSON.stringify(toArray(arrayWrap([['a', 'b']])));
14
14
  if (result !== '["[","a","b","]"]') {
15
15
  throw result;
16
16
  }
17
17
  },
18
18
  () => {
19
- const result = JSON.stringify(toArray(_.arrayWrap([['a'], ['b']])));
19
+ const result = JSON.stringify(toArray(arrayWrap([['a'], ['b']])));
20
20
  if (result !== '["[","a",",","b","]"]') {
21
21
  throw result;
22
22
  }
@@ -24,19 +24,19 @@ export default {
24
24
  ],
25
25
  objectWrap: [
26
26
  () => {
27
- const result = JSON.stringify(toArray(_.objectWrap(null)));
27
+ const result = JSON.stringify(toArray(objectWrap(null)));
28
28
  if (result !== '["{","}"]') {
29
29
  throw result;
30
30
  }
31
31
  },
32
32
  () => {
33
- const result = JSON.stringify(toArray(_.objectWrap([['a', 'b']])));
33
+ const result = JSON.stringify(toArray(objectWrap([['a', 'b']])));
34
34
  if (result !== '["{","a","b","}"]') {
35
35
  throw result;
36
36
  }
37
37
  },
38
38
  () => {
39
- const result = JSON.stringify(toArray(_.objectWrap([['a'], ['b']])));
39
+ const result = JSON.stringify(toArray(objectWrap([['a'], ['b']])));
40
40
  if (result !== '["{","a",",","b","}"]') {
41
41
  throw result;
42
42
  }
@@ -44,13 +44,13 @@ export default {
44
44
  ],
45
45
  stringSerialize: [
46
46
  () => {
47
- const result = JSON.stringify(toArray(_.stringSerialize('abc')));
47
+ const result = JSON.stringify(toArray(stringSerialize('abc')));
48
48
  if (result !== '["\\"abc\\""]') {
49
49
  throw result;
50
50
  }
51
51
  },
52
52
  () => {
53
- const result = JSON.stringify(toArray(_.stringSerialize('123')));
53
+ const result = JSON.stringify(toArray(stringSerialize('123')));
54
54
  if (result !== '["\\"123\\""]') {
55
55
  throw result;
56
56
  }
@@ -58,13 +58,13 @@ export default {
58
58
  ],
59
59
  numberSerialize: [
60
60
  () => {
61
- const result = JSON.stringify(toArray(_.numberSerialize(123)));
61
+ const result = JSON.stringify(toArray(numberSerialize(123)));
62
62
  if (result !== '["123"]') {
63
63
  throw result;
64
64
  }
65
65
  },
66
66
  () => {
67
- const result = JSON.stringify(toArray(_.numberSerialize(10e20)));
67
+ const result = JSON.stringify(toArray(numberSerialize(10e20)));
68
68
  if (result !== '["1e+21"]') {
69
69
  throw result;
70
70
  }
@@ -72,13 +72,13 @@ export default {
72
72
  ],
73
73
  boolSerialize: [
74
74
  () => {
75
- const result = JSON.stringify(toArray(_.boolSerialize(false)));
75
+ const result = JSON.stringify(toArray(boolSerialize(false)));
76
76
  if (result !== '["false"]') {
77
77
  throw result;
78
78
  }
79
79
  },
80
80
  () => {
81
- const result = JSON.stringify(toArray(_.boolSerialize(true)));
81
+ const result = JSON.stringify(toArray(boolSerialize(true)));
82
82
  if (result !== '["true"]') {
83
83
  throw result;
84
84
  }
package/json/test.f.js CHANGED
@@ -1,25 +1,23 @@
1
- import * as json from "./module.f.js";
2
- import * as o from "../types/object/module.f.js";
3
- const { sort } = o;
4
- import * as f from "../types/function/module.f.js";
5
- const { identity } = f;
1
+ import { setProperty, stringify } from "./module.f.js";
2
+ import { sort } from "../types/object/module.f.js";
3
+ import { identity } from "../types/function/module.f.js";
6
4
  export default {
7
5
  setProperty: () => {
8
- if (json.setProperty("Hello")([])({}) !== "Hello") {
6
+ if (setProperty("Hello")([])({}) !== "Hello") {
9
7
  throw 'error';
10
8
  }
11
9
  },
12
10
  stringify: [
13
11
  {
14
12
  sort: () => {
15
- const r = json.setProperty("Hello")(['a'])({});
16
- const x = json.stringify(sort)(r);
13
+ const r = setProperty("Hello")(['a'])({});
14
+ const x = stringify(sort)(r);
17
15
  if (x !== '{"a":"Hello"}') {
18
16
  throw x;
19
17
  }
20
18
  },
21
19
  identity: () => {
22
- const x = json.stringify(identity)(json.setProperty("Hello")(['a'])({}));
20
+ const x = stringify(identity)(setProperty("Hello")(['a'])({}));
23
21
  if (x !== '{"a":"Hello"}') {
24
22
  throw x;
25
23
  }
@@ -27,13 +25,13 @@ export default {
27
25
  },
28
26
  {
29
27
  sort: () => {
30
- const x = json.stringify(sort)(json.setProperty("Hello")(['a'])({ c: [], b: 12 }));
28
+ const x = stringify(sort)(setProperty("Hello")(['a'])({ c: [], b: 12 }));
31
29
  if (x !== '{"a":"Hello","b":12,"c":[]}') {
32
30
  throw x;
33
31
  }
34
32
  },
35
33
  identity: () => {
36
- const x = json.stringify(identity)(json.setProperty("Hello")(['a'])({ c: [], b: 12 }));
34
+ const x = stringify(identity)(setProperty("Hello")(['a'])({ c: [], b: 12 }));
37
35
  if (x !== '{"c":[],"b":12,"a":"Hello"}') {
38
36
  throw x;
39
37
  }
@@ -42,16 +40,16 @@ export default {
42
40
  {
43
41
  sort: () => {
44
42
  const _0 = { a: { y: [24] }, c: [], b: 12 };
45
- const _1 = json.setProperty("Hello")(['a', 'x'])(_0);
46
- const _2 = json.stringify(sort)(_1);
43
+ const _1 = setProperty("Hello")(['a', 'x'])(_0);
44
+ const _2 = stringify(sort)(_1);
47
45
  if (_2 !== '{"a":{"x":"Hello","y":[24]},"b":12,"c":[]}') {
48
46
  throw _2;
49
47
  }
50
48
  },
51
49
  identity: () => {
52
50
  const _0 = { a: { y: [24] }, c: [], b: 12 };
53
- const _1 = json.setProperty("Hello")(['a', 'x'])(_0);
54
- const _2 = json.stringify(identity)(_1);
51
+ const _1 = setProperty("Hello")(['a', 'x'])(_0);
52
+ const _2 = stringify(identity)(_1);
55
53
  if (_2 !== '{"a":{"y":[24],"x":"Hello"},"c":[],"b":12}') {
56
54
  throw _2;
57
55
  }
@@ -1,8 +1,8 @@
1
- import * as list from '../../types/list/module.f.ts';
2
- import * as jsTokenizer from '../../js/tokenizer/module.f.ts';
1
+ import { type List } from '../../types/list/module.f.ts';
2
+ import { type EofToken, type ErrorToken, type NumberToken, type StringToken } from '../../js/tokenizer/module.f.ts';
3
3
  export type JsonToken = {
4
4
  readonly kind: 'true' | 'false' | 'null';
5
5
  } | {
6
6
  readonly kind: '{' | '}' | ':' | ',' | '[' | ']';
7
- } | jsTokenizer.StringToken | jsTokenizer.NumberToken | jsTokenizer.ErrorToken | jsTokenizer.EofToken;
8
- export declare const tokenize: (input: list.List<number>) => list.List<JsonToken>;
7
+ } | StringToken | NumberToken | ErrorToken | EofToken;
8
+ export declare const tokenize: (input: List<number>) => List<JsonToken>;
@@ -1,8 +1,7 @@
1
- import * as list from "../../types/list/module.f.js";
2
- const { empty, flat, stateScan } = list;
3
- import * as bf from "../../types/bigfloat/module.f.js";
4
- const { multiply } = bf;
5
- import * as jsTokenizer from "../../js/tokenizer/module.f.js";
1
+ import {} from "../../types/function/operator/module.f.js";
2
+ import { concat, empty, flat, stateScan } from "../../types/list/module.f.js";
3
+ import { multiply } from "../../types/bigfloat/module.f.js";
4
+ import { tokenize as jsTokenize } from "../../js/tokenizer/module.f.js";
6
5
  const mapToken = input => {
7
6
  switch (input.kind) {
8
7
  case '{':
@@ -47,6 +46,6 @@ const scanToken = state => input => {
47
46
  }
48
47
  };
49
48
  export const tokenize = (input) => {
50
- const jsTokens = jsTokenizer.tokenize(input)('');
51
- return flat(stateScan(scanToken)({ kind: 'def' })(list.concat(jsTokens)([null])));
49
+ const jsTokens = jsTokenize(input)('');
50
+ return flat(stateScan(scanToken)({ kind: 'def' })(concat(jsTokens)([null])));
52
51
  };
@@ -1,12 +1,10 @@
1
- import * as tokenizer from "./module.f.js";
2
- import * as list from "../../types/list/module.f.js";
3
- const { toArray } = list;
4
- import * as serializer from "../../djs/serializer/module.f.js";
5
- import * as o from "../../types/object/module.f.js";
6
- const { sort } = o;
7
- import * as encoding from "../../text/utf16/module.f.js";
8
- const tokenizeString = s => toArray(tokenizer.tokenize(encoding.stringToList(s)));
9
- const stringify = serializer.stringifyAsTree(sort);
1
+ import { tokenize } from "./module.f.js";
2
+ import { toArray } from "../../types/list/module.f.js";
3
+ import { stringifyAsTree } from "../../djs/serializer/module.f.js";
4
+ import { sort } from "../../types/object/module.f.js";
5
+ import { stringToList } from "../../text/utf16/module.f.js";
6
+ const tokenizeString = s => toArray(tokenize(stringToList(s)));
7
+ const stringify = stringifyAsTree(sort);
10
8
  export default {
11
9
  json: [
12
10
  () => {
@@ -0,0 +1,25 @@
1
+ declare const _default: {
2
+ stringCoercion: {
3
+ number: () => void;
4
+ bool: () => void;
5
+ null: () => void;
6
+ undefined: () => void;
7
+ bigint: () => void;
8
+ array: () => void;
9
+ func: () => void;
10
+ object: {
11
+ norm: () => void;
12
+ toString: () => void;
13
+ toStringThrow: {
14
+ throw: () => void;
15
+ };
16
+ toStringNotFunc: {
17
+ throw: () => void;
18
+ };
19
+ toStringNonPrimitive: {
20
+ throw: () => void;
21
+ };
22
+ };
23
+ };
24
+ };
25
+ export default _default;
@@ -0,0 +1,105 @@
1
+ const stringCoercion = (a) => a + '';
2
+ export default {
3
+ stringCoercion: {
4
+ number: () => {
5
+ if (stringCoercion(123) !== '123') {
6
+ throw [123, 'toString', '123'];
7
+ }
8
+ if (stringCoercion(-456) !== '-456') {
9
+ throw [-456, 'toString', '-456'];
10
+ }
11
+ if (stringCoercion(0) !== '0') {
12
+ throw [0, 'toString', '0'];
13
+ }
14
+ if (stringCoercion(-0) !== '0') {
15
+ throw [0, 'toString', '0'];
16
+ }
17
+ if (stringCoercion(1 / (-0)) !== '-Infinity') {
18
+ throw [0, 'toString', '-Infinity'];
19
+ }
20
+ if (stringCoercion(Infinity) !== 'Infinity') {
21
+ throw [Infinity, 'toString', 'Infinity'];
22
+ }
23
+ if (stringCoercion(-Infinity) !== '-Infinity') {
24
+ throw [-Infinity, 'toString', '-Infinity'];
25
+ }
26
+ if (stringCoercion(1 / -Infinity) !== '0') {
27
+ throw [-Infinity, 'toString', '0'];
28
+ }
29
+ if (stringCoercion(NaN) !== 'NaN') {
30
+ throw [NaN, 'toString', 'NaN'];
31
+ }
32
+ },
33
+ bool: () => {
34
+ if (stringCoercion(true) !== 'true') {
35
+ throw [true, 'toString', 'true'];
36
+ }
37
+ if (stringCoercion(false) !== 'false') {
38
+ throw [false, 'toString', 'false'];
39
+ }
40
+ },
41
+ null: () => {
42
+ if (stringCoercion(null) !== 'null') {
43
+ throw [null, 'toString', 'null'];
44
+ }
45
+ },
46
+ undefined: () => {
47
+ if (stringCoercion(undefined) !== 'undefined') {
48
+ throw [undefined, 'toString', 'undefined'];
49
+ }
50
+ },
51
+ bigint: () => {
52
+ if (stringCoercion(123n) !== '123') {
53
+ throw [123n, 'toString', '123'];
54
+ }
55
+ if (stringCoercion(-456n) !== '-456') {
56
+ throw [-456n, 'toString', '-456'];
57
+ }
58
+ },
59
+ array: () => {
60
+ const arr = [1, 2, 3];
61
+ if (stringCoercion(arr) !== '1,2,3') {
62
+ throw [arr, 'toString', '1,2,3'];
63
+ }
64
+ },
65
+ func: () => {
66
+ const func = () => 5;
67
+ if (typeof stringCoercion(func) !== 'string') {
68
+ throw [func, 'toString'];
69
+ }
70
+ // if (stringCoercion(func) !== '() => 5') { throw [func, 'toString', 'function result'] }
71
+ },
72
+ object: {
73
+ norm: () => {
74
+ const obj = { a: 1, b: 2 };
75
+ if (stringCoercion(obj) !== '[object Object]') {
76
+ throw [obj, 'toString', '[object Object]'];
77
+ }
78
+ },
79
+ toString: () => {
80
+ const x = { toString: () => 'custom string' };
81
+ if (stringCoercion(x) !== 'custom string') {
82
+ throw [x, 'toString', 'custom string'];
83
+ }
84
+ },
85
+ toStringThrow: {
86
+ throw: () => {
87
+ const x = { toString: () => { throw new Error('Custom error'); } };
88
+ stringCoercion(x);
89
+ }
90
+ },
91
+ toStringNotFunc: {
92
+ throw: () => {
93
+ const x = { toString: 'hello' };
94
+ stringCoercion(x);
95
+ }
96
+ },
97
+ toStringNonPrimitive: {
98
+ throw: () => {
99
+ const x = { toString: () => [] };
100
+ stringCoercion(x);
101
+ }
102
+ }
103
+ }
104
+ }
105
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "**/*.js",
@@ -11,12 +11,12 @@
11
11
  "prepack": "tsc --NoEmit false",
12
12
  "git-clean": "git clean -xf",
13
13
  "test20": "npm run prepack && node --test",
14
- "test22": "tsc && node --test --experimental-strip-types",
15
- "test": "tsc && node --test",
14
+ "test": "tsc && node --test --experimental-strip-types --experimental-test-coverage --test-coverage-include=**/module.f.ts",
16
15
  "index": "node ./dev/index/module.ts",
17
16
  "fsc": "node ./fsc/module.ts",
18
17
  "fst": "node ./dev/tf/module.ts",
19
- "update": "npm run index && npm install"
18
+ "ci-update": "node ./ci/module.ts",
19
+ "update": "npm install && npm run index && npm run ci-update"
20
20
  },
21
21
  "engines": {
22
22
  "node": ">=20"
@@ -30,7 +30,7 @@
30
30
  "url": "git+https://github.com/functionalscript/functionalscript.git"
31
31
  },
32
32
  "author": "Sergey Shandar",
33
- "license": "AGPL-3.0-only",
33
+ "license": "MIT",
34
34
  "keywords": [
35
35
  "lambda",
36
36
  "functional-programming",
@@ -45,8 +45,8 @@
45
45
  },
46
46
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
47
47
  "devDependencies": {
48
- "@types/node": "^24.2.0",
49
- "@typescript/native-preview": "^7.0.0-dev.20250805.1",
50
- "typescript": "^5.9.2"
48
+ "@playwright/test": "*",
49
+ "@types/node": "*",
50
+ "typescript": "*"
51
51
  }
52
52
  }
@@ -1,7 +1,7 @@
1
1
  import { range } from "./module.f.js";
2
- import * as json from "../../json/module.f.js";
2
+ import { stringify as jsonStringify } from "../../json/module.f.js";
3
3
  import { sort } from "../../types/object/module.f.js";
4
- const stringify = json.stringify(sort);
4
+ const stringify = jsonStringify(sort);
5
5
  export default {
6
6
  range: () => {
7
7
  const r = stringify(range("A"));
@@ -5,18 +5,19 @@ type ItemArray = readonly Item[];
5
5
  type ItemThunk = () => List<Item>;
6
6
  export type Item = string | ItemArray | ItemThunk;
7
7
  export declare const flat: (indent: string) => (text: Block) => List<string>;
8
+ export type Utf8 = Vec;
8
9
  /**
9
10
  * Converts a string to an UTF-8, represented as an MSB first bit vector.
10
11
  *
11
12
  * @param s The input string to be converted.
12
13
  * @returns The resulting UTF-8 bit vector, MSB first.
13
14
  */
14
- export declare const msbUtf8: (s: string) => Vec;
15
+ export declare const utf8: (s: string) => Utf8;
15
16
  /**
16
17
  * Converts a UTF-8 bit vector with MSB first encoding to a string.
17
18
  *
18
19
  * @param msbV - The UTF-8 bit vector with MSB first encoding.
19
20
  * @returns The resulting string.
20
21
  */
21
- export declare const msbUtf8ToString: (msbV: Vec) => string;
22
+ export declare const utf8ToString: (msbV: Utf8) => string;
22
23
  export {};
package/text/module.f.js CHANGED
@@ -16,11 +16,11 @@ const u8ListToVecMsb = u8ListToVec(msb);
16
16
  * @param s The input string to be converted.
17
17
  * @returns The resulting UTF-8 bit vector, MSB first.
18
18
  */
19
- export const msbUtf8 = (s) => u8ListToVecMsb(fromCodePointList(stringToCodePointList(s)));
19
+ export const utf8 = (s) => u8ListToVecMsb(fromCodePointList(stringToCodePointList(s)));
20
20
  /**
21
21
  * Converts a UTF-8 bit vector with MSB first encoding to a string.
22
22
  *
23
23
  * @param msbV - The UTF-8 bit vector with MSB first encoding.
24
24
  * @returns The resulting string.
25
25
  */
26
- export const msbUtf8ToString = (msbV) => codePointListToString(toCodePointList(u8List(msb)(msbV)));
26
+ export const utf8ToString = (msbV) => codePointListToString(toCodePointList(u8List(msb)(msbV)));
package/text/test.f.js CHANGED
@@ -1,4 +1,4 @@
1
- import { flat, msbUtf8, msbUtf8ToString } from "./module.f.js";
1
+ import { flat, utf8, utf8ToString } from "./module.f.js";
2
2
  import { join } from "../types/string/module.f.js";
3
3
  export default {
4
4
  block: () => {
@@ -17,8 +17,8 @@ export default {
17
17
  }
18
18
  },
19
19
  encoding: () => {
20
- const v = msbUtf8('Hello world!');
21
- const r = msbUtf8ToString(v);
20
+ const v = utf8('Hello world!');
21
+ const r = utf8ToString(v);
22
22
  if (r !== 'Hello world!') {
23
23
  throw r;
24
24
  }
@@ -1,8 +1,8 @@
1
1
  import { toCodePointList, fromCodePointList, stringToList, listToString, stringToCodePointList, codePointListToString } from "./module.f.js";
2
- import * as json from "../../json/module.f.js";
2
+ import { stringify as jsonStringify } from "../../json/module.f.js";
3
3
  import { sort } from "../../types/object/module.f.js";
4
4
  import { toArray } from "../../types/list/module.f.js";
5
- const stringify = (a) => json.stringify(sort)(a);
5
+ const stringify = (a) => jsonStringify(sort)(a);
6
6
  export default {
7
7
  toCodePointList: [
8
8
  () => {
@@ -1,8 +1,8 @@
1
1
  import { toCodePointList, fromCodePointList } from "./module.f.js";
2
- import * as json from "../../json/module.f.js";
2
+ import { stringify as jsonStringify } from "../../json/module.f.js";
3
3
  import { sort } from "../../types/object/module.f.js";
4
4
  import { toArray } from "../../types/list/module.f.js";
5
- const stringify = json.stringify(sort);
5
+ const stringify = jsonStringify(sort);
6
6
  export default {
7
7
  toCodePoint: [
8
8
  () => {
@@ -1,7 +1,7 @@
1
1
  import { at, first, last, head, tail, splitFirst, splitLast, empty } from "./module.f.js";
2
- import * as json from "../../json/module.f.js";
2
+ import { stringify as jsonStringify } from "../../json/module.f.js";
3
3
  import { sort } from "../object/module.f.js";
4
- const stringify = json.stringify(sort);
4
+ const stringify = jsonStringify(sort);
5
5
  export default {
6
6
  stringify: () => {
7
7
  const result = stringify([1, 20, 300]);
@@ -18,16 +18,16 @@
18
18
  * ```
19
19
  */
20
20
  import { type Sign } from '../function/compare/module.f.ts';
21
- import type * as Operator from '../function/operator/module.f.ts';
21
+ import type { Unary as OpUnary, Reduce as OpReduce } from '../function/operator/module.f.ts';
22
22
  import { type List } from '../list/module.f.ts';
23
23
  /**
24
24
  * Type representing a unary operation on `bigint`.
25
25
  */
26
- export type Unary = Operator.Unary<bigint, bigint>;
26
+ export type Unary = OpUnary<bigint, bigint>;
27
27
  /**
28
28
  * Type representing a reduction operation on `bigint` values.
29
29
  */
30
- export type Reduce = Operator.Reduce<bigint>;
30
+ export type Reduce = OpReduce<bigint>;
31
31
  /**
32
32
  * Adds two `bigint` values.
33
33
  *
@@ -165,3 +165,6 @@ export declare const factorial: (b: bigint) => bigint;
165
165
  * @returns The number of combinations.
166
166
  */
167
167
  export declare const combination: (...k: readonly bigint[]) => bigint;
168
+ export declare const xor: Reduce;
169
+ export declare const divUp: Reduce;
170
+ export declare const roundUp: Reduce;
@@ -17,7 +17,7 @@
17
17
  * const c = combination([3n, 2n, 1n]) // 60n
18
18
  * ```
19
19
  */
20
- import { unsafeCmp } from "../function/compare/module.f.js";
20
+ import { cmp } from "../function/compare/module.f.js";
21
21
  import { reduce } from "../list/module.f.js";
22
22
  /**
23
23
  * Adds two `bigint` values.
@@ -59,7 +59,7 @@ export const abs = a => a >= 0 ? a : -a;
59
59
  * @param a - The bigint value.
60
60
  * @returns `1` if positive, `-1` if negative, and `0` if zero.
61
61
  */
62
- export const sign = (a) => unsafeCmp(a)(0n);
62
+ export const sign = (a) => cmp(a)(0n);
63
63
  /**
64
64
  * Serializes a `bigint` to a string representation.
65
65
  *
@@ -160,15 +160,7 @@ export const log2 = (v) => {
160
160
  * The function uses the `log2` function to calculate the position of the most significant bit (MSB)
161
161
  * and adds `1n` to account for the MSB itself. For negative numbers, the absolute value is used.
162
162
  */
163
- export const bitLength = (v) => {
164
- if (v <= 0n) {
165
- if (v === 0n) {
166
- return 0n;
167
- }
168
- v = -v;
169
- }
170
- return log2(v) + 1n;
171
- };
163
+ export const bitLength = (v) => log2(abs(v)) + 1n;
172
164
  /**
173
165
  * Generates a bitmask with the specified number of bits set to 1.
174
166
  *
@@ -238,3 +230,12 @@ export const combination = (...k) => {
238
230
  }
239
231
  return partialFactorial(m)(s) / p;
240
232
  };
233
+ export const xor = a => b => a ^ b;
234
+ export const divUp = b => {
235
+ const m = b - 1n;
236
+ return v => (v + m) / b;
237
+ };
238
+ export const roundUp = b => {
239
+ const d = divUp(b);
240
+ return v => d(v) * b;
241
+ };
@@ -27,5 +27,7 @@ declare const _default: {
27
27
  combination: () => void;
28
28
  combination50x50: () => void;
29
29
  combination3: () => void;
30
+ divUp: () => void;
31
+ roundUp: () => void;
30
32
  };
31
33
  export default _default;
@@ -1,4 +1,4 @@
1
- import { sum, abs, serialize, log2, bitLength, mask, min, combination, factorial } from "./module.f.js";
1
+ import { sum, abs, serialize, log2, bitLength, mask, min, combination, factorial, divUp, roundUp } from "./module.f.js";
2
2
  const oldLog2 = (v) => {
3
3
  if (v <= 0n) {
4
4
  return -1n;
@@ -451,5 +451,24 @@ export default {
451
451
  if (r !== 69300n) {
452
452
  throw r;
453
453
  }
454
- }
454
+ },
455
+ divUp: () => {
456
+ if (divUp(8n)(8n) !== 1n) {
457
+ throw new Error("fail");
458
+ }
459
+ if (divUp(8n)(15n) !== 2n) {
460
+ throw new Error("fail");
461
+ }
462
+ },
463
+ roundUp: () => {
464
+ if (roundUp(8n)(8n) !== 8n) {
465
+ throw new Error("fail");
466
+ }
467
+ if (roundUp(8n)(15n) !== 16n) {
468
+ throw new Error("fail");
469
+ }
470
+ if (roundUp(8n)(3n) !== 8n) {
471
+ throw new Error("fail");
472
+ }
473
+ },
455
474
  };