forked from VimCommando/fx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd.js
More file actions
34 lines (29 loc) · 620 Bytes
/
std.js
File metadata and controls
34 lines (29 loc) · 620 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'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