functionalscript 0.0.272 → 0.0.274
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/package/index.js +2 -2
- package/commonjs/path/index.js +7 -7
- package/commonjs/path/test.js +39 -4
- package/package.json +1 -1
- package/types/list/test.js +10 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const json = require('../../json')
|
|
2
2
|
const dependencies = require('./dependencies')
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
5
|
* @typedef {{
|
|
6
6
|
* readonly name: string
|
|
7
7
|
* readonly version: string
|
|
8
8
|
* readonly dependencies?: dependencies.DependenciesJson
|
|
9
|
-
* }} PackageJson
|
|
9
|
+
* }} PackageJson
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
/** @type {(j: json.Unknown) => j is PackageJson} */
|
package/commonjs/path/index.js
CHANGED
|
@@ -46,22 +46,22 @@ const normItems = items => {
|
|
|
46
46
|
|
|
47
47
|
/** @type {(local: string) => (path: string) => LocalPath|undefined} */
|
|
48
48
|
const parseLocal = local => {
|
|
49
|
-
/** @type {(path: string) => readonly[boolean, list.List<string>]} */
|
|
49
|
+
/** @type {(path: string) => readonly[boolean, boolean, list.List<string>]} */
|
|
50
50
|
const fSeq = path => {
|
|
51
51
|
const pathSeq = split(path)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const dir = [undefined, '', '.', '..'].includes(pathSeq[pathSeq.length - 1])
|
|
53
|
+
return /** @type {readonly (string|undefined)[]} */(['.', '..']).includes(list.first(undefined)(pathSeq)) ?
|
|
54
|
+
[false, dir, list.flat([split(local), pathSeq])] :
|
|
55
|
+
[true, dir, pathSeq]
|
|
56
56
|
}
|
|
57
57
|
/** @type {(path: string) => LocalPath|undefined} */
|
|
58
58
|
const f = path => {
|
|
59
|
-
const [external, items] = fSeq(path)
|
|
59
|
+
const [external, dir, items] = fSeq(path)
|
|
60
60
|
const n = normItems(items)
|
|
61
61
|
if (n === undefined) { return undefined }
|
|
62
62
|
return {
|
|
63
63
|
external,
|
|
64
|
-
dir
|
|
64
|
+
dir,
|
|
65
65
|
items: list.toArray(n[0])
|
|
66
66
|
}
|
|
67
67
|
}
|
package/commonjs/path/test.js
CHANGED
|
@@ -30,7 +30,7 @@ const stringify = g => {
|
|
|
30
30
|
|
|
31
31
|
{
|
|
32
32
|
const result = _.parseLocal('a')('')
|
|
33
|
-
if (stringify(result) !== '{"external":true,"dir":
|
|
33
|
+
if (stringify(result) !== '{"external":true,"dir":true,"items":[]}') { throw result }
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
{
|
|
@@ -48,6 +48,11 @@ const stringify = g => {
|
|
|
48
48
|
if (stringify(result) !== '{"external":true,"dir":false,"items":["a","c"]}') { throw result }
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
{
|
|
52
|
+
const result = _.parseLocal('')('./x/..')
|
|
53
|
+
if (stringify(result) !== '{"external":false,"dir":true,"items":[]}') { throw result }
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
{
|
|
52
57
|
if (_.parseGlobal(() => undefined)(false)(['a', 'b']) !== undefined) { throw 'error' }
|
|
53
58
|
if (_.parseGlobal(() => undefined)(false)(['b']) !== undefined) { throw 'error' }
|
|
@@ -91,15 +96,45 @@ const stringify = g => {
|
|
|
91
96
|
const path = `node_modules/${x}`
|
|
92
97
|
return at(path)(packages) !== undefined ? path : undefined
|
|
93
98
|
},
|
|
94
|
-
file:
|
|
99
|
+
file: path => at(path)({
|
|
100
|
+
'index.js': 'return "index.js"',
|
|
101
|
+
'x/index.js': 'return "x/index.js"',
|
|
102
|
+
'x.js': 'return "x.js"',
|
|
103
|
+
})
|
|
95
104
|
},
|
|
96
105
|
'node_modules/z': {
|
|
97
106
|
dependency: () => todo(),
|
|
98
107
|
file: path => at(path)({ 'a/c/index.js': 'return "a/c"' }),
|
|
99
108
|
}
|
|
100
109
|
}
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
{
|
|
111
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))('')('a/b')('z/a/c'))
|
|
112
|
+
if (result !== '{"package":"node_modules/z","file":"a/c/index.js","source":"return \\"a/c\\""}') { throw result }
|
|
113
|
+
}
|
|
114
|
+
{
|
|
115
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))('')('a/b')('../..'))
|
|
116
|
+
if (result !== '{"package":"","file":"index.js","source":"return \\"index.js\\""}') { throw result }
|
|
117
|
+
}
|
|
118
|
+
{
|
|
119
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))('')('')('./x'))
|
|
120
|
+
if (result !== '{"package":"","file":"x.js","source":"return \\"x.js\\""}') { throw result }
|
|
121
|
+
}
|
|
122
|
+
{
|
|
123
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))('')('')('./x.js'))
|
|
124
|
+
if (result !== '{"package":"","file":"x.js","source":"return \\"x.js\\""}') { throw result }
|
|
125
|
+
}
|
|
126
|
+
{
|
|
127
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))('')('')('./x/'))
|
|
128
|
+
if (result !== '{"package":"","file":"x/index.js","source":"return \\"x/index.js\\""}') { throw result }
|
|
129
|
+
}
|
|
130
|
+
{
|
|
131
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))('')('x/a')('../'))
|
|
132
|
+
if (result !== '{"package":"","file":"x/index.js","source":"return \\"x/index.js\\""}') { throw result }
|
|
133
|
+
}
|
|
134
|
+
{
|
|
135
|
+
const result = stringify(_.parseAndFind(p => at(p)(packages))('')('x/a')('..'))
|
|
136
|
+
if (result !== '{"package":"","file":"x/index.js","source":"return \\"x/index.js\\""}') { throw result }
|
|
137
|
+
}
|
|
103
138
|
}
|
|
104
139
|
|
|
105
140
|
{
|
package/package.json
CHANGED
package/types/list/test.js
CHANGED
|
@@ -58,6 +58,11 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
58
58
|
if (result !== '[]') { throw result }
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
{
|
|
62
|
+
const result = _.find(undefined)(x => x % 2 === 0)([1, 3, 5, 7])
|
|
63
|
+
if (result !== undefined) { throw result }
|
|
64
|
+
}
|
|
65
|
+
|
|
61
66
|
{
|
|
62
67
|
const result = _.find(undefined)(x => x % 2 === 0)([1, 2, 3, 4])
|
|
63
68
|
if (result !== 2) { throw result }
|
|
@@ -119,6 +124,11 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
119
124
|
if (result !== '') { throw result }
|
|
120
125
|
}
|
|
121
126
|
|
|
127
|
+
{
|
|
128
|
+
const result = _.join(' ')(['hello', 'world', '!'])
|
|
129
|
+
if (result !== 'hello world !') { throw result }
|
|
130
|
+
}
|
|
131
|
+
|
|
122
132
|
{
|
|
123
133
|
const result = stringify(_.entries([]))
|
|
124
134
|
if (result !== '[]') { throw result }
|