mirror of
https://github.com/antonmedv/fx
synced 2024-11-05 12:00:46 +00:00
35 lines
620 B
JavaScript
35 lines
620 B
JavaScript
'use strict'
|
|
const fs = require('fs')
|
|
|
|
const skip = Symbol('skip')
|
|
|
|
function select(cb) {
|
|
return json => {
|
|
if (!cb(json)) {
|
|
throw skip
|
|
}
|
|
return json
|
|
}
|
|
}
|
|
|
|
function filter(cb) {
|
|
return json => {
|
|
if (cb(json)) {
|
|
throw skip
|
|
}
|
|
return json
|
|
}
|
|
}
|
|
|
|
function save(json) {
|
|
if (!global.FX_FILENAME) {
|
|
throw "No filename provided.\nTo edit-in-place, specify JSON file as first argument."
|
|
}
|
|
fs.writeFileSync(global.FX_FILENAME, JSON.stringify(json, null, 2))
|
|
return json
|
|
}
|
|
|
|
Object.assign(exports, {skip, select, filter, save})
|
|
Object.assign(global, exports)
|
|
global.std = exports
|