functionalscript 0.0.419 → 0.0.422

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.
@@ -13,5 +13,5 @@ jobs:
13
13
  - uses: actions/checkout@v2
14
14
  - uses: denoland/setup-deno@v1
15
15
  with:
16
- deno-version: v1.25.1
17
- - run: deno run --unstable --compat --allow-read --allow-env ./test.f.cjs
16
+ deno-version: v1.x
17
+ - run: deno run --allow-read --allow-env ./denotest.mjs
@@ -89,3 +89,5 @@ const getOrBuild = _.getOrBuild
89
89
  throw r
90
90
  }
91
91
  }
92
+
93
+ module.exports = {}
@@ -7,3 +7,5 @@ const _ = require('./module.f.cjs')
7
7
  if (!_.isDependenciesJson({'a':'b'})) { throw 'error' }
8
8
  if (_.isDependenciesJson({ 'a': 12 })) { throw 'error' }
9
9
  }
10
+
11
+ module.exports = {}
@@ -188,4 +188,6 @@ const stringify = g => {
188
188
  }
189
189
  const result = stringify(_.parseAndFind(p => at(p)(packages))({package: '', path: ['a', 'b']})('z/a/c'))
190
190
  if (result !== '{"id":{"package":"node_modules/z/a/c","path":["index.js"]},"source":"return \\"a/c\\""}') { throw result }
191
- }
191
+ }
192
+
193
+ module.exports = {}
package/denotest.mjs ADDED
@@ -0,0 +1,96 @@
1
+ // import * as fs from "https://deno.land/std/node/fs.ts"
2
+
3
+ /**
4
+ * @type {{
5
+ * readonly readDir: (path: string | URL) => AsyncIterable<DirEntry>,
6
+ * readonly readTextFile: (path: string | URL) => Promise<string>,
7
+ * }}
8
+ */
9
+ const {
10
+ readDir,
11
+ readTextFile,
12
+ } = Deno
13
+
14
+ /**
15
+ * @typedef {{
16
+ * readonly isDirectory: boolean
17
+ * readonly isFile: boolean
18
+ * readonly isSymlink: boolean
19
+ * readonly name: string
20
+ * }} DirEntry
21
+ */
22
+
23
+ /** @typedef {{ exports?: unknown }} Module */
24
+
25
+ /** @typedef {(name: string) => unknown} Require */
26
+
27
+ /**
28
+ * @typedef {{
29
+ * [k in string]: Function
30
+ * }} FunctionMap
31
+ */
32
+
33
+ /** @type {(path: string) => Promise<FunctionMap>} */
34
+ const dir = async p => {
35
+ /** @type {FunctionMap} */
36
+ const map = {}
37
+ /** @type {(path: string) => Promise<void>} */
38
+ const f = async p => {
39
+ for await (const i of readDir(p)) {
40
+ const { name } = i
41
+ if (!name.startsWith('.')) {
42
+ const file = `${p}/${name}`
43
+ if (i.isDirectory) {
44
+ if (!['node_modules', 'target'].includes(name)) {
45
+ await f(file)
46
+ }
47
+ } else if (name.endsWith('.f.cjs')) {
48
+ console.log(`loading ${file}`)
49
+ const source = await readTextFile(file)
50
+ map[file] = Function('module', 'require', `"use strict";${source}`)
51
+ }
52
+ }
53
+ }
54
+ }
55
+ await f(p)
56
+ return map
57
+ }
58
+
59
+ /**
60
+ * @typedef {{
61
+ * [k in string]: unknown
62
+ * }} ModuleMap
63
+ */
64
+
65
+ const run = async () => {
66
+ const m = await dir('.')
67
+ /** @type {ModuleMap} */
68
+ const d = {}
69
+ /** @type {(base: readonly string[]) => (i: string) => (k: string) => unknown} */
70
+ const req = p => i => k => {
71
+ const relativePath = k.split('/')
72
+ const dif = relativePath.filter(v => v === '..').length
73
+ const path = [p.slice(0, p.length - dif), relativePath.filter(v => !['..', '.'].includes(v))]
74
+ .flat()
75
+ const pathStr = path.join('/')
76
+ const newBase = path.slice(0, path.length - 1)
77
+ const result = d[pathStr]
78
+ if (result === undefined) {
79
+ /** @type {Module} */
80
+ const me = {}
81
+ console.log(`${i}building ${pathStr}`)
82
+ m[pathStr](me, req(newBase)(`${i}| `))
83
+ const newResult = me.exports
84
+ d[pathStr] = newResult
85
+ return newResult
86
+ } else {
87
+ return result
88
+ }
89
+ }
90
+ const r = req(['.'])('')
91
+ for (const k of Object.keys(m)) {
92
+ r(k)
93
+ }
94
+ }
95
+
96
+ run()
package/html/test.f.cjs CHANGED
@@ -10,4 +10,6 @@ const _ = require('./module.f.cjs')
10
10
  const x = ['div', {}, ['<div>&amp;</div>', ['a', { href: 'hello"' }, []]]]
11
11
  const s = _.htmlToString(x)
12
12
  if (s !== '<!DOCTYPE html><div>&lt;div&gt;&amp;amp;&lt;/div&gt;<a href="hello&quot;"></a></div>') { throw s }
13
- }
13
+ }
14
+
15
+ module.exports = {}
package/json/test.f.cjs CHANGED
@@ -38,3 +38,5 @@ if (json.setProperty("Hello")([])({}) !== "Hello") { throw 'error' }
38
38
  const _2 = json.stringify(identity)(_1)
39
39
  if (_2 !== '{"a":{"y":[24],"x":"Hello"},"c":[],"b":12}') { throw _2 }
40
40
  }
41
+
42
+ module.exports = {}
@@ -302,4 +302,6 @@ const stringify = json.stringify(sort)
302
302
  {
303
303
  const result = stringify(tokenizeString('0e-'))
304
304
  if (result !== '[{"kind":"error","message":"invalid number"}]') { throw result }
305
- }
305
+ }
306
+
307
+ module.exports = {}
@@ -1,9 +1,11 @@
1
- /**
1
+ /**
2
2
  * @typedef {{
3
3
  * readonly execSync: (cmd: string) => Buffer
4
4
  * }} ChildProcess
5
5
  */
6
6
 
7
+ /** @typedef {{}} Buffer */
8
+
7
9
  /**
8
10
  * @template T
9
11
  * @typedef {{
@@ -28,10 +30,10 @@ const version = ({ child_process, fs }) =>
28
30
  'package.json',
29
31
  stringify(
30
32
  {
31
- ...parse(fs.readFileSync('package.json').toString()),
32
- version: `0.0.${child_process.execSync('git log --oneline').toString().split('\n').length - 1}`
33
- },
34
- null,
33
+ ...parse(fs.readFileSync('package.json').toString()),
34
+ version: `0.0.${child_process.execSync('git log --oneline').toString().split('\n').length - 1}`
35
+ },
36
+ null,
35
37
  2))
36
38
 
37
39
  module.exports = {
@@ -72,12 +72,17 @@ const e = '{\n' +
72
72
  ' }\n' +
73
73
  '}'
74
74
 
75
+ /** @type {(s: string) => _.Buffer} */
76
+ const buffer = s => ({
77
+ toString: () => s
78
+ })
79
+
75
80
  {
76
81
  /** @type {_.Node<string>} */
77
82
  const node = {
78
- child_process: { execSync: () => Buffer.from("123\n456\n") },
83
+ child_process: { execSync: () => buffer("123\n456\n") },
79
84
  fs: {
80
- readFileSync: () => Buffer.from(JSON.stringify(x)),
85
+ readFileSync: () => buffer(JSON.stringify(x)),
81
86
  writeFileSync: (_, content) => content
82
87
  }
83
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.419",
3
+ "version": "0.0.422",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
31
31
  "devDependencies": {
32
- "@types/node": "^18.7.8",
33
- "typescript": "^4.7.4"
32
+ "@types/node": "^18.7.16",
33
+ "typescript": "^4.8.3"
34
34
  }
35
35
  }
package/test.f.cjs CHANGED
@@ -8,11 +8,12 @@ require('./types/btree/test.f.cjs')
8
8
  require('./types/byteSet/test.f.cjs')
9
9
  require('./types/nibbleSet/test.f.cjs')
10
10
  require('./sha2/test.f.cjs')
11
+ require('./types/map/test.f.cjs')
11
12
  require('./json/test.f.cjs')
12
13
  require('./types/string/test.f.cjs')
13
14
  require('./json/tokenizer/test.f.cjs')
14
15
  require('./types/object/test.f.cjs')
15
- require('./commonjs/test.cjs')
16
+ // require('./commonjs/test.cjs')
16
17
  require('./commonjs/package/dependencies/test.f.cjs')
17
18
  require('./commonjs/package/test.f.cjs')
18
19
  require('./commonjs/path/test.f.cjs')
@@ -89,4 +90,6 @@ const assert_if = c => { if (c) { throw 'assert_if' } }
89
90
  const x = { 'a': 12 }
90
91
  const c = Object.getOwnPropertyDescriptor(x, 'constructor')
91
92
  const a = Object.getOwnPropertyDescriptor(x, 'a')
92
- }
93
+ }
94
+
95
+ module.exports = {}
@@ -1,9 +1,8 @@
1
1
  const list = require('../../types/list/module.f.cjs')
2
2
  const operator = require('../../types/function/operator/module.f.cjs')
3
- const array = require('../../types/array/module.f.cjs')
4
3
  const { contains } = require('../../types/range/module.f.cjs')
5
- const { compose } = require('../../types/function/module.f.cjs')
6
- const { map, flat, stateScan, concat, reduce, flatMap } = list
4
+ const { fn } = require('../../types/function/module.f.cjs')
5
+ const { map, flat, stateScan, reduce, flatMap } = list
7
6
 
8
7
  /** @typedef {u16|undefined} WordOrEof */
9
8
 
@@ -13,48 +12,57 @@ const { map, flat, stateScan, concat, reduce, flatMap } = list
13
12
 
14
13
  /** @typedef {number} i32 */
15
14
 
16
- /** @type {(a:number) => boolean} */
17
- const isBmpCodePoint = a => a >= 0x0000 && a <= 0xd7ff || a >= 0xe000 && a <= 0xffff
15
+ const lowBmp = contains([0x0000, 0xd7ff])
16
+ const highBmp = contains([0xe000, 0xffff])
18
17
 
18
+ /** @type {(codePoint: i32) => boolean} */
19
+ const isBmpCodePoint = codePoint => lowBmp(codePoint) || highBmp(codePoint)
20
+
21
+ /** @type {(codePoint: i32) => boolean} */
19
22
  const isHighSurrogate = contains([0xd800, 0xdbff])
20
23
 
21
- /** @type {(a:number) => boolean} */
24
+ /** @type {(codePoint: i32) => boolean} */
22
25
  const isLowSurrogate = contains([0xdc00, 0xdfff])
23
26
 
24
27
  const errorMask = 0b1000_0000_0000_0000_0000_0000_0000_0000
25
28
 
26
- /** @type {(input:i32) => list.List<u16>} */
27
- const codePointToUtf16 = input =>
28
- {
29
- if (isBmpCodePoint(input)) { return [input] }
30
- if (input >= 0x010000 && input <= 0x10ffff) {
31
- const high = ((input - 0x10000) >> 10) + 0xd800
32
- const low = ((input - 0x10000) & 0b0011_1111_1111) + 0xdc00
29
+ /** @type {(a: i32) => boolean} */
30
+ const isSupplementaryPlane = contains([0x01_0000, 0x10_ffff])
31
+
32
+ /** @type {(input: i32) => list.List<u16>} */
33
+ const codePointToUtf16 = codePoint => {
34
+ if (isBmpCodePoint(codePoint)) { return [codePoint] }
35
+ if (isSupplementaryPlane(codePoint)) {
36
+ const n = codePoint - 0x1_0000
37
+ const high = (n >> 10) + 0xd800
38
+ const low = (n & 0b0011_1111_1111) + 0xdc00
33
39
  return [high, low]
34
40
  }
35
- return [input & 0xffff]
41
+ return [codePoint & 0xffff]
36
42
  }
37
43
 
38
44
  const fromCodePointList = flatMap(codePointToUtf16)
39
45
 
46
+ const u16 = contains([0x0000, 0xFFFF])
47
+
40
48
  /** @type {operator.StateScan<u16, Utf16State, list.List<i32>>} */
41
- const utf16ByteToCodePointOp = state => byte => {
42
- if (byte < 0x00 || byte > 0xffff) {
49
+ const utf16ByteToCodePointOp = state => word => {
50
+ if (!u16(word)) {
43
51
  return [[0xffffffff], state]
44
52
  }
45
53
  if (state === undefined) {
46
- if (isBmpCodePoint(byte)) { return [[byte], undefined] }
47
- if (isHighSurrogate(byte)) { return [[], byte] }
48
- return [[byte | errorMask], undefined]
54
+ if (isBmpCodePoint(word)) { return [[word], undefined] }
55
+ if (isHighSurrogate(word)) { return [[], word] }
56
+ return [[word | errorMask], undefined]
49
57
  }
50
- if (isLowSurrogate(byte)) {
58
+ if (isLowSurrogate(word)) {
51
59
  const high = state - 0xd800
52
- const low = byte - 0xdc00
60
+ const low = word - 0xdc00
53
61
  return [[(high << 10) + low + 0x10000], undefined]
54
62
  }
55
- if (isBmpCodePoint(byte)) { return [[state | errorMask, byte], undefined] }
56
- if (isHighSurrogate(byte)) { return [[state | errorMask], byte] }
57
- return [[state | errorMask, byte | errorMask], undefined]
63
+ if (isBmpCodePoint(word)) { return [[state | errorMask, word], undefined] }
64
+ if (isHighSurrogate(word)) { return [[state | errorMask], word] }
65
+ return [[state | errorMask, word | errorMask], undefined]
58
66
  }
59
67
 
60
68
  /** @type {(state: Utf16State) => readonly[list.List<i32>, Utf16State]} */
@@ -63,8 +71,11 @@ const utf16EofToCodePointOp = state => [state === undefined ? undefined : [state
63
71
  /** @type {operator.StateScan<WordOrEof, Utf16State, list.List<i32>>} */
64
72
  const utf16ByteOrEofToCodePointOp = state => input => input === undefined ? utf16EofToCodePointOp(state) : utf16ByteToCodePointOp(state)(input)
65
73
 
74
+ /** @type {list.List<WordOrEof>} */
75
+ const eofList = [undefined]
76
+
66
77
  /** @type {(input: list.List<u16>) => list.List<i32>} */
67
- const toCodePointList = input => flat(stateScan(utf16ByteOrEofToCodePointOp)(undefined)(concat(/** @type {list.List<WordOrEof>} */(input))([undefined])))
78
+ const toCodePointList = input => flat(stateScan(utf16ByteOrEofToCodePointOp)(undefined)(flat([input, eofList])))
68
79
 
69
80
  /** @type {(s: string) => list.List<u16>} */
70
81
  const stringToList = s => {
@@ -76,7 +87,10 @@ const stringToList = s => {
76
87
  return at(0)
77
88
  }
78
89
 
79
- const listToString = compose(map(String.fromCharCode))(reduce(operator.concat)(''))
90
+ /** @type {(input: list.List<u16>) => string} */
91
+ const listToString = fn(map(String.fromCharCode))
92
+ .then(reduce(operator.concat)(''))
93
+ .result
80
94
 
81
95
  module.exports = {
82
96
  /** @readonly */
@@ -1,7 +1,7 @@
1
1
  const list = require('../../types/list/module.f.cjs')
2
2
  const operator = require('../../types/function/operator/module.f.cjs')
3
3
  const array = require('../../types/array/module.f.cjs')
4
- const { flatMap } = list
4
+ const { flatMap, flat, stateScan } = list
5
5
 
6
6
  /** @typedef {u8|undefined} ByteOrEof */
7
7
 
@@ -16,8 +16,7 @@ const { flatMap } = list
16
16
  const errorMask = 0b1000_0000_0000_0000_0000_0000_0000_0000
17
17
 
18
18
  /** @type {(input:number) => list.List<u8>} */
19
- const codePointToUtf8 = input =>
20
- {
19
+ const codePointToUtf8 = input => {
21
20
  if (input >= 0x0000 && input <= 0x007f) { return [input & 0b01111_1111] }
22
21
  if (input >= 0x0080 && input <= 0x07ff) { return [input >> 6 | 0b1100_0000, input & 0b0011_1111 | 0b1000_0000] }
23
22
  if (input >= 0x0800 && input <= 0xffff) { return [input >> 12 | 0b1110_0000, input >> 6 & 0b0011_1111 | 0b1000_0000, input & 0b0011_1111 | 0b1000_0000] }
@@ -35,9 +34,9 @@ const fromCodePointList = flatMap(codePointToUtf8)
35
34
 
36
35
  /** @type {(state: Utf8NonEmptyState) => i32}*/
37
36
  const utf8StateToError = state => {
38
- switch(state.length) {
37
+ switch (state.length) {
39
38
  case 1:
40
- return state[0] | errorMask
39
+ return state[0] | errorMask
41
40
  case 2:
42
41
  if (state[0] < 0b1111_0000) return (((state[0] & 0b0000_1111) << 6) + (state[1] & 0b0011_1111) + 0b0000_0100_0000_0000) | errorMask
43
42
  return (((state[0] & 0b0000_0111) << 6) + (state[1] & 0b0011_1111) + 0b0000_0010_0000_0000) | errorMask
@@ -57,7 +56,7 @@ const utf8ByteToCodePointOp = state => byte => {
57
56
  return [[byte | errorMask], undefined]
58
57
  }
59
58
  if (byte >= 0b1000_0000 && byte < 0b1100_0000) {
60
- switch(state.length) {
59
+ switch (state.length) {
61
60
  case 1:
62
61
  if (state[0] < 0b1110_0000) { return [[((state[0] & 0b0001_1111) << 6) + (byte & 0b0011_1111)], undefined] }
63
62
  if (state[0] < 0b1111_1000) { return [[], [state[0], byte]] }
@@ -85,8 +84,11 @@ const utf8EofToCodePointOp = state => {
85
84
  /** @type {operator.StateScan<ByteOrEof, Utf8State, list.List<i32>>} */
86
85
  const utf8ByteOrEofToCodePointOp = state => input => input === undefined ? utf8EofToCodePointOp(state) : utf8ByteToCodePointOp(state)(input)
87
86
 
87
+ /** @type {list.List<ByteOrEof>} */
88
+ const eofList = [undefined]
89
+
88
90
  /** @type {(input: list.List<u8>) => list.List<i32>} */
89
- const toCodePointList = input => list.flat(list.stateScan(utf8ByteOrEofToCodePointOp)(undefined)(list.concat(/** @type {list.List<ByteOrEof>} */(input))([undefined])))
91
+ const toCodePointList = input => flat(stateScan(utf8ByteOrEofToCodePointOp)(undefined)(flat([input, eofList])))
90
92
 
91
93
  module.exports = {
92
94
  /** @readonly */
package/tsconfig.json CHANGED
@@ -97,5 +97,5 @@
97
97
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
98
98
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
99
99
  },
100
- "exclude": ["target"]
100
+ "exclude": ["target", "denotest.mjs"]
101
101
  }
@@ -111,4 +111,6 @@ const find = i => m => str(_.find(cmp(i))(m))
111
111
  const r = find("91")(_map)
112
112
  if (r !== '[4,2,2]') { throw r }
113
113
  }
114
- }
114
+ }
115
+
116
+ module.exports = {}
@@ -484,4 +484,6 @@ const jsonStr = json.stringify(sort)
484
484
  _map = remove(_map)("1")
485
485
  if (_map !== undefined) { throw _map }
486
486
  }
487
- }
487
+ }
488
+
489
+ module.exports = {}
@@ -377,3 +377,5 @@ const jsonStr = json.stringify(sort)
377
377
  '[[["529"],"576",["625"]],"64",[["676"],"729",["784"]],"81",[["841"],"9",["900","961"]]]]]'
378
378
  ) { throw r }
379
379
  }
380
+
381
+ module.exports = {}
@@ -76,4 +76,6 @@ const test = () => {
76
76
  }
77
77
  }
78
78
 
79
- test()
79
+ test()
80
+
81
+ module.exports = {}
@@ -70,3 +70,5 @@ const seq = require('../list/module.f.cjs')
70
70
  */
71
71
  }
72
72
  }
73
+
74
+ module.exports = {}
@@ -10,4 +10,6 @@ const _ = require('./module.f.cjs')
10
10
  const a = { constructor: 42}
11
11
  const value = _.at('constructor')(a)
12
12
  if (value !== 42) { throw value }
13
- }
13
+ }
14
+
15
+ module.exports = {}
@@ -7,3 +7,5 @@ const _ = require('./module.f.cjs')
7
7
  if (_.contains([0, 5])(-1)) { throw -1 }
8
8
  if (_.contains([0, 5])(6)) { throw 6 }
9
9
  }
10
+
11
+ module.exports = {}
@@ -31,3 +31,5 @@ const _ = require('./module.f.cjs')
31
31
  r = _.remove('WORLD!')(r)
32
32
  if (r !== undefined) { throw r }
33
33
  }
34
+
35
+ module.exports = {}