functionalscript 0.0.421 → 0.0.424

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.
@@ -12,4 +12,4 @@ jobs:
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
14
  - run: curl https://bun.sh/install | bash
15
- - run: /home/runner/.bun/bin/bun ./test.f.cjs
15
+ - run: /home/runner/.bun/bin/bun ./test.mjs
@@ -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 --allow-read ./denotest.mjs
17
+ - run: deno run --allow-read --allow-env --allow-net ./test.mjs
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.421",
3
+ "version": "0.0.424",
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.f.cjs"
10
+ "test-only": "node --trace-uncaught ./test.mjs"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
package/test.f.cjs CHANGED
@@ -1,95 +1,58 @@
1
1
  const i = require('./module.f.cjs')
2
2
 
3
- require('./types/list/test.f.cjs')
4
- require('./types/number/test.f.cjs')
5
- require('./types/bigint/module.f.cjs')
6
- require('./types/array/test.f.cjs')
7
- require('./types/btree/test.f.cjs')
8
- require('./types/byteSet/test.f.cjs')
9
- require('./types/nibbleSet/test.f.cjs')
10
- require('./sha2/test.f.cjs')
11
- require('./types/map/test.f.cjs')
12
- require('./json/test.f.cjs')
13
- require('./types/string/test.f.cjs')
14
- require('./json/tokenizer/test.f.cjs')
15
- require('./types/object/test.f.cjs')
16
- // require('./commonjs/test.cjs')
17
- require('./commonjs/package/dependencies/test.f.cjs')
18
- require('./commonjs/package/test.f.cjs')
19
- require('./commonjs/path/test.f.cjs')
20
- require('./types/function/test.f.cjs')
21
- require('./types/function/compare/test.f.cjs')
22
- require('./types/stringset/test.f.cjs')
23
- require('./types/option/test.f.cjs')
24
- require('./commonjs/build/test.f.cjs')
25
- require('./types/range/test.f.cjs')
26
- require('./html/test.f.cjs')
27
- require('./text/test.f.cjs')
28
- require('./text/utf8/test.f.cjs')
29
- require('./text/utf16/test.f.cjs')
30
- require('./com/cs/test.f.cjs')
31
- require('./com/cpp/test.f.cjs')
32
- require('./nodejs/version/test.f.cjs')
33
- require('./com/rust/test.f.cjs')
34
-
35
3
  /** @type {() => never} */
36
4
  const assert = () => { throw 'assert' }
37
5
 
38
6
  /** @type {(_: boolean) => void} */
39
7
  const assert_if = c => { if (c) { throw 'assert_if' } }
40
8
 
41
- {
42
- const c = (()=>{})['constructor']
43
- const f = c('return 5')
44
- const result = f()
45
- if (result !== 5) { throw 'function' }
46
- }
47
-
48
- {
49
- /** @type {any} */
50
- const o = {}
51
- const c = o['constructor']
52
- // console.log(c)
53
- // console.log(c(()=>{}))
54
- }
55
-
56
- {
57
- /** @type {any} */
58
- const o = {
59
- constructor: undefined
9
+ module.exports = {
10
+ ctor: () => {
11
+ const c = (() => { })['constructor']
12
+ const f = c('return 5')
13
+ const result = f()
14
+ if (result !== 5) { throw 'function' }
15
+ },
16
+ ctorEmpty: () => {
17
+ /** @type {any} */
18
+ const o = {}
19
+ const c = o['constructor']
20
+ // console.log(c)
21
+ // console.log(c(()=>{}))
22
+ },
23
+ ctorUndefined: () => {
24
+ /** @type {any} */
25
+ const o = {
26
+ constructor: undefined
27
+ }
28
+ const c = o['constructor']
29
+ //console.log(c)
30
+ },
31
+ number: () => {
32
+ /** @type {any} */
33
+ const b = '42'
34
+ const r = Number(b)
35
+ //console.log(r)
36
+ },
37
+ properties: () => {
38
+ /** @type {any} */
39
+ const o = {}
40
+ //const c = o['constructor']
41
+ //const c = o['__proto__']
42
+ //const c = o['__defineGetter__']
43
+ //const c = o['__defineSetter__']
44
+ //const c = o['__lookupGetter__']
45
+ //const c = o['__lookupSetter__']
46
+ //const c = o['hasOwnProperty']
47
+ //const c = o['isPrototypeOf']
48
+ //const c = o['propertyIsEnumerable']
49
+ //const c = o['toString']
50
+ const c = o['valueOf']
51
+ //console.log(c)
52
+ },
53
+ getOwnPropertyDescriptor: () => {
54
+ const x = { 'a': 12 }
55
+ const c = Object.getOwnPropertyDescriptor(x, 'constructor')
56
+ const a = Object.getOwnPropertyDescriptor(x, 'a')
60
57
  }
61
- const c = o['constructor']
62
- //console.log(c)
63
- }
64
-
65
- {
66
- /** @type {any} */
67
- const b = '42'
68
- const r = Number(b)
69
- //console.log(r)
70
- }
71
-
72
- {
73
- /** @type {any} */
74
- const o = {}
75
- //const c = o['constructor']
76
- //const c = o['__proto__']
77
- //const c = o['__defineGetter__']
78
- //const c = o['__defineSetter__']
79
- //const c = o['__lookupGetter__']
80
- //const c = o['__lookupSetter__']
81
- //const c = o['hasOwnProperty']
82
- //const c = o['isPrototypeOf']
83
- //const c = o['propertyIsEnumerable']
84
- //const c = o['toString']
85
- const c = o['valueOf']
86
- //console.log(c)
87
- }
88
-
89
- {
90
- const x = { 'a': 12 }
91
- const c = Object.getOwnPropertyDescriptor(x, 'constructor')
92
- const a = Object.getOwnPropertyDescriptor(x, 'a')
93
- }
94
-
95
- module.exports = {}
58
+ }
package/test.mjs ADDED
@@ -0,0 +1,142 @@
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
+ /** @typedef {{ exports?: unknown }} Module */
25
+
26
+ /** @typedef {(name: string) => unknown} Require */
27
+
28
+ /**
29
+ * @typedef {{
30
+ * readonly[k in string]: Function
31
+ * }} FunctionMap
32
+ */
33
+
34
+ /**
35
+ * @template T
36
+ * @typedef {readonly[string, T]} Entry
37
+ */
38
+
39
+ /** @type {(a: Entry<Function>, b: Entry<Function>) => number} */
40
+ const cmp = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
41
+
42
+ /** @type {() => Promise<FunctionMap>} */
43
+ const load = async () => {
44
+ /** @type {(readonly[string, Function])[]} */
45
+ const map = []
46
+ /** @type {(path: string) => Promise<void>} */
47
+ const f = async p => {
48
+ for (const i of await readdir(p, { withFileTypes: true })) {
49
+ const { name } = i
50
+ if (!name.startsWith('.')) {
51
+ const file = `${p}/${name}`
52
+ if (i.isDirectory()) {
53
+ if (!['node_modules', 'target'].includes(name)) {
54
+ await f(file)
55
+ }
56
+ } else if (name.endsWith('.f.cjs')) {
57
+ console.log(`loading ${file}`)
58
+ const source = await readFile(file, 'utf8')
59
+ map.push([file, Function('module', 'require', `"use strict";${source}`)])
60
+ }
61
+ }
62
+ }
63
+ }
64
+ await f('.')
65
+ map.sort(cmp)
66
+ return Object.fromEntries(map)
67
+ }
68
+
69
+ const map = await load()
70
+
71
+ /**
72
+ * @typedef {{
73
+ * [k in string]: unknown
74
+ * }} ModuleMap
75
+ */
76
+
77
+ const build = async () => {
78
+ /** @type {ModuleMap} */
79
+ const d = {}
80
+ /** @type {(base: readonly string[]) => (i: string) => (k: string) => unknown} */
81
+ const req = p => i => k => {
82
+ const relativePath = k.split('/')
83
+ const dif = relativePath.filter(v => v === '..').length
84
+ const path = [p.slice(0, p.length - dif), relativePath.filter(v => !['..', '.'].includes(v))]
85
+ .flat()
86
+ const pathStr = path.join('/')
87
+ const newBase = path.slice(0, path.length - 1)
88
+ const result = d[pathStr]
89
+ if (result === undefined) {
90
+ /** @type {Module} */
91
+ const me = {}
92
+ console.log(`${i}building ${pathStr}`)
93
+ map[pathStr](me, req(newBase)(`${i}| `))
94
+ const newResult = me.exports
95
+ d[pathStr] = newResult
96
+ return newResult
97
+ } else {
98
+ return result
99
+ }
100
+ }
101
+ const r = req(['.'])('')
102
+ for (const k of Object.keys(map)) {
103
+ r(k)
104
+ }
105
+ return d
106
+ }
107
+
108
+ const modules = await build()
109
+
110
+ const test = i => v => {
111
+ switch (typeof v) {
112
+ case 'function': {
113
+ if (v.length === 0) {
114
+ const r = v()
115
+ console.log(`${i}() passed`)
116
+ test(`${i}| `)(r)
117
+ }
118
+ return;
119
+ }
120
+ case 'object': {
121
+ if (v instanceof Array) {
122
+ for (const v2 of v) {
123
+ test(`${i}| `)(v2)
124
+ }
125
+ } else {
126
+ for (const [k, v2] of Object.entries(v)) {
127
+ const i2 = `${i}| `
128
+ console.log(`${i}${k}:`)
129
+ test(i2)(v2)
130
+ }
131
+ }
132
+ return;
133
+ }
134
+ }
135
+ }
136
+
137
+ for (const [k, v] of Object.entries(modules)) {
138
+ if (k.endsWith('test.f.cjs')) {
139
+ console.log(`testing ${k}`)
140
+ test('| ')(v)
141
+ }
142
+ }
@@ -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", "denotest.mjs"]
100
+ "exclude": ["target", "test.mjs"]
101
101
  }
@@ -89,6 +89,4 @@ const stringify = a => json.stringify(sort)(a)
89
89
  if (result !== undefined) {throw result}
90
90
  }
91
91
 
92
- module.exports = {
93
-
94
- }
92
+ module.exports = {}
@@ -1,8 +1,8 @@
1
1
  const { sum } = require('./module.f.cjs')
2
2
 
3
- {
4
- const result = sum([2n, 3n, 4n, 5n])
5
- if (result !== 14n) { throw result }
6
- }
7
-
8
- module.exports = {}
3
+ module.exports = {
4
+ sum: () => {
5
+ const result = sum([2n, 3n, 4n, 5n])
6
+ if (result !== 14n) { throw result }
7
+ }
8
+ }
@@ -1,44 +1,41 @@
1
1
  const { join, concat, repeat, cmp } = require('./module.f.cjs')
2
2
  const { repeat: repeatList } = require('../list/module.f.cjs')
3
3
 
4
- {
5
- const result = join('/')([])
6
- if (result !== '') { throw result }
4
+ module.exports = {
5
+ join: {
6
+ 0: () => {
7
+ const result = join('/')([])
8
+ if (result !== '') { throw result }
9
+ },
10
+ 1: () => {
11
+ const result = join('/')([''])
12
+ if (result !== '') { throw result }
13
+ },
14
+ 3: () => {
15
+ const result = join(' ')(['hello', 'world', '!'])
16
+ if (result !== 'hello world !') { throw result }
17
+ }
18
+ },
19
+ concat: () => {
20
+ const result = concat(['hello', 'world'])
21
+ if (result !== 'helloworld') { throw result }
22
+ },
23
+ repeatList: {
24
+ 0: () => {
25
+ const s = join('.')(repeatList('x')(0))
26
+ if (s != '') { throw s }
27
+ },
28
+ 5: () => {
29
+ const s = join('.')(repeatList('x')(5))
30
+ if (s != 'x.x.x.x.x') { throw s }
31
+ }
32
+ },
33
+ repeat: () => {
34
+ const s = repeat('x')(5)
35
+ if(s != 'xxxxx') { throw s }
36
+ },
37
+ cmp: () => {
38
+ const result = cmp('3')('4')
39
+ if (result !== -1) { throw result }
40
+ }
7
41
  }
8
-
9
- {
10
- const result = join('/')([''])
11
- if (result !== '') { throw result }
12
- }
13
-
14
- {
15
- const result = join(' ')(['hello', 'world', '!'])
16
- if (result !== 'hello world !') { throw result }
17
- }
18
-
19
- {
20
- const result = concat(['hello', 'world'])
21
- if (result !== 'helloworld') { throw result }
22
- }
23
-
24
- {
25
- const s = join('.')(repeatList('x')(0))
26
- if (s != '') { throw s }
27
- }
28
-
29
- {
30
- const s = join('.')(repeatList('x')(5))
31
- if (s != 'x.x.x.x.x') { throw s }
32
- }
33
-
34
- {
35
- const s = repeat('x')(5)
36
- if (s != 'xxxxx') { throw s }
37
- }
38
-
39
- {
40
- const result = cmp('3')('4')
41
- if (result !== -1) { throw result }
42
- }
43
-
44
- module.exports = {}
@@ -1,35 +1,34 @@
1
1
  const _ = require('./module.f.cjs')
2
2
 
3
- {
4
- const r = _.set('hello')(undefined)
5
- if (!_.contains('hello')(r)) { throw r }
6
- if (_.contains('hello1')(r)) { throw r }
7
- }
8
-
9
- {
10
- let r = _.set('hello')(undefined)
11
- r = _.set('world')(r)
12
- r = _.set('HELLO')(r)
13
- r = _.set('WORLD!')(r)
14
- if (!_.contains('hello')(r)) { throw r }
15
- if (_.contains('hello1')(r)) { throw r }
16
- if (!_.contains('HELLO')(r)) { throw r }
17
- if (_.contains('WORLD')(r)) { throw r }
18
- if (!_.contains('world')(r)) { throw r }
19
- if (_.contains('world!')(r)) { throw r }
20
- if (!_.contains('WORLD!')(r)) { throw r }
21
- //
22
- r = _.remove('hello')(r)
23
- if (_.contains('hello')(r)) { throw r }
24
- if (!_.contains('world')(r)) { throw r }
25
- r = _.remove('world')(r)
26
- if (_.contains('world')(r)) { throw r }
27
- if (!_.contains('HELLO')(r)) { throw r }
28
- r = _.remove('HELLO')(r)
29
- if (_.contains('HELLO')(r)) { throw r }
30
- if (!_.contains('WORLD!')(r)) { throw r }
31
- r = _.remove('WORLD!')(r)
32
- if (r !== undefined) { throw r }
33
- }
34
-
35
- module.exports = {}
3
+ module.exports = {
4
+ contains: () => {
5
+ const r = _.set('hello')(undefined)
6
+ if (!_.contains('hello')(r)) { throw r }
7
+ if (_.contains('hello1')(r)) { throw r }
8
+ },
9
+ remove: () => {
10
+ let r = _.set('hello')(undefined)
11
+ r = _.set('world')(r)
12
+ r = _.set('HELLO')(r)
13
+ r = _.set('WORLD!')(r)
14
+ if (!_.contains('hello')(r)) { throw r }
15
+ if (_.contains('hello1')(r)) { throw r }
16
+ if (!_.contains('HELLO')(r)) { throw r }
17
+ if (_.contains('WORLD')(r)) { throw r }
18
+ if (!_.contains('world')(r)) { throw r }
19
+ if (_.contains('world!')(r)) { throw r }
20
+ if (!_.contains('WORLD!')(r)) { throw r }
21
+ //
22
+ r = _.remove('hello')(r)
23
+ if (_.contains('hello')(r)) { throw r }
24
+ if (!_.contains('world')(r)) { throw r }
25
+ r = _.remove('world')(r)
26
+ if (_.contains('world')(r)) { throw r }
27
+ if (!_.contains('HELLO')(r)) { throw r }
28
+ r = _.remove('HELLO')(r)
29
+ if (_.contains('HELLO')(r)) { throw r }
30
+ if (!_.contains('WORLD!')(r)) { throw r }
31
+ r = _.remove('WORLD!')(r)
32
+ if (r !== undefined) { throw r }
33
+ }
34
+ }
package/denotest.mjs DELETED
@@ -1,89 +0,0 @@
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()