functionalscript 0.0.230 → 0.0.234

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.
Files changed (43) hide show
  1. package/commonjs/index.js +11 -0
  2. package/commonjs/package/dependencies/index.js +71 -0
  3. package/commonjs/package/dependencies/test.js +33 -0
  4. package/commonjs/package/index.js +37 -0
  5. package/commonjs/package/test.js +14 -0
  6. package/commonjs/path/index.js +66 -0
  7. package/commonjs/path/test.js +47 -0
  8. package/commonjs/run/index.js +17 -0
  9. package/io/commonjs/index.js +28 -0
  10. package/io/commonjs/test.js +72 -0
  11. package/io/result/index.js +15 -0
  12. package/json/index.js +29 -29
  13. package/json/test.js +9 -9
  14. package/package.json +23 -23
  15. package/test.js +6 -6
  16. package/{sequence → types}/array/index.js +2 -2
  17. package/{btree → types/btree}/README.md +0 -0
  18. package/{btree → types/btree}/index.js +6 -6
  19. package/{btree → types/btree}/test.js +1 -1
  20. package/{cmp → types/function/compare}/index.js +6 -6
  21. package/{function → types/function}/index.js +0 -0
  22. package/{function → types/function}/operator/index.js +15 -0
  23. package/{map → types/map}/index.js +3 -3
  24. package/{map → types/map}/test.js +0 -0
  25. package/{object → types/object}/index.js +1 -2
  26. package/{object → types/object}/test.js +0 -0
  27. package/{option → types/option}/index.js +0 -0
  28. package/types/result/index.js +36 -0
  29. package/{sequence → types/sequence}/README.md +0 -0
  30. package/{sequence → types/sequence}/index.js +96 -49
  31. package/{sequence → types/sequence}/test.js +138 -11
  32. package/version.js +6 -3
  33. package/module-manager/README.md +0 -35
  34. package/module-manager/index.js +0 -110
  35. package/module-manager/node/index.js +0 -18
  36. package/module-manager/node/test.js +0 -75
  37. package/module-manager/test.js +0 -120
  38. package/result/index.js +0 -17
  39. package/sequence/asyncIterable/index.js +0 -111
  40. package/sequence/asyncIterable/test.js +0 -24
  41. package/sequence/iterable/index.js +0 -109
  42. package/sequence/iterable/test.js +0 -51
  43. package/sequence/operator/index.js +0 -92
@@ -1,9 +1,9 @@
1
1
  const _ = require('.')
2
- const json = require('../json')
2
+ const json = require('../../json')
3
3
  const { sort } = require('../object')
4
- const { addition } = require('../function/operator')
4
+ const { addition, strictEqual } = require('../function/operator')
5
5
 
6
- /** @type {(sequence: _.Sequence<json.Json>) => string} */
6
+ /** @type {(sequence: _.Sequence<json.Unknown>) => string} */
7
7
  const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
8
8
 
9
9
  {
@@ -17,13 +17,15 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
17
17
  }
18
18
 
19
19
  {
20
- const result = stringify(_.concat([1, 2, 3], [4, 5], [6], [], [7, 8, 9]))
20
+ const result = stringify(_.flat([[1, 2, 3], [4, 5], [6], [], [7, 8, 9]]))
21
21
  if (result !== '[1,2,3,4,5,6,7,8,9]') { throw result }
22
22
  }
23
23
 
24
24
  {
25
- const result = _.concat([1], [2])
25
+ const result = _.concat([1])([2])
26
26
  const x = _.next(result)
27
+ if (x === undefined) { throw x }
28
+ if (x.first !== 1) { throw x }
27
29
  }
28
30
 
29
31
  {
@@ -36,6 +38,21 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
36
38
  if (result !== '[1,2,3,4,5]') { throw result }
37
39
  }
38
40
 
41
+ {
42
+ const result = stringify(_.take(3)([1, 2, 3, 4, 5, 6, 7, 8, 9]))
43
+ if (result !== '[1,2,3]') { throw result }
44
+ }
45
+
46
+ {
47
+ const result = stringify(_.take(20)([1, 2, 3, 4, 5, 6, 7, 8, 9]))
48
+ if (result !== '[1,2,3,4,5,6,7,8,9]') { throw result }
49
+ }
50
+
51
+ {
52
+ const result = stringify(_.take(0)([1, 2, 3, 4, 5, 6, 7, 8, 9]))
53
+ if (result !== '[]') { throw result }
54
+ }
55
+
39
56
  {
40
57
  const result = _.find(undefined)(x => x % 2 === 0)([1, 2, 3, 4])
41
58
  if (result !== 2) { throw result }
@@ -51,6 +68,21 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
51
68
  if (result !== '[10,11]') { throw result }
52
69
  }
53
70
 
71
+ {
72
+ const result = stringify(_.drop(3)([1, 2, 3, 4, 5, 10, 11]))
73
+ if (result !== '[4,5,10,11]') { throw result }
74
+ }
75
+
76
+ {
77
+ const result = stringify(_.drop(0)([1, 2, 3, 4, 5, 10, 11]))
78
+ if (result !== '[1,2,3,4,5,10,11]') { throw result }
79
+ }
80
+
81
+ {
82
+ const result = stringify(_.drop(10)([1, 2, 3, 4, 5, 10, 11]))
83
+ if (result !== '[]') { throw result }
84
+ }
85
+
54
86
  {
55
87
  const op = _.scanState(addition)
56
88
  const result = stringify(_.scan(op)([2, 3, 4, 5]))
@@ -102,6 +134,81 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
102
134
  if (result !== '[5,4,3,2,1]') { throw result }
103
135
  }
104
136
 
137
+ {
138
+ const result = stringify(_.zip([0, 1, 2])(['a', 'b', 'c', 'd']))
139
+ if (result !== '[[0,"a"],[1,"b"],[2,"c"]]') { throw result }
140
+ }
141
+
142
+ {
143
+ const result = stringify(_.zip([0, 1, 2])(['a', 'b']))
144
+ if (result !== '[[0,"a"],[1,"b"]]') { throw result }
145
+ }
146
+
147
+ {
148
+ const result = _.some(_.map(x => x > 5)([0, 1, 7]))
149
+ if (!result) { throw result}
150
+ }
151
+
152
+ {
153
+ const result = _.some(_.map(x => x > 5)([0, 1, 4]))
154
+ if (result) { throw result }
155
+ }
156
+
157
+ {
158
+ const result = _.some(_.map(x => x > 5)([]))
159
+ if (result) { throw result }
160
+ }
161
+
162
+ {
163
+ const result = _.every(_.map(x => x > 5)([0, 1, 7]))
164
+ if (result) { throw result }
165
+ }
166
+
167
+ {
168
+ const result = _.every(_.map(x => x > 5)([6, 11, 7]))
169
+ if (!result) { throw result }
170
+ }
171
+
172
+ {
173
+ const result = _.every(_.map(x => x > 5)([]))
174
+ if (!result) { throw result }
175
+ }
176
+
177
+ {
178
+ const result = _.equal(strictEqual)([1])([2, 3])
179
+ if (result) { throw result}
180
+ }
181
+
182
+ {
183
+ const result = _.equal(strictEqual)([1, 3])([1])
184
+ if (result) { throw result }
185
+ }
186
+
187
+ {
188
+ const result = _.equal(strictEqual)([15, 78])([15, 78])
189
+ if (!result) { throw result }
190
+ }
191
+
192
+ {
193
+ const result = _.equal(strictEqual)([])([])
194
+ if (!result) { throw result }
195
+ }
196
+
197
+ {
198
+ const result = _.min([])
199
+ if (result !== undefined) { throw result }
200
+ }
201
+
202
+ {
203
+ const result = _.min([1, 2, 12, -4, 8])
204
+ if (result !== -4) { throw result }
205
+ }
206
+
207
+ {
208
+ const result = _.max([1, 2, 12, -4, 8])
209
+ if (result !== 12) { throw result }
210
+ }
211
+
105
212
  // stress tests
106
213
 
107
214
  const stress = () => {
@@ -129,9 +236,19 @@ const stress = () => {
129
236
  {
130
237
  /** @type {_.Sequence<number>} */
131
238
  let sequence = []
132
- // 2_000_000 is too much
133
- for (let i = 0; i < 1_000_000; ++i) {
134
- sequence = _.concat(sequence, [i])
239
+ // 10_000_000 is too much
240
+ for (let i = 0; i < 5_000_000; ++i) {
241
+ sequence = _.concat(sequence)([i])
242
+ }
243
+ const r = _.toArray(sequence)
244
+ }
245
+
246
+ {
247
+ /** @type {_.Sequence<number>} */
248
+ let sequence = []
249
+ // 4_000_000 is too much
250
+ for (let i = 0; i < 2_000_000; ++i) {
251
+ sequence = _.flat([sequence, [i]])
135
252
  }
136
253
  const r = _.toArray(sequence)
137
254
  }
@@ -141,7 +258,17 @@ const stress = () => {
141
258
  let sequence = []
142
259
  // 5_000_000 is too much
143
260
  for (let i = 0; i < 2_000_000; ++i) {
144
- sequence = _.concat(sequence, [i])
261
+ sequence = _.flat([sequence, [i]])
262
+ }
263
+ const a = _.next(sequence)
264
+ }
265
+
266
+ {
267
+ /** @type {_.Sequence<number>} */
268
+ let sequence = []
269
+ // 20_000_000 is too much
270
+ for (let i = 0; i < 10_000_000; ++i) {
271
+ sequence = _.concat([i])(sequence)
145
272
  }
146
273
  const a = _.next(sequence)
147
274
  }
@@ -151,7 +278,7 @@ const stress = () => {
151
278
  let sequence = []
152
279
  // 10_000_000 is too much
153
280
  for (let i = 0; i < 5_000_000; ++i) {
154
- sequence = _.concat([i], sequence)
281
+ sequence = _.flat([[i], sequence])
155
282
  }
156
283
  const a = _.next(sequence)
157
284
  }
@@ -183,4 +310,4 @@ const stress = () => {
183
310
 
184
311
  module.exports = {
185
312
 
186
- }
313
+ }
package/version.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const cp = require('child_process')
2
2
  const fs = require('fs')
3
3
  const json = require('./json')
4
+ const { isPackage } = require('./commonjs/package')
4
5
 
5
6
  const b =cp.execSync('git log --oneline')
6
7
 
@@ -10,8 +11,10 @@ const v = `0.0.${r}`
10
11
 
11
12
  console.log(`version: ${v}`)
12
13
 
13
- let package_json = json.parse(fs.readFileSync('package.json').toString())
14
+ const package_json = json.parse(fs.readFileSync('package.json').toString())
14
15
 
15
- package_json = json.addProperty(v)(['version'])(package_json)
16
+ if (!isPackage(package_json)) { throw 'error' }
16
17
 
17
- fs.writeFileSync('package.json', JSON.stringify(package_json, null, 3))
18
+ const x = { ...package_json, version: v }
19
+
20
+ fs.writeFileSync('package.json', JSON.stringify(x, null, 2))
@@ -1,35 +0,0 @@
1
- # Module Manager
2
-
3
- ## Module Provider
4
-
5
- ```js
6
- /** @typedef {(packageName: string) => PackageMap|Package|undefined} PackageMap */
7
-
8
- /**
9
- * @typedef {readonly[
10
- * string,
11
- * PackageMap,
12
- * (fileName: string) => string|undefined
13
- * ]} Package
14
- */
15
- ```
16
-
17
- ## Runner IO
18
-
19
- The main target of this design is to simplify `RunnerIo` as much as possible.
20
-
21
- ```js
22
- /**
23
- * @template T
24
- * @typedef {readonly[Result<unknown, Error>, Require<T>]} RunnerResult
25
- */
26
-
27
- /** @typedef {<T>(require: Require<T>) => (source: string) => RunnerResult<T>} RunnerIo */
28
-
29
- /**
30
- * @template T
31
- * @typedef {readonly[(path: string) => RunnerResult<T>, T]} Require<T>
32
- */
33
- ```
34
-
35
- `Require` is using a `Package` and it contains also `RunnerIo` to provide sources also it contains
@@ -1,110 +0,0 @@
1
- const array = require('../sequence/array')
2
- const { compose } = require('../function')
3
- const option = require('../option')
4
- const { head, last, splitLast, splitFirst } = array
5
- const iter = require('../sequence/iterable')
6
- const seq = require('../sequence/operator')
7
-
8
- /**
9
- * @template T
10
- * @typedef {array.Array<T>} Array
11
- */
12
-
13
- /** @typedef {Array<string>} Path */
14
-
15
- /** @typedef {(_: string) => string|undefined} ReadFile */
16
-
17
- /**
18
- * @typedef {{
19
- * readonly id: Array<string>
20
- * readonly dependencies: Dependencies
21
- * readonly file: ReadFile
22
- * }} Package
23
- */
24
-
25
- /**
26
- * @typedef {{
27
- * readonly pack: Package,
28
- * readonly local: Array<string>,
29
- * }} Location
30
- */
31
-
32
- /**
33
- * @typedef {{
34
- * readonly fileName: string
35
- * readonly location: Location
36
- * readonly source: string
37
- * }} Module
38
- */
39
-
40
- /** @typedef {(_: string) => undefined|Package|Dependencies} Dependencies */
41
-
42
- /** @type {seq.ExclusiveScan<string, undefined|Path>} */
43
- const pathNormReduce = seq.exclusiveScan
44
- (path => item =>
45
- path === undefined ?
46
- undefined :
47
- ['', '.'].includes(item) ?
48
- path :
49
- item === '..' ?
50
- head(path) :
51
- [...path, item])
52
- ([])
53
-
54
- /** @type {(_: Array<string>) => boolean} */
55
- const isRelative = localId => ['.', '..'].includes(localId[0])
56
-
57
- const pathNorm = iter.reduce(pathNormReduce)
58
-
59
- /** @type {(_: Package) => (_: Path) => Module|undefined} */
60
- const internal = pack => {
61
- /** @type {(_: Path) => (_: string) => Module|undefined} */
62
- const readFile = local => fileName => {
63
- const source = pack.file([...local, fileName].join('/'))
64
- return source === undefined ? undefined : { fileName, location: { pack, local }, source}
65
- }
66
- return path => {
67
- /** @type {(_: Path) => Module|undefined} */
68
- const read = local => {
69
- /** @type {(_: readonly[Path, string]) => Module|undefined} */
70
- const tryFiles = ([head, file]) => {
71
- /** @type {(_: string) => Module|undefined} */
72
- const one = ext => readFile(head)(file + ext)
73
- return ['.', '..', '', undefined].includes(last(path)) ? undefined : one('') ?? one('.js')
74
- }
75
- return option.map(tryFiles)(splitLast(local)) ?? readFile(local)('index.js')
76
- }
77
- return option.map(read)(pathNorm(path))
78
- }
79
- }
80
-
81
- /** @type {(_: Package|Dependencies|undefined) => (_: Path) => Module|undefined} */
82
- const externalOrInternal = p =>
83
- p === undefined ? () => undefined : (typeof p === 'function' ? external(p) : internal(p))
84
-
85
- /** @type {(_: Dependencies) => (path: Path) => Module|undefined} */
86
- const external = packages => {
87
- /** @type {(_: readonly [string, Path]) => Module|undefined} */
88
- const defined = ([first, tail]) => externalOrInternal(packages(first))(tail)
89
- return path => option.map(defined)(splitFirst(path))
90
- }
91
-
92
- /** @type {(_: Location) => (_: string) => Module|undefined} */
93
- const getModule = ({pack, local}) => path => {
94
- const pathArray = path.split('/')
95
- return isRelative(pathArray) ? internal(pack)([...local, ...pathArray]) : external(pack.dependencies)(pathArray)
96
- }
97
-
98
- /** @type {(_: Module) => string} */
99
- const moduleId = module => [...module.location.pack.id, ...module.location.local, module.fileName].join('/')
100
-
101
- module.exports = {
102
- /** @readonly */
103
- isRelative,
104
- /** @readonly */
105
- pathNorm,
106
- /** @readonly */
107
- getModule,
108
- /** @readonly */
109
- moduleId,
110
- }
@@ -1,18 +0,0 @@
1
- const m = require('..')
2
-
3
- /** @type {(_: m.ReadFile) => m.Location} */
4
- module.exports = readFile => {
5
- /** @type {(_: string[]) => (_: string) => m.Package|m.Dependencies|undefined} */
6
- const packages = path => name => {
7
- const newPath = [...path, name]
8
- // we only need to check if 'package.json' exist
9
- return (readFile([...newPath, 'package.json'].join('/')) === undefined ? packages : pack)(newPath)
10
- }
11
- /** @type {(_: string[]) => m.Package} */
12
- const pack = path => ({
13
- id: path,
14
- dependencies: packages(['node_modules']),
15
- file: filePath => readFile([...path, ...filePath.split('/')].join('/'))
16
- })
17
- return { pack: pack([]), local: [] }
18
- }
@@ -1,75 +0,0 @@
1
- const mm = require('..')
2
- const i = require('.')
3
-
4
- /** @type {{ readonly [_ in string]: string}} */
5
- const files = {
6
- 'index.js': './index.js',
7
- 'a/index.js': './a/index.js',
8
- 'a/b/x.js': './a/b/x.js',
9
- 'c/t.js': './c/t.js',
10
- 'node_modules/@functionalscript/functionalscript/package.json': '',
11
- 'node_modules/@functionalscript/functionalscript/index.js': '@functionalscript/functionalscript ./index.js',
12
- 'node_modules/my/package.json': '',
13
- 'node_modules/my/src/x.js': 'my ./src/x.js',
14
- 'node_modules/my/b/index.js': 'my ./b/index.js',
15
- }
16
-
17
- /** @type {(_: string) => string|undefined} */
18
- const readFile = path => files[path]
19
-
20
- const root = i(readFile)
21
-
22
- {
23
- const index = mm.getModule(root)('.')
24
- if (index === undefined) { throw 'no module' }
25
- if (index.fileName !== 'index.js') { throw 'fileName' }
26
- if (index.source !== './index.js') { throw 'source' }
27
- if (index.location.local.join('/') !== '') { throw 'location' }
28
- if (index.location.pack.id.join('/') !== '') { throw 'pack.id' }
29
- if (mm.moduleId(index) !== 'index.js') { throw 'moduleId' }
30
- const a = mm.getModule(index.location)('./a')
31
- if (a === undefined) { throw 'no module' }
32
- if (a.fileName !== 'index.js') { throw 'fileName' }
33
- if (a.source !== './a/index.js') { throw 'source' }
34
- if (a.location.local.join('/') !== 'a') { throw 'location' }
35
- if (a.location.pack.id.join('/') !== '') { throw 'pack.id' }
36
- if (mm.moduleId(a) !== 'a/index.js') { throw 'moduleId' }
37
- const abx = mm.getModule(a.location)('./b/x')
38
- if (abx === undefined) { throw 'no module' }
39
- if (abx.fileName !== 'x.js') { throw 'fileName' }
40
- if (abx.source !== './a/b/x.js') { throw 'source' }
41
- if (abx.location.local.join('/') !== 'a/b') { throw 'location' }
42
- if (abx.location.pack.id.join('/') !== '') { throw 'pack.id' }
43
- if (mm.moduleId(abx) !== 'a/b/x.js') { throw 'moduleId' }
44
- const ct = mm.getModule(abx.location)('../../c/t.js')
45
- if (ct === undefined) { throw 'no module' }
46
- if (ct.fileName !== 't.js') { throw 'fileName' }
47
- if (ct.source !== './c/t.js') { throw 'source' }
48
- if (ct.location.local.join('/') !== 'c') { throw 'location' }
49
- if (ct.location.pack.id.join('/') !== '') { throw 'pack.id' }
50
- if (mm.getModule(ct.location)('./d') !== undefined) { throw 'no module' }
51
- if (mm.getModule(ct.location)('@functionalscript') !== undefined) { throw 'no module' }
52
- if (mm.moduleId(ct) !== 'c/t.js') { throw 'moduleId' }
53
- const fs = mm.getModule(ct.location)('@functionalscript/functionalscript')
54
- if (fs === undefined) { throw 'no module' }
55
- if (fs.source !== '@functionalscript/functionalscript ./index.js') { throw 'source' }
56
- if (fs.fileName !== 'index.js') { throw 'fileName' }
57
- if (fs.location.local.join('/') !== '') { throw 'location' }
58
- if (fs.location.pack.id.join('/') !== 'node_modules/@functionalscript/functionalscript') { throw 'pack.id' }
59
- if (mm.getModule(fs.location)('my/src/x/') !== undefined) { throw 'no module '}
60
- if (mm.moduleId(fs) !== 'node_modules/@functionalscript/functionalscript/index.js') { throw 'moduleId' }
61
- const mySrcX = mm.getModule(fs.location)('my/src/x')
62
- if (mySrcX === undefined) { throw 'no module' }
63
- if (mySrcX.fileName !== 'x.js') { throw 'fileName' }
64
- if (mySrcX.source !== 'my ./src/x.js') { throw 'source' }
65
- if (mySrcX.location.local.join('/') !== 'src') { throw 'location' }
66
- if (mySrcX.location.pack.id.join('/') !== 'node_modules/my') { throw 'pack.id' }
67
- if (mm.moduleId(mySrcX) !== 'node_modules/my/src/x.js') { throw 'moduleId' }
68
- const myB = mm.getModule(mySrcX.location)('../b/')
69
- if (myB === undefined) { throw 'no module' }
70
- if (myB.fileName !== 'index.js') { throw 'fileName' }
71
- if (myB.source !== 'my ./b/index.js') { throw 'source' }
72
- if (myB.location.local.join('/') !== 'b') { throw 'location' }
73
- if (myB.location.pack.id.join('/') !== 'node_modules/my') { throw 'pack.id' }
74
- if (mm.moduleId(myB) !== 'node_modules/my/b/index.js') { throw 'moduleId' }
75
- }
@@ -1,120 +0,0 @@
1
- const i = require('.')
2
-
3
- require('./node/test')
4
-
5
- /** @type {<T>(_: T | undefined) => T} */
6
- const cast = x => {
7
- if (x === undefined) { throw 'x' }
8
- return x
9
- }
10
-
11
- if (i.isRelative('a/b/c'.split('/'))) { throw 'error '}
12
- if (!i.isRelative('./a/b/c'.split('/'))) { throw 'error ' }
13
- if (cast(i.pathNorm('a/../b'.split('/'))).join('/') !== 'b') { throw 'error ' }
14
- if (cast(i.pathNorm('a/../b/../c'.split('/'))).join('/') !== 'c') { throw 'error ' }
15
- if (cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('/') !== 'b/d') { throw 'error ' }
16
-
17
- {
18
- /** @type {i.Package} */
19
- const a = {
20
- dependencies: () => undefined,
21
- file: path => {
22
- /** @type {{ [_ in string]?: string}} */
23
- const f = {
24
- 'index.js': 'a ./index.js',
25
- }
26
- return f[path]
27
- },
28
- id: ['a']
29
- }
30
- /** @type {i.Package} */
31
- const c = {
32
- dependencies: () => undefined,
33
- file: path => {
34
- /** @type {{ readonly [_ in string]?: string}} */
35
- const f = {
36
- 'index.js': 'b/c ./index.js',
37
- 'x/index.js': 'b/c ./x/index.js',
38
- }
39
- if (['.js', '', 'undefined.js'].includes(path)) { throw '.js' }
40
- return f[path]
41
- },
42
- id: ['c']
43
- }
44
- /** @type {{ readonly [_ in string]: i.Package|i.Dependencies}} */
45
- const packages = {
46
- a,
47
- b: s => {
48
- /** @type {{ readonly [_ in string]: i.Package|i.Dependencies}} */
49
- const p = { c }
50
- return p[s]
51
- }
52
- }
53
- /** @type {i.Package} */
54
- const pack = {
55
- dependencies: s => packages[s],
56
- file: path => {
57
- /** @type {{ readonly [_ in string]?: string}} */
58
- const f = {
59
- 'index.js': './index.js',
60
- 'index/index.js': './index/index.js',
61
- 'a/index.js': './a/index.js',
62
- 'a/index.js.js': './a/index.js.js',
63
- }
64
- if (['.js', '', 'undefined.js'].includes(path)) { throw '.js' }
65
- return f[path]
66
- },
67
- id: ['']
68
- }
69
- /** @type {(_: i.Module|undefined) => (_: i.Module) => void} */
70
- const expect = a => b => {
71
- if (a === undefined) { throw 'undefined' }
72
- if (a.location.local.join('/') !== b.location.local.join('/')) { throw 'local'}
73
- if (a.location.pack !== b.location.pack) { throw 'pack' }
74
- if (a.source !== b.source) { throw 'source' }
75
- }
76
- {
77
- const g = i.getModule({pack, local: []})
78
- if (g('') !== undefined) { throw 'error' }
79
- if (g('..') !== undefined) { throw 'error' }
80
- expect(g('.'))({ fileName: 'index.js', location: { pack, local: []}, source: './index.js'})
81
- expect(g('./index'))({ fileName: 'index.js', location: { pack, local: []}, source: './index.js'})
82
- expect(g('./index.js'))({ fileName: 'index.js', location: { pack, local: []}, source: './index.js'})
83
- expect(g('./index/'))({ fileName: 'index.js', location: { pack, local: ['index']}, source: './index/index.js'})
84
- expect(g('./a'))({ fileName: 'index.js', location: { pack, local: ['a']}, source: './a/index.js'})
85
- expect(g('./a/index'))({ fileName: 'index.js', location: { pack, local: ['a']}, source: './a/index.js'})
86
- expect(g('./a/index.js'))({ fileName: 'index.js.js', location: { pack, local: ['a']}, source: './a/index.js'})
87
- if (g('./x') !== undefined) { throw 'error' }
88
- expect(g('a'))({ fileName: 'index.js', location: { pack: a, local: []}, source: 'a ./index.js'})
89
- expect(g('a/index'))({ fileName: 'index.js', location: { pack: a, local: []}, source: 'a ./index.js'})
90
- if (g('b') !== undefined) { throw 'error' }
91
- expect(g('b/c'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
92
- expect(g('b/c/index'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
93
- expect(g('b/c/index.js'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
94
- expect(g('b/c/x'))({ fileName: 'index.js', location: { pack: c, local: ['x']}, source: 'b/c ./x/index.js'})
95
- expect(g('b/c/r/..'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
96
- }
97
- {
98
- const g = i.getModule({pack, local: ['index']})
99
- if (g('') !== undefined) { throw 'error' }
100
- expect(g('..'))({ fileName: 'index.js', location: { pack, local: []}, source: './index.js'})
101
- expect(g('.'))({ fileName: 'index.js', location: { pack, local: ['index']}, source: './index/index.js'})
102
- expect(g('./index'))({ fileName: 'index.js', location: { pack, local: ['index']}, source: './index/index.js'})
103
- expect(g('./index.js'))({ fileName: 'index.js', location: { pack, local: ['index']}, source: './index/index.js'})
104
- if (g('./index/') !== undefined) { throw 'error' }
105
- if (g('./a') !== undefined) { throw 'error' }
106
- expect(g('../a'))({ fileName: 'index.js', location: { pack, local: ['a']}, source: './a/index.js'})
107
- expect(g('../a/index'))({ fileName: 'index.js', location: { pack, local: ['a']}, source: './a/index.js'})
108
- expect(g('../a/index.js'))({ fileName: 'index.js', location: { pack, local: ['a']}, source: './a/index.js'})
109
- expect(g('../a/index.js.js'))({ fileName: 'index.js.js', location: { pack, local: ['a']}, source: './a/index.js.js'})
110
- if (g('./x') !== undefined) { throw 'error' }
111
- expect(g('a'))({ fileName: 'index.js', location: { pack: a, local: []}, source: 'a ./index.js'})
112
- expect(g('a/index'))({ fileName: 'index.js', location: { pack: a, local: []}, source: 'a ./index.js'})
113
- if (g('b') !== undefined) { throw 'error' }
114
- expect(g('b/c'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
115
- expect(g('b/c/index'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
116
- expect(g('b/c/index.js'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
117
- expect(g('b/c/x'))({ fileName: 'index.js', location: { pack: c, local: ['x']}, source: 'b/c ./x/index.js'})
118
- expect(g('b/c/r/..'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
119
- }
120
- }
package/result/index.js DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * @template T
3
- * @typedef {readonly['ok', T]} Ok
4
- */
5
-
6
- /**
7
- * @template E
8
- * @typedef {readonly['error', E]} Error
9
- */
10
-
11
- /**
12
- * @template T
13
- * @template E
14
- * @typedef {Ok<T>|Error<E>} Result
15
- */
16
-
17
- module.exports = {}