Comparing version 2.0.1 to 3.0.0
127
index.js
@@ -1,8 +0,4 @@ | ||
'use strict' | ||
const glob = require('glob') | ||
const arrayify = require('array-back') | ||
/** | ||
* Exports a contructor taking a list of file patterns as input, returning a `file-set` instance containing the expanded patterns split into separate lists of `files`, `dirs` and `notExisting`. | ||
* @module | ||
* Breaks an input list of file paths and glob expressions into three categories: files, directories and not existing. | ||
* @module file-set | ||
* @example | ||
@@ -12,85 +8,72 @@ * ```js | ||
* ``` | ||
* @typicalname FileSet | ||
*/ | ||
module.exports = FileSet | ||
/* Polyfill for old node versions */ | ||
if (!String.prototype.endsWith) { | ||
String.prototype.endsWith = function (searchString, position) { | ||
const subjectString = this.toString() | ||
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) { | ||
position = subjectString.length | ||
} | ||
position -= searchString.length | ||
const lastIndex = subjectString.indexOf(searchString, position) | ||
return lastIndex !== -1 && lastIndex === position | ||
} | ||
} | ||
const glob = require('glob') | ||
const arrayify = require('array-back') | ||
/** | ||
* @class | ||
* @classdesc Expands file patterns, returning the matched and unmatched files and directories | ||
* @param {string | string[]} - A pattern, or array of patterns to expand | ||
* @param {string | string[]} - One or more file paths or glob expressions to inspect. | ||
* @alias module:file-set | ||
*/ | ||
function FileSet (patternList) { | ||
if (!(this instanceof FileSet)) return new FileSet(patternList) | ||
class FileSet { | ||
constructor (patternList) { | ||
/** | ||
* The existing files found | ||
* @type {string[]} | ||
*/ | ||
this.files = [] | ||
/** | ||
* The existing files found | ||
* @type {string[]} | ||
*/ | ||
this.files = [] | ||
/** | ||
* The existing directories found | ||
* @type {string[]} | ||
*/ | ||
this.dirs = [] | ||
/** | ||
* The existing directories found | ||
* @type {string[]} | ||
*/ | ||
this.dirs = [] | ||
/** | ||
* Paths which were not found | ||
* @type {string[]} | ||
*/ | ||
this.notExisting = [] | ||
this.add(patternList) | ||
} | ||
/** | ||
* Paths which were not found | ||
* @type {string[]} | ||
* Add file patterns to the set. | ||
* @param files {string|string[]} - One or more file paths or glob expressions to inspect. | ||
*/ | ||
this.notExisting = [] | ||
add (files) { | ||
const fs = require('fs') | ||
this.add(patternList) | ||
} | ||
/** | ||
* add file patterns to the set | ||
* @param files {string|string[]} - A pattern, or array of patterns to expand | ||
*/ | ||
FileSet.prototype.add = function (files) { | ||
const self = this | ||
const fs = require('fs') | ||
files = arrayify(files) | ||
files.forEach(function (file) { | ||
try { | ||
const stat = fs.statSync(file) | ||
if (stat.isFile()) { | ||
if (self.files.indexOf(file) === -1) self.files.push(file) | ||
} else if (stat.isDirectory()) { | ||
if (self.dirs.indexOf(file) === -1) self.dirs.push(file) | ||
} | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
const found = glob.sync(file, { mark: true }) | ||
if (found.length) { | ||
found.forEach(function (match) { | ||
if (match.endsWith('/')) { | ||
if (self.dirs.indexOf(match) === -1) self.dirs.push(match) | ||
} else { | ||
if (self.files.indexOf(match) === -1) self.files.push(match) | ||
files = arrayify(files) | ||
for (const file of files) { | ||
try { | ||
const stat = fs.statSync(file) | ||
if (stat.isFile()) { | ||
if (this.files.indexOf(file) === -1) this.files.push(file) | ||
} else if (stat.isDirectory()) { | ||
if (this.dirs.indexOf(file) === -1) this.dirs.push(file) | ||
} | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
const found = glob.sync(file, { mark: true }) | ||
if (found.length) { | ||
for (const match of found) { | ||
if (match.endsWith('/')) { | ||
if (this.dirs.indexOf(match) === -1) this.dirs.push(match) | ||
} else { | ||
if (this.files.indexOf(match) === -1) this.files.push(match) | ||
} | ||
} | ||
}) | ||
} else { | ||
if (this.notExisting.indexOf(file) === -1) this.notExisting.push(file) | ||
} | ||
} else { | ||
if (self.notExisting.indexOf(file) === -1) self.notExisting.push(file) | ||
throw err | ||
} | ||
} else { | ||
throw err | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
module.exports = FileSet |
{ | ||
"name": "file-set", | ||
"version": "2.0.1", | ||
"description": "Expands file patterns, returning the matched and unmatched files and directories.", | ||
"version": "3.0.0", | ||
"description": "Expands file paths and glob expressions, returning matched and unmatched files and directories", | ||
"license": "MIT", | ||
@@ -10,15 +10,18 @@ "repository": "https://github.com/75lb/file-set", | ||
], | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "test-runner test/*.js", | ||
"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/file-set.js > README.md; echo " | ||
"docs": "jsdoc2md -t README.hbs index.js > README.md" | ||
}, | ||
"author": "Lloyd Brookes", | ||
"devDependencies": { | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"test-runner": "^0.5.0" | ||
"jsdoc-to-markdown": "^5.0.2", | ||
"test-runner": "^0.6.0" | ||
}, | ||
"dependencies": { | ||
"array-back": "^2.0.0", | ||
"glob": "^7.1.3" | ||
"array-back": "^4.0.0", | ||
"glob": "^7.1.5" | ||
} | ||
} |
[![view on npm](http://img.shields.io/npm/v/file-set.svg)](https://www.npmjs.org/package/file-set) | ||
[![npm module downloads](http://img.shields.io/npm/dt/file-set.svg)](https://www.npmjs.org/package/file-set) | ||
[![Build Status](https://travis-ci.org/75lb/file-set.svg?branch=master)](https://travis-ci.org/75lb/file-set) | ||
[![Dependency Status](https://david-dm.org/75lb/file-set.svg)](https://david-dm.org/75lb/file-set) | ||
[![Dependency Status](https://badgen.net/david/dep/75lb/file-set)](https://david-dm.org/75lb/file-set) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard) | ||
# file-set | ||
Exports a contructor taking a list of file patterns as input, returning a `file-set` instance containing the expanded patterns split into separate lists of `files`, `dirs` and `notExisting`. | ||
Breaks an input list of file paths and glob expressions into three categories: files, directories and not existing. | ||
**Example** | ||
@@ -17,7 +18,9 @@ ```js | ||
## Install | ||
```sh | ||
$ npm install file-set --save | ||
$ npm install file-set | ||
``` | ||
## Usage | ||
```js | ||
@@ -34,4 +37,5 @@ > const FileSet = require('file-set'); | ||
# API | ||
Exports a contructor taking a list of file patterns as input, returning a `file-set` instance containing the expanded patterns split into separate lists of `files`, `dirs` and `notExisting`. | ||
Breaks an input list of file paths and glob expressions into three categories: files, directories and not existing. | ||
**Example** | ||
@@ -53,4 +57,2 @@ ```js | ||
### FileSet ⏏ | ||
Expands file patterns, returning the matched and unmatched files and directories | ||
**Kind**: Exported class | ||
@@ -63,3 +65,3 @@ <a name="new_module_file-set--FileSet_new"></a> | ||
| --- | --- | --- | | ||
| patternList | <code>string</code> \| <code>Array.<string></code> | A pattern, or array of patterns to expand | | ||
| patternList | <code>string</code> \| <code>Array.<string></code> | One or more file paths or glob expressions to inspect. | | ||
@@ -87,3 +89,3 @@ <a name="module_file-set--FileSet+files"></a> | ||
#### fileSet.add(files) | ||
add file patterns to the set | ||
Add file patterns to the set. | ||
@@ -94,3 +96,3 @@ **Kind**: instance method of [<code>FileSet</code>](#exp_module_file-set--FileSet) | ||
| --- | --- | --- | | ||
| files | <code>string</code> \| <code>Array.<string></code> | A pattern, or array of patterns to expand | | ||
| files | <code>string</code> \| <code>Array.<string></code> | One or more file paths or glob expressions to inspect. | | ||
@@ -100,2 +102,2 @@ | ||
© 2014-18 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). | ||
© 2014-19 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8033
5
97
70
+ Addedarray-back@4.0.2(transitive)
- Removedarray-back@2.0.0(transitive)
- Removedtypical@2.6.1(transitive)
Updatedarray-back@^4.0.0
Updatedglob@^7.1.5