Socket
Socket
Sign inDemoInstall

dir-glob

Package Overview
Dependencies
1
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.2 to 3.0.0

62

index.js

@@ -9,3 +9,3 @@ 'use strict';

const pth = filepath[0] === '!' ? filepath.slice(1) : filepath;
return path.isAbsolute(pth) ? pth : path.join(cwd, pth);
return path.isAbsolute(pth) ? pth : path.posix.join(cwd, pth);
};

@@ -21,47 +21,57 @@

const getGlob = (dir, opts) => {
if (opts.files && !Array.isArray(opts.files)) {
throw new TypeError(`Expected \`files\` to be of type \`Array\` but received type \`${typeof opts.files}\``);
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 (opts.extensions && !Array.isArray(opts.extensions)) {
throw new TypeError(`Expected \`extensions\` to be of type \`Array\` but received type \`${typeof opts.extensions}\``);
if (options.extensions && !Array.isArray(options.extensions)) {
throw new TypeError(`Expected \`extensions\` to be of type \`Array\` but received type \`${typeof options.extensions}\``);
}
if (opts.files && opts.extensions) {
return opts.files.map(x => path.join(dir, addExtensions(x, opts.extensions)));
if (options.files && options.extensions) {
return options.files.map(x => path.posix.join(directory, addExtensions(x, options.extensions)));
}
if (opts.files) {
return opts.files.map(x => path.join(dir, `**/${x}`));
if (options.files) {
return options.files.map(x => path.posix.join(directory, `**/${x}`));
}
if (opts.extensions) {
return [path.join(dir, `**/*.${getExtensions(opts.extensions)}`)];
if (options.extensions) {
return [path.posix.join(directory, `**/*.${getExtensions(options.extensions)}`)];
}
return [path.join(dir, '**')];
return [path.posix.join(directory, '**')];
};
module.exports = (input, opts) => {
opts = Object.assign({cwd: process.cwd()}, opts);
module.exports = async (input, options) => {
options = {
cwd: process.cwd(),
...options
};
if (typeof opts.cwd !== 'string') {
return Promise.reject(new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof opts.cwd}\``));
if (typeof options.cwd !== 'string') {
throw new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof options.cwd}\``);
}
return Promise.all([].concat(input).map(x => pathType.dir(getPath(x, opts.cwd))
.then(isDir => isDir ? getGlob(x, opts) : x)))
.then(globs => [].concat.apply([], globs));
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, opts) => {
opts = Object.assign({cwd: process.cwd()}, opts);
module.exports.sync = (input, options) => {
options = {
cwd: process.cwd(),
...options
};
if (typeof opts.cwd !== 'string') {
throw new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof opts.cwd}\``);
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.dirSync(getPath(x, opts.cwd)) ? getGlob(x, opts) : x);
return [].concat.apply([], globs);
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
};
{
"name": "dir-glob",
"version": "2.2.2",
"version": "3.0.0",
"description": "Convert directories to glob compatible strings",

@@ -13,3 +13,3 @@ "license": "MIT",

"engines": {
"node": ">=4"
"node": ">=8"
},

@@ -30,11 +30,11 @@ "scripts": {

"dependencies": {
"path-type": "^3.0.0"
"path-type": "^4.0.0"
},
"devDependencies": {
"ava": "^0.25.0",
"del": "^3.0.0",
"make-dir": "^1.0.0",
"ava": "^2.1.0",
"del": "^4.1.1",
"make-dir": "^3.0.0",
"rimraf": "^2.5.0",
"xo": "^0.20.3"
"xo": "^0.24.0"
}
}

@@ -18,29 +18,21 @@ # dir-glob [![Build Status](https://travis-ci.org/kevva/dir-glob.svg?branch=master)](https://travis-ci.org/kevva/dir-glob)

dirGlob(['index.js', 'test.js', 'fixtures']).then(files => {
console.log(files);
(async () => {
console.log(await dirGlob(['index.js', 'test.js', 'fixtures']));
//=> ['index.js', 'test.js', 'fixtures/**']
});
dirGlob(['index.js', 'inner_folder'], {
cwd: 'fixtures'
}).then(files => {
console.log(files);
console.log(await dirGlob(['index.js', 'inner_folder'], {cwd: 'fixtures'}));
//=> ['index.js', 'inner_folder/**']
});
dirGlob(['lib/**', 'fixtures'], {
files: ['test', 'unicorn']
extensions: ['js']
}).then(files => {
console.log(files);
console.log(await dirGlob(['lib/**', 'fixtures'], {
files: ['test', 'unicorn']
extensions: ['js']
}));
//=> ['lib/**', 'fixtures/**/test.js', 'fixtures/**/unicorn.js']
});
dirGlob(['lib/**', 'fixtures'], {
files: ['test', 'unicorn', '*.jsx'],
extensions: ['js', 'png']
}).then(files => {
console.log(files);
console.log(await dirGlob(['lib/**', 'fixtures'], {
files: ['test', 'unicorn', '*.jsx'],
extensions: ['js', 'png']
}));
//=> ['lib/**', 'fixtures/**/test.{js,png}', 'fixtures/**/unicorn.{js,png}', 'fixtures/**/*.jsx']
});
})();
```

@@ -51,21 +43,23 @@

### dirGlob(input, [options])
### dirGlob(input, options?)
Returns a `Promise` for an array of glob strings.
Returns a `Promise<string[]>` with globs.
### dirGlob.sync(input, [options])
### dirGlob.sync(input, options?)
Returns an array of glob strings.
Returns a `string[]` with globs.
#### input
Type: `Array` `string`
Type: `string | string[]`
A `string` or an `Array` of paths.
Paths.
#### options
Type: `object`
##### extensions
Type: `Array`
Type: `string[]`

@@ -76,3 +70,3 @@ Append extensions to the end of your globs.

Type: `Array`
Type: `string[]`

@@ -83,9 +77,4 @@ Only glob for certain files.

Type: `string`
Type: `string[]`
Test in specific directory.
## License
MIT © [Kevin Mårtensson](https://github.com/kevva)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc