functionalscript 0.0.388 → 0.0.389

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/html/module.f.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  const list = require('../types/list/module.f.cjs')
2
2
  const object = require('../types/object/module.f.cjs')
3
3
  const { operator, compose } = require('../types/function/module.f.cjs')
4
+ const encoding = require('../text/encoding/module.f.cjs');
4
5
 
5
6
  /**
6
7
  * @typedef {|
@@ -73,7 +74,7 @@ const escapeCharCode = code => {
73
74
  }
74
75
  }
75
76
 
76
- const escape = compose(list.toCharCodeList)(list.map(escapeCharCode))
77
+ const escape = compose(encoding.stringToUtf16List)(list.map(escapeCharCode))
77
78
 
78
79
  /** @type {(n: Node) => list.List<string>} */
79
80
  const node = n => typeof n === 'string' ? escape(n) : element(n)
@@ -2,9 +2,10 @@ const tokenizer = require('./module.f.cjs')
2
2
  const list = require('../../types/list/module.f.cjs')
3
3
  const json = require('../module.f.cjs')
4
4
  const { sort } = require('../../types/object/module.f.cjs')
5
+ const encoding = require('../../text/encoding/module.f.cjs');
5
6
 
6
7
  /** @type {(s: string) => readonly tokenizer.JsonToken[]} */
7
- const tokenizeString = s => list.toArray(tokenizer.tokenize(list.toCharCodeList(s)))
8
+ const tokenizeString = s => list.toArray(tokenizer.tokenize(encoding.stringToUtf16List(s)))
8
9
 
9
10
  const stringify = json.stringify(sort)
10
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.388",
3
+ "version": "0.0.389",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -3,6 +3,8 @@ const list = require('../../types/list/module.f.cjs')
3
3
  const operator = require('../../types/function/operator/module.f.cjs')
4
4
  const array = require('../../types/array/module.f.cjs')
5
5
  const { contains } = require('../../types/range/module.f.cjs')
6
+ const { compose } = require('../../types/function/module.f.cjs')
7
+ const { map, flat, stateScan, concat, fold, toArray, flatMap } = list
6
8
  const { ok, error } = result
7
9
 
8
10
  /** @typedef {result.Result<number,number>} ByteResult */
@@ -54,10 +56,10 @@ const codePointToUtf16 = input =>
54
56
  }
55
57
 
56
58
  /** @type {(input: list.List<number>) => list.List<ByteResult>} */
57
- const codePointListToUtf8List = list.flatMap(codePointToUtf8)
59
+ const codePointListToUtf8List = flatMap(codePointToUtf8)
58
60
 
59
61
  /** @type {(input: list.List<i32>) => list.List<u16>} */
60
- const codePointListToUtf16List = list.flatMap(codePointToUtf16)
62
+ const codePointListToUtf16List = flatMap(codePointToUtf16)
61
63
 
62
64
  /** @type {operator.StateScan<number, Utf8State, list.List<CodePointResult>>} */
63
65
  const utf8ByteToCodePointOp = state => byte => {
@@ -85,7 +87,7 @@ const utf8ByteToCodePointOp = state => byte => {
85
87
  return [[ok(((state[0] & 0x07) << 18) + ((state[1] & 0x3f) << 12) + ((state[2] & 0x3f) << 6) + (byte & 0x3f))], undefined]
86
88
  }
87
89
  }
88
- return [[error(list.toArray(list.concat(state)([byte])))], undefined]
90
+ return [[error(toArray(concat(state)([byte])))], undefined]
89
91
  }
90
92
 
91
93
  /** @type {(state: Utf8State) => readonly[list.List<CodePointResult>, Utf8State]} */
@@ -95,7 +97,7 @@ const utf8EofToCodePointOp = state => [state === undefined ? undefined : [error(
95
97
  const utf8ByteOrEofToCodePointOp = state => input => input === undefined ? utf8EofToCodePointOp(state) : utf8ByteToCodePointOp(state)(input)
96
98
 
97
99
  /** @type {(input: list.List<number>) => list.List<CodePointResult>} */
98
- const utf8ListToCodePointList = input => list.flat(list.stateScan(utf8ByteOrEofToCodePointOp)(undefined)(list.concat(/** @type {list.List<ByteOrEof>} */(input))([undefined])))
100
+ const utf8ListToCodePointList = input => flat(stateScan(utf8ByteOrEofToCodePointOp)(undefined)(concat(/** @type {list.List<ByteOrEof>} */(input))([undefined])))
99
101
 
100
102
  /** @type {operator.StateScan<u16, Utf16State, list.List<i32>>} */
101
103
  const utf16ByteToCodePointOp = state => byte => {
@@ -124,7 +126,19 @@ const utf16EofToCodePointOp = state => [state === undefined ? undefined : [state
124
126
  const utf16ByteOrEofToCodePointOp = state => input => input === undefined ? utf16EofToCodePointOp(state) : utf16ByteToCodePointOp(state)(input)
125
127
 
126
128
  /** @type {(input: list.List<u16>) => list.List<i32>} */
127
- const utf16ListToCodePointList = input => list.flat(list.stateScan(utf16ByteOrEofToCodePointOp)(undefined)(list.concat(/** @type {list.List<WordOrEof>} */(input))([undefined])))
129
+ const utf16ListToCodePointList = input => flat(stateScan(utf16ByteOrEofToCodePointOp)(undefined)(concat(/** @type {list.List<WordOrEof>} */(input))([undefined])))
130
+
131
+ /** @type {(s: string) => list.List<u16>} */
132
+ const stringToUtf16List = s => {
133
+ /** @type {(i: number) => list.Result<number>} */
134
+ const at = i => {
135
+ const first = s.charCodeAt(i)
136
+ return isNaN(first) ? undefined : { first, tail: () => at(i + 1) }
137
+ }
138
+ return at(0)
139
+ }
140
+
141
+ const utf16ListToString = compose(map(String.fromCharCode))(fold(operator.concat)(''))
128
142
 
129
143
  module.exports = {
130
144
  /** @readonly */
@@ -134,5 +148,9 @@ module.exports = {
134
148
  /** @readonly */
135
149
  utf8ListToCodePointList,
136
150
  /** @readonly */
137
- utf16ListToCodePointList
151
+ utf16ListToCodePointList,
152
+ /** @readonly */
153
+ stringToUtf16List,
154
+ /** @readonly */
155
+ utf16ListToString
138
156
  }
@@ -206,4 +206,18 @@ const stringify = a => json.stringify(sort)(a)
206
206
  if (result !== '[-2147427328,0]') { throw result }
207
207
  }
208
208
 
209
+ {
210
+ const utf16List = encoding.stringToUtf16List("Hello world!😂🚜🚲")
211
+ const result = encoding.utf16ListToString(utf16List)
212
+ if (result !== "Hello world!😂🚜🚲") { throw result }
213
+ }
214
+
215
+ {
216
+ const a = encoding.stringToUtf16List("Hello world!😂🚜🚲")
217
+ const b = encoding.utf16ListToCodePointList(a)
218
+ const c = encoding.codePointListToUtf16List(b)
219
+ const result = encoding.utf16ListToString(c)
220
+ if (result !== "Hello world!😂🚜🚲") { throw result }
221
+ }
222
+
209
223
  module.exports = {}
@@ -296,18 +296,6 @@ const equalZip = e => a => b => () => {
296
296
  /** @type {<T>(e: operator.Equal<T>) => (a: List<T>) => (b: List<T>) => boolean} */
297
297
  const equal = e => a => b => every(equalZip(e)(a)(b))
298
298
 
299
- /** @type {(s: string) => List<number>} */
300
- const toCharCodeList = s => {
301
- /** @type {(i: number) => Result<number>} */
302
- const at = i => {
303
- const first = s.charCodeAt(i)
304
- return isNaN(first) ? undefined : { first, tail: () => at(i + 1) }
305
- }
306
- return at(0)
307
- }
308
-
309
- const fromCharCodeList = compose(map(String.fromCharCode))(fold(operator.concat)(''))
310
-
311
299
  module.exports = {
312
300
  /** @readonly */
313
301
  empty: undefined,
@@ -384,9 +372,5 @@ module.exports = {
384
372
  /** @readonly */
385
373
  zip,
386
374
  /** @readonly */
387
- equal,
388
- /** @readonly */
389
- toCharCodeList,
390
- /** @readonly */
391
- fromCharCodeList,
375
+ equal
392
376
  }
@@ -236,11 +236,7 @@ const map5 = _.map(x => x > 5)
236
236
  if (result !== false) { throw result }
237
237
  }
238
238
 
239
- {
240
- const r = _.toCharCodeList("Hello world!")
241
- const x = _.fromCharCodeList(r)
242
- if (x !== "Hello world!") { throw x }
243
- }
239
+
244
240
 
245
241
  // stress tests
246
242