fx 39.0.4 → 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 +17 -20
- 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,7 +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))`
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (/^\?/.test(code)) {
|
|
133
|
+
const jsCode = transpile(code.substring(1))
|
|
134
|
+
return `filter((x, i) => apply(${jsCode}, x, i))`
|
|
129
135
|
}
|
|
130
136
|
|
|
131
137
|
return code
|
|
@@ -159,21 +165,16 @@ async function run(json, code) {
|
|
|
159
165
|
throw new Error(`Cannot sort ${typeof x}`)
|
|
160
166
|
}
|
|
161
167
|
|
|
168
|
+
function isFalsely(x) {
|
|
169
|
+
return x === false || x === null || x === undefined
|
|
170
|
+
}
|
|
171
|
+
|
|
162
172
|
function filter(fn) {
|
|
163
173
|
return function (x) {
|
|
164
174
|
if (Array.isArray(x)) {
|
|
165
|
-
return x.filter((v, i) => fn(v, i))
|
|
166
|
-
} else if (x !== null && typeof x === 'object') {
|
|
167
|
-
const result = {}
|
|
168
|
-
for (const [k, v] of Object.entries(x)) {
|
|
169
|
-
if (fn(v, k)) {
|
|
170
|
-
result[k] = v
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return result
|
|
174
|
-
} else {
|
|
175
|
-
throw new Error(`Cannot filter ${typeof x}`)
|
|
175
|
+
return x.filter((v, i) => !isFalsely(fn(v, i)))
|
|
176
176
|
}
|
|
177
|
+
return isFalsely(fn(x))? skip : x
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
|
|
@@ -181,15 +182,8 @@ async function run(json, code) {
|
|
|
181
182
|
return function (x) {
|
|
182
183
|
if (Array.isArray(x)) {
|
|
183
184
|
return x.map((v, i) => fn(v, i))
|
|
184
|
-
} else if (x !== null && typeof x === 'object') {
|
|
185
|
-
const result = {}
|
|
186
|
-
for (const [k, v] of Object.entries(x)) {
|
|
187
|
-
result[k] = fn(v, k)
|
|
188
|
-
}
|
|
189
|
-
return result
|
|
190
|
-
} else {
|
|
191
|
-
throw new Error(`Cannot map over ${typeof x}`)
|
|
192
185
|
}
|
|
186
|
+
return fn(x)
|
|
193
187
|
}
|
|
194
188
|
}
|
|
195
189
|
|
|
@@ -720,7 +714,10 @@ function themes(id) {
|
|
|
720
714
|
'6': ['', '38;5;69', '38;5;78', '38;5;221', '38;5;203', '38;5;243'],
|
|
721
715
|
'7': ['', '1;38;5;42', '1;38;5;213', '1;38;5;201', '1;38;5;201', '38;5;243'],
|
|
722
716
|
'8': ['', '1;38;5;51', '38;5;195', '38;5;123', '38;5;50', '38;5;243'],
|
|
717
|
+
'9': ['', '1;38;5;39', '38;5;49', '38;5;220', '38;5;205', '38;5;243'],
|
|
718
|
+
'🔥': ['1;38;5;208', '1;38;5;202', '38;5;214', '38;5;202', '38;5;196', '38;5;243'],
|
|
723
719
|
'🔵': ['1;38;5;33', '38;5;33', '', '', '', ''],
|
|
720
|
+
'🟣': ['', '1;38;5;141', '38;5;183', '38;5;219', '38;5;81', '38;5;243'],
|
|
724
721
|
'🥝': ['38;5;179', '1;38;5;154', '38;5;82', '38;5;226', '38;5;226', '38;5;230'],
|
|
725
722
|
}
|
|
726
723
|
return themes[id] || themes['1']
|