Comparing version 0.1.1 to 0.2.0
@@ -13,19 +13,16 @@ var fs = require("fs"), | ||
/** | ||
Expands file patterns, returning the matched and unmatched files and directories. | ||
Pass a list of file patterns to expand | ||
@class | ||
@alias module:file-set | ||
@param {string[]} files - The input files to stat | ||
The file-set constructor. | ||
@param {string | string[]} - A pattern, or array of patterns to expand | ||
@example | ||
```js | ||
var FileSet = require("file-set"); | ||
var fileSet = FileSet([ "these/*.js", "those/*.txt" ]); | ||
var fileSet = require("file-set"); | ||
``` | ||
@alias module:file-set | ||
*/ | ||
function FileSet(files){ | ||
if (!(this instanceof FileSet)) return new FileSet(files); | ||
function FileSet(patternList){ | ||
if (!(this instanceof FileSet)) return new FileSet(patternList); | ||
/** | ||
A list of unique paths, all which exist | ||
The full list of unique paths found, and not found. | ||
@type {string[]} | ||
@@ -35,3 +32,3 @@ */ | ||
/** | ||
List of files which exist | ||
The existing files found | ||
@type {string[]} | ||
@@ -41,3 +38,3 @@ */ | ||
/** | ||
List of dirs which exist | ||
The existing directories found | ||
@type {string[]} | ||
@@ -47,3 +44,3 @@ */ | ||
/** | ||
Paths which do not exist | ||
Paths which were not found | ||
@type {string[]} | ||
@@ -53,7 +50,7 @@ */ | ||
this.add(files); | ||
this.add(patternList); | ||
} | ||
/** | ||
add files to the set | ||
@param files {string|string[]} - the files to add | ||
add file patterns to the set | ||
@param files {string|string[]} - A pattern, or array of patterns to expand | ||
*/ | ||
@@ -72,7 +69,7 @@ FileSet.prototype.add = function(files){ | ||
if (stat.isFile()){ | ||
fileSetItem.type = FileSet.FILE; | ||
fileSetItem.type = FileSet.eFileType.FILE; | ||
self.files.push(file); | ||
} | ||
if (stat.isDirectory()){ | ||
fileSetItem.type = FileSet.DIR; | ||
fileSetItem.type = FileSet.eFileType.DIR; | ||
self.dirs.push(file); | ||
@@ -103,3 +100,3 @@ } | ||
} else { | ||
self.list.push({ path: file, type: FileSet.NOEXIST }); | ||
self.list.push({ path: file, type: FileSet.eFileType.NOEXIST }); | ||
self.notExisting.push(file); | ||
@@ -110,9 +107,11 @@ } | ||
FileSet.NOEXIST = 0; | ||
FileSet.FILE = 1; | ||
FileSet.DIR = 2; | ||
function FileSetItem(){ | ||
this.path = null; | ||
this.type = null; | ||
} | ||
/** | ||
Enum for the `type` value of each record in `fileSet.list` | ||
@readonly | ||
@enum {number} | ||
*/ | ||
FileSet.eFileType = { | ||
NOEXIST: 0, | ||
FILE: 1, | ||
DIR: 2 | ||
}; |
{ | ||
"name": "file-set", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Expands file patterns, returning the matched and unmatched files and directories.", | ||
@@ -9,7 +9,7 @@ "main": "lib/file-set.js", | ||
"test": "tape test/*.js", | ||
"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/file-set.js > README.md; echo " | ||
"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/file-set.js --index > README.md; echo " | ||
}, | ||
"author": "Lloyd Brookes", | ||
"devDependencies": { | ||
"jsdoc-to-markdown": "^0.1", | ||
"jsdoc-to-markdown": "^0.2", | ||
"tape": "^2.13.2" | ||
@@ -16,0 +16,0 @@ }, |
@@ -6,9 +6,41 @@ [![view on npm](http://img.shields.io/npm/v/file-set.svg)](https://www.npmjs.org/package/file-set) | ||
#file-set | ||
Exports a single 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`. | ||
##Install | ||
```sh | ||
$ npm install file-set --save | ||
``` | ||
##Usage | ||
```js | ||
> var fileSet = require("file-set"); | ||
> var ls = fileSet([ "*", "not/existing/*" ]) | ||
{ list: | ||
[ { path: 'README.md', type: 1 }, | ||
{ path: 'jsdoc2md', type: 2 }, | ||
{ path: 'lib', type: 2 }, | ||
{ path: 'node_modules', type: 2 }, | ||
{ path: 'package.json', type: 1 }, | ||
{ path: 'test', type: 2 }, | ||
{ path: 'not/existing/*', type: 0 } ], | ||
files: [ 'README.md', 'package.json' ], | ||
dirs: | ||
[ 'jsdoc2md', | ||
'lib', | ||
'node_modules', | ||
'test' ], | ||
notExisting: [ 'not/existing/*' ] } | ||
``` | ||
<a name="module_file-set"></a> | ||
##file-set(patternList) | ||
- patternList `string | Array.<string>` - A pattern, or array of patterns to expand | ||
####Example | ||
```js | ||
var fileSet = require("file-set"); | ||
``` | ||
**Contents** | ||
@@ -19,48 +51,39 @@ * [list](#module_file-set#list) | ||
* [notExisting](#module_file-set#notExisting) | ||
* [eFileType](#module_file-set.eFileType) | ||
* [add(files)](#module_file-set#add) | ||
<a name="module_file-set#list"></a> | ||
###fileSet.list | ||
A list of unique paths, all which exist | ||
The full list of unique paths found, and not found. | ||
**Type**: `Array.<string>` | ||
<a name="module_file-set#files"></a> | ||
###fileSet.files | ||
List of files which exist | ||
The existing files found | ||
**Type**: `Array.<string>` | ||
<a name="module_file-set#dirs"></a> | ||
###fileSet.dirs | ||
List of dirs which exist | ||
The existing directories found | ||
**Type**: `Array.<string>` | ||
<a name="module_file-set#notExisting"></a> | ||
###fileSet.notExisting | ||
Paths which do not exist | ||
Paths which were not found | ||
**Type**: `Array.<string>` | ||
<a name="module_file-set#add"></a> | ||
###add(files) | ||
add files to the set | ||
###fileSet.add(files) | ||
add file patterns to the set | ||
- files `string | Array.<string>` the files to add | ||
- files `string | Array.<string>` - A pattern, or array of patterns to expand | ||
<a name="module_file-set.eFileType"></a> | ||
###fileSet.eFileType | ||
Enum for the `type` value of each record in `fileSet.list` | ||
**Enum** with properties: `NOEXIST`, `FILE`, `DIR` | ||
**Read only**: true | ||
**Type**: `number` | ||
@@ -7,9 +7,9 @@ var test = require("tape"), | ||
t.deepEqual(fileSet.list, [ | ||
{ path: "test/fixture/file1", type: FileSet.FILE }, | ||
{ path: "test/fixture/folder1", type: FileSet.DIR }, | ||
{ path: "test/fixture/folder2", type: FileSet.DIR }, | ||
{ path: "clive", type: FileSet.NOEXIST }, | ||
{ path: "test/fixture/folder2/file3", type: FileSet.FILE }, | ||
{ path: "test/fixture/folder2/folder3", type: FileSet.DIR }, | ||
{ path: "test/fixture/folder2/folder3/file4", type: FileSet.FILE } | ||
{ path: "test/fixture/file1", type: FileSet.eFileType.FILE }, | ||
{ path: "test/fixture/folder1", type: FileSet.eFileType.DIR }, | ||
{ path: "test/fixture/folder2", type: FileSet.eFileType.DIR }, | ||
{ path: "clive", type: FileSet.eFileType.NOEXIST }, | ||
{ path: "test/fixture/folder2/file3", type: FileSet.eFileType.FILE }, | ||
{ path: "test/fixture/folder2/folder3", type: FileSet.eFileType.DIR }, | ||
{ path: "test/fixture/folder2/folder3/file4", type: FileSet.eFileType.FILE } | ||
]); | ||
@@ -16,0 +16,0 @@ |
Sorry, the diff of this file is not supported yet
8599
138
88