pax_global_header00006660000000000000000000000064135057033340014515gustar00rootroot0000000000000052 comment=bffbe3282621c39d28dc6aa2219d0b8c917a7594 dir-glob-3.0.1/000077500000000000000000000000001350570333400132155ustar00rootroot00000000000000dir-glob-3.0.1/.editorconfig000066400000000000000000000002571350570333400156760ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 dir-glob-3.0.1/.gitattributes000066400000000000000000000000231350570333400161030ustar00rootroot00000000000000* text=auto eol=lf dir-glob-3.0.1/.gitignore000066400000000000000000000000271350570333400152040ustar00rootroot00000000000000node_modules yarn.lock dir-glob-3.0.1/.npmrc000066400000000000000000000000231350570333400143300ustar00rootroot00000000000000package-lock=false dir-glob-3.0.1/.travis.yml000066400000000000000000000000651350570333400153270ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' dir-glob-3.0.1/index.js000066400000000000000000000044001350570333400146600ustar00rootroot00000000000000'use strict'; const path = require('path'); const pathType = require('path-type'); const getExtensions = extensions => extensions.length > 1 ? `{${extensions.join(',')}}` : extensions[0]; const getPath = (filepath, cwd) => { const pth = filepath[0] === '!' ? filepath.slice(1) : filepath; return path.isAbsolute(pth) ? pth : path.join(cwd, pth); }; const addExtensions = (file, extensions) => { if (path.extname(file)) { return `**/${file}`; } return `**/${file}.${getExtensions(extensions)}`; }; const getGlob = (directory, options) => { if (options.files && !Array.isArray(options.files)) { throw new TypeError(`Expected \`files\` to be of type \`Array\` but received type \`${typeof options.files}\``); } if (options.extensions && !Array.isArray(options.extensions)) { throw new TypeError(`Expected \`extensions\` to be of type \`Array\` but received type \`${typeof options.extensions}\``); } if (options.files && options.extensions) { return options.files.map(x => path.posix.join(directory, addExtensions(x, options.extensions))); } if (options.files) { return options.files.map(x => path.posix.join(directory, `**/${x}`)); } if (options.extensions) { return [path.posix.join(directory, `**/*.${getExtensions(options.extensions)}`)]; } return [path.posix.join(directory, '**')]; }; module.exports = async (input, options) => { options = { cwd: process.cwd(), ...options }; if (typeof options.cwd !== 'string') { throw new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof options.cwd}\``); } const globs = await Promise.all([].concat(input).map(async x => { const isDirectory = await pathType.isDirectory(getPath(x, options.cwd)); return isDirectory ? getGlob(x, options) : x; })); return [].concat.apply([], globs); // eslint-disable-line prefer-spread }; module.exports.sync = (input, options) => { options = { cwd: process.cwd(), ...options }; if (typeof options.cwd !== 'string') { throw new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof options.cwd}\``); } const globs = [].concat(input).map(x => pathType.isDirectorySync(getPath(x, options.cwd)) ? getGlob(x, options) : x); return [].concat.apply([], globs); // eslint-disable-line prefer-spread }; dir-glob-3.0.1/license000066400000000000000000000021341350570333400145620ustar00rootroot00000000000000MIT License Copyright (c) Kevin MÃ¥rtensson (github.com/kevva) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dir-glob-3.0.1/package.json000066400000000000000000000012001350570333400154740ustar00rootroot00000000000000{ "name": "dir-glob", "version": "3.0.1", "description": "Convert directories to glob compatible strings", "license": "MIT", "repository": "kevva/dir-glob", "author": { "name": "Kevin MÃ¥rtensson", "email": "kevinmartensson@gmail.com", "url": "github.com/kevva" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "convert", "directory", "extensions", "files", "glob" ], "dependencies": { "path-type": "^4.0.0" }, "devDependencies": { "ava": "^2.1.0", "del": "^4.1.1", "make-dir": "^3.0.0", "rimraf": "^2.5.0", "xo": "^0.24.0" } } dir-glob-3.0.1/readme.md000066400000000000000000000025151350570333400147770ustar00rootroot00000000000000# dir-glob [![Build Status](https://travis-ci.org/kevva/dir-glob.svg?branch=master)](https://travis-ci.org/kevva/dir-glob) > Convert directories to glob compatible strings ## Install ``` $ npm install dir-glob ``` ## Usage ```js const dirGlob = require('dir-glob'); (async () => { console.log(await dirGlob(['index.js', 'test.js', 'fixtures'])); //=> ['index.js', 'test.js', 'fixtures/**'] console.log(await dirGlob(['index.js', 'inner_folder'], {cwd: 'fixtures'})); //=> ['index.js', 'inner_folder/**'] console.log(await dirGlob(['lib/**', 'fixtures'], { files: ['test', 'unicorn'] extensions: ['js'] })); //=> ['lib/**', 'fixtures/**/test.js', 'fixtures/**/unicorn.js'] console.log(await dirGlob(['lib/**', 'fixtures'], { files: ['test', 'unicorn', '*.jsx'], extensions: ['js', 'png'] })); //=> ['lib/**', 'fixtures/**/test.{js,png}', 'fixtures/**/unicorn.{js,png}', 'fixtures/**/*.jsx'] })(); ``` ## API ### dirGlob(input, options?) Returns a `Promise` with globs. ### dirGlob.sync(input, options?) Returns a `string[]` with globs. #### input Type: `string | string[]` Paths. #### options Type: `object` ##### extensions Type: `string[]` Append extensions to the end of your globs. ##### files Type: `string[]` Only glob for certain files. ##### cwd Type: `string[]` Test in specific directory. dir-glob-3.0.1/test.js000066400000000000000000000074111350570333400145350ustar00rootroot00000000000000import del from 'del'; import makeDir from 'make-dir'; import test from 'ava'; import dirGlob from '.'; test.before(() => { makeDir.sync('tmp/inner_tmp'); }); test.after(() => { del.sync('tmp'); }); test('convert directories to glob - async', async t => { t.deepEqual(await dirGlob('tmp'), ['tmp/**']); t.deepEqual(await dirGlob(['index.js', 'tmp']), ['index.js', 'tmp/**']); t.deepEqual(await dirGlob(['index.js', 'tmp'], {extensions: ['js']}), ['index.js', 'tmp/**/*.js']); t.deepEqual(await dirGlob(['index.js', 'tmp'], {extensions: ['js', 'png']}), ['index.js', 'tmp/**/*.{js,png}']); t.deepEqual(await dirGlob(['foo/**', 'tmp']), ['foo/**', 'tmp/**']); t.deepEqual(await dirGlob(['index.js', '!tmp']), ['index.js', '!tmp/**']); t.deepEqual(await dirGlob(['index.js', '!tmp'], {extensions: ['js', 'png']}), ['index.js', '!tmp/**/*.{js,png}']); t.deepEqual(await dirGlob(['index.js', 'tmp'], {files: ['unicorn', '*.png'], extensions: ['js']}), ['index.js', 'tmp/**/unicorn.js', 'tmp/**/*.png']); t.deepEqual(await dirGlob(['index.js', 'tmp'], {files: ['unicorn', '*.png'], extensions: ['js', 'png']}), ['index.js', 'tmp/**/unicorn.{js,png}', 'tmp/**/*.png']); t.deepEqual(await dirGlob(['index.js', 'tmp'], {files: ['test', 'unicorn'], extensions: ['js', 'png']}), ['index.js', 'tmp/**/test.{js,png}', 'tmp/**/unicorn.{js,png}']); t.deepEqual(await dirGlob('inner_tmp', {cwd: 'tmp'}), ['inner_tmp/**']); t.deepEqual(await dirGlob(['index.js', 'inner_tmp'], {cwd: 'tmp'}), ['index.js', 'inner_tmp/**']); t.deepEqual(await dirGlob(['index.js', 'inner_tmp'], {cwd: 'tmp', files: ['unicorn', '*.png'], extensions: ['js', 'png']}), ['index.js', 'inner_tmp/**/unicorn.{js,png}', 'inner_tmp/**/*.png']); t.deepEqual(await dirGlob([__dirname], {extensions: ['js']}), [`${__dirname}/**/*.js`]); t.deepEqual(await dirGlob([__dirname], {files: ['*.js']}), [`${__dirname}/**/*.js`]); await t.throwsAsync(dirGlob(['index.js'], {cwd: undefined}), 'Expected `cwd` to be of type `string` but received type `undefined`'); }); test('convert directories to glob - sync', t => { t.deepEqual(dirGlob.sync('tmp'), ['tmp/**']); t.deepEqual(dirGlob.sync(['index.js', 'tmp']), ['index.js', 'tmp/**']); t.deepEqual(dirGlob.sync(['index.js', 'tmp'], {extensions: ['js']}), ['index.js', 'tmp/**/*.js']); t.deepEqual(dirGlob.sync(['index.js', 'tmp'], {extensions: ['js', 'png']}), ['index.js', 'tmp/**/*.{js,png}']); t.deepEqual(dirGlob.sync(['foo/**', 'tmp']), ['foo/**', 'tmp/**']); t.deepEqual(dirGlob.sync(['index.js', '!tmp']), ['index.js', '!tmp/**']); t.deepEqual(dirGlob.sync(['index.js', '!tmp'], {extensions: ['js', 'png']}), ['index.js', '!tmp/**/*.{js,png}']); t.deepEqual(dirGlob.sync(['index.js', 'tmp'], {files: ['unicorn', '*.png'], extensions: ['js']}), ['index.js', 'tmp/**/unicorn.js', 'tmp/**/*.png']); t.deepEqual(dirGlob.sync(['index.js', 'tmp'], {files: ['unicorn', '*.png'], extensions: ['js', 'png']}), ['index.js', 'tmp/**/unicorn.{js,png}', 'tmp/**/*.png']); t.deepEqual(dirGlob.sync(['index.js', 'tmp'], {files: ['test', 'unicorn'], extensions: ['js', 'png']}), ['index.js', 'tmp/**/test.{js,png}', 'tmp/**/unicorn.{js,png}']); t.deepEqual(dirGlob.sync('inner_tmp', {cwd: 'tmp'}), ['inner_tmp/**']); t.deepEqual(dirGlob.sync(['index.js', 'inner_tmp'], {cwd: 'tmp'}), ['index.js', 'inner_tmp/**']); t.deepEqual(dirGlob.sync(['index.js', 'inner_tmp'], {cwd: 'tmp', files: ['unicorn', '*.png'], extensions: ['js', 'png']}), ['index.js', 'inner_tmp/**/unicorn.{js,png}', 'inner_tmp/**/*.png']); t.deepEqual(dirGlob.sync([__dirname], {extensions: ['js']}), [`${__dirname}/**/*.js`]); t.deepEqual(dirGlob.sync([__dirname], {files: ['*.js']}), [`${__dirname}/**/*.js`]); t.throws(() => { dirGlob.sync(['index.js'], {cwd: undefined}); }, 'Expected `cwd` to be of type `string` but received type `undefined`'); });