functionalscript 0.0.428 → 0.0.431

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.
@@ -1,7 +1,9 @@
1
- name: Bun CI
1
+ name: bun
2
2
 
3
3
  on:
4
4
  push:
5
+ branches:
6
+ - master
5
7
  pull_request:
6
8
 
7
9
  jobs:
@@ -12,4 +14,4 @@ jobs:
12
14
  steps:
13
15
  - uses: actions/checkout@v2
14
16
  - run: curl https://bun.sh/install | bash
15
- - run: /home/runner/.bun/bin/bun ./test.mjs
17
+ - run: /home/runner/.bun/bin/bun ./dev/test.mjs
@@ -1,7 +1,9 @@
1
- name: Deno CI
1
+ name: deno
2
2
 
3
3
  on:
4
4
  push:
5
+ branches:
6
+ - master
5
7
  pull_request:
6
8
 
7
9
  jobs:
@@ -14,4 +16,4 @@ jobs:
14
16
  - uses: denoland/setup-deno@v1
15
17
  with:
16
18
  deno-version: v1.x
17
- - run: deno run --allow-read --allow-env --allow-net ./test.mjs
19
+ - run: deno run --allow-read --allow-env --allow-net ./dev/test.mjs
@@ -0,0 +1,26 @@
1
+ # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
+
4
+ name: node ci & pack
5
+
6
+ on:
7
+ push:
8
+ branches:
9
+ - master
10
+ pull_request:
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Use Node.js
20
+ uses: actions/setup-node@v2
21
+ with:
22
+ node-version: 18
23
+ - run: npm ci
24
+ - run: npm test
25
+ - run: npm run version
26
+ - run: npm pack
@@ -1,10 +1,12 @@
1
1
  # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
2
  # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
3
 
4
- name: Node.js CI
4
+ name: node install
5
5
 
6
6
  on:
7
7
  push:
8
+ branches:
9
+ - master
8
10
  pull_request:
9
11
 
10
12
  jobs:
@@ -1,7 +1,7 @@
1
1
  # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
2
  # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
3
 
4
- name: Node.js Package
4
+ name: node publish
5
5
 
6
6
  on:
7
7
  push:
@@ -14,7 +14,7 @@ jobs:
14
14
  - uses: actions/checkout@v2
15
15
  - uses: actions/setup-node@v2
16
16
  with:
17
- node-version: 16
17
+ node-version: 18
18
18
  - run: npm ci
19
19
  - run: npm test
20
20
 
@@ -27,7 +27,7 @@ jobs:
27
27
  fetch-depth: 0
28
28
  - uses: actions/setup-node@v2
29
29
  with:
30
- node-version: 16
30
+ node-version: 18
31
31
  registry-url: https://registry.npmjs.org/
32
32
  - run: npm ci
33
33
  - run: npm run version
@@ -8,7 +8,7 @@ const object = require('../../types/object/module.f.cjs')
8
8
  const { fromMap } = object
9
9
  const path = require('../path/module.f.cjs')
10
10
  const { parseAndFind } = path
11
- const stringSet = require('../../types/stringset/module.f.cjs')
11
+ const stringSet = require('../../types/string_set/module.f.cjs')
12
12
  const { set: setSet, contains: setContains } = stringSet
13
13
 
14
14
  /**
@@ -1,19 +1,75 @@
1
- const { todo } = require('../module.f.cjs')
2
- const list = require('../../types/list/module.f.cjs')
3
- const function_ = require('../../commonjs/module/function/module.f.cjs')
4
- const package_ = require('../../commonjs/package/module.f.cjs')
1
+ /**
2
+ * @typedef {{
3
+ * readonly[k in string]?: Module
4
+ * }} DependencyMap
5
+ */
6
+
7
+ /**
8
+ * @typedef {{
9
+ * readonly dependencyMap: DependencyMap
10
+ * readonly exports?: unknown
11
+ * }} Module
12
+ */
13
+
14
+ /**
15
+ * @typedef {{
16
+ * readonly[k in string]: Module
17
+ * }} ModuleMap
18
+ */
19
+
20
+ /**
21
+ * @template T
22
+ * @typedef {(v: string) => (state: T) => T} Log
23
+ */
5
24
 
6
25
  /**
7
- * @type {(c: function_.Compile) =>
8
- * (files: string) =>
9
- * (packageGet: package_.Get) =>
10
- * never}
26
+ * @template T
27
+ * @typedef {{
28
+ * readonly moduleMap: ModuleMap,
29
+ * readonly log: Log<T>,
30
+ * readonly state: T,
31
+ * }} Input
11
32
  */
12
- const test = compile => files => packageGet => {
13
- return todo()
33
+
34
+ /** @type {<T>(input: Input<T>) => T} */
35
+ const main = ({moduleMap, log, state}) => {
36
+ /** @typedef {log extends Log<infer T> ? T : never} T */
37
+ /** @type {(i: string) => (v: unknown) => (state: T) => T} */
38
+ const test = i => v => state => {
39
+ const next = test(`${i}| `)
40
+ switch (typeof v) {
41
+ case 'function': {
42
+ if (v.length === 0) {
43
+ const r = v()
44
+ state = log(`${i}() passed`)(state)
45
+ state = next(r)(state)
46
+ }
47
+ break
48
+ }
49
+ case 'object': {
50
+ if (v instanceof Array) {
51
+ for (const v2 of v) {
52
+ state = next(v2)(state)
53
+ }
54
+ } else if (v !== null) {
55
+ for (const [k, v2] of Object.entries(v)) {
56
+ state = log(`${i}${k}:`)(state)
57
+ state = next(v2)(state)
58
+ }
59
+ }
60
+ break
61
+ }
62
+ }
63
+ return state
64
+ }
65
+ const next = test('| ')
66
+ for (const [k, v] of Object.entries(moduleMap)) {
67
+ if (k.endsWith('test.f.cjs')) {
68
+ state = log(`testing ${k}`)(state)
69
+ state = next(v.exports)(state)
70
+ }
71
+ }
72
+ return state
14
73
  }
15
74
 
16
- module.exports = {
17
- /** @readonly */
18
- test,
19
- }
75
+ module.exports = main
package/dev/test.mjs ADDED
@@ -0,0 +1,175 @@
1
+ /**
2
+ * @typedef {{
3
+ * readonly withFileTypes: true
4
+ * }} Options
5
+ */
6
+
7
+ /**
8
+ * @typedef {{
9
+ * readonly name: string
10
+ * readonly isDirectory: () => boolean
11
+ * }} Dirent
12
+ */
13
+
14
+ /**
15
+ * @typedef {{
16
+ * readonly readdir: (path: string, options: Options) => Promise<readonly Dirent[]>
17
+ * readonly readFile: (path: string, options: 'utf8') => Promise<string>
18
+ * }} FsPromises
19
+ */
20
+
21
+ /**
22
+ * @typedef {{
23
+ * [k in string]?: MutableModule
24
+ * }} MutableDependencyMap
25
+ */
26
+
27
+ /**
28
+ * @typedef {{
29
+ * dependencyMap: MutableDependencyMap
30
+ * exports?: unknown
31
+ * }} MutableModule
32
+ */
33
+
34
+ /**
35
+ * @typedef {{
36
+ * readonly dependencyMap: DependencyMap
37
+ * readonly exports?: unknown
38
+ * }} Module
39
+ */
40
+
41
+ /**
42
+ * @typedef {{
43
+ * readonly[k in string]?: Module
44
+ * }} DependencyMap
45
+ */
46
+
47
+ /** @typedef {(name: string) => unknown} Require */
48
+
49
+ /**
50
+ * @typedef {{
51
+ * readonly[k in string]: Function
52
+ * }} FunctionMap
53
+ */
54
+
55
+ /**
56
+ * @template T
57
+ * @typedef {readonly[string, T]} Entry
58
+ */
59
+
60
+ /** @type {(a: Entry<Function>, b: Entry<Function>) => number} */
61
+ const cmp = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
62
+
63
+ /**
64
+ * @typedef {{
65
+ * [k in string]: MutableModule
66
+ * }} MutableModuleMap
67
+ */
68
+
69
+ /**
70
+ * @typedef {{
71
+ * readonly[k in string]: Module
72
+ * }} ModuleMap
73
+ */
74
+
75
+ /** @type {(v: readonly string[]) => (dif: number) => readonly string[]} */
76
+ const remove_tail = v => dif => v.slice(0, v.length - dif)
77
+
78
+ /** @type {any} */
79
+ const self = globalThis
80
+
81
+ const boot = async() => {
82
+ /** @type {FsPromises} */
83
+ const { readdir, readFile } = await import(self.Deno ? 'https://deno.land/std/node/fs/promises.ts' : 'node:fs/promises')
84
+
85
+ /** @type {() => Promise<FunctionMap>} */
86
+ const load = async () => {
87
+ /** @type {(readonly[string, Function])[]} */
88
+ const map = []
89
+ /** @type {(path: string) => Promise<void>} */
90
+ const f = async p => {
91
+ for (const i of await readdir(p, { withFileTypes: true })) {
92
+ const { name } = i
93
+ if (!name.startsWith('.')) {
94
+ const file = `${p}/${name}`
95
+ if (i.isDirectory()) {
96
+ await f(file)
97
+ } else if (name.endsWith('.f.cjs')) {
98
+ const source = await readFile(file, 'utf8')
99
+ map.push([file, Function('module', 'require', `"use strict";${source}`)])
100
+ }
101
+ }
102
+ }
103
+ }
104
+ await f('.')
105
+ map.sort(cmp)
106
+ return Object.fromEntries(map)
107
+ }
108
+
109
+ const map = await load()
110
+
111
+ /** @type {() => ModuleMap} */
112
+ const build = () => {
113
+ /** @type {MutableModuleMap} */
114
+ const d = {}
115
+ /** @type {(base: readonly string[]) => (k: string) => readonly[string, MutableModule]} */
116
+ const getModule = base => k => {
117
+ const relativePath = k.split('/')
118
+ const dif = relativePath.filter(v => v === '..').length
119
+ const path = [remove_tail(base)(dif), relativePath.filter(v => !['..', '.'].includes(v))]
120
+ .flat()
121
+ const pathStr = path.join('/')
122
+ {
123
+ const module = d[pathStr]
124
+ if (module !== undefined) {
125
+ return [pathStr, module]
126
+ }
127
+ }
128
+ {
129
+ /** @type {MutableDependencyMap} */
130
+ const dependencyMap = {}
131
+ /** @type {MutableModule} */
132
+ const module = { dependencyMap }
133
+ const get = getModule(remove_tail(path)(1))
134
+ /** @type {(s: string) => unknown} */
135
+ const newReq = s => {
136
+ const [p, result] = get(s)
137
+ dependencyMap[p] = result
138
+ return result.exports
139
+ }
140
+ map[pathStr](module, newReq)
141
+ d[pathStr] = module
142
+ return [pathStr, module]
143
+ }
144
+ }
145
+ {
146
+ const get = getModule(['.'])
147
+ for (const k of Object.keys(map)) {
148
+ get(k)
149
+ }
150
+ }
151
+ return d
152
+ }
153
+
154
+ return build()
155
+ }
156
+
157
+ // test runner.
158
+ const main = async() => {
159
+ const moduleMap = await boot()
160
+
161
+ /** @type {(s: string) => (_: undefined) => undefined} */
162
+ const log = s => state => {
163
+ console.log(s)
164
+ return state
165
+ }
166
+
167
+ /** @type {any} */
168
+ const f = moduleMap['./dev/test/module.f.cjs'].exports
169
+ f({
170
+ moduleMap,
171
+ log,
172
+ })
173
+ }
174
+
175
+ main()
package/fsm/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # FSM
2
+
3
+ This module is about a [finite-state machine](https://en.wikipedia.org/wiki/Finite-state_machine). It's not about
4
+ [Flying Spaghetti Monster](https://en.wikipedia.org/wiki/Flying_Spaghetti_Monster).
@@ -0,0 +1,28 @@
1
+ const { todo } = require('../dev/module.f.cjs')
2
+ const list = require('../types/list/module.f.cjs')
3
+ const byteSet = require('../types/byte_set/module.f.cjs')
4
+
5
+ /** @typedef {readonly[string, byteSet.ByteSet, string]} Rule */
6
+
7
+ /** @typedef {list.List<Rule>} Grammar */
8
+
9
+ /** @typedef {readonly string[]} ByteMap */
10
+
11
+ /**
12
+ * @typedef {{
13
+ * readonly[state in string]: ByteMap
14
+ * }} Dfa
15
+ */
16
+
17
+ /** @type {(faId: string) => string} */
18
+ const escape = faId => todo()
19
+
20
+ /** @type {(grammar: Grammar) => Dfa} */
21
+ const dfa = grammar => todo()
22
+
23
+ module.exports = {
24
+ /** @readonly */
25
+ escape,
26
+ /** @readonly */
27
+ dfa,
28
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.428",
3
+ "version": "0.0.431",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
7
7
  "tsc": "tsc",
8
8
  "test": "tsc && npm run test-only",
9
9
  "version": "node ./nodejs/version/main.cjs",
10
- "test-only": "node --trace-uncaught ./test.mjs"
10
+ "test-only": "node --trace-uncaught ./dev/test.mjs"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
31
31
  "devDependencies": {
32
- "@types/node": "^18.7.16",
32
+ "@types/node": "^18.7.18",
33
33
  "typescript": "^4.8.3"
34
34
  }
35
35
  }
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", "test.mjs"]
100
+ "exclude": ["target"]
101
101
  }
@@ -0,0 +1,57 @@
1
+ const { fn } = require('../function/module.f.cjs')
2
+
3
+ /** @typedef {bigint} ByteSet */
4
+ /** @typedef {number} Byte */
5
+
6
+ /** @type {(n: Byte) => (s: ByteSet) => boolean} */
7
+ const has = n => s => ((s >> BigInt(n)) & 1n) === 1n
8
+
9
+ // create a set
10
+
11
+ const empty = 0n
12
+
13
+ /** @type {(n: Byte) => ByteSet} */
14
+ const one = n => 1n << BigInt(n)
15
+
16
+ /** @type {(r: readonly[Byte, Byte]) => ByteSet} */
17
+ const range = ([b, e]) => one(e - b + 1) - 1n << BigInt(b)
18
+
19
+ // set operations
20
+
21
+ /** @type {(a: ByteSet) => (b: ByteSet) => ByteSet} */
22
+ const union = a => b => a | b
23
+
24
+ /** @type {(a: ByteSet) => (b: ByteSet) => ByteSet} */
25
+ const intersect = a => b => a & b
26
+
27
+ /** @type {(a: ByteSet) => (b: ByteSet) => ByteSet} */
28
+ const difference = a => b => intersect(a)(complement(b))
29
+
30
+ /** @type {(n: ByteSet) => ByteSet} */
31
+ const complement = n => ~n
32
+
33
+ // additional operations
34
+
35
+ const set = fn(one).then(union).result
36
+
37
+ const setRange = fn(range).then(union).result
38
+
39
+ /** @type {(n: Byte) => (s: ByteSet) => ByteSet} */
40
+ const unset = n => s => difference(s)(one(n))
41
+
42
+ module.exports = {
43
+ /** @readonly */
44
+ empty,
45
+ /** @readonly */
46
+ has,
47
+ /** @readonly */
48
+ set,
49
+ /** @readonly */
50
+ unset,
51
+ /** @readonly */
52
+ union,
53
+ /** @readonly */
54
+ setRange,
55
+ /** @readonly */
56
+ range,
57
+ }
File without changes
@@ -10,13 +10,15 @@ module.exports = {
10
10
  /** @readonly */
11
11
  map: require('./map/module.f.cjs'),
12
12
  /** @readonly */
13
+ nibbleSet: require('./nibble_set/module.f.cjs'),
14
+ /** @readonly */
13
15
  object: require('./object/module.f.cjs'),
14
16
  /** @readonly */
15
17
  range: require('./range/module.f.cjs'),
16
18
  /** @readonly */
17
19
  result: require('./result/module.f.cjs'),
18
20
  /** @readonly */
19
- stringset: require('./stringset/module.f.cjs'),
21
+ stringSet: require('./string_set/module.f.cjs'),
20
22
  /** @readonly */
21
23
  bigint: require('./bigint/module.f.cjs'),
22
24
  /** @readonly */
File without changes
File without changes
File without changes
File without changes
package/test.mjs DELETED
@@ -1,174 +0,0 @@
1
- /**
2
- * @typedef {{
3
- * readonly withFileTypes: true
4
- * }} Options
5
- */
6
-
7
- /**
8
- * @typedef {{
9
- * readonly name: string
10
- * readonly isDirectory: () => boolean
11
- * }} Dirent
12
- */
13
-
14
- /**
15
- * @typedef {{
16
- * readonly readdir: (path: string, options: Options) => Promise<readonly Dirent[]>
17
- * readonly readFile: (path: string, options: 'utf8') => Promise<Buffer>
18
- * }} FsPromises
19
- */
20
-
21
- /** @type {FsPromises} */
22
- const { readdir, readFile } = await import(globalThis.Deno ? 'https://deno.land/std/node/fs/promises.ts' : 'node:fs/promises')
23
-
24
- /**
25
- * @typedef {{
26
- * [k: in string]?: Module
27
- * }} Dependencies
28
- */
29
-
30
- /**
31
- * @typedef {{
32
- * dependencies: Dependencies
33
- * exports?: unknown
34
- * }} Module
35
- */
36
-
37
- /** @typedef {(name: string) => unknown} Require */
38
-
39
- /**
40
- * @typedef {{
41
- * readonly[k in string]: Function
42
- * }} FunctionMap
43
- */
44
-
45
- /**
46
- * @template T
47
- * @typedef {readonly[string, T]} Entry
48
- */
49
-
50
- /** @type {(a: Entry<Function>, b: Entry<Function>) => number} */
51
- const cmp = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
52
-
53
- /** @type {() => Promise<FunctionMap>} */
54
- const load = async () => {
55
- /** @type {(readonly[string, Function])[]} */
56
- const map = []
57
- /** @type {(path: string) => Promise<void>} */
58
- const f = async p => {
59
- for (const i of await readdir(p, { withFileTypes: true })) {
60
- const { name } = i
61
- if (!name.startsWith('.')) {
62
- const file = `${p}/${name}`
63
- if (i.isDirectory()) {
64
- if (!['node_modules', 'target'].includes(name)) {
65
- await f(file)
66
- }
67
- } else if (name.endsWith('.f.cjs')) {
68
- // console.log(`loading ${file}`)
69
- const source = await readFile(file, 'utf8')
70
- map.push([file, Function('module', 'require', `"use strict";${source}`)])
71
- }
72
- }
73
- }
74
- }
75
- await f('.')
76
- map.sort(cmp)
77
- return Object.fromEntries(map)
78
- }
79
-
80
- const map = await load()
81
-
82
- /**
83
- * @typedef {{
84
- * [k in string]: Module
85
- * }} ModuleMap
86
- */
87
-
88
- const build = async () => {
89
- /** @type {ModuleMap} */
90
- const d = {}
91
- /** @type {(base: readonly string[]) => (i: string) => (k: string) => readonly[string, Module]} */
92
- const req = base => i => k => {
93
- const relativePath = k.split('/')
94
- const dif = relativePath.filter(v => v === '..').length
95
- const path = [base.slice(0, base.length - dif), relativePath.filter(v => !['..', '.'].includes(v))]
96
- .flat()
97
- const pathStr = path.join('/')
98
- const newBase = path.slice(0, path.length - 1)
99
- {
100
- const module = d[pathStr]
101
- if (module !== undefined) {
102
- return [pathStr, module]
103
- }
104
- }
105
- {
106
- /** @type {Module} */
107
- const module = {
108
- dependencies: {}
109
- }
110
- // console.log(`${i}building ${pathStr}`)
111
- const getModule = req(newBase)(`${i}| `)
112
- const newReq = s => {
113
- const [p, result] = getModule(s)
114
- module.dependencies[p] = result
115
- return result.exports
116
- }
117
- map[pathStr](module, newReq)
118
- d[pathStr] = module
119
- return [pathStr, module]
120
- }
121
- }
122
- const r = req(['.'])('')
123
- for (const k of Object.keys(map)) {
124
- r(k)
125
- }
126
- return d
127
- }
128
-
129
- const modules = await build()
130
-
131
- // graph
132
-
133
- /*
134
- for (const [k, v] of Object.entries(modules)) {
135
- console.log(`: ${k}`)
136
- console.log(Object.keys(v.dependencies))
137
- }
138
- */
139
-
140
- // test runner.
141
-
142
- /** @type {(i: string) => (v: unknown) => void} */
143
- const test = i => v => {
144
- switch (typeof v) {
145
- case 'function': {
146
- if (v.length === 0) {
147
- const r = v()
148
- console.log(`${i}() passed`)
149
- test(`${i}| `)(r)
150
- }
151
- return;
152
- }
153
- case 'object': {
154
- if (v instanceof Array) {
155
- for (const v2 of v) {
156
- test(`${i}| `)(v2)
157
- }
158
- } else {
159
- for (const [k, v2] of Object.entries(v)) {
160
- console.log(`${i}${k}:`)
161
- test(`${i}| `)(v2)
162
- }
163
- }
164
- return;
165
- }
166
- }
167
- }
168
-
169
- for (const [k, v] of Object.entries(modules)) {
170
- if (k.endsWith('test.f.cjs')) {
171
- console.log(`testing ${k}`)
172
- test('| ')(v.exports)
173
- }
174
- }
@@ -1,30 +0,0 @@
1
- /** @typedef {bigint} byteSet */
2
- /** @typedef {number} byte */
3
-
4
- /** @type {(n: byte) => (s: byteSet) => boolean} */
5
- const has = n => s => ((s >> BigInt(n)) & 1n) === 1n
6
-
7
- /** @type {(n: byte) => (s: byteSet) => byteSet} */
8
- const set = n => s => s | (1n << BigInt(n))
9
-
10
- /** @type {(n: byte) => (s: byteSet) => byteSet} */
11
- const unset = n => s => s & ~(1n << BigInt(n))
12
-
13
- /** @type {(r: readonly[number, number]) => (s: byteSet) => byteSet} */
14
- const setRange = ([b, e]) => s => s | ((1n << BigInt(e - b + 1)) - 1n << BigInt(b))
15
-
16
- // how to define FA???
17
- // const stateA = [init, set] ????
18
-
19
- module.exports = {
20
- /** @readonly */
21
- empty: 0n,
22
- /** @readonly */
23
- has,
24
- /** @readonly */
25
- set,
26
- /** @readonly */
27
- unset,
28
- /** @readonly */
29
- setRange
30
- }