fx 39.1.0 → 39.2.0
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/index.js +10 -21
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -73,6 +73,7 @@ async function transform(json, args, theme) {
|
|
|
73
73
|
return ${jsCode}
|
|
74
74
|
})`
|
|
75
75
|
output = await run(output, fn)
|
|
76
|
+
if (output === skip) break
|
|
76
77
|
} catch (err) {
|
|
77
78
|
await printErr(err)
|
|
78
79
|
}
|
|
@@ -125,12 +126,12 @@ function transpile(code) {
|
|
|
125
126
|
|
|
126
127
|
if (/^@/.test(code)) {
|
|
127
128
|
const jsCode = transpile(code.substring(1))
|
|
128
|
-
return `
|
|
129
|
+
return `map((x, i) => apply(${jsCode}, x, i))`
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
if (/^\?/.test(code)) {
|
|
132
133
|
const jsCode = transpile(code.substring(1))
|
|
133
|
-
return `
|
|
134
|
+
return `filter((x, i) => apply(${jsCode}, x, i))`
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
return code
|
|
@@ -164,21 +165,16 @@ async function run(json, code) {
|
|
|
164
165
|
throw new Error(`Cannot sort ${typeof x}`)
|
|
165
166
|
}
|
|
166
167
|
|
|
168
|
+
function isFalsely(x) {
|
|
169
|
+
return x === false || x === null || x === undefined
|
|
170
|
+
}
|
|
171
|
+
|
|
167
172
|
function filter(fn) {
|
|
168
173
|
return function (x) {
|
|
169
174
|
if (Array.isArray(x)) {
|
|
170
|
-
return x.filter((v, i) => fn(v, i))
|
|
171
|
-
} else if (x !== null && typeof x === 'object') {
|
|
172
|
-
const result = {}
|
|
173
|
-
for (const [k, v] of Object.entries(x)) {
|
|
174
|
-
if (fn(v, k)) {
|
|
175
|
-
result[k] = v
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return result
|
|
179
|
-
} else {
|
|
180
|
-
throw new Error(`Cannot filter ${typeof x}`)
|
|
175
|
+
return x.filter((v, i) => !isFalsely(fn(v, i)))
|
|
181
176
|
}
|
|
177
|
+
return isFalsely(fn(x))? skip : x
|
|
182
178
|
}
|
|
183
179
|
}
|
|
184
180
|
|
|
@@ -186,15 +182,8 @@ async function run(json, code) {
|
|
|
186
182
|
return function (x) {
|
|
187
183
|
if (Array.isArray(x)) {
|
|
188
184
|
return x.map((v, i) => fn(v, i))
|
|
189
|
-
} else if (x !== null && typeof x === 'object') {
|
|
190
|
-
const result = {}
|
|
191
|
-
for (const [k, v] of Object.entries(x)) {
|
|
192
|
-
result[k] = fn(v, k)
|
|
193
|
-
}
|
|
194
|
-
return result
|
|
195
|
-
} else {
|
|
196
|
-
throw new Error(`Cannot map over ${typeof x}`)
|
|
197
185
|
}
|
|
186
|
+
return fn(x)
|
|
198
187
|
}
|
|
199
188
|
}
|
|
200
189
|
|