functionalscript 0.0.272 → 0.0.277
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/README.md +1 -1
- 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/test.js +1 -0
- package/types/array/index.js +17 -22
- package/types/array/test.js +94 -0
- package/types/list/test.js +10 -0
package/README.md
CHANGED
|
@@ -161,7 +161,7 @@ Expressions could fall under these categories:
|
|
|
161
161
|
- Relations Operators: `in`, `instanceof`.
|
|
162
162
|
- Member Operators: `.`, `[]`.
|
|
163
163
|
|
|
164
|
-
Note: the `.` member operator has prohibitted property names, such as `constructor` and `push`. To access such properties, it's recommeded to use the
|
|
164
|
+
Note: the `.` member operator has prohibitted property names, such as `constructor` and `push`. To access such properties, it's recommeded to use the [Object.getOwnPropertyDescriptor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor) function.
|
|
165
165
|
|
|
166
166
|
## 4. Arrow Functions
|
|
167
167
|
|
|
@@ -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/test.js
CHANGED
package/types/array/index.js
CHANGED
|
@@ -3,53 +3,48 @@ const seq = require('../list')
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @template T
|
|
6
|
-
* @typedef {readonly
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @template T
|
|
11
|
-
* @typedef {readonly [T]} Array1
|
|
6
|
+
* @typedef {readonly[T]} Array1
|
|
12
7
|
*/
|
|
13
8
|
|
|
14
9
|
/** @typedef {0} Index1 */
|
|
15
10
|
|
|
16
11
|
/**
|
|
17
12
|
* @template T
|
|
18
|
-
* @typedef {readonly
|
|
13
|
+
* @typedef {readonly[T, T]} Array2
|
|
19
14
|
*/
|
|
20
15
|
|
|
21
16
|
/**
|
|
22
17
|
* @template T0
|
|
23
18
|
* @template T1
|
|
24
|
-
* @typedef {readonly
|
|
19
|
+
* @typedef {readonly[T0, T1]} Tuple2
|
|
25
20
|
*/
|
|
26
21
|
|
|
27
22
|
/** @typedef {0|1} Index2 */
|
|
28
23
|
|
|
29
24
|
/**
|
|
30
25
|
* @template T
|
|
31
|
-
* @typedef {readonly
|
|
26
|
+
* @typedef {readonly[T, T, T]} Array3
|
|
32
27
|
*/
|
|
33
28
|
|
|
34
29
|
/**
|
|
35
30
|
* @template T0
|
|
36
31
|
* @template T1
|
|
37
32
|
* @template T2
|
|
38
|
-
* @typedef {readonly
|
|
33
|
+
* @typedef {readonly[T0, T1, T2]} Tuple3
|
|
39
34
|
*/
|
|
40
35
|
|
|
41
36
|
/** @typedef {0|1|2} Index3 */
|
|
42
37
|
|
|
43
38
|
/**
|
|
44
39
|
* @template T
|
|
45
|
-
* @typedef {readonly
|
|
40
|
+
* @typedef {readonly[T, T, T, T]} Array4
|
|
46
41
|
*/
|
|
47
42
|
|
|
48
43
|
/** @typedef {0|1|2|3} Index4 */
|
|
49
44
|
|
|
50
45
|
/**
|
|
51
46
|
* @template T
|
|
52
|
-
* @typedef {readonly
|
|
47
|
+
* @typedef {readonly[T, T, T, T, T]} Array5
|
|
53
48
|
*/
|
|
54
49
|
|
|
55
50
|
/**
|
|
@@ -59,40 +54,40 @@ const seq = require('../list')
|
|
|
59
54
|
|
|
60
55
|
/** @typedef {0|1|2|3|4} Index5 */
|
|
61
56
|
|
|
62
|
-
/** @type {<T>(_:
|
|
57
|
+
/** @type {<T>(_: readonly T[]) => readonly T[]} */
|
|
63
58
|
const uncheckTail = a => a.slice(1)
|
|
64
59
|
|
|
65
|
-
/** @type {<T>(_:
|
|
60
|
+
/** @type {<T>(_: readonly T[]) => readonly T[]} */
|
|
66
61
|
const uncheckHead = a => a.slice(0, -1)
|
|
67
62
|
|
|
68
|
-
/** @type {<T>(_:
|
|
63
|
+
/** @type {<T>(_: readonly T[]) => T|undefined} */
|
|
69
64
|
const first = a => a[0]
|
|
70
65
|
|
|
71
|
-
/** @type {<T>(_:
|
|
66
|
+
/** @type {<T>(_: readonly T[]) => T|undefined} */
|
|
72
67
|
const last = a => a[a.length - 1]
|
|
73
68
|
|
|
74
|
-
/** @type {<T>(_:
|
|
69
|
+
/** @type {<T>(_: readonly T[]) => readonly T[] | undefined} */
|
|
75
70
|
const tail = a => a.length === 0 ? undefined : uncheckTail(a)
|
|
76
71
|
|
|
77
|
-
/** @type {<T>(_:
|
|
72
|
+
/** @type {<T>(_: readonly T[]) => readonly[T, readonly T[]]|undefined} */
|
|
78
73
|
const splitFirst = a => {
|
|
79
74
|
/** @typedef {typeof a[0]} T*/
|
|
80
|
-
/** @type {(_: T) => readonly
|
|
75
|
+
/** @type {(_: T) => readonly[T, readonly T[]]} */
|
|
81
76
|
const split = first => [first, uncheckTail(a)]
|
|
82
77
|
return option.map(split)(a[0])
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
/** @type {<T>(_:
|
|
80
|
+
/** @type {<T>(_: readonly T[]) => readonly T[]|undefined} */
|
|
86
81
|
const head = a => a.length === 0 ? undefined : uncheckHead(a)
|
|
87
82
|
|
|
88
|
-
/** @type {<T>(_:
|
|
83
|
+
/** @type {<T>(_: readonly T[]) => readonly[readonly T[], T]|undefined} */
|
|
89
84
|
const splitLast = a => {
|
|
90
85
|
const lastA = last(a)
|
|
91
86
|
if (lastA === undefined) { return undefined }
|
|
92
87
|
return [uncheckHead(a), lastA]
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
/** @type {(index: number) => <T>(a:
|
|
90
|
+
/** @type {(index: number) => <T>(a: readonly T[]) => readonly[T]|undefined} */
|
|
96
91
|
const at = index => a => index < a.length ? [a[index]] : undefined
|
|
97
92
|
|
|
98
93
|
module.exports = {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const _ = require('.')
|
|
2
|
+
const json = require('../../json')
|
|
3
|
+
const { sort } = require('../object')
|
|
4
|
+
|
|
5
|
+
/** @type {(a: readonly json.Unknown[]) => string} */
|
|
6
|
+
const stringify = a => json.stringify(sort)(a)
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
const result = stringify([1, 20, 300])
|
|
10
|
+
if (result !== '[1,20,300]') { throw result }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
{
|
|
14
|
+
const result = _.at(2)([1, 20, 300])
|
|
15
|
+
if (result === undefined) {throw result}
|
|
16
|
+
if (result[0] !== 300) { throw result }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
{
|
|
20
|
+
const result = _.at(3)([1, 20, 300])
|
|
21
|
+
if (result !== undefined) {throw result}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
{
|
|
25
|
+
const result = _.first([1, 20, 300])
|
|
26
|
+
if (result !== 1) { throw result }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
{
|
|
30
|
+
const result = _.first([])
|
|
31
|
+
if (result !== undefined) {throw result}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
{
|
|
35
|
+
const result = _.last([1, 20, 300])
|
|
36
|
+
if (result !== 300) { throw result }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
{
|
|
40
|
+
const result = _.last([])
|
|
41
|
+
if (result !== undefined) {throw result}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
const result = _.head([1, 20, 300])
|
|
46
|
+
if (result === undefined) {throw result}
|
|
47
|
+
const str = stringify(result)
|
|
48
|
+
if (str !== '[1,20]') { throw str }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
{
|
|
52
|
+
const result = _.head([])
|
|
53
|
+
if (result !== undefined) {throw result}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
{
|
|
57
|
+
const result = _.tail([1, 20, 300])
|
|
58
|
+
if (result === undefined) {throw result}
|
|
59
|
+
const str = stringify(result)
|
|
60
|
+
if (str !== '[20,300]') { throw str }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
{
|
|
64
|
+
const result = _.tail([])
|
|
65
|
+
if (result !== undefined) {throw result}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
{
|
|
69
|
+
const result = _.splitFirst([1, 20, 300])
|
|
70
|
+
if (result === undefined) {throw result}
|
|
71
|
+
const str = stringify(result)
|
|
72
|
+
if (str !== '[1,[20,300]]') { throw str }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
const result = _.splitFirst([])
|
|
77
|
+
if (result !== undefined) {throw result}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
{
|
|
81
|
+
const result = _.splitLast([1, 20, 300])
|
|
82
|
+
if (result === undefined) {throw result}
|
|
83
|
+
const str = stringify(result)
|
|
84
|
+
if (str !== '[[1,20],300]') { throw str }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
const result = _.splitLast([])
|
|
89
|
+
if (result !== undefined) {throw result}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = {
|
|
93
|
+
|
|
94
|
+
}
|
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 }
|