-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpills.js
27 lines (21 loc) · 804 Bytes
/
pills.js
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
// Generics to be used in case of need
import * as R from "ramda"
import path from "path"
import fs from 'fs-extra'
import stringify from "json-stringify-pretty-compact"
// Assign `fn` as a callback for promise `pr`
export const then = fn => pr => pr.then(fn);
export const delay = ms => new Promise(res => setTimeout(res, ms))
// Read file as json data
export const read = R.compose(JSON.parse, fs.readFileSync)
// Write json `data` to `file`
export const write = file => data => fs.writeFileSync(
file,
stringify(data, { maxLength: 120 })
)
//// Location of country files
export const fileLocation = (dir, extension) => country => path.resolve(
// Make sure the given folder exists and return it.
R.either(R.curryN(1, fs.ensureDirSync), R.identity)(dir),
R.concat(country, extension)
)