functionalscript 0.0.203 → 0.0.210
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/function/index.js +2 -2
- package/json/index.js +43 -36
- package/json/test.js +22 -3
- package/module-manager/README.md +16 -11
- package/module-manager/index.js +1 -1
- package/object/index.js +18 -2
- package/object/test.js +13 -0
- package/package.json +1 -1
- package/result/index.js +17 -0
- package/sequence/asyncIterable/index.js +1 -1
- package/sequence/index.js +1 -1
- package/sequence/iterable/index.js +1 -1
- package/sequence/iterable/test.js +1 -1
- package/test.js +8 -1
package/function/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/** @type {<X, O>(f: Func<X, O>) => <I>(g: Func<I, X>) => Func<I, O>} */
|
|
8
|
-
const
|
|
8
|
+
const compose = f => g => x => f(g(x))
|
|
9
9
|
|
|
10
10
|
/** @type {<T>(value: T) => T} */
|
|
11
11
|
const id = value => value
|
|
@@ -14,5 +14,5 @@ module.exports = {
|
|
|
14
14
|
/** @readonly */
|
|
15
15
|
id,
|
|
16
16
|
/** @readonly */
|
|
17
|
-
|
|
17
|
+
compose,
|
|
18
18
|
}
|
package/json/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const seq = require('../sequence')
|
|
2
|
-
const map = require('../map')
|
|
3
2
|
const op = require('../sequence/operator')
|
|
4
3
|
const object = require('../object')
|
|
5
4
|
const array = require('../sequence/array')
|
|
5
|
+
const { compose: combine } = require('../function')
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {{
|
|
@@ -22,9 +22,9 @@ const addProperty = value => {
|
|
|
22
22
|
if (result === undefined) { return value }
|
|
23
23
|
const srcObject = (src === undefined || src === null || typeof src !== 'object' || src instanceof Array) ? {} : src
|
|
24
24
|
const [name, tail] = result
|
|
25
|
-
return { ...srcObject, [name]: f(tail)(
|
|
25
|
+
return { ...srcObject, [name]: f(tail)(object.at(name)(srcObject)) }
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return combine(f)(array.sequence)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/** @type {(_: string) => seq.Sequence<string>} */
|
|
@@ -42,12 +42,6 @@ const falseSerialize = seq.list('false')
|
|
|
42
42
|
/** @type {(_: boolean) => seq.Sequence<string>} */
|
|
43
43
|
const boolSerialize = value => value ? trueSerialize : falseSerialize
|
|
44
44
|
|
|
45
|
-
/** @type {(kv: readonly[string, Json]) => seq.Sequence<string>} */
|
|
46
|
-
const propertySerialize = ([k, v]) => seq.concat(
|
|
47
|
-
stringSerialize(k),
|
|
48
|
-
colon,
|
|
49
|
-
serialize(v))
|
|
50
|
-
|
|
51
45
|
const colon = seq.list(':')
|
|
52
46
|
const comma = seq.list(',')
|
|
53
47
|
|
|
@@ -74,33 +68,46 @@ const objectList = list('{')('}')
|
|
|
74
68
|
|
|
75
69
|
const arrayList = list('[')(']')
|
|
76
70
|
|
|
77
|
-
/** @
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** @type {(
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
71
|
+
/** @typedef {object.Entry<Json>} Entry*/
|
|
72
|
+
|
|
73
|
+
/** @typedef {(seq.Sequence<Entry>)} Entries */
|
|
74
|
+
|
|
75
|
+
/** @typedef {(entries: Entries) => Entries} MapEntries */
|
|
76
|
+
|
|
77
|
+
/** @type {(mapEntries: MapEntries) => (value: Json) => seq.Sequence<string>} */
|
|
78
|
+
const serialize = sort => {
|
|
79
|
+
/** @type {(kv: readonly[string, Json]) => seq.Sequence<string>} */
|
|
80
|
+
const propertySerialize = ([k, v]) => seq.concat(
|
|
81
|
+
stringSerialize(k),
|
|
82
|
+
colon,
|
|
83
|
+
f(v))
|
|
84
|
+
/** @type {(object: Object) => seq.Sequence<string>} */
|
|
85
|
+
const objectSerialize = input => {
|
|
86
|
+
const entries = object.entries(input)
|
|
87
|
+
const sortedEntries = sort(entries)
|
|
88
|
+
const serializedEntries = seq.map(propertySerialize)(sortedEntries)
|
|
89
|
+
return objectList(serializedEntries)
|
|
90
|
+
}
|
|
91
|
+
/** @type {(input: Array) => seq.Sequence<string>} */
|
|
92
|
+
const arraySerialize = input => {
|
|
93
|
+
const sequence = array.sequence(input)
|
|
94
|
+
const serializedEntries = seq.map(f)(sequence)
|
|
95
|
+
return arrayList(serializedEntries)
|
|
96
|
+
}
|
|
97
|
+
/** @type {(value: Json) => seq.Sequence < string >} */
|
|
98
|
+
const f = value => {
|
|
99
|
+
switch (typeof value) {
|
|
100
|
+
case 'boolean': { return boolSerialize(value) }
|
|
101
|
+
case 'number': { return numberSerialize(value) }
|
|
102
|
+
case 'string': { return stringSerialize(value) }
|
|
103
|
+
default: {
|
|
104
|
+
if (value === null) { return nullSerialize }
|
|
105
|
+
if (value instanceof Array) { return arraySerialize(value) }
|
|
106
|
+
return objectSerialize(value)
|
|
107
|
+
}
|
|
102
108
|
}
|
|
103
109
|
}
|
|
110
|
+
return f
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
/**
|
|
@@ -109,9 +116,9 @@ const serialize = value => {
|
|
|
109
116
|
* The standard `JSON.stringify` rules determines by
|
|
110
117
|
* https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
|
|
111
118
|
*
|
|
112
|
-
* @type {(value: Json) => string}
|
|
119
|
+
* @type {(mapEntries: MapEntries) => (value: Json) => string}
|
|
113
120
|
*/
|
|
114
|
-
const stringify = value => seq.join('')(serialize(value))
|
|
121
|
+
const stringify = sort => value => seq.join('')(serialize(sort)(value))
|
|
115
122
|
|
|
116
123
|
/** @type {(value: string) => Json} */
|
|
117
124
|
const parse = value => JSON.parse(value)
|
package/json/test.js
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
const json = require('.')
|
|
2
|
+
const { sort } = require('../object')
|
|
3
|
+
const { id } = require('../function')
|
|
2
4
|
|
|
3
5
|
if (json.addProperty("Hello")([])({}) !== "Hello") { throw 'error' }
|
|
4
6
|
|
|
5
7
|
{
|
|
6
|
-
const x = json.stringify(json.addProperty("Hello")(['a'])({}))
|
|
8
|
+
const x = json.stringify(sort)(json.addProperty("Hello")(['a'])({}))
|
|
7
9
|
if (x !== '{"a":"Hello"}') { throw x }
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
{
|
|
11
|
-
const x = json.stringify(json.addProperty("Hello")(['a'])({
|
|
13
|
+
const x = json.stringify(id)(json.addProperty("Hello")(['a'])({}))
|
|
14
|
+
if (x !== '{"a":"Hello"}') { throw x }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
{
|
|
18
|
+
const x = json.stringify(sort)(json.addProperty("Hello")(['a'])({c:[],b:12}))
|
|
12
19
|
if (x !== '{"a":"Hello","b":12,"c":[]}') { throw x }
|
|
13
20
|
}
|
|
14
21
|
|
|
22
|
+
{
|
|
23
|
+
const x = json.stringify(id)(json.addProperty("Hello")(['a'])({ c: [], b: 12 }))
|
|
24
|
+
if (x !== '{"c":[],"b":12,"a":"Hello"}') { throw x }
|
|
25
|
+
}
|
|
26
|
+
|
|
15
27
|
{
|
|
16
28
|
const _0 = { a: { y: [24] }, c: [], b: 12 }
|
|
17
29
|
const _1 = json.addProperty("Hello")(['a', 'x'])(_0)
|
|
18
|
-
const _2 = json.stringify(_1)
|
|
30
|
+
const _2 = json.stringify(sort)(_1)
|
|
19
31
|
if (_2 !== '{"a":{"x":"Hello","y":[24]},"b":12,"c":[]}') { throw _2 }
|
|
20
32
|
}
|
|
33
|
+
|
|
34
|
+
{
|
|
35
|
+
const _0 = { a: { y: [24] }, c: [], b: 12 }
|
|
36
|
+
const _1 = json.addProperty("Hello")(['a', 'x'])(_0)
|
|
37
|
+
const _2 = json.stringify(id)(_1)
|
|
38
|
+
if (_2 !== '{"a":{"y":[24],"x":"Hello"},"c":[],"b":12}') { throw _2 }
|
|
39
|
+
}
|
package/module-manager/README.md
CHANGED
|
@@ -5,26 +5,31 @@
|
|
|
5
5
|
```js
|
|
6
6
|
/** @typedef {(packageName: string) => PackageMap|Package|undefined} PackageMap */
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* }
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {readonly[
|
|
10
|
+
* string,
|
|
11
|
+
* PackageMap,
|
|
12
|
+
* (fileName: string) => string|undefined
|
|
13
|
+
* ]} Package
|
|
14
14
|
*/
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Runner IO
|
|
18
18
|
|
|
19
|
+
The main target of this design is to simplify `RunnerIo` as much as possible.
|
|
20
|
+
|
|
19
21
|
```js
|
|
20
|
-
/**
|
|
21
|
-
* @
|
|
22
|
+
/**
|
|
23
|
+
* @template T
|
|
24
|
+
* @typedef {readonly[Result<unknown, Error>, Require<T>]} RunnerResult
|
|
22
25
|
*/
|
|
23
|
-
```
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
/** @typedef {<T>(require: Require<T>) => (source: string) => RunnerResult<T>} RunnerIo */
|
|
28
|
+
|
|
26
29
|
/**
|
|
27
30
|
* @template T
|
|
28
|
-
* @typedef {(
|
|
31
|
+
* @typedef {readonly[(path: string) => RunnerResult<T>, T]} Require<T>
|
|
29
32
|
*/
|
|
30
33
|
```
|
|
34
|
+
|
|
35
|
+
`Require` is using a `Package` and it contains also `RunnerIo` to provide sources also it contains
|
package/module-manager/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const array = require('../sequence/array')
|
|
2
|
-
const { combine } = require('../function')
|
|
2
|
+
const { compose: combine } = require('../function')
|
|
3
3
|
const option = require('../option')
|
|
4
4
|
const { head, last, splitLast, splitFirst } = array
|
|
5
5
|
const iter = require('../sequence/iterable')
|
package/object/index.js
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
const array = require('../sequence/array')
|
|
2
2
|
const seq = require('../sequence')
|
|
3
|
+
const map = require('../map')
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @template T
|
|
6
7
|
* @typedef {{
|
|
7
8
|
* readonly [k in string]: T
|
|
8
|
-
* }}
|
|
9
|
+
* }} Map
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* @template T
|
|
14
|
+
* @typedef {readonly[string, T]} Entry
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** @type {<T>(object: Map<T>) => seq.Sequence<Entry<T>>} */
|
|
12
18
|
const entries = object => array.sequence(Object.entries(object))
|
|
13
19
|
|
|
20
|
+
/** @type {(name: string) => <T>(object: Map<T>) => T|undefined} */
|
|
21
|
+
const at = name => object => Object.getOwnPropertyDescriptor(object, name)?.value
|
|
22
|
+
|
|
23
|
+
/** @type {<T>(entries: seq.Sequence<Entry<T>>) => seq.Sequence<Entry<T>>} */
|
|
24
|
+
const sort = entries => map.fromEntries(entries).entries
|
|
25
|
+
|
|
14
26
|
module.exports = {
|
|
15
27
|
/** @readonly */
|
|
16
28
|
entries,
|
|
29
|
+
/** @readonly */
|
|
30
|
+
at,
|
|
31
|
+
/** @readonly */
|
|
32
|
+
sort,
|
|
17
33
|
}
|
package/object/test.js
ADDED
package/package.json
CHANGED
package/result/index.js
ADDED
package/sequence/index.js
CHANGED
package/test.js
CHANGED
|
@@ -6,6 +6,7 @@ require('./sequence/iterable/test')
|
|
|
6
6
|
require('./sequence/asyncIterable/test')
|
|
7
7
|
require('./module-manager/test')
|
|
8
8
|
require('./json/test')
|
|
9
|
+
require('./object/test')
|
|
9
10
|
|
|
10
11
|
/** @type {() => never} */
|
|
11
12
|
const assert = () => { throw 'assert' }
|
|
@@ -104,6 +105,12 @@ const assert_if = c => { if (c) { throw 'assert_if' } }
|
|
|
104
105
|
//const c = o['isPrototypeOf']
|
|
105
106
|
//const c = o['propertyIsEnumerable']
|
|
106
107
|
//const c = o['toString']
|
|
107
|
-
const c = o['valueOf']
|
|
108
|
+
const c = o['valueOf']
|
|
108
109
|
console.log(c)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
{
|
|
113
|
+
const x = { 'a': 12 }
|
|
114
|
+
const c = Object.getOwnPropertyDescriptor(x, 'constructor')
|
|
115
|
+
const a = Object.getOwnPropertyDescriptor(x, 'a')
|
|
109
116
|
}
|