functionalscript 0.0.417 → 0.0.420

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.
@@ -14,4 +14,4 @@ jobs:
14
14
  - uses: denoland/setup-deno@v1
15
15
  with:
16
16
  deno-version: v1.x
17
- - run: deno run --unstable --compat --allow-read --allow-env ./test.f.cjs
17
+ - run: deno run --allow-read ./deno-test
@@ -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/deno-test ADDED
@@ -0,0 +1,89 @@
1
+ const {
2
+ /** @type {(path: string | URL) => AsyncIterable<DirEntry>} */
3
+ readDir,
4
+ /** @type {(path: string | URL) => Promise<string>} */
5
+ readTextFile,
6
+ } = Deno
7
+
8
+ /**
9
+ * @typedef {{
10
+ * readonly isDirectory: boolean
11
+ * readonly isFile: boolean
12
+ * readonly isSymlink: boolean
13
+ * readonly name: string
14
+ * }} DirEntry
15
+ */
16
+
17
+ /** @typedef {{ exports?: unknown }} Module */
18
+
19
+ /** @typedef {(name: string) => unknown} Require */
20
+
21
+ /**
22
+ * @typedef {{
23
+ * [k in string]: Function
24
+ * }} FunctionMap
25
+ */
26
+
27
+ /** @type {(path: string) => Promise<FunctionMap>} */
28
+ const dir = async p => {
29
+ /** @type {FunctionMap} */
30
+ const map = {}
31
+ /** @type {(path: string) => Promise<void>} */
32
+ const f = async p => {
33
+ for await (const i of readDir(p)) {
34
+ const { name } = i
35
+ if (!name.startsWith('.')) {
36
+ const file = `${p}/${name}`
37
+ if (i.isDirectory) {
38
+ if (!['node_modules', 'target'].includes(name)) {
39
+ await f(file)
40
+ }
41
+ } else if (name.endsWith('.f.cjs')) {
42
+ // console.log(name)
43
+ const source = await readTextFile(file)
44
+ map[file] = Function('module', 'require', `"use strict";${source}`)
45
+ }
46
+ }
47
+ }
48
+ }
49
+ await f(p)
50
+ return map
51
+ }
52
+
53
+ /**
54
+ * @typedef {{
55
+ * [k in string]: unknown
56
+ * }} ModuleMap
57
+ */
58
+
59
+ const run = async () => {
60
+ const m = await dir('.')
61
+ /** @type {ModuleMap} */
62
+ const d = {}
63
+ /** @type {(base: readonly string[]) => (k: string) => unknown} */
64
+ const req = p => k => {
65
+ const relativePath = k.split('/')
66
+ const bPath = relativePath.filter(v => !['..', '.'].includes(v))
67
+ const dif = relativePath.filter(v => v === '..').length
68
+ const path = [p.slice(0, p.length - dif), bPath.slice(0, bPath.length)].flat()
69
+ const pathStr = path.join('/')
70
+ const newBase = path.slice(0, path.length - 1)
71
+ const result = d[pathStr]
72
+ if (result === undefined) {
73
+ /** @type {Module} */
74
+ const me = {}
75
+ m[pathStr](me, req(newBase))
76
+ const newResult = me.exports
77
+ d[pathStr] = newResult
78
+ return newResult
79
+ } else {
80
+ return result
81
+ }
82
+ }
83
+ const r = req(['.'])
84
+ for (const k of Object.keys(m)) {
85
+ r(k)
86
+ }
87
+ }
88
+
89
+ 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.417",
3
+ "version": "0.0.420",
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
@@ -5,12 +5,15 @@ require('./types/number/test.f.cjs')
5
5
  require('./types/bigint/module.f.cjs')
6
6
  require('./types/array/test.f.cjs')
7
7
  require('./types/btree/test.f.cjs')
8
+ require('./types/byteSet/test.f.cjs')
9
+ require('./types/nibbleSet/test.f.cjs')
8
10
  require('./sha2/test.f.cjs')
11
+ require('./types/map/test.f.cjs')
9
12
  require('./json/test.f.cjs')
10
13
  require('./types/string/test.f.cjs')
11
14
  require('./json/tokenizer/test.f.cjs')
12
15
  require('./types/object/test.f.cjs')
13
- require('./commonjs/test.cjs')
16
+ // require('./commonjs/test.cjs')
14
17
  require('./commonjs/package/dependencies/test.f.cjs')
15
18
  require('./commonjs/package/test.f.cjs')
16
19
  require('./commonjs/path/test.f.cjs')
@@ -87,4 +90,6 @@ const assert_if = c => { if (c) { throw 'assert_if' } }
87
90
  const x = { 'a': 12 }
88
91
  const c = Object.getOwnPropertyDescriptor(x, 'constructor')
89
92
  const a = Object.getOwnPropertyDescriptor(x, 'a')
90
- }
93
+ }
94
+
95
+ module.exports = {}
@@ -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 = {}
@@ -0,0 +1,32 @@
1
+ /** @typedef {bigint} byteSet */
2
+ /** @typedef {number} byte */
3
+
4
+ const empty = 0n
5
+
6
+ /** @type {(n: byte) => (s: byteSet) => boolean} */
7
+ const has = n => s => ((s >> BigInt(n)) & 1n) === 1n
8
+
9
+ /** @type {(n: byte) => (s: byteSet) => byteSet} */
10
+ const set = n => s => s | (1n << BigInt(n))
11
+
12
+ /** @type {(n: byte) => (s: byteSet) => byteSet} */
13
+ const unset = n => s => s & ~(1n << BigInt(n))
14
+
15
+ /** @type {(r: readonly[number, number]) => (s: byteSet) => byteSet} */
16
+ const setRange = r => s => s | ((1n << BigInt(r[1] - r[0] + 1)) - 1n << BigInt(r[0]))
17
+
18
+ // how to define FA???
19
+ // const stateA = [init, set] ????
20
+
21
+ module.exports = {
22
+ /** @readonly */
23
+ empty,
24
+ /** @readonly */
25
+ has,
26
+ /** @readonly */
27
+ set,
28
+ /** @readonly */
29
+ unset,
30
+ /** @readonly */
31
+ setRange
32
+ }
@@ -0,0 +1,44 @@
1
+ const _ = require('./module.f.cjs')
2
+
3
+ {
4
+ if (_.has(0)(_.empty)) { throw _.empty }
5
+ if (_.has(1)(_.empty)) { throw _.empty }
6
+ if (_.has(33)(_.empty)) { throw _.empty }
7
+ }
8
+
9
+ {
10
+ const s = _.set(0)(_.empty)
11
+ if (s !== 1n) { throw s }
12
+ if (!_.has(0)(s)) { throw s }
13
+ if (_.has(1)(s)) { throw s }
14
+ if (_.has(33)(s)) { throw s }
15
+ }
16
+
17
+ {
18
+ const s = _.set(33)(_.empty)
19
+ if (s !== 8589934592n) { throw s }
20
+ if (_.has(0)(s)) { throw s }
21
+ if (_.has(1)(s)) { throw s }
22
+ if (!_.has(33)(s)) { throw s }
23
+ }
24
+
25
+ {
26
+ const a = _.set(0)(_.empty)
27
+ const result = _.unset(0)(a)
28
+ if (result !== 0n) { throw result }
29
+ }
30
+
31
+ {
32
+ const a = _.set(255)(_.empty)
33
+ const result = _.unset(255)(a)
34
+ if (result !== 0n) { throw result }
35
+ }
36
+
37
+ {
38
+ const result = _.setRange([2, 5])(_.empty)
39
+ if (result !== 60n) { throw result }
40
+ }
41
+
42
+ module.exports = {
43
+
44
+ }
@@ -70,3 +70,5 @@ const seq = require('../list/module.f.cjs')
70
70
  */
71
71
  }
72
72
  }
73
+
74
+ module.exports = {}
@@ -0,0 +1,32 @@
1
+ /** @typedef {number} nibbleSet */
2
+ /** @typedef {number} nibble */
3
+
4
+ const empty = 0
5
+
6
+ /** @type {(n: nibble) => (s: nibbleSet) => boolean} */
7
+ const has = n => s => ((s >> n) & 1) === 1
8
+
9
+ /** @type {(n: nibble) => (s: nibbleSet) => nibbleSet} */
10
+ const set = n => s => s | (1 << n)
11
+
12
+ /** @type {(n: nibble) => (s: nibbleSet) => nibbleSet} */
13
+ const unset = n => s => s & ~(1 << n)
14
+
15
+ /** @type {(r: readonly[number, number]) => (s: nibbleSet) => nibbleSet} */
16
+ const setRange = r => s => s | (((1 << (r[1] - r[0] + 1)) - 1 << r[0]))
17
+
18
+ // how to define FA???
19
+ // const stateA = [init, set] ????
20
+
21
+ module.exports = {
22
+ /** @readonly */
23
+ empty,
24
+ /** @readonly */
25
+ has,
26
+ /** @readonly */
27
+ set,
28
+ /** @readonly */
29
+ unset,
30
+ /** @readonly */
31
+ setRange
32
+ }
@@ -0,0 +1,44 @@
1
+ const _ = require('./module.f.cjs')
2
+
3
+ {
4
+ if (_.has(0)(_.empty)) { throw _.empty }
5
+ if (_.has(1)(_.empty)) { throw _.empty }
6
+ if (_.has(15)(_.empty)) { throw _.empty }
7
+ }
8
+
9
+ {
10
+ const s = _.set(0)(_.empty)
11
+ if (s !== 1) { throw s }
12
+ if (!_.has(0)(s)) { throw s }
13
+ if (_.has(1)(s)) { throw s }
14
+ if (_.has(15)(s)) { throw s }
15
+ }
16
+
17
+ {
18
+ const s = _.set(15)(_.empty)
19
+ if (s !== 32768) { throw s }
20
+ if (_.has(0)(s)) { throw s }
21
+ if (_.has(1)(s)) { throw s }
22
+ if (!_.has(15)(s)) { throw s }
23
+ }
24
+
25
+ {
26
+ const a = _.set(0)(_.empty)
27
+ const result = _.unset(0)(a)
28
+ if (result !== 0) { throw result }
29
+ }
30
+
31
+ {
32
+ const a = _.set(15)(_.empty)
33
+ const result = _.unset(15)(a)
34
+ if (result !== 0) { throw result }
35
+ }
36
+
37
+ {
38
+ const result = _.setRange([2, 5])(_.empty)
39
+ if (result !== 60) { throw result }
40
+ }
41
+
42
+ module.exports = {
43
+
44
+ }
@@ -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 = {}