1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 'use strict';
- const defaults = {
- ignore: [],
- encoding: 'utf-8',
- disableGlobs: false,
- allowEmptyPaths: false,
- countMatches: false,
- isRegex: false,
- verbose: false,
- quiet: false,
- dry: false,
- glob: {},
- cwd: null,
- };
- module.exports = function parseConfig(config) {
-
- if (typeof config !== 'object' || config === null) {
- throw new Error('Must specify configuration object');
- }
-
- config.glob = config.glob || {};
-
- const {files, from, to, processor, ignore, encoding} = config;
- if (typeof processor !== 'undefined') {
- if (typeof processor !== 'function' && !Array.isArray(processor)) {
- throw new Error('Processor should be either a function or an array of functions');
- }
- } else {
-
- if (typeof files === 'undefined') {
- throw new Error('Must specify file or files');
- }
- if (typeof from === 'undefined') {
- throw new Error('Must specify string or regex to replace');
- }
- if (typeof to === 'undefined') {
- throw new Error('Must specify a replacement (can be blank string)');
- }
- }
-
- if (!Array.isArray(files)) {
- config.files = [files];
- }
- if (!Array.isArray(ignore)) {
- if (typeof ignore === 'undefined') {
- config.ignore = [];
- }
- else {
- config.ignore = [ignore];
- }
- }
-
- if (typeof encoding !== 'string' || encoding === '') {
- config.encoding = 'utf-8';
- }
-
- return Object.assign({}, defaults, config);
- };
|