nl_tokens: @typedef { Object } FSFacade @property { fs . readdir } readdir @property { fs . stat } stat @property { fs . lstat } lstat Validates and normalizes the options argument
pl_tokens: function normalizeOptions ( options , internalOptions ) { if ( options === null || options === undefined ) { options = { } ; } else if ( typeof options !== 'object' ) { throw new TypeError ( 'options must be an object' ) ; } let recurseDepth , recurseFn , recurseRegExp , recurseGlob , deep = options . deep ; if ( deep === null || deep === undefined ) { recurseDepth = 0 ; } else if ( typeof deep === 'boolean' ) { recurseDepth = deep ? Infinity : 0 ; } else if ( typeof deep === 'number' ) { if ( deep < 0 || isNaN ( deep ) ) { throw new Error ( 'options.deep must be a positive number' ) ; } else if ( Math . floor ( deep ) !== deep ) { throw new Error ( 'options.deep must be an integer' ) ; } else { recurseDepth = deep ; } } else if ( typeof deep === 'function' ) { recurseDepth = Infinity ; recurseFn = deep ; } else if ( deep instanceof RegExp ) { recurseDepth = Infinity ; recurseRegExp = deep ; } else if ( typeof deep === 'string' && deep . length > 0 ) { recurseDepth = Infinity ; recurseGlob = globToRegExp ( deep , { extended : true , globstar : true } ) ; } else { throw new TypeError ( 'options.deep must be a boolean, number, function, regular expression, or glob pattern' ) ; } let filterFn , filterRegExp , filterGlob , filter = options . filter ; if ( filter !== null && filter !== undefined ) { if ( typeof filter === 'function' ) { filterFn = filter ; } else if ( filter instanceof RegExp ) { filterRegExp = filter ; } else if ( typeof filter === 'string' && filter . length > 0 ) { filterGlob = globToRegExp ( <mask> , { extended : true , globstar : true } ) ; } else { throw new TypeError ( 'options.filter must be a function, regular expression, or glob pattern' ) ; } } let sep = options . sep ; if ( sep === null || sep === undefined ) { sep = path . sep ; } else if ( typeof sep !== 'string' ) { throw new TypeError ( 'options.sep must be a string' ) ; } let basePath = options . basePath ; if ( basePath === null || basePath === undefined ) { basePath = '' ; } else if ( typeof basePath === 'string' ) { // Append a path separator to the basePath, if necessary if ( basePath && basePath . substr ( - 1 ) !== sep ) { basePath += sep ; } } else { throw new TypeError ( 'options.basePath must be a string' ) ; } // Convert the basePath to POSIX (forward slashes) // so that glob pattern matching works consistently, even on Windows let posixBasePath = basePath ; if ( posixBasePath && sep !== '/' ) { posixBasePath = posixBasePath . replace ( new RegExp ( '\\' + sep , 'g' ) , '/' ) ; /* istanbul ignore if */ if ( isWindows ) { // Convert Windows root paths (C:\) and UNCs (\\) to POSIX root paths posixBasePath = posixBasePath . replace ( / ^([a-zA-Z]\:\/|\/\/) / , '/' ) ; } } // Determine which facade methods to use let facade ; if ( options . fs === null || options . fs === undefined ) { // The user didn't provide their own facades, so use our internal ones facade = internalOptions . facade ; } else if ( typeof options . fs === 'object' ) { // Merge the internal facade methods with the user-provided `fs` facades facade = Object . assign ( { } , internalOptions . facade ) ; facade . fs = Object . assign ( { } , internalOptions . facade . fs , options . fs ) ; } else { throw new TypeError ( 'options.fs must be an object' ) ; } return { recurseDepth , recurseFn , recurseRegExp , recurseGlob , filterFn , filterRegExp , filterGlob , sep , basePath , posixBasePath , facade , emit : ! ! internalOptions . emit , stats : ! ! internalOptions . stats , } ; }