Last change
on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
784 bytes
|
Line | |
---|
1 | const { promisify } = require('util')
|
---|
2 | const fs = require('fs')
|
---|
3 | const optsArg = opts => {
|
---|
4 | if (!opts)
|
---|
5 | opts = { mode: 0o777, fs }
|
---|
6 | else if (typeof opts === 'object')
|
---|
7 | opts = { mode: 0o777, fs, ...opts }
|
---|
8 | else if (typeof opts === 'number')
|
---|
9 | opts = { mode: opts, fs }
|
---|
10 | else if (typeof opts === 'string')
|
---|
11 | opts = { mode: parseInt(opts, 8), fs }
|
---|
12 | else
|
---|
13 | throw new TypeError('invalid options argument')
|
---|
14 |
|
---|
15 | opts.mkdir = opts.mkdir || opts.fs.mkdir || fs.mkdir
|
---|
16 | opts.mkdirAsync = promisify(opts.mkdir)
|
---|
17 | opts.stat = opts.stat || opts.fs.stat || fs.stat
|
---|
18 | opts.statAsync = promisify(opts.stat)
|
---|
19 | opts.statSync = opts.statSync || opts.fs.statSync || fs.statSync
|
---|
20 | opts.mkdirSync = opts.mkdirSync || opts.fs.mkdirSync || fs.mkdirSync
|
---|
21 | return opts
|
---|
22 | }
|
---|
23 | module.exports = optsArg
|
---|
Note:
See
TracBrowser
for help on using the repository browser.