functionalscript 0.0.270 → 0.0.271
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.
- package/commonjs/path/index.js +59 -24
- package/package.json +1 -1
- package/types/list/index.js +5 -0
- package/types/list/test.js +10 -0
package/commonjs/path/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const
|
|
1
|
+
const list = require("../../types/list")
|
|
2
2
|
const option = require("../../types/option")
|
|
3
3
|
const { compose } = require("../../types/function")
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
4
|
+
const { todo } = require("../../dev")
|
|
5
|
+
const package_ = require("../package")
|
|
6
|
+
const module_ = require("../module")
|
|
7
7
|
|
|
8
8
|
/** @typedef {readonly string[]} Items */
|
|
9
9
|
|
|
@@ -18,32 +18,32 @@ const { at } = require("../../types/object")
|
|
|
18
18
|
/** @type {(path: string) => readonly string[]} */
|
|
19
19
|
const split = path => path.split('/')
|
|
20
20
|
|
|
21
|
-
/** @type {(s: undefined|
|
|
21
|
+
/** @type {(s: undefined|list.List<string>) => (items: string) => undefined|list.List<string>} */
|
|
22
22
|
const normItemsOp = prior => item => {
|
|
23
23
|
if (prior === undefined) { return undefined }
|
|
24
24
|
switch (item) {
|
|
25
25
|
case '': case '.': { return prior }
|
|
26
26
|
case '..': {
|
|
27
|
-
const result =
|
|
27
|
+
const result = list.next(prior)
|
|
28
28
|
if (result === undefined) { return undefined }
|
|
29
29
|
return result.tail
|
|
30
30
|
}
|
|
31
31
|
default: {
|
|
32
|
-
return
|
|
32
|
+
return list.nonEmpty(item)(prior)
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/** @type {(items:
|
|
38
|
-
const normItems = compose(
|
|
37
|
+
/** @type {(items: list.List<string>) => list.List<string>|undefined} */
|
|
38
|
+
const normItems = compose(list.reduce(normItemsOp)([]))(option.map(list.reverse))
|
|
39
39
|
|
|
40
40
|
/** @type {(local: string) => (path: string) => LocalPath|undefined} */
|
|
41
41
|
const parseLocal = local => {
|
|
42
|
-
/** @type {(path: string) => readonly[boolean,
|
|
42
|
+
/** @type {(path: string) => readonly[boolean, list.List<string>]} */
|
|
43
43
|
const fSeq = path => {
|
|
44
44
|
const pathSeq = split(path)
|
|
45
|
-
switch (
|
|
46
|
-
case '.': case '..': { return [false,
|
|
45
|
+
switch (list.first(undefined)(pathSeq)) {
|
|
46
|
+
case '.': case '..': { return [false, list.flat([split(local), pathSeq])] }
|
|
47
47
|
default: { return [true, pathSeq] }
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -55,18 +55,18 @@ const parseLocal = local => {
|
|
|
55
55
|
return {
|
|
56
56
|
external,
|
|
57
57
|
dir: path[path.length - 1] === '/',
|
|
58
|
-
items:
|
|
58
|
+
items: list.toArray(n)
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
return f
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
/** @typedef {readonly[string,
|
|
64
|
+
/** @typedef {readonly[string, list.List<string>]} IdPath */
|
|
65
65
|
|
|
66
|
-
/** @type {(prior: readonly[string|undefined,
|
|
66
|
+
/** @type {(prior: readonly[string|undefined, list.List<string>]) => list.Thunk<IdPath>} */
|
|
67
67
|
const variants = prior => () => {
|
|
68
68
|
const [a, b] = prior
|
|
69
|
-
const r =
|
|
69
|
+
const r = list.next(b)
|
|
70
70
|
if (r === undefined) { return undefined }
|
|
71
71
|
const { first, tail } = r
|
|
72
72
|
/** @type {IdPath} */
|
|
@@ -82,35 +82,68 @@ const mapDependency = d => ([external, internal]) => {
|
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* @typedef {{
|
|
85
|
-
* readonly
|
|
85
|
+
* readonly packageId: string,
|
|
86
86
|
* readonly items: Items,
|
|
87
87
|
* readonly dir: boolean,
|
|
88
88
|
* }} Path
|
|
89
89
|
*/
|
|
90
90
|
|
|
91
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* @type {(d: (local: string) => string|undefined) =>
|
|
93
|
+
* (dir: boolean) =>
|
|
94
|
+
* (items: list.List<string>) =>
|
|
95
|
+
* Path|undefined}
|
|
96
|
+
*/
|
|
92
97
|
const parseGlobal = d => dir => items => {
|
|
93
98
|
const v = variants([undefined, items])
|
|
94
|
-
const r =
|
|
99
|
+
const r = list.first(undefined)(list.filterMap(mapDependency(d))(v))
|
|
95
100
|
if (r === undefined) { return undefined }
|
|
96
|
-
return {
|
|
101
|
+
return { packageId: r[0], items: list.toArray(r[1]), dir }
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
/**
|
|
100
|
-
* @type {(
|
|
105
|
+
* @type {(packageId: string) =>
|
|
101
106
|
* (dependencies: (local: string) => string|undefined) =>
|
|
102
107
|
* (local: string) =>
|
|
103
108
|
* (path: string) =>
|
|
104
109
|
* Path|undefined }
|
|
105
110
|
*/
|
|
106
|
-
const parse =
|
|
111
|
+
const parse = packageId => dependencies => local => path => {
|
|
107
112
|
const parsed = parseLocal(local)(path)
|
|
108
113
|
if (parsed === undefined) { return undefined }
|
|
109
|
-
const {external, dir, items} = parsed
|
|
110
|
-
if (!external) { return {
|
|
114
|
+
const {external, dir, items } = parsed
|
|
115
|
+
if (!external) { return { packageId, items, dir } }
|
|
111
116
|
return parseGlobal(dependencies)(dir)(items)
|
|
112
117
|
}
|
|
113
118
|
|
|
119
|
+
/** @typedef {readonly[string, string] | undefined} Result */
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @type {(packageGet: package_.Get) =>
|
|
123
|
+
* (packageId: string) =>
|
|
124
|
+
* (local: string) =>
|
|
125
|
+
* (path: string) =>
|
|
126
|
+
* Result
|
|
127
|
+
* }
|
|
128
|
+
*/
|
|
129
|
+
const parseAndFind = packageGet => packageId => local => path => {
|
|
130
|
+
const currentPack = packageGet(packageId)
|
|
131
|
+
if (currentPack === undefined) { return undefined }
|
|
132
|
+
const p = parse(packageId)(currentPack.dependency)(local)(path)
|
|
133
|
+
if (p === undefined) { return undefined }
|
|
134
|
+
const pack = packageGet(p.packageId)
|
|
135
|
+
if (pack === undefined) { return undefined }
|
|
136
|
+
/** @type {(fileId: string) => Result } */
|
|
137
|
+
const tryFile = fileId => {
|
|
138
|
+
const source = pack.file(fileId)
|
|
139
|
+
return source === undefined ? undefined : [fileId, source]
|
|
140
|
+
}
|
|
141
|
+
const file = p.items.join('/')
|
|
142
|
+
const indexJs = list.join('/')(list.concat(p.items)(['index.js']))
|
|
143
|
+
const fileList = p.dir || list.isEmpty(p.items) ? [indexJs] : [file, `${file}.js`, indexJs]
|
|
144
|
+
return list.first(undefined)(list.filterMap(tryFile)(fileList))
|
|
145
|
+
}
|
|
146
|
+
|
|
114
147
|
module.exports = {
|
|
115
148
|
/** @readonly */
|
|
116
149
|
parseLocal,
|
|
@@ -118,4 +151,6 @@ module.exports = {
|
|
|
118
151
|
parseGlobal,
|
|
119
152
|
/** @readonly */
|
|
120
153
|
parse,
|
|
154
|
+
/** @readonly */
|
|
155
|
+
parseAndFind,
|
|
121
156
|
}
|
package/package.json
CHANGED
package/types/list/index.js
CHANGED
|
@@ -199,6 +199,9 @@ const some = input => find
|
|
|
199
199
|
(/** @type {(_: boolean) => boolean} */(identity))
|
|
200
200
|
(input)
|
|
201
201
|
|
|
202
|
+
/** @type {<T>(input: List<T>) => boolean} */
|
|
203
|
+
const isEmpty = input => !some(map(() => true)(input))
|
|
204
|
+
|
|
202
205
|
/** @type {(input: List<boolean>) => boolean} */
|
|
203
206
|
const every = input => !some(map(logicalNot)(input))
|
|
204
207
|
|
|
@@ -336,6 +339,8 @@ module.exports = {
|
|
|
336
339
|
/** @readonly */
|
|
337
340
|
every,
|
|
338
341
|
/** @readonly */
|
|
342
|
+
isEmpty,
|
|
343
|
+
/** @readonly */
|
|
339
344
|
includes,
|
|
340
345
|
/** @readonly */
|
|
341
346
|
countdown,
|
package/types/list/test.js
CHANGED
|
@@ -214,6 +214,16 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
214
214
|
if (result !== 12) { throw result }
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
{
|
|
218
|
+
const result = _.isEmpty(() => [])
|
|
219
|
+
if (result !== true) { throw result }
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
{
|
|
223
|
+
const result = _.isEmpty(() => [2])
|
|
224
|
+
if (result !== false) { throw result }
|
|
225
|
+
}
|
|
226
|
+
|
|
217
227
|
// stress tests
|
|
218
228
|
|
|
219
229
|
const stress = () => {
|