-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.js
39 lines (30 loc) · 782 Bytes
/
sync.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
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require('fs')
const FakePromise = require('promise-faker')
const {factory} = require('promise.extra')
const {
ReaderBase, checkOptions, NO_EXT, PARSERS
} = require('./src/base')
const extra = factory(FakePromise)
class SyncReader extends ReaderBase {
constructor (options) {
super(options, FakePromise, extra)
}
_exists (abspath) {
try {
fs.accessSync(abspath, fs.constants.R_OK)
return true
} catch (err) {
return false
}
}
_readFile (abspath) {
return fs.readFileSync(abspath).toString()
}
_teardown (promise) {
return this._promise.resolve(promise, true)
}
}
const parse = options => new SyncReader(checkOptions(options)).parse()
parse.NO_EXT = NO_EXT
parse.PARSERS = PARSERS
module.exports = parse