functionalscript 0.0.356 → 0.0.359

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.
@@ -0,0 +1,15 @@
1
+ name: Bun CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ build:
9
+
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - run: curl https://bun.sh/install | bash
15
+ - run: /home/runner/.bun/bin/bun run ./test.f.js
@@ -0,0 +1,17 @@
1
+ name: Deno CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ build:
9
+
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - uses: denoland/setup-deno@v1
15
+ with:
16
+ deno-version: v1.x
17
+ - run: deno run --unstable --compat --allow-read --allow-env ./test.f.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.356",
3
+ "version": "0.0.359",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "main.f.js",
6
6
  "scripts": {
package/test.f.js CHANGED
@@ -17,6 +17,7 @@ require('./commonjs/build/test.f.js')
17
17
  require('./types/range/test.f.js')
18
18
  require('./html/test.f.js')
19
19
  require('./text/test.f.js')
20
+ require('./text/encoding/test.f.js')
20
21
  require('./com/cs/test.f.js')
21
22
 
22
23
  /** @type {() => never} */
@@ -0,0 +1,40 @@
1
+ const result = require('../../types/result/main.f.js')
2
+ const list = require('../../types/list/main.f.js')
3
+ const { ok, error } = result
4
+
5
+ /** @typedef {result.Result<number,number>} Utf8Result */
6
+
7
+ /** @type {(input:number) => list.List<Utf8Result>} */
8
+ const codePointToUtf8 = input =>
9
+ {
10
+ if (input >= 0x0000 && input <= 0x007f) { return [ok(input & 0x7f)] }
11
+ if (input >= 0x0080 && input <= 0x07ff) { return [ok(input >> 6 | 0xc0), ok(input & 0x3f | 0x80)] }
12
+ if (input >= 0x0800 && input <= 0xffff) { return [ok(input >> 12 | 0xe0), ok(input >> 6 & 0x3f | 0x80), ok(input & 0x3f | 0x80)] }
13
+ if (input >= 0x10000 && input <= 0x10ffff) { return [ok(input >> 18 | 0xf0), ok(input >> 12 & 0x3f | 0x80), ok(input >> 6 & 0x3f | 0x80), ok(input & 0x3f | 0x80)] }
14
+ return [error(input)]
15
+ }
16
+
17
+ /** @type {(input:number) => list.List<Utf8Result>} */
18
+ const codePointToUtf16 = input =>
19
+ {
20
+ if (input >= 0x0000 && input <= 0xd7ff || input >= 0xe000 && input <= 0xffff) { return [ok(input >> 8), ok(input & 0xff)] }
21
+ if (input >= 0x010000 && input <= 0x10ffff) {
22
+ const high = ((input - 0x10000) >> 10) + 0xd800
23
+ const low = ((input - 0x10000) & 0x3ff) + 0xdc00
24
+ return [ok(high >> 8), ok(high & 0xff), ok(low >> 8), ok(low & 0xff)]
25
+ }
26
+ return [error(input)]
27
+ }
28
+
29
+ /** @type {(input: list.List<number>) => list.List<Utf8Result>} */
30
+ const codePointListToUtf8 = list.flatMap(codePointToUtf8)
31
+
32
+ /** @type {(input: list.List<number>) => list.List<Utf8Result>} */
33
+ const codePointListToUtf16 = list.flatMap(codePointToUtf16)
34
+
35
+ module.exports = {
36
+ /** @readonly */
37
+ codePointListToUtf8,
38
+ /** @readonly */
39
+ codePointListToUtf16,
40
+ }
@@ -0,0 +1,119 @@
1
+ const encoding = require('./main.f.js')
2
+ const json = require('../../json/main.f')
3
+ const { sort } = require('../../types/object/main.f.js')
4
+ const { list } = require('../../types/main.f.js')
5
+
6
+ /** @type {(a: readonly json.Unknown[]) => string} */
7
+ const stringify = a => json.stringify(sort)(a)
8
+
9
+ {
10
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([0,1,0x7F])))
11
+ if (result !== '[["ok",0],["ok",1],["ok",127]]') { throw result }
12
+ }
13
+
14
+ {
15
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([0x80])))
16
+ if (result !== '[["ok",194],["ok",128]]') { throw result }
17
+ }
18
+
19
+ {
20
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([0xa9])))
21
+ if (result !== '[["ok",194],["ok",169]]') { throw result }
22
+ }
23
+
24
+ {
25
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([0x7ff])))
26
+ if (result !== '[["ok",223],["ok",191]]') { throw result }
27
+ }
28
+
29
+ {
30
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([0x800])))
31
+ if (result !== '[["ok",224],["ok",160],["ok",128]]') { throw result }
32
+ }
33
+
34
+ {
35
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([0x801])))
36
+ if (result !== '[["ok",224],["ok",160],["ok",129]]') { throw result }
37
+ }
38
+
39
+ {
40
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([0xffff])))
41
+ if (result !== '[["ok",239],["ok",191],["ok",191]]') { throw result }
42
+ }
43
+
44
+ {
45
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([0x10000])))
46
+ if (result !== '[["ok",240],["ok",144],["ok",128],["ok",128]]') { throw result }
47
+ }
48
+
49
+ {
50
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([0x10001])))
51
+ if (result !== '[["ok",240],["ok",144],["ok",128],["ok",129]]') { throw result }
52
+ }
53
+
54
+ {
55
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([0x10FFFF])))
56
+ if (result !== '[["ok",244],["ok",143],["ok",191],["ok",191]]') { throw result }
57
+ }
58
+
59
+ {
60
+ const result = stringify(list.toArray(encoding.codePointListToUtf8([-1,0x110000])))
61
+ if (result !== '[["error",-1],["error",1114112]]') { throw result }
62
+ }
63
+
64
+ {
65
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([0])))
66
+ if (result !== '[["ok",0],["ok",0]]') { throw result }
67
+ }
68
+
69
+ {
70
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([0x24])))
71
+ if (result !== '[["ok",0],["ok",36]]') { throw result }
72
+ }
73
+
74
+ {
75
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([0x20AC])))
76
+ if (result !== '[["ok",32],["ok",172]]') { throw result }
77
+ }
78
+
79
+ {
80
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([0xd7ff])))
81
+ if (result !== '[["ok",215],["ok",255]]') { throw result }
82
+ }
83
+
84
+ {
85
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([0xe000])))
86
+ if (result !== '[["ok",224],["ok",0]]') { throw result }
87
+ }
88
+
89
+ {
90
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([0xffff])))
91
+ if (result !== '[["ok",255],["ok",255]]') { throw result }
92
+ }
93
+
94
+ {
95
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([0x10000])))
96
+ if (result !== '[["ok",216],["ok",0],["ok",220],["ok",0]]') { throw result }
97
+ }
98
+
99
+ {
100
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([0x10437])))
101
+ if (result !== '[["ok",216],["ok",1],["ok",220],["ok",55]]') { throw result }
102
+ }
103
+
104
+ {
105
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([0x24B62])))
106
+ if (result !== '[["ok",216],["ok",82],["ok",223],["ok",98]]') { throw result }
107
+ }
108
+
109
+ {
110
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([0x10ffff])))
111
+ if (result !== '[["ok",219],["ok",255],["ok",223],["ok",255]]') { throw result }
112
+ }
113
+
114
+ {
115
+ const result = stringify(list.toArray(encoding.codePointListToUtf16([-1, 0xd800, 0xdfff, 0x110000])))
116
+ if (result !== '[["error",-1],["error",55296],["error",57343],["error",1114112]]') { throw result }
117
+ }
118
+
119
+ module.exports = {}