123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.getWriteFileOptions = exports.writeFileDefaults = exports.getRealpathOptsAndCb = exports.getRealpathOptions = exports.getStatOptsAndCb = exports.getStatOptions = exports.getAppendFileOptsAndCb = exports.getAppendFileOpts = exports.getOpendirOptsAndCb = exports.getOpendirOptions = exports.getReaddirOptsAndCb = exports.getReaddirOptions = exports.getReadFileOptions = exports.getRmOptsAndCb = exports.getRmdirOptions = exports.getDefaultOptsAndCb = exports.getDefaultOpts = exports.optsDefaults = exports.getMkdirOptions = void 0;
- exports.getOptions = getOptions;
- exports.optsGenerator = optsGenerator;
- exports.optsAndCbGenerator = optsAndCbGenerator;
- const constants_1 = require("./constants");
- const encoding_1 = require("../encoding");
- const util_1 = require("./util");
- const mkdirDefaults = {
- mode: 511 /* MODE.DIR */,
- recursive: false,
- };
- const getMkdirOptions = (options) => {
- if (typeof options === 'number')
- return Object.assign({}, mkdirDefaults, { mode: options });
- return Object.assign({}, mkdirDefaults, options);
- };
- exports.getMkdirOptions = getMkdirOptions;
- const ERRSTR_OPTS = tipeof => `Expected options to be either an object or a string, but got ${tipeof} instead`;
- function getOptions(defaults, options) {
- let opts;
- if (!options)
- return defaults;
- else {
- const tipeof = typeof options;
- switch (tipeof) {
- case 'string':
- opts = Object.assign({}, defaults, { encoding: options });
- break;
- case 'object':
- opts = Object.assign({}, defaults, options);
- break;
- default:
- throw TypeError(ERRSTR_OPTS(tipeof));
- }
- }
- if (opts.encoding !== 'buffer')
- (0, encoding_1.assertEncoding)(opts.encoding);
- return opts;
- }
- function optsGenerator(defaults) {
- return options => getOptions(defaults, options);
- }
- function optsAndCbGenerator(getOpts) {
- return (options, callback) => typeof options === 'function' ? [getOpts(), options] : [getOpts(options), (0, util_1.validateCallback)(callback)];
- }
- exports.optsDefaults = {
- encoding: 'utf8',
- };
- exports.getDefaultOpts = optsGenerator(exports.optsDefaults);
- exports.getDefaultOptsAndCb = optsAndCbGenerator(exports.getDefaultOpts);
- const rmdirDefaults = {
- recursive: false,
- };
- const getRmdirOptions = (options) => {
- return Object.assign({}, rmdirDefaults, options);
- };
- exports.getRmdirOptions = getRmdirOptions;
- const getRmOpts = optsGenerator(exports.optsDefaults);
- exports.getRmOptsAndCb = optsAndCbGenerator(getRmOpts);
- const readFileOptsDefaults = {
- flag: 'r',
- };
- exports.getReadFileOptions = optsGenerator(readFileOptsDefaults);
- const readdirDefaults = {
- encoding: 'utf8',
- recursive: false,
- withFileTypes: false,
- };
- exports.getReaddirOptions = optsGenerator(readdirDefaults);
- exports.getReaddirOptsAndCb = optsAndCbGenerator(exports.getReaddirOptions);
- const opendirDefaults = {
- encoding: 'utf8',
- bufferSize: 32,
- recursive: false,
- };
- exports.getOpendirOptions = optsGenerator(opendirDefaults);
- exports.getOpendirOptsAndCb = optsAndCbGenerator(exports.getOpendirOptions);
- const appendFileDefaults = {
- encoding: 'utf8',
- mode: 438 /* MODE.DEFAULT */,
- flag: constants_1.FLAGS[constants_1.FLAGS.a],
- };
- exports.getAppendFileOpts = optsGenerator(appendFileDefaults);
- exports.getAppendFileOptsAndCb = optsAndCbGenerator(exports.getAppendFileOpts);
- const statDefaults = {
- bigint: false,
- };
- const getStatOptions = (options = {}) => Object.assign({}, statDefaults, options);
- exports.getStatOptions = getStatOptions;
- const getStatOptsAndCb = (options, callback) => typeof options === 'function' ? [(0, exports.getStatOptions)(), options] : [(0, exports.getStatOptions)(options), (0, util_1.validateCallback)(callback)];
- exports.getStatOptsAndCb = getStatOptsAndCb;
- const realpathDefaults = exports.optsDefaults;
- exports.getRealpathOptions = optsGenerator(realpathDefaults);
- exports.getRealpathOptsAndCb = optsAndCbGenerator(exports.getRealpathOptions);
- exports.writeFileDefaults = {
- encoding: 'utf8',
- mode: 438 /* MODE.DEFAULT */,
- flag: constants_1.FLAGS[constants_1.FLAGS.w],
- };
- exports.getWriteFileOptions = optsGenerator(exports.writeFileDefaults);
- //# sourceMappingURL=options.js.map
|