Remove node_modules from repo, add travis tests for more recent versions of node
This commit is contained in:
parent
6b4e7c9f7a
commit
80c62b7986
@ -1,6 +1,8 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
|
|
||||||
node_js:
|
node_js:
|
||||||
|
- "iojs"
|
||||||
|
- "node"
|
||||||
- "0.11"
|
- "0.11"
|
||||||
- "0.10"
|
- "0.10"
|
||||||
|
|
||||||
|
11
Gruntfile.js
11
Gruntfile.js
@ -4,7 +4,7 @@ module.exports = function(grunt) {
|
|||||||
// Project configuration
|
// Project configuration
|
||||||
grunt.initConfig({
|
grunt.initConfig({
|
||||||
pkg: grunt.file.readJSON('package.json'),
|
pkg: grunt.file.readJSON('package.json'),
|
||||||
jsdoc: {
|
/*jsdoc: {
|
||||||
dist: {
|
dist: {
|
||||||
src: ['lib/*.js', 'README.md'],
|
src: ['lib/*.js', 'README.md'],
|
||||||
options: {
|
options: {
|
||||||
@ -13,7 +13,7 @@ module.exports = function(grunt) {
|
|||||||
destination: 'docs'
|
destination: 'docs'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},*/
|
||||||
nodeunit: {
|
nodeunit: {
|
||||||
all: ['tests/**/*_test.js'],
|
all: ['tests/**/*_test.js'],
|
||||||
options: {
|
options: {
|
||||||
@ -22,11 +22,12 @@ module.exports = function(grunt) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.loadNpmTasks('grunt-jsdoc');
|
//grunt.loadNpmTasks('grunt-jsdoc');
|
||||||
grunt.loadNpmTasks('grunt-contrib-nodeunit');
|
grunt.loadNpmTasks('grunt-contrib-nodeunit');
|
||||||
|
|
||||||
|
|
||||||
grunt.registerTask('default', ['nodeunit','jsdoc']);
|
//grunt.registerTask('default', ['nodeunit','jsdoc']);
|
||||||
|
grunt.registerTask('default', 'nodeunit');
|
||||||
grunt.registerTask('tests', 'nodeunit');
|
grunt.registerTask('tests', 'nodeunit');
|
||||||
grunt.registerTask('docs', 'jsdoc');
|
//grunt.registerTask('docs', 'jsdoc');
|
||||||
};
|
};
|
1
node_modules/.bin/grunt
generated
vendored
1
node_modules/.bin/grunt
generated
vendored
@ -1 +0,0 @@
|
|||||||
../grunt-cli/bin/grunt
|
|
1
node_modules/.bin/grunt-istanbul
generated
vendored
1
node_modules/.bin/grunt-istanbul
generated
vendored
@ -1 +0,0 @@
|
|||||||
../grunt-istanbul/bin/grunt-istanbul
|
|
1
node_modules/.bin/grunt-jsdoc
generated
vendored
1
node_modules/.bin/grunt-jsdoc
generated
vendored
@ -1 +0,0 @@
|
|||||||
../grunt-jsdoc/bin/grunt-jsdoc
|
|
1
node_modules/.bin/jsdoc
generated
vendored
1
node_modules/.bin/jsdoc
generated
vendored
@ -1 +0,0 @@
|
|||||||
../jsdoc/jsdoc.js
|
|
1
node_modules/.bin/nodeunit
generated
vendored
1
node_modules/.bin/nodeunit
generated
vendored
@ -1 +0,0 @@
|
|||||||
../nodeunit/bin/nodeunit
|
|
3
node_modules/async/.travis.yml
generated
vendored
3
node_modules/async/.travis.yml
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- "0.10"
|
|
19
node_modules/async/LICENSE
generated
vendored
19
node_modules/async/LICENSE
generated
vendored
@ -1,19 +0,0 @@
|
|||||||
Copyright (c) 2010-2014 Caolan McMahon
|
|
||||||
|
|
||||||
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.
|
|
1646
node_modules/async/README.md
generated
vendored
1646
node_modules/async/README.md
generated
vendored
File diff suppressed because it is too large
Load Diff
11
node_modules/async/component.json
generated
vendored
11
node_modules/async/component.json
generated
vendored
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "async",
|
|
||||||
"repo": "caolan/async",
|
|
||||||
"description": "Higher-order functions and common patterns for asynchronous code",
|
|
||||||
"version": "0.1.23",
|
|
||||||
"keywords": [],
|
|
||||||
"dependencies": {},
|
|
||||||
"development": {},
|
|
||||||
"main": "lib/async.js",
|
|
||||||
"scripts": [ "lib/async.js" ]
|
|
||||||
}
|
|
1123
node_modules/async/lib/async.js
generated
vendored
1123
node_modules/async/lib/async.js
generated
vendored
File diff suppressed because it is too large
Load Diff
45
node_modules/async/package.json
generated
vendored
45
node_modules/async/package.json
generated
vendored
File diff suppressed because one or more lines are too long
10
node_modules/dblite/.npmignore
generated
vendored
10
node_modules/dblite/.npmignore
generated
vendored
@ -1,10 +0,0 @@
|
|||||||
src/*
|
|
||||||
test/*
|
|
||||||
benchmark/*
|
|
||||||
template/*
|
|
||||||
node_modules/*
|
|
||||||
build/*.amd.js
|
|
||||||
Makefile
|
|
||||||
index.html
|
|
||||||
.gitignore
|
|
||||||
.travis.yml
|
|
19
node_modules/dblite/LICENSE.txt
generated
vendored
19
node_modules/dblite/LICENSE.txt
generated
vendored
@ -1,19 +0,0 @@
|
|||||||
Copyright (C) 2013 by WebReflection
|
|
||||||
|
|
||||||
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.
|
|
413
node_modules/dblite/README.md
generated
vendored
413
node_modules/dblite/README.md
generated
vendored
@ -1,413 +0,0 @@
|
|||||||
dblite
|
|
||||||
======
|
|
||||||
a zero hassle wrapper for sqlite
|
|
||||||
```javascript
|
|
||||||
var dblite = require('dblite'),
|
|
||||||
db = dblite('file.name');
|
|
||||||
|
|
||||||
// Asynchronous, fast, and ...
|
|
||||||
db.query('SELECT * FROM table', function(err, rows) {
|
|
||||||
// ... that easy!
|
|
||||||
});
|
|
||||||
```
|
|
||||||
More in [the related blogpost](http://webreflection.blogspot.com/2013/07/dblite-sqlite3-for-nodejs-made-easy.html) and here too :-)
|
|
||||||
|
|
||||||
[![build status](https://secure.travis-ci.org/WebReflection/dblite.png)](http://travis-ci.org/WebReflection/dblite)
|
|
||||||
|
|
||||||
[![NPM](https://nodei.co/npm/dblite.png?downloads=true)](https://nodei.co/npm/dblite/)
|
|
||||||
|
|
||||||
|
|
||||||
### Important
|
|
||||||
Starting from **sqlite3** version `3.8.6` you need a "_new line agnostic_" version of `dblite`, right now represented by the latest version `0.6.0`. This **will break** compatibility with older version of the database cli.
|
|
||||||
|
|
||||||
|
|
||||||
### The What And The Why
|
|
||||||
I've created `dblite` module because there's still not a simple and straight forward or standard way to have [sqlite](http://www.sqlite.org) in [node.js](http://nodejs.org) without requiring to re-compile, re-build, download sources a part or install dependencies instead of simply `apt-get install sqlite3` or `pacman -S sqlite3` in your \*nix system.
|
|
||||||
|
|
||||||
`dblite` has been created with portability, simplicity, and reasonable performance for **embedded Hardware** such [Raspberry Pi](http://www.raspberrypi.org) and [Cubieboard](http://cubieboard.org) in mind.
|
|
||||||
|
|
||||||
Generally speaking all linux based distributions like [Arch Linux](https://www.archlinux.org), where is not always that easy to `node-gyp` a module and add dependencies that work, can now use this battle tested wrap and perform basic to advanced sqlite operations.
|
|
||||||
|
|
||||||
|
|
||||||
### Bootstrap
|
|
||||||
To install dblite simply `npm install dblite` then in node:
|
|
||||||
```javascript
|
|
||||||
var dblite = require('dblite'),
|
|
||||||
db = dblite('/folder/to/file.sqlite');
|
|
||||||
|
|
||||||
// ready to go, i.e.
|
|
||||||
db.query('.databases');
|
|
||||||
db.query(
|
|
||||||
'SELECT * FROM users WHERE pass = ?',
|
|
||||||
[pass],
|
|
||||||
function (err, rows) {
|
|
||||||
var user = rows.length && rows[0];
|
|
||||||
}
|
|
||||||
);
|
|
||||||
```
|
|
||||||
By default the `dblite` function uses **sqlite3 as executable**. If you need to change the path simply update `dblite.bin = "/usr/local/bin/sqlite3";` before invoking the function.
|
|
||||||
|
|
||||||
|
|
||||||
### API
|
|
||||||
Right now a created `EventEmitter` `db` instance has 3 extra methods: `.query()`, `.lastRowID()`, and `.close()`.
|
|
||||||
|
|
||||||
The `.lastRowID(table, callback(rowid))` helper simplifies a common operation with SQL tables after inserts, handful as shortcut for the following query:
|
|
||||||
`SELECT ROWID FROM ``table`` ORDER BY ROWID DESC LIMIT 1`.
|
|
||||||
|
|
||||||
The method `.close()` does exactly what it suggests: it closes the database connection.
|
|
||||||
Please note that it is **not possible to perform other operations once it has been closed**.
|
|
||||||
|
|
||||||
Being an `EventEmitter` instance, the database variable will be notified with the `close` listener, if any.
|
|
||||||
|
|
||||||
|
|
||||||
### Understanding The .query() Method
|
|
||||||
The main role in this module is played by the `db.query()` method, a method rich in overloads all with perfect and natural meaning.
|
|
||||||
|
|
||||||
The amount of parameters goes from one to four, left to right, where left is the input going through the right which is the eventual output.
|
|
||||||
|
|
||||||
All parameters are optionals except the SQL one.
|
|
||||||
|
|
||||||
### db.query() Possible Combinations
|
|
||||||
```javascript
|
|
||||||
db.query(SQL)
|
|
||||||
db.query(SQL, callback:Function)
|
|
||||||
db.query(SQL, params:Array|Object)
|
|
||||||
db.query(SQL, fields:Array|Object)
|
|
||||||
db.query(SQL, params:Array|Object, callback:Function)
|
|
||||||
db.query(SQL, fields:Array|Object, callback:Function)
|
|
||||||
db.query(SQL, params:Array|Object, fields:Array|Object)
|
|
||||||
db.query(SQL, params:Array|Object, fields:Array|Object, callback:Function)
|
|
||||||
```
|
|
||||||
All above combinations are [tested properly in this file](test/dblite.js) together with many other tests able to make `dblite` robust enough and ready to be used.
|
|
||||||
|
|
||||||
Please note how `params` is always before `fields` and/or `callback` if `fields` is missing, just as reminder that order is left to right accordingly with what we are trying to do.
|
|
||||||
|
|
||||||
Following detailed explanation per each parameter.
|
|
||||||
|
|
||||||
#### The SQL:string
|
|
||||||
This string [accepts any query understood by SQLite](http://www.sqlite.org/lang.html) plus it accepts all commands that regular SQLite shell would accept such `.databases`, `.tables`, `.show` and all others passing through the specified `info` listener, if any, using just the console as fallback otherwise.
|
|
||||||
```javascript
|
|
||||||
var dblite = require('dblite'),
|
|
||||||
db = dblite('./db.sqlite');
|
|
||||||
|
|
||||||
// will call the implicit `info` console.log
|
|
||||||
db.query('.show');
|
|
||||||
/* will console.log something like:
|
|
||||||
|
|
||||||
echo: off
|
|
||||||
explain: off
|
|
||||||
headers: off
|
|
||||||
mode: csv
|
|
||||||
nullvalue: ""
|
|
||||||
output: stdout
|
|
||||||
separator: ","
|
|
||||||
stats: off
|
|
||||||
width:
|
|
||||||
*/
|
|
||||||
|
|
||||||
// normal query
|
|
||||||
db.query('CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, value TEXT)');
|
|
||||||
db.query('INSERT INTO test VALUES(null, ?)', ['some text']);
|
|
||||||
db.query('SELECT * FROM test');
|
|
||||||
// will implicitly log the following
|
|
||||||
// [ [ '1', 'some text' ] ]
|
|
||||||
```
|
|
||||||
|
|
||||||
#### The params:Array|Object
|
|
||||||
If the SQL string **contains special chars** such `?`, `:key`, `$key`, or `@key` properties, these will be replaced accordingly with the `params` `Array` or `Object` that, in this case, MUST be present.
|
|
||||||
```javascript
|
|
||||||
// params as Array
|
|
||||||
db.query('SELECT * FROM test WHERE id = ?', [1]);
|
|
||||||
|
|
||||||
// params as Object
|
|
||||||
db.query('SELECT * FROM test WHERE id = :id', {id:1});
|
|
||||||
// same as
|
|
||||||
db.query('SELECT * FROM test WHERE id = $id', {id:1});
|
|
||||||
// same as
|
|
||||||
db.query('SELECT * FROM test WHERE id = @id', {id:1});
|
|
||||||
```
|
|
||||||
|
|
||||||
#### The fields:Array|Object
|
|
||||||
By default, results are returned as an `Array` where all rows are the outer `Array` and each single row is another `Array`.
|
|
||||||
```javascript
|
|
||||||
db.query('SELECT * FROM test');
|
|
||||||
// will log something like:
|
|
||||||
[
|
|
||||||
[ '1', 'some text' ], // row1
|
|
||||||
[ '2', 'something else' ] // rowN
|
|
||||||
]
|
|
||||||
```
|
|
||||||
If we specify a fields parameter we can have each row represented by an object, instead of an array.
|
|
||||||
```javascript
|
|
||||||
// same query using fields as Array
|
|
||||||
db.query('SELECT * FROM test', ['key', 'value']);
|
|
||||||
// will log something like:
|
|
||||||
[
|
|
||||||
{key: '1', value: 'some text'}, // row1
|
|
||||||
{key: '2', value: 'something else'} // rowN
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Parsing Through The fields:Object
|
|
||||||
[SQLite Datatypes](http://www.sqlite.org/datatype3.html) are different from JavaScript plus SQLite works via affinity.
|
|
||||||
This module also parses sqlite3 output which is **always a string** and as string every result will always be returned **unless** we specify `fields` parameter as object, suggesting validation per each field.
|
|
||||||
```javascript
|
|
||||||
// same query using fields as Object
|
|
||||||
db.query('SELECT * FROM test', {
|
|
||||||
key: Number,
|
|
||||||
value: String
|
|
||||||
});
|
|
||||||
// note the key as integer!
|
|
||||||
[
|
|
||||||
{key: 1, value: 'some text'}, // row1
|
|
||||||
{key: 2, value: 'something else'} // rowN
|
|
||||||
]
|
|
||||||
```
|
|
||||||
More complex validators/transformers can be passed without problems:
|
|
||||||
```javascript
|
|
||||||
// same query using fields as Object
|
|
||||||
db.query('SELECT * FROM `table.users`', {
|
|
||||||
id: Number,
|
|
||||||
name: String,
|
|
||||||
adult: Boolean,
|
|
||||||
skills: JSON.parse,
|
|
||||||
birthday: Date,
|
|
||||||
cube: function (fieldValue) {
|
|
||||||
return fieldValue * 3;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
#### The params:Array|Object AND The fields:Array|Object
|
|
||||||
Not a surprise we can combine both params, using the left to right order input to output so **params first**!
|
|
||||||
```javascript
|
|
||||||
// same query using params AND fields
|
|
||||||
db.query('SELECT * FROM test WHERE id = :id', {
|
|
||||||
id: 1
|
|
||||||
},{
|
|
||||||
key: Number,
|
|
||||||
value: String
|
|
||||||
});
|
|
||||||
|
|
||||||
// same as...
|
|
||||||
db.query('SELECT * FROM test WHERE id = ?', [1], ['key', 'value']);
|
|
||||||
// same as...
|
|
||||||
db.query('SELECT * FROM test WHERE id = ?', [1], {
|
|
||||||
key: Number,
|
|
||||||
value: String
|
|
||||||
});
|
|
||||||
// same as...
|
|
||||||
db.query('SELECT * FROM test WHERE id = :id', {
|
|
||||||
id: 1
|
|
||||||
}, [
|
|
||||||
'key', 'value'
|
|
||||||
]);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### The callback:Function
|
|
||||||
When a `SELECT` or a `PRAGMA` `SQL` is executed the module puts itself in a *waiting for results* state.
|
|
||||||
|
|
||||||
**Update** - Starting from `0.4.0` the callback will be invoked with `err` and `data` if the callback length is greater than one. `function(err, data){}` VS `function(data){}`. However, latter mode will keep working in order to not break backward compatibility.
|
|
||||||
**Update** - Starting from `0.3.3` every other `SQL` statement will invoke the callback after the operation has been completed.
|
|
||||||
|
|
||||||
As soon as results are fully pushed to the output the module parses this result, if any, and send it to the specified callback.
|
|
||||||
|
|
||||||
The callback is **always the last specified parameter**, if any, or the implicit equivalent of `console.log.bind(console)`.
|
|
||||||
Latter case is simply helpful to operate directly via `node` **console** and see results without bothering writing a callback each `.query()` call.
|
|
||||||
|
|
||||||
#### Extra Bonus: JSON Serialization With fields:Array|Object
|
|
||||||
If one field value is not scalar (boolean, number, string, null) `JSON.stringify` is performed in order to save data.
|
|
||||||
This helps lazy developers that don't want to pre parse every field and let `dblite` do the magic.
|
|
||||||
```javascript
|
|
||||||
// test has two fields, id and value
|
|
||||||
db.query('INSERT INTO test VALUES(?, ?)', [
|
|
||||||
123,
|
|
||||||
{name: 'dblite', rate: 'awesome'} // value serialized
|
|
||||||
]);
|
|
||||||
|
|
||||||
// use the fields to parse back the object
|
|
||||||
db.query('SELECT * FROM test WHERE id = ?', [123], {
|
|
||||||
id: Number,
|
|
||||||
value: JSON.parse // value unserialized
|
|
||||||
}, function (err, rows) {
|
|
||||||
var record = rows[0];
|
|
||||||
console.log(record.id); // 123
|
|
||||||
console.log(record.value.name); // "dblite"
|
|
||||||
console.log(record.value.rate); // "awesome""
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### Automatic Fields Through Headers
|
|
||||||
Since version `0.3.0` it is possible to enable automatic fields parsing either through initialization (suggested) or at runtime.
|
|
||||||
```javascript
|
|
||||||
var dblite = require('dblite'),
|
|
||||||
// passing extra argument at creation
|
|
||||||
db = dblite('file.name', '-header');
|
|
||||||
|
|
||||||
db.query('SELECT * FROM table', function(err, rows) {
|
|
||||||
rows[0]; // {header0: value0, headerN: valueN}
|
|
||||||
});
|
|
||||||
|
|
||||||
// at runtime
|
|
||||||
db
|
|
||||||
.query('.headers ON')
|
|
||||||
.query('SELECT * FROM table', function(err, rows) {
|
|
||||||
rows[0]; // {header0: value0, headerN: valueN}
|
|
||||||
})
|
|
||||||
.query('.headers OFF')
|
|
||||||
;
|
|
||||||
```
|
|
||||||
|
|
||||||
In version `0.3.2` a smarter approach for combined _headers/fields_ is used where the right key order is granted by headers but it's possible to validate known fields too.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var db = require('dblite')('file.name', '-header');
|
|
||||||
|
|
||||||
db.query('SELECT 1 as one, 2 as two', {two:Number}, function(err, rows) {
|
|
||||||
rows[0]; // {one: "1", two: 2} // note "1" as String
|
|
||||||
});
|
|
||||||
```
|
|
||||||
In this way these two options can be supplementary when and if necessary.
|
|
||||||
|
|
||||||
|
|
||||||
### Handling Infos And Errors - Listeners
|
|
||||||
The `EventEmitter` will notify any listener attached to `info`, `error`, or `close` accordingly with the current status.
|
|
||||||
```javascript
|
|
||||||
db.on('info', function (data) {
|
|
||||||
// show data returned by special syntax
|
|
||||||
// such: .databases .tables .show and others
|
|
||||||
console.log(data);
|
|
||||||
// by default, it does the same
|
|
||||||
});
|
|
||||||
|
|
||||||
db.on('error', function (err) {
|
|
||||||
// same as `info` but for errors
|
|
||||||
console.error(err.toString());
|
|
||||||
// by default, it does the same
|
|
||||||
});
|
|
||||||
|
|
||||||
db.on('close', function (code) {
|
|
||||||
// by default, it logs "bye bye"
|
|
||||||
// invoked once the database has been closed
|
|
||||||
// and every statement in the queue executed
|
|
||||||
// the code is the exit code returned via SQLite3
|
|
||||||
// usually 0 if everything was OK
|
|
||||||
console.log('safe to get out of here ^_^_');
|
|
||||||
});
|
|
||||||
```
|
|
||||||
Please **note** that error is invoked only if the callback is not handling it already via double argument.
|
|
||||||
|
|
||||||
The `close` event ensures that all operations have been successfully performed and your app is ready to exit or move next.
|
|
||||||
|
|
||||||
Please note that after invoking `db.close()` any other query will be ignored and the instance will be put in a _waiting to complete_ state which will invoke the `close` listener once operations have been completed.
|
|
||||||
|
|
||||||
|
|
||||||
### Raspberry Pi Performance
|
|
||||||
This is the output generated after a `make test` call in this repo folder within Arch Linux for RPi.
|
|
||||||
```
|
|
||||||
npm test
|
|
||||||
|
|
||||||
> dblite@0.1.2 test /home/dblite
|
|
||||||
> node test/.test.js
|
|
||||||
|
|
||||||
/home/dblite/dblite.test.sqlite
|
|
||||||
------------------------------
|
|
||||||
main
|
|
||||||
passes: 1, fails: 0, errors: 0
|
|
||||||
------------------------------
|
|
||||||
create table if not exists
|
|
||||||
passes: 1, fails: 0, errors: 0
|
|
||||||
------------------------------
|
|
||||||
100 sequential inserts
|
|
||||||
100 records in 3.067 seconds
|
|
||||||
passes: 1, fails: 0, errors: 0
|
|
||||||
------------------------------
|
|
||||||
1 transaction with 100 inserts
|
|
||||||
200 records in 0.178 seconds
|
|
||||||
passes: 1, fails: 0, errors: 0
|
|
||||||
------------------------------
|
|
||||||
auto escape
|
|
||||||
passes: 1, fails: 0, errors: 0
|
|
||||||
------------------------------
|
|
||||||
auto field
|
|
||||||
fetched 201 rows as objects in 0.029 seconds
|
|
||||||
passes: 1, fails: 0, errors: 0
|
|
||||||
------------------------------
|
|
||||||
auto parsing field
|
|
||||||
fetched 201 rows as normalized objects in 0.038 seconds
|
|
||||||
passes: 1, fails: 0, errors: 0
|
|
||||||
------------------------------
|
|
||||||
many selects at once
|
|
||||||
different selects in 0.608 seconds
|
|
||||||
passes: 1, fails: 0, errors: 0
|
|
||||||
------------------------------
|
|
||||||
db.query() arguments
|
|
||||||
[ [ '1' ] ]
|
|
||||||
[ [ '2' ] ]
|
|
||||||
[ { id: 1 } ]
|
|
||||||
[ { id: 2 } ]
|
|
||||||
passes: 5, fails: 0, errors: 0
|
|
||||||
------------------------------
|
|
||||||
utf-8
|
|
||||||
¥ · £ · € · $ · ¢ · ₡ · ₢ · ₣ · ₤ · ₥ · ₦ · ₧ · ₨ · ₩ · ₪ · ₫ · ₭ · ₮ · ₯ · ₹
|
|
||||||
passes: 1, fails: 0, errors: 0
|
|
||||||
------------------------------
|
|
||||||
erease file
|
|
||||||
passes: 1, fails: 0, errors: 0
|
|
||||||
|
|
||||||
------------------------------
|
|
||||||
15 Passes
|
|
||||||
------------------------------
|
|
||||||
```
|
|
||||||
If an SD card can do this good, I guess any other environment should not have problems here ;-)
|
|
||||||
|
|
||||||
### F.A.Q.
|
|
||||||
Here a list of probably common Q&A about this module. Please do not hesitate to ask me more, if necessary, thanks.
|
|
||||||
|
|
||||||
* **How Does It Work?** `dblite` uses a [spawned](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) version of the `sqlite3` executable. It could theoretically work with any other SQL like database but it's tested with `sqlite3-shell` only
|
|
||||||
* **Does It Spawn Per Each Query?** this is a quick one: **NO**! `dblite` spawns once per each database file where usually there is only one database file opened per time.
|
|
||||||
* **How About Memory And Performance?** Accordingly with `node` manual:
|
|
||||||
|
|
||||||
> These child Nodes are still whole new instances of V8.
|
|
||||||
> Assume at least 30ms startup and 10mb memory for each new Node.
|
|
||||||
> That is, you cannot create many thousands of them.
|
|
||||||
|
|
||||||
Since `dblite` spawns only once, there is a little overhead during the database initialization but that's pretty much it, the amount of RAM increases with the amount of data we save or retrieve from the database. The above **Raspberry Pi Benchmark** should ensure that with most common operation, and using transactions where possible, latency and RAM aren't a real issue.
|
|
||||||
* **Why Not The Native One?** I had some difficulty installing this [node-sqlite3 module](https://github.com/developmentseed/node-sqlite3#name) due `node-gyp` incompatibilities with some **ARM** based device in both *Debian* and *ArchLinux*. Since I really needed an sqlite manager for the next version of [polpetta](https://github.com/WebReflection/polpetta#က-polpetta) which aim is to have a complete, lightweight, and super fast web server in many embedded hardware such RPi, Cubieboard, and others, and since I needed something able to work with multiple core too, I've decided to try this road wrapping the native, easy to install and update, `sqlite3` shell client and do everything I need. So far, so good I would say ;-)
|
|
||||||
* **Isn't `params` and `fields` an ambiguous choice?** At the very beginning I wasn't sure myself if that would have worked as API choice but later on I've changed my mind. First of all, it's very easy to spot special chars in the `SQL` statement. If present, params is mandatory and used, as easy as that. Secondly, if an object has functions as value, it's obviously a `fields` object, 'cause `params` cannot contains functions since these are not compatible with `JSON` serialization, neither meaningful for the database. The only case where `fields` might be confused with `params` is when no `params` has been specified, and `fields` is an `Array`. In this case I believe you are the same one that wrote the SQL too and know upfront if there are fields to retrieve from `params` or not so this is actually a *non real-world* problem and as soon as you try this API you'll realize it feels intuitive and right.
|
|
||||||
* **Are Transactions Supported?** ... **YES**, transactions are supported simply performing multiple queries as you would do in *sqlite3* shell:
|
|
||||||
```javascript
|
|
||||||
db.query('BEGIN TRANSACTION');
|
|
||||||
for(var i = 0; i < 100; i++) {
|
|
||||||
db.query('INSERT INTO table VALUES(?, ?)', [null, Math.random()]);
|
|
||||||
}
|
|
||||||
db.query('COMMIT');
|
|
||||||
```
|
|
||||||
The test file has a transaction with 100 records in it, [have a look](test/dblite.js).
|
|
||||||
* **Can I Connect To A `:memory:` Database?** well, you can do anything you would do with `sqlite3` shell so **YES**
|
|
||||||
```javascript
|
|
||||||
var db = dblite(':memory:'); // that's it!
|
|
||||||
```
|
|
||||||
|
|
||||||
### License
|
|
||||||
The usual Mit Style, thinking about the [WTFPL](http://en.wikipedia.org/wiki/WTFPL) though ... stay tuned for updates.
|
|
||||||
|
|
||||||
Copyright (C) 2013 by WebReflection
|
|
||||||
|
|
||||||
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.
|
|
61
node_modules/dblite/package.json
generated
vendored
61
node_modules/dblite/package.json
generated
vendored
@ -1,61 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "0.6.1",
|
|
||||||
"license": "MIT",
|
|
||||||
"engine": "node >= 0.6.0",
|
|
||||||
"name": "dblite",
|
|
||||||
"description": "a zero hassle wrapper for sqlite - requires sqlite3 3.8.6 or greater",
|
|
||||||
"homepage": "https://github.com/WebReflection/dblite",
|
|
||||||
"keywords": [
|
|
||||||
"sqlite",
|
|
||||||
"sqlite3",
|
|
||||||
"shell",
|
|
||||||
"query",
|
|
||||||
"embedded",
|
|
||||||
"arch linux",
|
|
||||||
"raspberry pi",
|
|
||||||
"cubieboard",
|
|
||||||
"cubieboard2",
|
|
||||||
"simple",
|
|
||||||
"no gyp",
|
|
||||||
"no compile",
|
|
||||||
"no hassle",
|
|
||||||
"wrap",
|
|
||||||
"spawn"
|
|
||||||
],
|
|
||||||
"author": {
|
|
||||||
"name": "Andrea Giammarchi",
|
|
||||||
"url": "http://webreflection.blogspot.com/"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/WebReflection/dblite.git"
|
|
||||||
},
|
|
||||||
"main": "./build/dblite.node.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "node test/.test.js"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/WebReflection/dblite/issues"
|
|
||||||
},
|
|
||||||
"_id": "dblite@0.6.1",
|
|
||||||
"_shasum": "18e6d3811f4031ff0119e8a7b13ef1558215376a",
|
|
||||||
"_from": "dblite@>=0.6.1 <0.7.0",
|
|
||||||
"_npmVersion": "1.4.9",
|
|
||||||
"_npmUser": {
|
|
||||||
"name": "webreflection",
|
|
||||||
"email": "andrea.giammarchi@gmail.com"
|
|
||||||
},
|
|
||||||
"maintainers": [
|
|
||||||
{
|
|
||||||
"name": "webreflection",
|
|
||||||
"email": "andrea.giammarchi@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dist": {
|
|
||||||
"shasum": "18e6d3811f4031ff0119e8a7b13ef1558215376a",
|
|
||||||
"tarball": "http://registry.npmjs.org/dblite/-/dblite-0.6.1.tgz"
|
|
||||||
},
|
|
||||||
"directories": {},
|
|
||||||
"_resolved": "https://registry.npmjs.org/dblite/-/dblite-0.6.1.tgz",
|
|
||||||
"readme": "ERROR: No README data found!"
|
|
||||||
}
|
|
8
node_modules/es6-shim/.flowconfig
generated
vendored
8
node_modules/es6-shim/.flowconfig
generated
vendored
@ -1,8 +0,0 @@
|
|||||||
[ignore]
|
|
||||||
.min.js
|
|
||||||
Gruntfile.js
|
|
||||||
.map
|
|
||||||
|
|
||||||
[include]
|
|
||||||
es6-shim.js
|
|
||||||
es6-sham.js
|
|
68
node_modules/es6-shim/.jscs.json
generated
vendored
68
node_modules/es6-shim/.jscs.json
generated
vendored
@ -1,68 +0,0 @@
|
|||||||
{
|
|
||||||
"additionalRules": [],
|
|
||||||
|
|
||||||
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
|
|
||||||
|
|
||||||
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch", "function"],
|
|
||||||
|
|
||||||
"disallowSpaceAfterKeywords": [],
|
|
||||||
|
|
||||||
"requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true },
|
|
||||||
"requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true },
|
|
||||||
"disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true },
|
|
||||||
"requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true },
|
|
||||||
"disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true },
|
|
||||||
|
|
||||||
"requireSpaceBetweenArguments": true,
|
|
||||||
|
|
||||||
"disallowSpacesInsideParentheses": true,
|
|
||||||
|
|
||||||
"disallowSpacesInsideArrayBrackets": true,
|
|
||||||
|
|
||||||
"disallowQuotedKeysInObjects": "allButReserved",
|
|
||||||
|
|
||||||
"disallowSpaceAfterObjectKeys": true,
|
|
||||||
|
|
||||||
"requireCommaBeforeLineBreak": true,
|
|
||||||
|
|
||||||
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
|
|
||||||
"requireSpaceAfterPrefixUnaryOperators": [],
|
|
||||||
|
|
||||||
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
|
|
||||||
"requireSpaceBeforePostfixUnaryOperators": [],
|
|
||||||
|
|
||||||
"disallowSpaceBeforeBinaryOperators": [],
|
|
||||||
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
|
|
||||||
|
|
||||||
"requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
|
|
||||||
"disallowSpaceAfterBinaryOperators": [],
|
|
||||||
|
|
||||||
"disallowImplicitTypeConversion": ["binary", "string"],
|
|
||||||
|
|
||||||
"disallowKeywords": ["with", "eval"],
|
|
||||||
|
|
||||||
"requireKeywordsOnNewLine": [],
|
|
||||||
"disallowKeywordsOnNewLine": ["else"],
|
|
||||||
|
|
||||||
"requireLineFeedAtFileEnd": true,
|
|
||||||
|
|
||||||
"disallowTrailingWhitespace": true,
|
|
||||||
|
|
||||||
"disallowTrailingComma": true,
|
|
||||||
|
|
||||||
"excludeFiles": ["node_modules/**", "vendor/**"],
|
|
||||||
|
|
||||||
"disallowMultipleLineStrings": true,
|
|
||||||
|
|
||||||
"requireDotNotation": true,
|
|
||||||
|
|
||||||
"requireParenthesesAroundIIFE": true,
|
|
||||||
|
|
||||||
"validateLineBreaks": "LF",
|
|
||||||
|
|
||||||
"validateQuoteMarks": {
|
|
||||||
"escape": true,
|
|
||||||
"mark": "'"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
3
node_modules/es6-shim/.jshintrc
generated
vendored
3
node_modules/es6-shim/.jshintrc
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"es3": true
|
|
||||||
}
|
|
7
node_modules/es6-shim/.npmignore
generated
vendored
7
node_modules/es6-shim/.npmignore
generated
vendored
@ -1,7 +0,0 @@
|
|||||||
.DS_Store
|
|
||||||
node_modules/
|
|
||||||
test/
|
|
||||||
components
|
|
||||||
build
|
|
||||||
.travis.yml
|
|
||||||
testling.html
|
|
233
node_modules/es6-shim/CHANGELOG.md
generated
vendored
233
node_modules/es6-shim/CHANGELOG.md
generated
vendored
@ -1,233 +0,0 @@
|
|||||||
# es6-shim x.x.x (not yet released)
|
|
||||||
|
|
||||||
# es6-shim 0.23.0 (26 Jan 2015)
|
|
||||||
* Use Symbol.species when available, else fall back to "@@species" (renamed from "@@create")
|
|
||||||
* Fix `npm run test-native`
|
|
||||||
* Correct broken Math implementations: `log1p`, `exmp1`, `tanh`, `acosh`, `cosh`, `sinh`, `round` (#314)
|
|
||||||
* Update `jscs`, `grunt-saucelabs`, `jshint`
|
|
||||||
|
|
||||||
# es6-shim 0.22.2 (4 Jan 2015)
|
|
||||||
* Faster travis-ci builds
|
|
||||||
* Better ES3 support: quoting/avoiding reserved words
|
|
||||||
* Update `mocha`, `jscs`, `jshint`, `grunt-saucelabs`, `uglify-js`
|
|
||||||
|
|
||||||
# es6-shim 0.22.1 (13 Dec 2014)
|
|
||||||
* Make RegExp#flags generic, per spec (#310)
|
|
||||||
|
|
||||||
# es6-shim 0.22.0 (12 Dec 2014)
|
|
||||||
* Add RegExp#flags
|
|
||||||
* Make `new RegExp` work with both a regex and a flags string
|
|
||||||
* Remove non-spec `Object.{getPropertyNames,getPropertyDescriptor}`
|
|
||||||
|
|
||||||
# es6-shim 0.21.1 (4 Dec 2014)
|
|
||||||
* Promise/Promise.prototype methods, and String#{startsWith,endsWith} are now not enumerable
|
|
||||||
* Array#{keys, values, entries} should all be @@unscopeable in browsers that support that
|
|
||||||
* Ensure that tampering with Function#{call,apply} won’t break internal methods
|
|
||||||
* Add Math.clz32, RegExp tests
|
|
||||||
* Update es6-sham UMD
|
|
||||||
* Update `chai`, `es5-shim`, `grunt-saucelabs`, `jscs`
|
|
||||||
|
|
||||||
# es6-shim 0.21.0 (21 Nov 2014)
|
|
||||||
* String#contains → String#includes per 2014-11-19 TC39 meeting
|
|
||||||
* Use an invalid identifier as the es6-shim iterator key, so it doesn’t show up in the console as easily.
|
|
||||||
|
|
||||||
# es6-shim 0.20.4 (20 Nov 2014)
|
|
||||||
* Performance improvements: avoid slicing arguments, avoid `Function#call` when possible
|
|
||||||
* Name `String.{fromCodePoint,raw}` for debugging
|
|
||||||
* Fix `String.raw` to match spec
|
|
||||||
* Ensure Chrome’s excess Promise methods are purged
|
|
||||||
* Ensure `Set#keys === Set#values`, per spec
|
|
||||||
|
|
||||||
# es6-shim 0.20.3 (19 Nov 2014)
|
|
||||||
* Fix Set#add and Map#set to always return "this" (#302)
|
|
||||||
* Clarify TypeError messages thrown by Map/Set
|
|
||||||
* Fix Chrome 38 bug with Array#values
|
|
||||||
|
|
||||||
# es6-shim 0.20.2 (28 Oct 2014)
|
|
||||||
* Fix AMD (#299)
|
|
||||||
|
|
||||||
# es6-shim 0.20.1 (27 Oct 2014)
|
|
||||||
* Set#delete and Map#delete should return false unless a deletion occurred. (#298)
|
|
||||||
|
|
||||||
# es6-shim 0.20.0 (26 Oct 2014)
|
|
||||||
* Use a more reliable UMD
|
|
||||||
* export the global object rather than undefined
|
|
||||||
|
|
||||||
# es6-shim 0.19.2 (25 Oct 2014)
|
|
||||||
* Set#delete and Map#delete should return a boolean indicating success. (#298)
|
|
||||||
* Make style consistent; add jscs
|
|
||||||
|
|
||||||
# es6-shim 0.19.1 (14 Oct 2014)
|
|
||||||
* Fix Map#set and Set#add to be chainable (#295)
|
|
||||||
* Update mocha
|
|
||||||
|
|
||||||
# es6-shim 0.19.0 (9 Oct 2014)
|
|
||||||
* Detect and override noncompliant Map in Firefox 32 (#294)
|
|
||||||
* Fix Map and Set for engines that don’t preserve numeric key order (#292, #290)
|
|
||||||
* Detect and override noncompliant Safari 7.1 Promises (#289)
|
|
||||||
* Fix Array#keys and Array#entries in Safari 7.1
|
|
||||||
* General style and whitespace cleanup
|
|
||||||
* Update dependencies
|
|
||||||
* Clean up tests for ES3 by removing reserved words
|
|
||||||
|
|
||||||
# es6-shim 0.18.0 (6 Sep 2014)
|
|
||||||
* Speed up String#trim replacement (#284)
|
|
||||||
* named Array#find and Array#findIndex for easier debugging
|
|
||||||
* Replace broken native implementation in Firefox 25-31 for Array#find and Array#findIndex
|
|
||||||
* Ensure String.fromCodePoint has the correct length in Firefox
|
|
||||||
* List the license in `package.json` for `npm`
|
|
||||||
* Array.from: fix spec bug with Array.from([], undefined) throwing
|
|
||||||
* Array.from: fix Firefox Array.from bug wrt swallowing negative lengths vs throwing
|
|
||||||
|
|
||||||
# es6-shim 0.17.0 (31 Aug 2014)
|
|
||||||
* Added es6-sham (#281)
|
|
||||||
* Fixing some flaky tests (#268)
|
|
||||||
* Tweaking how ArrayIterator is checked in its "next" function
|
|
||||||
* Cleaning up some of the logic in Array.from
|
|
||||||
|
|
||||||
# es6-shim 0.16.0 (6 Aug 2014)
|
|
||||||
* Array#find and Array#findIndex: no longer skips holes in sparse arrays, per https://bugs.ecmascript.org/show_bug.cgi?id=3107
|
|
||||||
|
|
||||||
# es6-shim 0.15.1 (5 Aug 2014)
|
|
||||||
* Array.from: now correctly throws if provided `undefined` as a mapper function
|
|
||||||
* Array.from: now correctly works if provided a falsy `thisArg`
|
|
||||||
* Fix tests so they work properly when Array#(values|keys|entries) are not present
|
|
||||||
* Add `npm run lint` to run style checks independently
|
|
||||||
* Add `test/native.html` so browsers can be easily checked for shim-less compliance.
|
|
||||||
|
|
||||||
# es6-shim 0.15.0 (31 Jul 2014)
|
|
||||||
* Object.assign no longer throws on null or undefined sources, per https://bugs.ecmascript.org/show_bug.cgi?id=3096
|
|
||||||
|
|
||||||
# es6-shim 0.14.0 (20 Jul 2014)
|
|
||||||
* Properly recognize Symbol.iterator when it is present (#277)
|
|
||||||
* Fix Math.clz’s improper handling of values that coerce to NaN (#269)
|
|
||||||
* Fix incorrect handling of negative end index on Array#fill (#270)
|
|
||||||
* Removed Object.getOwnPropertyKeys, which shouldn’t be anywhere (#267)
|
|
||||||
* Fixed arity of Map and Set constructors, per 2014.04.27 draft spec (rev 24)
|
|
||||||
* Added a full additional suite of ES6 promise tests (thanks to @smikes!) (#265)
|
|
||||||
* Make Number.isInteger a bit more efficient (#266)
|
|
||||||
* Added `npm run test-native` to expose how broken implementations are without the shim ;-)
|
|
||||||
* Added additional tests
|
|
||||||
|
|
||||||
# es6-shim 0.13.0 (11 Jun 2014)
|
|
||||||
* Adapt to new Array.from changes: mapper function is now called with both value and index (#261, #262)
|
|
||||||
* More reliably getting the global object in strict mode to fix node-webkit (#258, #259)
|
|
||||||
* Properly test the global Promise for ignoring non-function callbacks (#258)
|
|
||||||
|
|
||||||
# es6-shim 0.12.0 (4 Jun 2014)
|
|
||||||
* Fix String#trim implementations that incorrectly trim \u0085
|
|
||||||
* Stop relying on ArrayIterator being a public var, fixing Safari 8
|
|
||||||
|
|
||||||
# es6-shim 0.11.1 (2 Jun 2014)
|
|
||||||
* Make sure to shim Object.assign in all environments, not just true ES5
|
|
||||||
* Now including minified file and source map
|
|
||||||
|
|
||||||
# es6-shim 0.11.0 (11 May 2014)
|
|
||||||
* Remove `Object.getOwnPropertyDescriptors`, per spec. (#234, #235)
|
|
||||||
* IE8 fixes. (#163, #236)
|
|
||||||
* Improve `Promise` scheduling. (#231)
|
|
||||||
* Add some more standalone shims
|
|
||||||
* Use an Object.create fallback, for better ES3 compatibility
|
|
||||||
* Fix Math.expm1 in more browsers (#84)
|
|
||||||
* Fix es6-shim in Web Workers (#247, #248)
|
|
||||||
* Correct Object.assign to take multiple sources (#241)
|
|
||||||
|
|
||||||
# es6-shim 0.10.1 (13 Mar 2014)
|
|
||||||
* Update bower.json, component.json, and .npmignore (#229, #230, #233)
|
|
||||||
* Minor updates to `Promise` implementation and test suite.
|
|
||||||
* Workaround lack of "strict mode" in IE9. (#232)
|
|
||||||
|
|
||||||
# es6-shim 0.10.0 (1 March 2014)
|
|
||||||
* Implement `Promise`, per spec. (#209, #215, #224, #225)
|
|
||||||
* Make `Map`/`Set` subclassable; support `iterable` argument to
|
|
||||||
constructor (#218)
|
|
||||||
* Rename `Number#clz` to `Math.clz32` (#217)
|
|
||||||
* Bug fixes to `Array#find` and `Array#findIndex` on sparse arrays (#213)
|
|
||||||
* Re-add `Number.isInteger` (mistakenly removed in 0.9.0)
|
|
||||||
* Allow use of `arguments` as an iterable
|
|
||||||
* Minor spec-compliance fixes for `String.raw`
|
|
||||||
* In ES6, `Object.keys` accepts non-Object types (#220)
|
|
||||||
* Improved browser compatibility with IE 9/10, Opera 12 (#225)
|
|
||||||
|
|
||||||
# es6-shim 0.9.3 (5 February 2014)
|
|
||||||
* Per spec, removed `Object.mixin` (#192)
|
|
||||||
* Per spec, treat -0 and +0 keys as identical in Map/Set (#129, #204)
|
|
||||||
* Per spec, `ArrayIterator`/`Array#values()` skips sparse indexes now. (#189)
|
|
||||||
* Added `Array.from`, supporting Map/Set/Array/String iterators (the String iterator iterates over codepoints, not indexes) (#182)
|
|
||||||
* Bug fixes to Map/Set iteration after concurrent delete. (#183)
|
|
||||||
* Bug fixes to `Number.clz`: 0 and 0x100000000 are handled correctly now. (#196)
|
|
||||||
* Added `Math.fround` to truncate to a 32-bit floating point number. (#140)
|
|
||||||
* Bug fix for `Math.cosh` (#178)
|
|
||||||
* Work around Firefox bugs in `String#startsWith` and `String#endsWith` (#172)
|
|
||||||
* Work around Safari bug in `Math.imul`
|
|
||||||
|
|
||||||
# es6-shim 0.9.2 (18 December 2013)
|
|
||||||
* Negative `String#endsWith` position is now handled properly.
|
|
||||||
* `TypeError` is now thrown when string methods are called
|
|
||||||
on `null` / `undefined`.
|
|
||||||
|
|
||||||
# es6-shim 0.9.1 (28 October 2013)
|
|
||||||
* Added `Array#copyWithin` and `Number.MIN_SAFE_INTEGER`
|
|
||||||
* Big speed-up of Maps / Sets for string / number keys:
|
|
||||||
they are O(1) now.
|
|
||||||
* Changed `Math.hypot` according to spec.
|
|
||||||
* Other small fixes.
|
|
||||||
|
|
||||||
# es6-shim 0.9.0 (30 August 2013)
|
|
||||||
* Added Array iteration methods: `Array#keys`, `Array#values`, `Array#entries`, which return an `ArrayIterator`
|
|
||||||
* Changed `Map` and `Set` constructors to conform to spec when called without `new`
|
|
||||||
* Added `Math.imul`
|
|
||||||
* Per spec, removed `Number.toInteger`, `Number.isInteger`, and `Number.MAX_INTEGER`; added `Number.isSafeInteger`, `Number.MAX_SAFE_INTEGER`
|
|
||||||
* Added extensive additional tests for many methods
|
|
||||||
|
|
||||||
# es6-shim 0.8.0 (8 June 2013)
|
|
||||||
* Added `Object.setPrototypeOf`, `Set#keys`, `Set#values`, `Map#keys`, `Map#values`, `Map#entries`, `Set#entries`.
|
|
||||||
* Fixed `String#repeat` according to spec.
|
|
||||||
|
|
||||||
# es6-shim 0.7.0 (2 April 2013)
|
|
||||||
* Added `Array#find`, `Array#findIndex`, `Object.assign`, `Object.mixin`,
|
|
||||||
`Math.cbrt`, `String.fromCodePoint`, `String#codePointAt`.
|
|
||||||
* Removed `Object.isnt`.
|
|
||||||
* Made Math functions fully conform spec.
|
|
||||||
|
|
||||||
# es6-shim 0.6.0 (15 January 2013)
|
|
||||||
* Added `Map#keys`, `Map#values`, `Map#size`, `Set#size`, `Set#clear`.
|
|
||||||
|
|
||||||
# es6-shim 0.5.3 (2 September 2012)
|
|
||||||
* Made `String#startsWith`, `String#endsWith` fully conform spec.
|
|
||||||
|
|
||||||
# es6-shim 0.5.2 (17 June 2012)
|
|
||||||
* Removed `String#toArray` and `Object.isObject` as per spec updates.
|
|
||||||
|
|
||||||
# es6-shim 0.5.1 (14 June 2012)
|
|
||||||
* Made Map and Set follow Spidermonkey implementation instead of V8.
|
|
||||||
`var m = Map(); m.set('key', void 0); m.has('key');` now gives true.
|
|
||||||
|
|
||||||
# es6-shim 0.5.0 (13 June 2012)
|
|
||||||
* Added Number.MAX_INTEGER, Number.EPSILON, Number.parseInt,
|
|
||||||
Number.parseFloat, Number.prototype.clz, Object.isObject.
|
|
||||||
|
|
||||||
# es6-shim 0.4.1 (11 May 2012)
|
|
||||||
* Fixed boundary checking in Number.isInteger.
|
|
||||||
|
|
||||||
# es6-shim 0.4.0 (8 February 2012)
|
|
||||||
* Added Math.log10, Math.log2, Math.log1p, Math.expm1, Math.cosh,
|
|
||||||
Math.sinh, Math.tanh, Math.acosh, Math.asinh, Math.atanh, Math.hypot,
|
|
||||||
Math.trunc.
|
|
||||||
|
|
||||||
# es6-shim 0.3.1 (30 January 2012)
|
|
||||||
* Added IE8 support.
|
|
||||||
|
|
||||||
# es6-shim 0.3.0 (27 January 2012)
|
|
||||||
* Added Number.isFinite() and Object.isnt().
|
|
||||||
|
|
||||||
# es6-shim 0.2.1 (7 January 2012)
|
|
||||||
* Fixed a bug in String#endsWith().
|
|
||||||
|
|
||||||
# es6-shim 0.2.0 (25 December 2011)
|
|
||||||
* Added browser support.
|
|
||||||
* Added tests.
|
|
||||||
* Added Math.sign().
|
|
||||||
|
|
||||||
# es6-shim 0.1.0 (25 December 2011)
|
|
||||||
* Initial release
|
|
98
node_modules/es6-shim/Gruntfile.js
generated
vendored
98
node_modules/es6-shim/Gruntfile.js
generated
vendored
@ -1,98 +0,0 @@
|
|||||||
module.exports = function (grunt) {
|
|
||||||
var browsers = [
|
|
||||||
{ browserName: "firefox", version: "19", platform: "XP" },
|
|
||||||
{ browserName: "firefox", platform: "linux" },
|
|
||||||
{ browserName: "chrome", platform: "linux" },
|
|
||||||
{ browserName: "internet explorer", platform: "Windows 8.1", version: "11" },
|
|
||||||
{ browserName: "internet explorer", platform: "WIN8", version: "10" },
|
|
||||||
{ browserName: "internet explorer", platform: "VISTA", version: "9" },
|
|
||||||
{ browserName: 'safari', platform: 'OS X 10.6' },
|
|
||||||
{ browserName: 'safari', platform: 'OS X 10.8' },
|
|
||||||
{ browserName: 'safari', platform: 'OS X 10.9' },
|
|
||||||
{ browserName: 'iphone', platform: 'OS X 10.9', version: '7.1' },
|
|
||||||
{ browserName: 'android', platform: 'Linux', version: '4.4' },
|
|
||||||
];
|
|
||||||
var extraBrowsers = [
|
|
||||||
{ browserName: "firefox", platform: "linux", version: "30" },
|
|
||||||
{ browserName: "firefox", platform: "linux", version: "25" },
|
|
||||||
{ browserName: "firefox", platform: "OS X 10.9" },
|
|
||||||
{ browserName: "chrome", platform: "XP" },
|
|
||||||
{ browserName: "chrome", platform: "OS X 10.9" },
|
|
||||||
{ browserName: 'iphone', platform: 'OS X 10.8', version: '6.1' },
|
|
||||||
{ browserName: 'iphone', platform: 'OS X 10.8', version: '5.1' },
|
|
||||||
{ browserName: 'android', platform: 'Linux', version: '4.2' },
|
|
||||||
// XXX haven't investigated these:
|
|
||||||
//{ browserName: "opera", platform: "Windows 2008", version: "12" }
|
|
||||||
//{ browserName: 'iphone', platform: 'OS X 10.6', version: '4.3' },
|
|
||||||
//{ browserName: 'android', platform: 'Linux', version: '4.0' },
|
|
||||||
];
|
|
||||||
if (grunt.option('extra')) {
|
|
||||||
browsers = browsers.concat(extraBrowsers);
|
|
||||||
}
|
|
||||||
grunt.initConfig({
|
|
||||||
connect: {
|
|
||||||
server: {
|
|
||||||
options: {
|
|
||||||
base: "",
|
|
||||||
port: 9999,
|
|
||||||
useAvailablePort: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'saucelabs-mocha': {
|
|
||||||
all: {
|
|
||||||
options: {
|
|
||||||
urls: (function () {
|
|
||||||
var urls = ["http://localhost:9999/test/"];
|
|
||||||
if (grunt.option('extra')) {
|
|
||||||
urls.push("http://localhost:9999/test-sham/");
|
|
||||||
}
|
|
||||||
return urls;
|
|
||||||
}()),
|
|
||||||
//tunnelTimeout: 5,
|
|
||||||
build: process.env.TRAVIS_BUILD_NUMBER,
|
|
||||||
tunneled: !process.env.SAUCE_HAS_TUNNEL,
|
|
||||||
identifier: process.env.TRAVIS_JOB_NUMBER,
|
|
||||||
sauceConfig: {
|
|
||||||
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER
|
|
||||||
},
|
|
||||||
//concurrency: 3,
|
|
||||||
browsers: browsers,
|
|
||||||
testname: (function () {
|
|
||||||
var testname = "mocha";
|
|
||||||
if (process.env.TRAVIS_PULL_REQUEST &&
|
|
||||||
process.env.TRAVIS_PULL_REQUEST !== 'false') {
|
|
||||||
testname += ' (PR '+process.env.TRAVIS_PULL_REQUEST+')';
|
|
||||||
}
|
|
||||||
if (process.env.TRAVIS_BRANCH &&
|
|
||||||
process.env.TRAVIS_BRANCH !== 'false') {
|
|
||||||
testname += ' (branch '+process.env.TRAVIS_BRANCH+')';
|
|
||||||
}
|
|
||||||
return testname;
|
|
||||||
})(),
|
|
||||||
tags: (function () {
|
|
||||||
var tags = [];
|
|
||||||
if (process.env.TRAVIS_PULL_REQUEST &&
|
|
||||||
process.env.TRAVIS_PULL_REQUEST !== 'false') {
|
|
||||||
tags.push('PR-'+process.env.TRAVIS_PULL_REQUEST);
|
|
||||||
}
|
|
||||||
if (process.env.TRAVIS_BRANCH &&
|
|
||||||
process.env.TRAVIS_BRANCH !== 'false') {
|
|
||||||
tags.push(process.env.TRAVIS_BRANCH);
|
|
||||||
}
|
|
||||||
return tags;
|
|
||||||
})()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {}
|
|
||||||
});
|
|
||||||
// Loading dependencies
|
|
||||||
for (var key in grunt.file.readJSON("package.json").devDependencies) {
|
|
||||||
if (key !== "grunt" && key.indexOf("grunt") === 0) {
|
|
||||||
grunt.loadNpmTasks(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
grunt.registerTask("dev", ["connect", "watch"]);
|
|
||||||
grunt.registerTask("sauce", ["connect", "saucelabs-mocha"]);
|
|
||||||
};
|
|
217
node_modules/es6-shim/README.md
generated
vendored
217
node_modules/es6-shim/README.md
generated
vendored
@ -1,217 +0,0 @@
|
|||||||
# ES6 Shim
|
|
||||||
Provides compatibility shims so that legacy JavaScript engines behave as
|
|
||||||
closely as possible to ECMAScript 6 (Harmony).
|
|
||||||
|
|
||||||
[![Build Status][1]][2] [![dependency status][3]][4] [![dev dependency status][5]][6]
|
|
||||||
|
|
||||||
[![browser support](https://ci.testling.com/paulmillr/es6-shim.png)](https://ci.testling.com/paulmillr/es6-shim)
|
|
||||||
|
|
||||||
[![Sauce Test Status](https://saucelabs.com/browser-matrix/es6-shim.svg)](https://saucelabs.com/u/es6-shim)
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
If you want to use it in browser:
|
|
||||||
|
|
||||||
* Just include es6-shim before your scripts.
|
|
||||||
* Include [es5-shim](https://github.com/kriskowal/es5-shim) if your browser doesn't support ECMAScript 5.
|
|
||||||
* `component install paulmillr/es6-shim` if you’re using [component(1)](https://github.com/component/component).
|
|
||||||
* `bower install es6-shim` if you’re using [Twitter Bower](http://bower.io/).
|
|
||||||
|
|
||||||
For node.js:
|
|
||||||
|
|
||||||
npm install es6-shim
|
|
||||||
|
|
||||||
In both browser and node you may also want to include `unorm`; see the
|
|
||||||
[`String.prototype.normalize`](#stringprototypenormalize) section for
|
|
||||||
details.
|
|
||||||
|
|
||||||
## Safe shims
|
|
||||||
|
|
||||||
* `Map`, `Set` (requires ES5)
|
|
||||||
* `Promise`
|
|
||||||
* `String`:
|
|
||||||
* `fromCodePoint()` ([a standalone shim is also available](http://mths.be/fromcodepoint))
|
|
||||||
* `raw()`
|
|
||||||
* `String.prototype`:
|
|
||||||
* `codePointAt()` ([a standalone shim is also available](http://mths.be/codepointat))
|
|
||||||
* `repeat()` ([a standalone shim is also available](http://mths.be/repeat))
|
|
||||||
* `startsWith()` ([a standalone shim is also available](http://mths.be/startswith))
|
|
||||||
* `endsWith()` ([a standalone shim is also available](http://mths.be/endswith))
|
|
||||||
* `includes()` ([a standalone shim is also available](http://mths.be/includes))
|
|
||||||
* `RegExp`:
|
|
||||||
* `new RegExp`, when given a RegExp as the pattern, will no longer throw when given a "flags" string argument. (requires ES5)
|
|
||||||
* `RegExp.prototype`:
|
|
||||||
* `flags` (requires ES5) ([a standalone shim is also available](https://github.com/es-shims/RegExp.prototype.flags))
|
|
||||||
* `Number`:
|
|
||||||
* `MAX_SAFE_INTEGER`
|
|
||||||
* `MIN_SAFE_INTEGER`
|
|
||||||
* `EPSILON`
|
|
||||||
* `parseInt()`
|
|
||||||
* `parseFloat()`
|
|
||||||
* `isNaN()`([a standalone shim is also available](https://npmjs.org/package/is-nan))
|
|
||||||
* `isInteger()`
|
|
||||||
* `isSafeInteger()`
|
|
||||||
* `isFinite()`
|
|
||||||
* `Array`:
|
|
||||||
* `from()` ([a standalone shim is also available](https://npmjs.org/package/array.from))
|
|
||||||
* `of()` ([a standalone shim is also available](https://npmjs.org/package/array.of))
|
|
||||||
* `Array.prototype`:
|
|
||||||
* `copyWithin()`
|
|
||||||
* `fill()`
|
|
||||||
* `find()` ([a standalone shim is also available](https://github.com/paulmillr/Array.prototype.find))
|
|
||||||
* `findIndex()` ([a standalone shim is also available](https://github.com/paulmillr/Array.prototype.findIndex))
|
|
||||||
* `keys()` (note: keys/values/entries return an `ArrayIterator` object)
|
|
||||||
* `entries()`
|
|
||||||
* `values()`
|
|
||||||
* `Object`:
|
|
||||||
* `keys()` (in ES5, but no longer throws on non-object non-null/undefined values in ES6)
|
|
||||||
* `is()` ([a standalone shim is also available](https://github.com/ljharb/object-is))
|
|
||||||
* `assign()` ([a standalone shim is also available](https://github.com/ljharb/object.assign))
|
|
||||||
* `setPrototypeOf()` (IE >= 11)
|
|
||||||
* `Math`:
|
|
||||||
* `acosh()`
|
|
||||||
* `asinh()`
|
|
||||||
* `atanh()`
|
|
||||||
* `cbrt()`
|
|
||||||
* `clz32()`
|
|
||||||
* `cosh()`
|
|
||||||
* `expm1()`
|
|
||||||
* `hypot()`
|
|
||||||
* `log2()`
|
|
||||||
* `log10()`
|
|
||||||
* `log1p()`
|
|
||||||
* `sign()`
|
|
||||||
* `sinh()`
|
|
||||||
* `tanh()`
|
|
||||||
* `trunc()`
|
|
||||||
* `imul()`
|
|
||||||
* `fround()`
|
|
||||||
|
|
||||||
Math functions accuracy is 1e-11.
|
|
||||||
|
|
||||||
## Subclassing
|
|
||||||
The `Map`, `Set`, and `Promise` implementations are subclassable.
|
|
||||||
You should use the following pattern to create a subclass in ES5 which
|
|
||||||
will continue to work in ES6:
|
|
||||||
```javascript
|
|
||||||
function MyPromise(exec) {
|
|
||||||
Promise.call(this, exec);
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
Object.setPrototypeOf(MyPromise, Promise);
|
|
||||||
MyPromise.prototype = Object.create(Promise.prototype, {
|
|
||||||
constructor: { value: MyPromise }
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## String.prototype.normalize
|
|
||||||
Including a proper shim for `String.prototype.normalize` would
|
|
||||||
increase the size of this library by a factor of more than 4.
|
|
||||||
So instead we recommend that you install the
|
|
||||||
[`unorm`](https://github.com/walling/unorm)
|
|
||||||
package alongside `es6-shim` if you need `String.prototype.normalize`.
|
|
||||||
See https://github.com/paulmillr/es6-shim/issues/134 for more
|
|
||||||
discussion.
|
|
||||||
|
|
||||||
|
|
||||||
## WeakMap shim
|
|
||||||
It is not possible to implement WeakMap in pure javascript.
|
|
||||||
The [es6-collections](https://github.com/WebReflection/es6-collections)
|
|
||||||
implementation doesn't hold values strongly, which is critical
|
|
||||||
for the collection. es6-shim decided to not include an incorrect shim.
|
|
||||||
|
|
||||||
WeakMap has a very unusual use-case so you probably won't need it at all
|
|
||||||
(use simple `Map` instead).
|
|
||||||
|
|
||||||
## Getting started
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
'abc'.startsWith('a') // true
|
|
||||||
'abc'.endsWith('a') // false
|
|
||||||
'john alice'.includes('john') // true
|
|
||||||
'123'.repeat(2) // '123123'
|
|
||||||
|
|
||||||
Object.is(NaN, NaN) // Fixes ===. 0 isnt -0, NaN is NaN
|
|
||||||
Object.assign({a: 1}, {b: 2}) // {a: 1, b: 2}
|
|
||||||
|
|
||||||
Number.isNaN('123') // false. isNaN('123') will give true.
|
|
||||||
Number.isFinite('asd') // false. Global isFinite() will give true.
|
|
||||||
// Tests if value is a number, finite,
|
|
||||||
// >= -9007199254740992 && <= 9007199254740992 and floor(value) === value
|
|
||||||
Number.isInteger(2.4) // false.
|
|
||||||
|
|
||||||
Math.sign(400) // 1, 0 or -1 depending on sign. In this case 1.
|
|
||||||
|
|
||||||
[5, 10, 15, 10].find(function (item) {return item / 2 === 5;}) // 10
|
|
||||||
[5, 10, 15, 10].findIndex(function (item) {return item / 2 === 5;}) // 1
|
|
||||||
|
|
||||||
// Replacement for `{}` key-value storage.
|
|
||||||
// Keys can be anything.
|
|
||||||
var map = new Map()
|
|
||||||
map.set('John', 25)
|
|
||||||
map.set('Alice', 400)
|
|
||||||
map.set(['meh'], 555)
|
|
||||||
map.get(['meh']) // undefined because you need to use exactly the same object.
|
|
||||||
map.delete('Alice')
|
|
||||||
map.keys()
|
|
||||||
map.values()
|
|
||||||
map.size // 2
|
|
||||||
|
|
||||||
// Useful for storing unique items.
|
|
||||||
var set = new Set()
|
|
||||||
set.add(1)
|
|
||||||
set.add(5)
|
|
||||||
set.has(1)
|
|
||||||
set.has(4) // => false
|
|
||||||
set.delete(5)
|
|
||||||
|
|
||||||
// Promises, see
|
|
||||||
// http://www.slideshare.net/domenicdenicola/callbacks-promises-and-coroutines-oh-my-the-evolution-of-asynchronicity-in-javascript
|
|
||||||
// https://github.com/petkaantonov/bluebird/#what-are-promises-and-why-should-i-use-them
|
|
||||||
Promise.resolve(5).then(function (value) {
|
|
||||||
if ( ... ) throw new Error("whoops!");
|
|
||||||
// do some stuff
|
|
||||||
return anotherPromise();
|
|
||||||
}).catch(function (e) {
|
|
||||||
// any errors thrown asynchronously end up here
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
Other stuff:
|
|
||||||
|
|
||||||
* [ECMAScript 6 drafts](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts)
|
|
||||||
* [Harmony proposals](http://wiki.ecmascript.org/doku.php?id=harmony:harmony)
|
|
||||||
|
|
||||||
## License
|
|
||||||
The project was initially based on [es6-shim by Axel Rauschmayer](https://github.com/rauschma/es6-shim).
|
|
||||||
|
|
||||||
Current maintainers are: [Paul Miller](http://paulmillr.com), [Jordan Harband](https://github.com/ljharb), and [C. Scott Ananian](http://cscott.net).
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013-2014 Paul Miller (http://paulmillr.com)
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
[1]: https://travis-ci.org/paulmillr/es6-shim.svg
|
|
||||||
[2]: https://travis-ci.org/paulmillr/es6-shim
|
|
||||||
[3]: https://david-dm.org/paulmillr/es6-shim.svg
|
|
||||||
[4]: https://david-dm.org/paulmillr/es6-shim
|
|
||||||
[5]: https://david-dm.org/paulmillr/es6-shim/dev-status.svg
|
|
||||||
[6]: https://david-dm.org/paulmillr/es6-shim#info=devDependencies
|
|
||||||
|
|
29
node_modules/es6-shim/bower.json
generated
vendored
29
node_modules/es6-shim/bower.json
generated
vendored
@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "es6-shim",
|
|
||||||
"version": "0.23.0",
|
|
||||||
"repo": "paulmillr/es6-shim",
|
|
||||||
"description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines",
|
|
||||||
"keywords": [
|
|
||||||
"ecmascript",
|
|
||||||
"harmony",
|
|
||||||
"es6",
|
|
||||||
"shim",
|
|
||||||
"promise",
|
|
||||||
"promises",
|
|
||||||
"setPrototypeOf",
|
|
||||||
"map",
|
|
||||||
"set",
|
|
||||||
"__proto__"
|
|
||||||
],
|
|
||||||
"main": "es6-shim.js",
|
|
||||||
"scripts": ["es6-shim.js"],
|
|
||||||
"dependencies": {},
|
|
||||||
"development": {},
|
|
||||||
"ignore": [
|
|
||||||
"**/.*",
|
|
||||||
"node_modules",
|
|
||||||
"components",
|
|
||||||
"test"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
23
node_modules/es6-shim/component.json
generated
vendored
23
node_modules/es6-shim/component.json
generated
vendored
@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "es6-shim",
|
|
||||||
"version": "0.23.0",
|
|
||||||
"repo": "paulmillr/es6-shim",
|
|
||||||
"description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines",
|
|
||||||
"keywords": [
|
|
||||||
"ecmascript",
|
|
||||||
"harmony",
|
|
||||||
"es6",
|
|
||||||
"shim",
|
|
||||||
"promise",
|
|
||||||
"promises",
|
|
||||||
"setPrototypeOf",
|
|
||||||
"map",
|
|
||||||
"set",
|
|
||||||
"__proto__"
|
|
||||||
],
|
|
||||||
"main": "es6-shim.js",
|
|
||||||
"scripts": ["es6-shim.js"],
|
|
||||||
"dependencies": {},
|
|
||||||
"development": {}
|
|
||||||
}
|
|
||||||
|
|
119
node_modules/es6-shim/es6-sham.js
generated
vendored
119
node_modules/es6-shim/es6-sham.js
generated
vendored
@ -1,119 +0,0 @@
|
|||||||
/*!
|
|
||||||
* https://github.com/paulmillr/es6-shim
|
|
||||||
* @license es6-shim Copyright 2013-2014 by Paul Miller (http://paulmillr.com)
|
|
||||||
* and contributors, MIT License
|
|
||||||
* es6-sham: v0.23.0
|
|
||||||
* see https://github.com/paulmillr/es6-shim/blob/0.22.2/LICENSE
|
|
||||||
* Details and documentation:
|
|
||||||
* https://github.com/paulmillr/es6-shim/
|
|
||||||
*/
|
|
||||||
|
|
||||||
// UMD (Universal Module Definition)
|
|
||||||
// see https://github.com/umdjs/umd/blob/master/returnExports.js
|
|
||||||
(function (root, factory) {
|
|
||||||
/*global define, exports, module */
|
|
||||||
if (typeof define === 'function' && define.amd) {
|
|
||||||
// AMD. Register as an anonymous module.
|
|
||||||
define(factory);
|
|
||||||
} else if (typeof exports === 'object') {
|
|
||||||
// Node. Does not work with strict CommonJS, but
|
|
||||||
// only CommonJS-like enviroments that support module.exports,
|
|
||||||
// like Node.
|
|
||||||
module.exports = factory();
|
|
||||||
} else {
|
|
||||||
// Browser globals (root is window)
|
|
||||||
root.returnExports = factory();
|
|
||||||
}
|
|
||||||
}(this, function (undefined) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/*jshint evil: true */
|
|
||||||
var getGlobal = new Function('return this;');
|
|
||||||
/*jshint evil: false */
|
|
||||||
|
|
||||||
var globals = getGlobal();
|
|
||||||
var Object = globals.Object;
|
|
||||||
|
|
||||||
// NOTE: This versions needs object ownership
|
|
||||||
// beacuse every promoted object needs to be reassigned
|
|
||||||
// otherwise uncompatible browsers cannot work as expected
|
|
||||||
//
|
|
||||||
// NOTE: This might need es5-shim or polyfills upfront
|
|
||||||
// because it's based on ES5 API.
|
|
||||||
// (probably just an IE <= 8 problem)
|
|
||||||
//
|
|
||||||
// NOTE: nodejs is fine in version 0.8, 0.10, and future versions.
|
|
||||||
(function () {
|
|
||||||
if (Object.setPrototypeOf) { return; }
|
|
||||||
|
|
||||||
/*jshint proto: true */
|
|
||||||
// @author Andrea Giammarchi - @WebReflection
|
|
||||||
// define into target descriptors from source
|
|
||||||
var copyDescriptors = function (target, source) {
|
|
||||||
getOwnPropertyNames(source).forEach(function (key) {
|
|
||||||
defineProperty(
|
|
||||||
target,
|
|
||||||
key,
|
|
||||||
getOwnPropertyDescriptor(source, key)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return target;
|
|
||||||
};
|
|
||||||
// used as fallback when no promotion is possible
|
|
||||||
var createAndCopy = function (origin, proto) {
|
|
||||||
return copyDescriptors(create(proto), origin);
|
|
||||||
};
|
|
||||||
var create = Object.create;
|
|
||||||
var defineProperty = Object.defineProperty;
|
|
||||||
var getPrototypeOf = Object.getPrototypeOf;
|
|
||||||
var getOwnPropertyNames = Object.getOwnPropertyNames;
|
|
||||||
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
||||||
var proto = Object.prototype;
|
|
||||||
var set, setPrototypeOf;
|
|
||||||
try {
|
|
||||||
// this might fail for various reasons
|
|
||||||
// ignore if Chrome cought it at runtime
|
|
||||||
set = getOwnPropertyDescriptor(proto, '__proto__').set;
|
|
||||||
set.call({}, null);
|
|
||||||
// setter not poisoned, it can promote
|
|
||||||
// Firefox, Chrome
|
|
||||||
setPrototypeOf = function (origin, proto) {
|
|
||||||
set.call(origin, proto);
|
|
||||||
return origin;
|
|
||||||
};
|
|
||||||
} catch (e) {
|
|
||||||
// do one or more feature detections
|
|
||||||
set = {__proto__: null};
|
|
||||||
// if proto does not work, needs to fallback
|
|
||||||
// some Opera, Rhino, ducktape
|
|
||||||
if (set instanceof Object) {
|
|
||||||
setPrototypeOf = createAndCopy;
|
|
||||||
} else {
|
|
||||||
// verify if null objects are buggy
|
|
||||||
set.__proto__ = proto;
|
|
||||||
// if null objects are buggy
|
|
||||||
// nodejs 0.8 to 0.10
|
|
||||||
if (set instanceof Object) {
|
|
||||||
setPrototypeOf = function (origin, proto) {
|
|
||||||
// use such bug to promote
|
|
||||||
origin.__proto__ = proto;
|
|
||||||
return origin;
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
// try to use proto or fallback
|
|
||||||
// Safari, old Firefox, many others
|
|
||||||
setPrototypeOf = function (origin, proto) {
|
|
||||||
// if proto is not null
|
|
||||||
return getPrototypeOf(origin) ?
|
|
||||||
// use __proto__ to promote
|
|
||||||
((origin.__proto__ = proto), origin) :
|
|
||||||
// otherwise unable to promote: fallback
|
|
||||||
createAndCopy(origin, proto);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Object.setPrototypeOf = setPrototypeOf;
|
|
||||||
}());
|
|
||||||
|
|
||||||
}));
|
|
1
node_modules/es6-shim/es6-sham.map
generated
vendored
1
node_modules/es6-shim/es6-sham.map
generated
vendored
@ -1 +0,0 @@
|
|||||||
{"version":3,"sources":["es6-sham.js"],"names":["root","factory","define","amd","exports","module","returnExports","this","undefined","getGlobal","Function","globals","Object","setPrototypeOf","copyDescriptors","target","source","getOwnPropertyNames","forEach","key","defineProperty","getOwnPropertyDescriptor","createAndCopy","origin","proto","create","getPrototypeOf","prototype","set","call","e","__proto__"],"mappings":";;;;;;;;;CAYC,SAAUA,EAAMC,GAEf,SAAWC,UAAW,YAAcA,OAAOC,IAAK,CAE9CD,OAAOD,OACF,UAAWG,WAAY,SAAU,CAItCC,OAAOD,QAAUH,QACZ,CAELD,EAAKM,cAAgBL,OAEvBM,KAAM,SAAUC,GAChB,YAGA,IAAIC,GAAY,GAAIC,UAAS,eAG7B,IAAIC,GAAUF,GACd,IAAIG,GAASD,EAAQC,QAWpB,WACC,GAAIA,EAAOC,eAAgB,CAAE,OAK7B,GAAIC,GAAkB,SAAUC,EAAQC,GACtCC,EAAoBD,GAAQE,QAAQ,SAAUC,GAC5CC,EACEL,EACAI,EACAE,EAAyBL,EAAQG,KAGrC,OAAOJ,GAGT,IAAIO,GAAgB,SAAUC,EAAQC,GACpC,MAAOV,GAAgBW,EAAOD,GAAQD,GAExC,IAAIE,GAASb,EAAOa,MACpB,IAAIL,GAAiBR,EAAOQ,cAC5B,IAAIM,GAAiBd,EAAOc,cAC5B,IAAIT,GAAsBL,EAAOK,mBACjC,IAAII,GAA2BT,EAAOS,wBACtC,IAAIG,GAAQZ,EAAOe,SACnB,IAAIC,GAAKf,CACT,KAGEe,EAAMP,EAAyBG,EAAO,aAAaI,GACnDA,GAAIC,QAAS,KAGbhB,GAAiB,SAAUU,EAAQC,GACjCI,EAAIC,KAAKN,EAAQC,EACjB,OAAOD,IAET,MAAOO,GAEPF,GAAOG,UAAW,KAGlB,IAAIH,YAAehB,GAAQ,CACzBC,EAAiBS,MACZ,CAELM,EAAIG,UAAYP,CAGhB,IAAII,YAAehB,GAAQ,CACzBC,EAAiB,SAAUU,EAAQC,GAEjCD,EAAOQ,UAAYP,CACnB,OAAOD,QAEJ,CAGLV,EAAiB,SAAUU,EAAQC,GAEjC,MAAOE,GAAeH,IAElBA,EAAOQ,UAAYP,EAAQD,GAE7BD,EAAcC,EAAQC,MAKhCZ,EAAOC,eAAiBA"}
|
|
11
node_modules/es6-shim/es6-sham.min.js
generated
vendored
11
node_modules/es6-shim/es6-sham.min.js
generated
vendored
@ -1,11 +0,0 @@
|
|||||||
/*!
|
|
||||||
* https://github.com/paulmillr/es6-shim
|
|
||||||
* @license es6-shim Copyright 2013-2014 by Paul Miller (http://paulmillr.com)
|
|
||||||
* and contributors, MIT License
|
|
||||||
* es6-sham: v0.23.0
|
|
||||||
* see https://github.com/paulmillr/es6-shim/blob/0.22.2/LICENSE
|
|
||||||
* Details and documentation:
|
|
||||||
* https://github.com/paulmillr/es6-shim/
|
|
||||||
*/
|
|
||||||
(function(t,e){if(typeof define==="function"&&define.amd){define(e)}else if(typeof exports==="object"){module.exports=e()}else{t.returnExports=e()}})(this,function(t){"use strict";var e=new Function("return this;");var r=e();var n=r.Object;(function(){if(n.setPrototypeOf){return}var t=function(t,e){i(e).forEach(function(r){o(t,r,c(e,r))});return t};var e=function(e,n){return t(r(n),e)};var r=n.create;var o=n.defineProperty;var f=n.getPrototypeOf;var i=n.getOwnPropertyNames;var c=n.getOwnPropertyDescriptor;var u=n.prototype;var a,_;try{a=c(u,"__proto__").set;a.call({},null);_=function(t,e){a.call(t,e);return t}}catch(p){a={__proto__:null};if(a instanceof n){_=e}else{a.__proto__=u;if(a instanceof n){_=function(t,e){t.__proto__=e;return t}}else{_=function(t,r){return f(t)?(t.__proto__=r,t):e(t,r)}}}}n.setPrototypeOf=_})()});
|
|
||||||
//# sourceMappingURL=es6-sham.map
|
|
2136
node_modules/es6-shim/es6-shim.js
generated
vendored
2136
node_modules/es6-shim/es6-shim.js
generated
vendored
File diff suppressed because it is too large
Load Diff
1
node_modules/es6-shim/es6-shim.map
generated
vendored
1
node_modules/es6-shim/es6-shim.map
generated
vendored
File diff suppressed because one or more lines are too long
11
node_modules/es6-shim/es6-shim.min.js
generated
vendored
11
node_modules/es6-shim/es6-shim.min.js
generated
vendored
File diff suppressed because one or more lines are too long
110
node_modules/es6-shim/package.json
generated
vendored
110
node_modules/es6-shim/package.json
generated
vendored
@ -1,110 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "es6-shim",
|
|
||||||
"version": "0.23.0",
|
|
||||||
"author": {
|
|
||||||
"name": "Paul Miller",
|
|
||||||
"url": "http://paulmillr.com"
|
|
||||||
},
|
|
||||||
"description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines",
|
|
||||||
"keywords": [
|
|
||||||
"ecmascript",
|
|
||||||
"harmony",
|
|
||||||
"es6",
|
|
||||||
"shim",
|
|
||||||
"promise",
|
|
||||||
"promises",
|
|
||||||
"setPrototypeOf",
|
|
||||||
"map",
|
|
||||||
"set",
|
|
||||||
"__proto__"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/paulmillr/es6-shim/",
|
|
||||||
"license": "MIT",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/paulmillr/es6-shim.git"
|
|
||||||
},
|
|
||||||
"main": "es6-shim",
|
|
||||||
"scripts": {
|
|
||||||
"test": "npm run lint && npm run test-shim && npm run test-sham",
|
|
||||||
"test-shim": "mocha test/*.js test/*/*.js",
|
|
||||||
"test-sham": "mocha test-sham/*.js",
|
|
||||||
"test-native": "npm run jshint-shim && NO_ES6_SHIM=1 mocha test/*.js test/*/*.js",
|
|
||||||
"lint": "npm run lint-shim && npm run lint-sham",
|
|
||||||
"lint-shim": "npm run jshint-shim && npm run jscs-shim",
|
|
||||||
"lint-sham": "npm run jshint-sham && npm run jscs-sham",
|
|
||||||
"jshint": "npm run jshint-shim && npm run jshint-sham",
|
|
||||||
"jshint-shim": "jshint es6-shim.js test/*.js test/*/*.js",
|
|
||||||
"jshint-sham": "jshint es6-sham.js test-sham/*.js",
|
|
||||||
"jscs": "npm run jscs-shim && npm run jscs-sham",
|
|
||||||
"jscs-shim": "jscs es6-shim.js test/*.js test/*/*.js",
|
|
||||||
"jscs-sham": "jscs es6-sham.js test-sham/*.js",
|
|
||||||
"minify": "npm run minify-shim && npm run minify-sham",
|
|
||||||
"minify-shim": "uglifyjs es6-shim.js --comments --source-map=es6-shim.map -m -b ascii_only=true,beautify=false > es6-shim.min.js",
|
|
||||||
"minify-sham": "uglifyjs es6-sham.js --comments --source-map=es6-sham.map -m -b ascii_only=true,beautify=false > es6-sham.min.js",
|
|
||||||
"sauce": "grunt sauce"
|
|
||||||
},
|
|
||||||
"testling": {
|
|
||||||
"html": "testling.html",
|
|
||||||
"browsers": [
|
|
||||||
"iexplore/6.0..latest",
|
|
||||||
"firefox/3.0..6.0",
|
|
||||||
"firefox/10.0",
|
|
||||||
"firefox/15.0..latest",
|
|
||||||
"firefox/nightly",
|
|
||||||
"chrome/4.0..10.0",
|
|
||||||
"chrome/20.0..latest",
|
|
||||||
"chrome/canary",
|
|
||||||
"opera/10.0..latest",
|
|
||||||
"opera/next",
|
|
||||||
"safari/4.0..latest",
|
|
||||||
"ipad/6.0..latest",
|
|
||||||
"iphone/6.0..latest",
|
|
||||||
"android-browser/4.2..latest"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"dependencies": {},
|
|
||||||
"devDependencies": {
|
|
||||||
"chai": "~1.10.0",
|
|
||||||
"es5-shim": "~4.0.5",
|
|
||||||
"grunt": "~0.4.5",
|
|
||||||
"grunt-contrib-connect": "~0.9.0",
|
|
||||||
"grunt-contrib-watch": "~0.6.1",
|
|
||||||
"grunt-saucelabs": "~8.5.0",
|
|
||||||
"jscs": "~1.10.0",
|
|
||||||
"jshint": "~2.6.0",
|
|
||||||
"mocha": "~2.1.0",
|
|
||||||
"promises-aplus-tests": "~2.1.0",
|
|
||||||
"promises-es6-tests": "~0.5.0",
|
|
||||||
"uglify-js": "~2.4.16"
|
|
||||||
},
|
|
||||||
"gitHead": "fde6f2134762d36e9b1324f212fd939282700ca5",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/paulmillr/es6-shim/issues"
|
|
||||||
},
|
|
||||||
"_id": "es6-shim@0.23.0",
|
|
||||||
"_shasum": "ea65bdcfc076eb109ea839f92dfed8c0517a2b72",
|
|
||||||
"_from": "es6-shim@0.23.0",
|
|
||||||
"_npmVersion": "1.4.28",
|
|
||||||
"_npmUser": {
|
|
||||||
"name": "ljharb",
|
|
||||||
"email": "ljharb@gmail.com"
|
|
||||||
},
|
|
||||||
"maintainers": [
|
|
||||||
{
|
|
||||||
"name": "paulmillr",
|
|
||||||
"email": "paul@paulmillr.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ljharb",
|
|
||||||
"email": "ljharb@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dist": {
|
|
||||||
"shasum": "ea65bdcfc076eb109ea839f92dfed8c0517a2b72",
|
|
||||||
"tarball": "http://registry.npmjs.org/es6-shim/-/es6-shim-0.23.0.tgz"
|
|
||||||
},
|
|
||||||
"directories": {},
|
|
||||||
"_resolved": "https://registry.npmjs.org/es6-shim/-/es6-shim-0.23.0.tgz",
|
|
||||||
"readme": "ERROR: No README data found!"
|
|
||||||
}
|
|
22
node_modules/es6-shim/test-sham/index.html
generated
vendored
22
node_modules/es6-shim/test-sham/index.html
generated
vendored
@ -1,22 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>es6-shim tests</title>
|
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript"></script>
|
|
||||||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
|
|
||||||
<script src="../node_modules/es5-shim/es5-shim.js"></script>
|
|
||||||
<script src="../node_modules/es5-shim/es5-sham.js"></script>
|
|
||||||
<script src="../node_modules/mocha/mocha.js"></script>
|
|
||||||
<!-- note that chai uses Object.create() so needs es5-sham to be loaded -->
|
|
||||||
<script src="../node_modules/chai/chai.js"></script>
|
|
||||||
<script src="../es6-sham.js"></script>
|
|
||||||
<script src="../test/browser-setup.js"></script>
|
|
||||||
<script src="set-prototype-of.js"></script>
|
|
||||||
<script src="../test/browser-onload.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="mocha"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
25
node_modules/es6-shim/test-sham/set-prototype-of.js
generated
vendored
25
node_modules/es6-shim/test-sham/set-prototype-of.js
generated
vendored
@ -1,25 +0,0 @@
|
|||||||
/*global expect */
|
|
||||||
describe('Object.setPrototypeOf(o, p)', function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
it('changes prototype to regular objects', function () {
|
|
||||||
var obj = {a: 123};
|
|
||||||
expect(obj).to.be.an.instanceOf(Object);
|
|
||||||
// sham requires assignment to work cross browser
|
|
||||||
obj = Object.setPrototypeOf(obj, null);
|
|
||||||
expect(obj).not.to.be.an.instanceOf(Object);
|
|
||||||
expect(obj.a).to.equal(123);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('changes prototype to null objects', function () {
|
|
||||||
var obj = Object.create(null);
|
|
||||||
obj.a = 456;
|
|
||||||
expect(obj).not.to.be.an.instanceOf(Object);
|
|
||||||
expect(obj.a).to.equal(456);
|
|
||||||
// sham requires assignment to work cross browser
|
|
||||||
obj = Object.setPrototypeOf(obj, {});
|
|
||||||
expect(obj).to.be.an.instanceOf(Object);
|
|
||||||
expect(obj.a).to.equal(456);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
1
node_modules/getargs/.npmignore
generated
vendored
1
node_modules/getargs/.npmignore
generated
vendored
@ -1 +0,0 @@
|
|||||||
/node_modules
|
|
78
node_modules/getargs/README.md
generated
vendored
78
node_modules/getargs/README.md
generated
vendored
@ -1,78 +0,0 @@
|
|||||||
getargs
|
|
||||||
=======
|
|
||||||
|
|
||||||
Simple utility for parsing/processing variable length argument lists for Javascript functions; also verifies argument types and argument list length.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
Bower - `bower install getargs`; NPM - `npm install getargs`.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
var getArgs = require('getargs')
|
|
||||||
|
|
||||||
function ajax(/* url:string|array, [options]:object, callback:function */){
|
|
||||||
var args = getArgs('url:string|array, [options]:object, callback:function', arguments)
|
|
||||||
|
|
||||||
console.log('url is', args.url)
|
|
||||||
console.log('options is optionally', args.options)
|
|
||||||
console.log('callback', args.callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
## Argument Spec Syntax
|
|
||||||
|
|
||||||
The argument spec is a comma delimited string of individual specs, which look like
|
|
||||||
|
|
||||||
argname:type
|
|
||||||
|
|
||||||
You can specify multiple types by using `|`
|
|
||||||
|
|
||||||
argname:type|type|type
|
|
||||||
|
|
||||||
* `argname` is the name of the argument, and can be called anything
|
|
||||||
* `type` is an optional basic Javascript type. Currently these are supported
|
|
||||||
* `string`
|
|
||||||
* `boolean`
|
|
||||||
* `number`
|
|
||||||
* `object`
|
|
||||||
* `function`
|
|
||||||
* `array`
|
|
||||||
|
|
||||||
### Optional Arguments
|
|
||||||
|
|
||||||
To denote optional arguments, you'd surround `argname` with square brackets `[]`.
|
|
||||||
|
|
||||||
### Type Verification
|
|
||||||
|
|
||||||
getArgs will throw if the arguments have the wrong types
|
|
||||||
|
|
||||||
var args = getArgs('url:string', [1])
|
|
||||||
// Error: Expected url(pos 0) to be a string
|
|
||||||
|
|
||||||
### Argument List Length Verification
|
|
||||||
|
|
||||||
getArgs will throw if there are too many or too few arguments
|
|
||||||
|
|
||||||
> getArgs('a,b', [1])
|
|
||||||
Error: Not enough arguments, expected 2, got 1
|
|
||||||
> getArgs('a,b', [1,1])
|
|
||||||
{ a: 1, b: 1 }
|
|
||||||
> getArgs('a,b', [1,1,1])
|
|
||||||
Error: Too many arguments, expected 2, got 3
|
|
||||||
|
|
||||||
### Spread Operator
|
|
||||||
|
|
||||||
You can mimick ES6's spread operator
|
|
||||||
|
|
||||||
var args = getArgs('first,...rest', [1,2,3,4])
|
|
||||||
console.log(args.first) // 1
|
|
||||||
console.log(args.rest) // [2,3,4]
|
|
||||||
|
|
||||||
### Set properties on an object
|
|
||||||
|
|
||||||
If you pass an object as its third argument, it will set the arguments as properties on that object.
|
|
||||||
|
|
||||||
getArgs('a,b,c', arguments, this)
|
|
||||||
// Now you can access the arguments by
|
|
||||||
// this.a, this.b, and this.c
|
|
||||||
|
|
6
node_modules/getargs/TODO.md
generated
vendored
6
node_modules/getargs/TODO.md
generated
vendored
@ -1,6 +0,0 @@
|
|||||||
TODO
|
|
||||||
====
|
|
||||||
|
|
||||||
1. spread operator in the middle.
|
|
||||||
2. one-character type aliases.
|
|
||||||
3. wider browser support.
|
|
15
node_modules/getargs/example.js
generated
vendored
15
node_modules/getargs/example.js
generated
vendored
@ -1,15 +0,0 @@
|
|||||||
var getArgs = require('./index')
|
|
||||||
|
|
||||||
function ajax(url, opts, callback){
|
|
||||||
var args = getArgs(
|
|
||||||
'url:string|array,[opts]:object,[callback]:function',
|
|
||||||
arguments)
|
|
||||||
console.log(JSON.stringify(args, null, ' '))
|
|
||||||
}
|
|
||||||
|
|
||||||
ajax()
|
|
||||||
ajax('/submit')
|
|
||||||
ajax(['/submit'])
|
|
||||||
ajax('/submit', {method: 'POST', params: {foo: 'bar'}}, function(dat){
|
|
||||||
|
|
||||||
})
|
|
100
node_modules/getargs/index.js
generated
vendored
100
node_modules/getargs/index.js
generated
vendored
@ -1,100 +0,0 @@
|
|||||||
var is = {
|
|
||||||
'string': function(s){ return typeof s === 'string' },
|
|
||||||
'function': function(f){ return typeof f === 'function' },
|
|
||||||
'number': function(f){ return typeof f === 'number' },
|
|
||||||
'array': Array.isArray || function(a){ return a instanceof Array },
|
|
||||||
'object': function(o){ return typeof o === 'object' && o != null },
|
|
||||||
'boolean': function(b){ return typeof b === 'boolean' }
|
|
||||||
}
|
|
||||||
|
|
||||||
function ArgSpec(str){
|
|
||||||
var ret
|
|
||||||
str = str.trim()
|
|
||||||
var parts = str.split(':')
|
|
||||||
if (parts.length > 1){
|
|
||||||
ret = {
|
|
||||||
name: parts[0],
|
|
||||||
type: parts[1].split('|')
|
|
||||||
}
|
|
||||||
}else if (parts.length === 1){
|
|
||||||
ret = {
|
|
||||||
name: str
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
throw new Error('Expected arg spec to be format name or name:type but was ' + str)
|
|
||||||
}
|
|
||||||
var m
|
|
||||||
if (m = ret.name.match(/^\[(.+)\]$/)){
|
|
||||||
ret.name = m[1]
|
|
||||||
ret.optional = true
|
|
||||||
}
|
|
||||||
if (m = ret.name.match(/^\.\.\.(.+)$/)){
|
|
||||||
ret.name = m[1]
|
|
||||||
ret.spread = true
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
function typeMatches(spec, arg) {
|
|
||||||
if (!spec.type) return true
|
|
||||||
|
|
||||||
var match = false;
|
|
||||||
|
|
||||||
var type = null;
|
|
||||||
for (var i = 0; i<spec.type.length; i++ ) {
|
|
||||||
type = spec.type[i];
|
|
||||||
var fun = is[type.toLowerCase()]
|
|
||||||
if (!fun) {
|
|
||||||
throw new Error('Unknown type: ' + spec.type)
|
|
||||||
}
|
|
||||||
match = fun(arg);
|
|
||||||
if (match) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function getArgs(spec, args, target){
|
|
||||||
var ret = target || {}
|
|
||||||
spec = spec.split(',').map(function(s){
|
|
||||||
s = ArgSpec(s);
|
|
||||||
return s;
|
|
||||||
})
|
|
||||||
var minExpected = spec.filter(function(s){
|
|
||||||
return !s.optional
|
|
||||||
}).length
|
|
||||||
var maxExpected = spec.length
|
|
||||||
var argIdxOffset = 0
|
|
||||||
var length = Math.max(spec.length, args.length)
|
|
||||||
for (var i = 0; i < length; i++){
|
|
||||||
var sp = spec[i]
|
|
||||||
var argIdx = i + argIdxOffset
|
|
||||||
if (argIdx >= args.length){
|
|
||||||
if (argIdx < minExpected){
|
|
||||||
throw new Error(
|
|
||||||
'Not enough arguments, expected ' +
|
|
||||||
minExpected + ', got ' + argIdx)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if (argIdx >= maxExpected){
|
|
||||||
throw new Error('Too many arguments, expected ' +
|
|
||||||
maxExpected + ', got ' + (argIdx + 1))
|
|
||||||
}
|
|
||||||
var arg = args[argIdx]
|
|
||||||
if (typeMatches(sp, arg)){
|
|
||||||
if (sp.spread){
|
|
||||||
ret[sp.name] = Array.prototype.slice.call(args, argIdx)
|
|
||||||
break
|
|
||||||
}else{
|
|
||||||
ret[sp.name] = arg
|
|
||||||
}
|
|
||||||
}else if (sp.optional){
|
|
||||||
argIdxOffset--
|
|
||||||
}else{
|
|
||||||
throw new Error('Expected ' + sp.name +
|
|
||||||
'(pos ' + i + ') to be a ' + sp.type.join(' or '))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
50
node_modules/getargs/package.json
generated
vendored
50
node_modules/getargs/package.json
generated
vendored
@ -1,50 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "getargs",
|
|
||||||
"version": "0.0.8",
|
|
||||||
"description": "Utility to handle optional arguments and argument type checking.",
|
|
||||||
"main": "index.js",
|
|
||||||
"dependencies": {},
|
|
||||||
"devDependencies": {
|
|
||||||
"chai": "~1.7.2"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "mocha tests.js -u tdd"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"arguments",
|
|
||||||
"utility"
|
|
||||||
],
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git@github.com:airportyh/getargs.git"
|
|
||||||
},
|
|
||||||
"author": {
|
|
||||||
"name": "Toby Ho"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"readme": "getargs\n=======\n\nSimple utility for parsing/processing variable length argument lists for Javascript functions; also verifies argument types and argument list length.\n\n## Install\n\nBower - `bower install getargs`; NPM - `npm install getargs`.\n\n## Usage\n\n var getArgs = require('getargs')\n\n function ajax(/* url:string|array, [options]:object, callback:function */){\n var args = getArgs('url:string|array, [options]:object, callback:function', arguments)\n\n console.log('url is', args.url)\n console.log('options is optionally', args.options)\n console.log('callback', args.callback)\n }\n\n## Argument Spec Syntax\n\nThe argument spec is a comma delimited string of individual specs, which look like\n\n argname:type\n\nYou can specify multiple types by using `|`\n\n argname:type|type|type\n\n* `argname` is the name of the argument, and can be called anything\n* `type` is an optional basic Javascript type. Currently these are supported\n * `string`\n * `boolean`\n * `number`\n * `object`\n * `function`\n * `array`\n\n### Optional Arguments\n\nTo denote optional arguments, you'd surround `argname` with square brackets `[]`.\n\n### Type Verification\n\ngetArgs will throw if the arguments have the wrong types\n\n var args = getArgs('url:string', [1])\n // Error: Expected url(pos 0) to be a string\n\n### Argument List Length Verification\n\ngetArgs will throw if there are too many or too few arguments\n\n > getArgs('a,b', [1])\n Error: Not enough arguments, expected 2, got 1\n > getArgs('a,b', [1,1])\n { a: 1, b: 1 }\n > getArgs('a,b', [1,1,1])\n Error: Too many arguments, expected 2, got 3\n\n### Spread Operator\n\nYou can mimick ES6's spread operator\n\n var args = getArgs('first,...rest', [1,2,3,4])\n console.log(args.first) // 1\n console.log(args.rest) // [2,3,4]\n\n### Set properties on an object\n\nIf you pass an object as its third argument, it will set the arguments as properties on that object.\n\n getArgs('a,b,c', arguments, this)\n // Now you can access the arguments by\n // this.a, this.b, and this.c\n \n",
|
|
||||||
"readmeFilename": "README.md",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/airportyh/getargs/issues"
|
|
||||||
},
|
|
||||||
"_id": "getargs@0.0.8",
|
|
||||||
"dist": {
|
|
||||||
"shasum": "8516605872c980178e01ca70106fccd22521fc7c",
|
|
||||||
"tarball": "http://registry.npmjs.org/getargs/-/getargs-0.0.8.tgz"
|
|
||||||
},
|
|
||||||
"_from": "getargs@*",
|
|
||||||
"_npmVersion": "1.3.8",
|
|
||||||
"_npmUser": {
|
|
||||||
"name": "airportyh",
|
|
||||||
"email": "airportyh@gmail.com"
|
|
||||||
},
|
|
||||||
"maintainers": [
|
|
||||||
{
|
|
||||||
"name": "airportyh",
|
|
||||||
"email": "airportyh@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"directories": {},
|
|
||||||
"_shasum": "8516605872c980178e01ca70106fccd22521fc7c",
|
|
||||||
"_resolved": "https://registry.npmjs.org/getargs/-/getargs-0.0.8.tgz"
|
|
||||||
}
|
|
96
node_modules/getargs/tests.js
generated
vendored
96
node_modules/getargs/tests.js
generated
vendored
@ -1,96 +0,0 @@
|
|||||||
var getArgs = require('./index')
|
|
||||||
var assert = require('chai').assert
|
|
||||||
|
|
||||||
test('basic', function(){
|
|
||||||
var args = [1, 2]
|
|
||||||
var result = getArgs('a,b', args)
|
|
||||||
assert(result.a === 1)
|
|
||||||
assert(result.b === 2)
|
|
||||||
assert.deepEqual(result, getArgs('a, b', args))
|
|
||||||
})
|
|
||||||
|
|
||||||
test('not enough throws', function(){
|
|
||||||
getArgs('a', [1])
|
|
||||||
assert.throws(function(){
|
|
||||||
getArgs('a', [])
|
|
||||||
}, 'Not enough arguments, expected 1, got 0')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('too many throws', function(){
|
|
||||||
var args = [1, 2]
|
|
||||||
assert.throws(function(){
|
|
||||||
getArgs('a', args)
|
|
||||||
}, 'Too many arguments, expected 1, got 2')
|
|
||||||
assert.throws(function(){
|
|
||||||
getArgs('a,b', [1,2,3])
|
|
||||||
}, 'Too many arguments, expected 2, got 3')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('checks type', function(){
|
|
||||||
var result = getArgs('a:string', ['abc'])
|
|
||||||
assert(result.a === 'abc')
|
|
||||||
assert.throws(function(){
|
|
||||||
getArgs('a:string', [1])
|
|
||||||
}, 'Expected a(pos 0) to be a string')
|
|
||||||
getArgs('a:Array', [[]])
|
|
||||||
assert.throws(function(){
|
|
||||||
getArgs('a:array', [1])
|
|
||||||
}, 'Expected a(pos 0) to be a array')
|
|
||||||
getArgs('a:number', [3])
|
|
||||||
assert.throws(function(){
|
|
||||||
getArgs('a:number', ['a'])
|
|
||||||
}, 'Expected a(pos 0) to be a number')
|
|
||||||
assert.throws(function(){
|
|
||||||
getArgs('a:boolean', ['a'])
|
|
||||||
}, 'Expected a(pos 0) to be a boolean')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('supports multiple types', function(){
|
|
||||||
var result = getArgs('a:string|array', ['abc'])
|
|
||||||
assert.equal(result.a, 'abc')
|
|
||||||
var result = getArgs('a:string|array', [['abc']])
|
|
||||||
assert.deepEqual(result.a, ['abc'])
|
|
||||||
})
|
|
||||||
|
|
||||||
test('unknown type', function(){
|
|
||||||
assert.throws(function(){
|
|
||||||
getArgs('a:blarg', ['abc'])
|
|
||||||
}, 'Unknown type: blarg')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('optional by type', function(){
|
|
||||||
var result = getArgs(
|
|
||||||
'[user]:object,callback:function',
|
|
||||||
[{name: 'bobby'}, function(){}])
|
|
||||||
assert(result.user.name === 'bobby')
|
|
||||||
result = getArgs(
|
|
||||||
'[user]:object,callback:function',
|
|
||||||
[function(){}])
|
|
||||||
assert(result.user === undefined)
|
|
||||||
assert(result.callback instanceof Function)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('optional + spread', function(){
|
|
||||||
var result = getArgs('[user]:object,...rest',[1,2,3])
|
|
||||||
assert.deepEqual(result.rest, [1,2,3])
|
|
||||||
})
|
|
||||||
|
|
||||||
test('optional last', function(){
|
|
||||||
var result = getArgs('a,[b]', [1])
|
|
||||||
assert(result.a === 1)
|
|
||||||
assert(result.b === undefined)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('spread operator', function(){
|
|
||||||
var result = getArgs('a,...b', [1, 2, 3, 4])
|
|
||||||
assert(result.b == '2,3,4')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('sets properties on target if passed in', function(){
|
|
||||||
var target = {}
|
|
||||||
var args = [1, 2]
|
|
||||||
getArgs('a,b', args, target)
|
|
||||||
assert(target.a == 1)
|
|
||||||
assert(target.b == 2)
|
|
||||||
})
|
|
||||||
|
|
3
node_modules/grunt-cli/.npmignore
generated
vendored
3
node_modules/grunt-cli/.npmignore
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
node_modules
|
|
||||||
npm-debug.log
|
|
||||||
tmp
|
|
4
node_modules/grunt-cli/.travis.yml
generated
vendored
4
node_modules/grunt-cli/.travis.yml
generated
vendored
@ -1,4 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- "0.8"
|
|
||||||
- "0.10"
|
|
4
node_modules/grunt-cli/AUTHORS
generated
vendored
4
node_modules/grunt-cli/AUTHORS
generated
vendored
@ -1,4 +0,0 @@
|
|||||||
Tyler Kellen (http://goingslowly.com)
|
|
||||||
Ben Alman (http://gruntjs.com)
|
|
||||||
Scott González (http://nemikor.com)
|
|
||||||
Forbes Lindesay (https://github.com/)
|
|
49
node_modules/grunt-cli/Gruntfile.js
generated
vendored
49
node_modules/grunt-cli/Gruntfile.js
generated
vendored
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* grunt-cli
|
|
||||||
* http://gruntjs.com/
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012 Tyler Kellen, contributors
|
|
||||||
* Licensed under the MIT license.
|
|
||||||
* https://github.com/gruntjs/grunt-init/blob/master/LICENSE-MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = function(grunt) {
|
|
||||||
|
|
||||||
// Project configuration.
|
|
||||||
grunt.initConfig({
|
|
||||||
jshint: {
|
|
||||||
all: [
|
|
||||||
'Gruntfile.js',
|
|
||||||
'lib/**/*.js',
|
|
||||||
'bin/*',
|
|
||||||
],
|
|
||||||
options: {
|
|
||||||
curly: true,
|
|
||||||
eqeqeq: true,
|
|
||||||
immed: true,
|
|
||||||
latedef: true,
|
|
||||||
newcap: true,
|
|
||||||
noarg: true,
|
|
||||||
sub: true,
|
|
||||||
undef: true,
|
|
||||||
unused: true,
|
|
||||||
boss: true,
|
|
||||||
eqnull: true,
|
|
||||||
node: true,
|
|
||||||
es5: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// These plugins provide necessary tasks.
|
|
||||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
||||||
|
|
||||||
// "npm test" runs these tasks
|
|
||||||
grunt.registerTask('test', ['jshint']);
|
|
||||||
|
|
||||||
// Default task.
|
|
||||||
grunt.registerTask('default', ['test']);
|
|
||||||
|
|
||||||
};
|
|
22
node_modules/grunt-cli/LICENSE-MIT
generated
vendored
22
node_modules/grunt-cli/LICENSE-MIT
generated
vendored
@ -1,22 +0,0 @@
|
|||||||
Copyright (c) 2012 Tyler Kellen, contributors
|
|
||||||
|
|
||||||
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.
|
|
30
node_modules/grunt-cli/README.md
generated
vendored
30
node_modules/grunt-cli/README.md
generated
vendored
@ -1,30 +0,0 @@
|
|||||||
# grunt-cli [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-cli.png?branch=master)](http://travis-ci.org/gruntjs/grunt-cli)
|
|
||||||
> The Grunt command line interface.
|
|
||||||
|
|
||||||
Install this globally and you'll have access to the `grunt` command anywhere on your system.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
npm install -g grunt-cli
|
|
||||||
```
|
|
||||||
|
|
||||||
**Note:** The job of the `grunt` command is to load and run the version of Grunt you have installed locally to your project, irrespective of its version. Starting with Grunt v0.4, you should never install Grunt itself globally. For more information about why, [please read this](http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation).
|
|
||||||
|
|
||||||
See the [Getting Started](http://gruntjs.com/getting-started) guide for more information.
|
|
||||||
|
|
||||||
## Shell tab auto-completion
|
|
||||||
To enable tab auto-completion for Grunt, add one of the following lines to your `~/.bashrc` or `~/.zshrc` file.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Bash, ~/.bashrc
|
|
||||||
eval "$(grunt --completion=bash)"
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Zsh, ~/.zshrc
|
|
||||||
eval "$(grunt --completion=zsh)"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installing grunt-cli locally
|
|
||||||
If you prefer the idiomatic Node.js method to get started with a project (`npm install && npm test`) then install grunt-cli locally with `npm install grunt-cli --save-dev`. Then add a script to your `package.json` to run the associated grunt command: `"scripts": { "test": "grunt test" } `. Now `npm test` will use the locally installed `./node_modules/.bin/grunt` executable to run your Grunt commands.
|
|
||||||
|
|
||||||
To read more about npm scripts, please visit the npm docs: [https://npmjs.org/doc/misc/npm-scripts.html](https://npmjs.org/doc/misc/npm-scripts.html).
|
|
45
node_modules/grunt-cli/bin/grunt
generated
vendored
45
node_modules/grunt-cli/bin/grunt
generated
vendored
@ -1,45 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
process.title = 'grunt';
|
|
||||||
|
|
||||||
// Especially badass external libs.
|
|
||||||
var findup = require('findup-sync');
|
|
||||||
var resolve = require('resolve').sync;
|
|
||||||
|
|
||||||
// Internal libs.
|
|
||||||
var options = require('../lib/cli').options;
|
|
||||||
var completion = require('../lib/completion');
|
|
||||||
var info = require('../lib/info');
|
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
|
|
||||||
var basedir = process.cwd();
|
|
||||||
var gruntpath;
|
|
||||||
|
|
||||||
// Do stuff based on CLI options.
|
|
||||||
if ('completion' in options) {
|
|
||||||
completion.print(options.completion);
|
|
||||||
} else if (options.version) {
|
|
||||||
info.version();
|
|
||||||
} else if (options.base && !options.gruntfile) {
|
|
||||||
basedir = path.resolve(options.base);
|
|
||||||
} else if (options.gruntfile) {
|
|
||||||
basedir = path.resolve(path.dirname(options.gruntfile));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
gruntpath = resolve('grunt', {basedir: basedir});
|
|
||||||
} catch (ex) {
|
|
||||||
gruntpath = findup('lib/grunt.js');
|
|
||||||
// No grunt install found!
|
|
||||||
if (!gruntpath) {
|
|
||||||
if (options.version) { process.exit(); }
|
|
||||||
if (options.help) { info.help(); }
|
|
||||||
info.fatal('Unable to find local grunt.', 99);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Everything looks good. Require local grunt and run it.
|
|
||||||
require(gruntpath).cli();
|
|
49
node_modules/grunt-cli/completion/bash
generated
vendored
49
node_modules/grunt-cli/completion/bash
generated
vendored
@ -1,49 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# grunt-cli
|
|
||||||
# http://gruntjs.com/
|
|
||||||
#
|
|
||||||
# Copyright (c) 2012 Tyler Kellen, contributors
|
|
||||||
# Licensed under the MIT license.
|
|
||||||
# https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
|
|
||||||
|
|
||||||
# Usage:
|
|
||||||
#
|
|
||||||
# To enable bash <tab> completion for grunt, add the following line (minus the
|
|
||||||
# leading #, which is the bash comment character) to your ~/.bashrc file:
|
|
||||||
#
|
|
||||||
# eval "$(grunt --completion=bash)"
|
|
||||||
|
|
||||||
# Search the current directory and all parent directories for a gruntfile.
|
|
||||||
function _grunt_gruntfile() {
|
|
||||||
local curpath="$PWD"
|
|
||||||
while [[ "$curpath" ]]; do
|
|
||||||
for gruntfile in "$curpath/"{G,g}runtfile.{js,coffee}; do
|
|
||||||
if [[ -e "$gruntfile" ]]; then
|
|
||||||
echo "$gruntfile"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
curpath="${curpath%/*}"
|
|
||||||
done
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Enable bash autocompletion.
|
|
||||||
function _grunt_completions() {
|
|
||||||
# The currently-being-completed word.
|
|
||||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
|
||||||
# The current gruntfile, if it exists.
|
|
||||||
local gruntfile="$(_grunt_gruntfile)"
|
|
||||||
# The current grunt version, available tasks, options, etc.
|
|
||||||
local gruntinfo="$(grunt --version --verbose 2>/dev/null)"
|
|
||||||
# Options and tasks.
|
|
||||||
local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')"
|
|
||||||
local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')"
|
|
||||||
# Only add -- or - options if the user has started typing -
|
|
||||||
[[ "$cur" == -* ]] && compls="$compls $opts"
|
|
||||||
# Tell complete what stuff to show.
|
|
||||||
COMPREPLY=($(compgen -W "$compls" -- "$cur"))
|
|
||||||
}
|
|
||||||
|
|
||||||
complete -o default -F _grunt_completions grunt
|
|
37
node_modules/grunt-cli/completion/zsh
generated
vendored
37
node_modules/grunt-cli/completion/zsh
generated
vendored
@ -1,37 +0,0 @@
|
|||||||
#!/bin/zsh
|
|
||||||
|
|
||||||
# grunt-cli
|
|
||||||
# http://gruntjs.com/
|
|
||||||
#
|
|
||||||
# Copyright (c) 2012 Tyler Kellen, contributors
|
|
||||||
# Licensed under the MIT license.
|
|
||||||
# https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
|
|
||||||
|
|
||||||
# Usage:
|
|
||||||
#
|
|
||||||
# To enable zsh <tab> completion for grunt, add the following line (minus the
|
|
||||||
# leading #, which is the zsh comment character) to your ~/.zshrc file:
|
|
||||||
#
|
|
||||||
# eval "$(grunt --completion=zsh)"
|
|
||||||
|
|
||||||
# Enable zsh autocompletion.
|
|
||||||
function _grunt_completion() {
|
|
||||||
local completions
|
|
||||||
# The currently-being-completed word.
|
|
||||||
local cur="${words[@]}"
|
|
||||||
# The current grunt version, available tasks, options, etc.
|
|
||||||
local gruntinfo="$(grunt --version --verbose 2>/dev/null)"
|
|
||||||
# Options and tasks.
|
|
||||||
local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')"
|
|
||||||
local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')"
|
|
||||||
# Only add -- or - options if the user has started typing -
|
|
||||||
[[ "$cur" == -* ]] && compls="$compls $opts"
|
|
||||||
# Trim whitespace.
|
|
||||||
compls=$(echo "$compls" | sed -e 's/^ *//g' -e 's/ *$//g')
|
|
||||||
# Turn compls into an array to of completions.
|
|
||||||
completions=(${=compls})
|
|
||||||
# Tell complete what stuff to show.
|
|
||||||
compadd -- $completions
|
|
||||||
}
|
|
||||||
|
|
||||||
compdef _grunt_completion grunt
|
|
24
node_modules/grunt-cli/lib/cli.js
generated
vendored
24
node_modules/grunt-cli/lib/cli.js
generated
vendored
@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* grunt-cli
|
|
||||||
* http://gruntjs.com/
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012 Tyler Kellen, contributors
|
|
||||||
* Licensed under the MIT license.
|
|
||||||
* https://github.com/gruntjs/grunt-init/blob/master/LICENSE-MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// External lib.
|
|
||||||
var nopt = require('nopt');
|
|
||||||
|
|
||||||
// CLI options we care about.
|
|
||||||
exports.known = {help: Boolean, version: Boolean, completion: String};
|
|
||||||
exports.aliases = {h: '--help', V: '--version', v: '--verbose'};
|
|
||||||
|
|
||||||
// Parse them and return an options object.
|
|
||||||
Object.defineProperty(exports, 'options', {
|
|
||||||
get: function() {
|
|
||||||
return nopt(exports.known, exports.aliases, process.argv, 2);
|
|
||||||
}
|
|
||||||
});
|
|
34
node_modules/grunt-cli/lib/completion.js
generated
vendored
34
node_modules/grunt-cli/lib/completion.js
generated
vendored
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* grunt-cli
|
|
||||||
* http://gruntjs.com/
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012 Tyler Kellen, contributors
|
|
||||||
* Licensed under the MIT license.
|
|
||||||
* https://github.com/gruntjs/grunt-init/blob/master/LICENSE-MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Nodejs libs.
|
|
||||||
var fs = require('fs');
|
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
exports.print = function(name) {
|
|
||||||
var code = 0;
|
|
||||||
var filepath = path.join(__dirname, '../completion', name);
|
|
||||||
var output;
|
|
||||||
try {
|
|
||||||
// Attempt to read shell completion file.
|
|
||||||
output = String(fs.readFileSync(filepath));
|
|
||||||
} catch (err) {
|
|
||||||
code = 5;
|
|
||||||
output = 'echo "Specified grunt shell auto-completion rules ';
|
|
||||||
if (name && name !== 'true') {
|
|
||||||
output += 'for \'' + name + '\' ';
|
|
||||||
}
|
|
||||||
output += 'not found."';
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(output);
|
|
||||||
process.exit(code);
|
|
||||||
};
|
|
51
node_modules/grunt-cli/lib/info.js
generated
vendored
51
node_modules/grunt-cli/lib/info.js
generated
vendored
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* grunt-cli
|
|
||||||
* http://gruntjs.com/
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012 Tyler Kellen, contributors
|
|
||||||
* Licensed under the MIT license.
|
|
||||||
* https://github.com/gruntjs/grunt-init/blob/master/LICENSE-MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Project metadata.
|
|
||||||
var pkg = require('../package.json');
|
|
||||||
|
|
||||||
// Display grunt-cli version.
|
|
||||||
exports.version = function() {
|
|
||||||
console.log('grunt-cli v' + pkg.version);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Show help, then exit with a message and error code.
|
|
||||||
exports.fatal = function(msg, code) {
|
|
||||||
exports.helpHeader();
|
|
||||||
console.log('Fatal error: ' + msg);
|
|
||||||
console.log('');
|
|
||||||
exports.helpFooter();
|
|
||||||
process.exit(code);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Show help and exit.
|
|
||||||
exports.help = function() {
|
|
||||||
exports.helpHeader();
|
|
||||||
exports.helpFooter();
|
|
||||||
process.exit();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Help header.
|
|
||||||
exports.helpHeader = function() {
|
|
||||||
console.log('grunt-cli: ' + pkg.description + ' (v' + pkg.version + ')');
|
|
||||||
console.log('');
|
|
||||||
};
|
|
||||||
|
|
||||||
// Help footer.
|
|
||||||
exports.helpFooter = function() {
|
|
||||||
[
|
|
||||||
'If you\'re seeing this message, either a Gruntfile wasn\'t found or grunt',
|
|
||||||
'hasn\'t been installed locally to your project. For more information about',
|
|
||||||
'installing and configuring grunt, please see the Getting Started guide:',
|
|
||||||
'',
|
|
||||||
'http://gruntjs.com/getting-started',
|
|
||||||
].forEach(function(str) { console.log(str); });
|
|
||||||
};
|
|
1
node_modules/grunt-cli/node_modules/.bin/nopt
generated
vendored
1
node_modules/grunt-cli/node_modules/.bin/nopt
generated
vendored
@ -1 +0,0 @@
|
|||||||
../nopt/bin/nopt.js
|
|
15
node_modules/grunt-cli/node_modules/findup-sync/.jshintrc
generated
vendored
15
node_modules/grunt-cli/node_modules/findup-sync/.jshintrc
generated
vendored
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"loopfunc": true,
|
|
||||||
"curly": true,
|
|
||||||
"eqeqeq": true,
|
|
||||||
"immed": true,
|
|
||||||
"latedef": true,
|
|
||||||
"newcap": true,
|
|
||||||
"noarg": true,
|
|
||||||
"sub": true,
|
|
||||||
"undef": true,
|
|
||||||
"unused": true,
|
|
||||||
"boss": true,
|
|
||||||
"eqnull": true,
|
|
||||||
"node": true
|
|
||||||
}
|
|
0
node_modules/grunt-cli/node_modules/findup-sync/.npmignore
generated
vendored
0
node_modules/grunt-cli/node_modules/findup-sync/.npmignore
generated
vendored
5
node_modules/grunt-cli/node_modules/findup-sync/.travis.yml
generated
vendored
5
node_modules/grunt-cli/node_modules/findup-sync/.travis.yml
generated
vendored
@ -1,5 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- 0.8
|
|
||||||
before_script:
|
|
||||||
- npm install -g grunt-cli
|
|
25
node_modules/grunt-cli/node_modules/findup-sync/Gruntfile.js
generated
vendored
25
node_modules/grunt-cli/node_modules/findup-sync/Gruntfile.js
generated
vendored
@ -1,25 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = function(grunt) {
|
|
||||||
|
|
||||||
// Project configuration.
|
|
||||||
grunt.initConfig({
|
|
||||||
nodeunit: {
|
|
||||||
files: ['test/**/*_test.js'],
|
|
||||||
},
|
|
||||||
jshint: {
|
|
||||||
options: {
|
|
||||||
jshintrc: '.jshintrc'
|
|
||||||
},
|
|
||||||
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Load plugins.
|
|
||||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
||||||
grunt.loadNpmTasks('grunt-contrib-nodeunit');
|
|
||||||
|
|
||||||
// Default task.
|
|
||||||
grunt.registerTask('default', ['jshint', 'nodeunit']);
|
|
||||||
|
|
||||||
};
|
|
22
node_modules/grunt-cli/node_modules/findup-sync/LICENSE-MIT
generated
vendored
22
node_modules/grunt-cli/node_modules/findup-sync/LICENSE-MIT
generated
vendored
@ -1,22 +0,0 @@
|
|||||||
Copyright (c) 2013 "Cowboy" Ben Alman
|
|
||||||
|
|
||||||
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.
|
|
45
node_modules/grunt-cli/node_modules/findup-sync/README.md
generated
vendored
45
node_modules/grunt-cli/node_modules/findup-sync/README.md
generated
vendored
@ -1,45 +0,0 @@
|
|||||||
# findup-sync [![Build Status](https://secure.travis-ci.org/cowboy/node-findup-sync.png?branch=master)](http://travis-ci.org/cowboy/node-findup-sync)
|
|
||||||
|
|
||||||
Find the first file matching a given pattern in the current directory or the nearest ancestor directory.
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
Install the module with: `npm install findup-sync`
|
|
||||||
|
|
||||||
```js
|
|
||||||
var findup = require('findup-sync');
|
|
||||||
|
|
||||||
// Start looking in the CWD.
|
|
||||||
var filepath1 = findup('{a,b}*.txt');
|
|
||||||
|
|
||||||
// Start looking somewhere else, and ignore case (probably a good idea).
|
|
||||||
var filepath2 = findup('{a,b}*.txt', {cwd: '/some/path', nocase: true});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
findup(patternOrPatterns [, minimatchOptions])
|
|
||||||
```
|
|
||||||
|
|
||||||
### patternOrPatterns
|
|
||||||
Type: `String` or `Array`
|
|
||||||
Default: none
|
|
||||||
|
|
||||||
One or more wildcard glob patterns. Or just filenames.
|
|
||||||
|
|
||||||
### minimatchOptions
|
|
||||||
Type: `Object`
|
|
||||||
Default: `{}`
|
|
||||||
|
|
||||||
Options to be passed to [minimatch](https://github.com/isaacs/minimatch).
|
|
||||||
|
|
||||||
Note that if you want to start in a different directory than the current working directory, specify a `cwd` property here.
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
|
|
||||||
|
|
||||||
## Release History
|
|
||||||
2014-03-14 - v0.1.3 - Updated dependencies.
|
|
||||||
2013-03-08 - v0.1.2 - Updated dependencies. Fixed a Node 0.9.x bug. Updated unit tests to work cross-platform.
|
|
||||||
2012-11-15 - v0.1.1 - Now works without an options object.
|
|
||||||
2012-11-01 - v0.1.0 - Initial release.
|
|
46
node_modules/grunt-cli/node_modules/findup-sync/lib/findup-sync.js
generated
vendored
46
node_modules/grunt-cli/node_modules/findup-sync/lib/findup-sync.js
generated
vendored
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* findup-sync
|
|
||||||
* https://github.com/cowboy/node-findup-sync
|
|
||||||
*
|
|
||||||
* Copyright (c) 2013 "Cowboy" Ben Alman
|
|
||||||
* Licensed under the MIT license.
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Nodejs libs.
|
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
// External libs.
|
|
||||||
var glob = require('glob');
|
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
// Search for a filename in the given directory or all parent directories.
|
|
||||||
module.exports = function(patterns, options) {
|
|
||||||
// Normalize patterns to an array.
|
|
||||||
if (!Array.isArray(patterns)) { patterns = [patterns]; }
|
|
||||||
// Create globOptions so that it can be modified without mutating the
|
|
||||||
// original object.
|
|
||||||
var globOptions = Object.create(options || {});
|
|
||||||
globOptions.maxDepth = 1;
|
|
||||||
globOptions.cwd = path.resolve(globOptions.cwd || '.');
|
|
||||||
|
|
||||||
var files, lastpath;
|
|
||||||
do {
|
|
||||||
// Search for files matching patterns.
|
|
||||||
files = _(patterns).map(function(pattern) {
|
|
||||||
return glob.sync(pattern, globOptions);
|
|
||||||
}).flatten().uniq().value();
|
|
||||||
// Return file if found.
|
|
||||||
if (files.length > 0) {
|
|
||||||
return path.resolve(path.join(globOptions.cwd, files[0]));
|
|
||||||
}
|
|
||||||
// Go up a directory.
|
|
||||||
lastpath = globOptions.cwd;
|
|
||||||
globOptions.cwd = path.resolve(globOptions.cwd, '..');
|
|
||||||
// If parentpath is the same as basedir, we can't go any higher.
|
|
||||||
} while (globOptions.cwd !== lastpath);
|
|
||||||
|
|
||||||
// No files were found!
|
|
||||||
return null;
|
|
||||||
};
|
|
2
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/.npmignore
generated
vendored
2
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/.npmignore
generated
vendored
@ -1,2 +0,0 @@
|
|||||||
.*.swp
|
|
||||||
test/a/
|
|
3
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/.travis.yml
generated
vendored
3
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/.travis.yml
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- 0.8
|
|
27
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/LICENSE
generated
vendored
27
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/LICENSE
generated
vendored
@ -1,27 +0,0 @@
|
|||||||
Copyright (c) Isaac Z. Schlueter ("Author")
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
The BSD License
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
|
|
||||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
||||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
||||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
|
||||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
250
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/README.md
generated
vendored
250
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/README.md
generated
vendored
@ -1,250 +0,0 @@
|
|||||||
# Glob
|
|
||||||
|
|
||||||
Match files using the patterns the shell uses, like stars and stuff.
|
|
||||||
|
|
||||||
This is a glob implementation in JavaScript. It uses the `minimatch`
|
|
||||||
library to do its matching.
|
|
||||||
|
|
||||||
## Attention: node-glob users!
|
|
||||||
|
|
||||||
The API has changed dramatically between 2.x and 3.x. This library is
|
|
||||||
now 100% JavaScript, and the integer flags have been replaced with an
|
|
||||||
options object.
|
|
||||||
|
|
||||||
Also, there's an event emitter class, proper tests, and all the other
|
|
||||||
things you've come to expect from node modules.
|
|
||||||
|
|
||||||
And best of all, no compilation!
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var glob = require("glob")
|
|
||||||
|
|
||||||
// options is optional
|
|
||||||
glob("**/*.js", options, function (er, files) {
|
|
||||||
// files is an array of filenames.
|
|
||||||
// If the `nonull` option is set, and nothing
|
|
||||||
// was found, then files is ["**/*.js"]
|
|
||||||
// er is an error object or null.
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
Please see the [minimatch
|
|
||||||
documentation](https://github.com/isaacs/minimatch) for more details.
|
|
||||||
|
|
||||||
Supports these glob features:
|
|
||||||
|
|
||||||
* Brace Expansion
|
|
||||||
* Extended glob matching
|
|
||||||
* "Globstar" `**` matching
|
|
||||||
|
|
||||||
See:
|
|
||||||
|
|
||||||
* `man sh`
|
|
||||||
* `man bash`
|
|
||||||
* `man 3 fnmatch`
|
|
||||||
* `man 5 gitignore`
|
|
||||||
* [minimatch documentation](https://github.com/isaacs/minimatch)
|
|
||||||
|
|
||||||
## glob(pattern, [options], cb)
|
|
||||||
|
|
||||||
* `pattern` {String} Pattern to be matched
|
|
||||||
* `options` {Object}
|
|
||||||
* `cb` {Function}
|
|
||||||
* `err` {Error | null}
|
|
||||||
* `matches` {Array<String>} filenames found matching the pattern
|
|
||||||
|
|
||||||
Perform an asynchronous glob search.
|
|
||||||
|
|
||||||
## glob.sync(pattern, [options])
|
|
||||||
|
|
||||||
* `pattern` {String} Pattern to be matched
|
|
||||||
* `options` {Object}
|
|
||||||
* return: {Array<String>} filenames found matching the pattern
|
|
||||||
|
|
||||||
Perform a synchronous glob search.
|
|
||||||
|
|
||||||
## Class: glob.Glob
|
|
||||||
|
|
||||||
Create a Glob object by instanting the `glob.Glob` class.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var Glob = require("glob").Glob
|
|
||||||
var mg = new Glob(pattern, options, cb)
|
|
||||||
```
|
|
||||||
|
|
||||||
It's an EventEmitter, and starts walking the filesystem to find matches
|
|
||||||
immediately.
|
|
||||||
|
|
||||||
### new glob.Glob(pattern, [options], [cb])
|
|
||||||
|
|
||||||
* `pattern` {String} pattern to search for
|
|
||||||
* `options` {Object}
|
|
||||||
* `cb` {Function} Called when an error occurs, or matches are found
|
|
||||||
* `err` {Error | null}
|
|
||||||
* `matches` {Array<String>} filenames found matching the pattern
|
|
||||||
|
|
||||||
Note that if the `sync` flag is set in the options, then matches will
|
|
||||||
be immediately available on the `g.found` member.
|
|
||||||
|
|
||||||
### Properties
|
|
||||||
|
|
||||||
* `minimatch` The minimatch object that the glob uses.
|
|
||||||
* `options` The options object passed in.
|
|
||||||
* `error` The error encountered. When an error is encountered, the
|
|
||||||
glob object is in an undefined state, and should be discarded.
|
|
||||||
* `aborted` Boolean which is set to true when calling `abort()`. There
|
|
||||||
is no way at this time to continue a glob search after aborting, but
|
|
||||||
you can re-use the statCache to avoid having to duplicate syscalls.
|
|
||||||
* `statCache` Collection of all the stat results the glob search
|
|
||||||
performed.
|
|
||||||
* `cache` Convenience object. Each field has the following possible
|
|
||||||
values:
|
|
||||||
* `false` - Path does not exist
|
|
||||||
* `true` - Path exists
|
|
||||||
* `1` - Path exists, and is not a directory
|
|
||||||
* `2` - Path exists, and is a directory
|
|
||||||
* `[file, entries, ...]` - Path exists, is a directory, and the
|
|
||||||
array value is the results of `fs.readdir`
|
|
||||||
|
|
||||||
### Events
|
|
||||||
|
|
||||||
* `end` When the matching is finished, this is emitted with all the
|
|
||||||
matches found. If the `nonull` option is set, and no match was found,
|
|
||||||
then the `matches` list contains the original pattern. The matches
|
|
||||||
are sorted, unless the `nosort` flag is set.
|
|
||||||
* `match` Every time a match is found, this is emitted with the matched.
|
|
||||||
* `error` Emitted when an unexpected error is encountered, or whenever
|
|
||||||
any fs error occurs if `options.strict` is set.
|
|
||||||
* `abort` When `abort()` is called, this event is raised.
|
|
||||||
|
|
||||||
### Methods
|
|
||||||
|
|
||||||
* `abort` Stop the search.
|
|
||||||
|
|
||||||
### Options
|
|
||||||
|
|
||||||
All the options that can be passed to Minimatch can also be passed to
|
|
||||||
Glob to change pattern matching behavior. Also, some have been added,
|
|
||||||
or have glob-specific ramifications.
|
|
||||||
|
|
||||||
All options are false by default, unless otherwise noted.
|
|
||||||
|
|
||||||
All options are added to the glob object, as well.
|
|
||||||
|
|
||||||
* `cwd` The current working directory in which to search. Defaults
|
|
||||||
to `process.cwd()`.
|
|
||||||
* `root` The place where patterns starting with `/` will be mounted
|
|
||||||
onto. Defaults to `path.resolve(options.cwd, "/")` (`/` on Unix
|
|
||||||
systems, and `C:\` or some such on Windows.)
|
|
||||||
* `dot` Include `.dot` files in normal matches and `globstar` matches.
|
|
||||||
Note that an explicit dot in a portion of the pattern will always
|
|
||||||
match dot files.
|
|
||||||
* `nomount` By default, a pattern starting with a forward-slash will be
|
|
||||||
"mounted" onto the root setting, so that a valid filesystem path is
|
|
||||||
returned. Set this flag to disable that behavior.
|
|
||||||
* `mark` Add a `/` character to directory matches. Note that this
|
|
||||||
requires additional stat calls.
|
|
||||||
* `nosort` Don't sort the results.
|
|
||||||
* `stat` Set to true to stat *all* results. This reduces performance
|
|
||||||
somewhat, and is completely unnecessary, unless `readdir` is presumed
|
|
||||||
to be an untrustworthy indicator of file existence. It will cause
|
|
||||||
ELOOP to be triggered one level sooner in the case of cyclical
|
|
||||||
symbolic links.
|
|
||||||
* `silent` When an unusual error is encountered
|
|
||||||
when attempting to read a directory, a warning will be printed to
|
|
||||||
stderr. Set the `silent` option to true to suppress these warnings.
|
|
||||||
* `strict` When an unusual error is encountered
|
|
||||||
when attempting to read a directory, the process will just continue on
|
|
||||||
in search of other matches. Set the `strict` option to raise an error
|
|
||||||
in these cases.
|
|
||||||
* `cache` See `cache` property above. Pass in a previously generated
|
|
||||||
cache object to save some fs calls.
|
|
||||||
* `statCache` A cache of results of filesystem information, to prevent
|
|
||||||
unnecessary stat calls. While it should not normally be necessary to
|
|
||||||
set this, you may pass the statCache from one glob() call to the
|
|
||||||
options object of another, if you know that the filesystem will not
|
|
||||||
change between calls. (See "Race Conditions" below.)
|
|
||||||
* `sync` Perform a synchronous glob search.
|
|
||||||
* `nounique` In some cases, brace-expanded patterns can result in the
|
|
||||||
same file showing up multiple times in the result set. By default,
|
|
||||||
this implementation prevents duplicates in the result set.
|
|
||||||
Set this flag to disable that behavior.
|
|
||||||
* `nonull` Set to never return an empty set, instead returning a set
|
|
||||||
containing the pattern itself. This is the default in glob(3).
|
|
||||||
* `nocase` Perform a case-insensitive match. Note that case-insensitive
|
|
||||||
filesystems will sometimes result in glob returning results that are
|
|
||||||
case-insensitively matched anyway, since readdir and stat will not
|
|
||||||
raise an error.
|
|
||||||
* `debug` Set to enable debug logging in minimatch and glob.
|
|
||||||
* `globDebug` Set to enable debug logging in glob, but not minimatch.
|
|
||||||
|
|
||||||
## Comparisons to other fnmatch/glob implementations
|
|
||||||
|
|
||||||
While strict compliance with the existing standards is a worthwhile
|
|
||||||
goal, some discrepancies exist between node-glob and other
|
|
||||||
implementations, and are intentional.
|
|
||||||
|
|
||||||
If the pattern starts with a `!` character, then it is negated. Set the
|
|
||||||
`nonegate` flag to suppress this behavior, and treat leading `!`
|
|
||||||
characters normally. This is perhaps relevant if you wish to start the
|
|
||||||
pattern with a negative extglob pattern like `!(a|B)`. Multiple `!`
|
|
||||||
characters at the start of a pattern will negate the pattern multiple
|
|
||||||
times.
|
|
||||||
|
|
||||||
If a pattern starts with `#`, then it is treated as a comment, and
|
|
||||||
will not match anything. Use `\#` to match a literal `#` at the
|
|
||||||
start of a line, or set the `nocomment` flag to suppress this behavior.
|
|
||||||
|
|
||||||
The double-star character `**` is supported by default, unless the
|
|
||||||
`noglobstar` flag is set. This is supported in the manner of bsdglob
|
|
||||||
and bash 4.1, where `**` only has special significance if it is the only
|
|
||||||
thing in a path part. That is, `a/**/b` will match `a/x/y/b`, but
|
|
||||||
`a/**b` will not.
|
|
||||||
|
|
||||||
If an escaped pattern has no matches, and the `nonull` flag is set,
|
|
||||||
then glob returns the pattern as-provided, rather than
|
|
||||||
interpreting the character escapes. For example,
|
|
||||||
`glob.match([], "\\*a\\?")` will return `"\\*a\\?"` rather than
|
|
||||||
`"*a?"`. This is akin to setting the `nullglob` option in bash, except
|
|
||||||
that it does not resolve escaped pattern characters.
|
|
||||||
|
|
||||||
If brace expansion is not disabled, then it is performed before any
|
|
||||||
other interpretation of the glob pattern. Thus, a pattern like
|
|
||||||
`+(a|{b),c)}`, which would not be valid in bash or zsh, is expanded
|
|
||||||
**first** into the set of `+(a|b)` and `+(a|c)`, and those patterns are
|
|
||||||
checked for validity. Since those two are valid, matching proceeds.
|
|
||||||
|
|
||||||
## Windows
|
|
||||||
|
|
||||||
**Please only use forward-slashes in glob expressions.**
|
|
||||||
|
|
||||||
Though windows uses either `/` or `\` as its path separator, only `/`
|
|
||||||
characters are used by this glob implementation. You must use
|
|
||||||
forward-slashes **only** in glob expressions. Back-slashes will always
|
|
||||||
be interpreted as escape characters, not path separators.
|
|
||||||
|
|
||||||
Results from absolute patterns such as `/foo/*` are mounted onto the
|
|
||||||
root setting using `path.join`. On windows, this will by default result
|
|
||||||
in `/foo/*` matching `C:\foo\bar.txt`.
|
|
||||||
|
|
||||||
## Race Conditions
|
|
||||||
|
|
||||||
Glob searching, by its very nature, is susceptible to race conditions,
|
|
||||||
since it relies on directory walking and such.
|
|
||||||
|
|
||||||
As a result, it is possible that a file that exists when glob looks for
|
|
||||||
it may have been deleted or modified by the time it returns the result.
|
|
||||||
|
|
||||||
As part of its internal implementation, this program caches all stat
|
|
||||||
and readdir calls that it makes, in order to cut down on system
|
|
||||||
overhead. However, this also makes it even more susceptible to races,
|
|
||||||
especially if the cache or statCache objects are reused between glob
|
|
||||||
calls.
|
|
||||||
|
|
||||||
Users are thus advised not to use a glob result as a guarantee of
|
|
||||||
filesystem state in the face of rapid changes. For the vast majority
|
|
||||||
of operations, this is never a problem.
|
|
9
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/examples/g.js
generated
vendored
9
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/examples/g.js
generated
vendored
@ -1,9 +0,0 @@
|
|||||||
var Glob = require("../").Glob
|
|
||||||
|
|
||||||
var pattern = "test/a/**/[cg]/../[cg]"
|
|
||||||
console.log(pattern)
|
|
||||||
|
|
||||||
var mg = new Glob(pattern, {mark: true, sync:true}, function (er, matches) {
|
|
||||||
console.log("matches", matches)
|
|
||||||
})
|
|
||||||
console.log("after")
|
|
@ -1,9 +0,0 @@
|
|||||||
var Glob = require("../").Glob
|
|
||||||
|
|
||||||
var pattern = "{./*/*,/*,/usr/local/*}"
|
|
||||||
console.log(pattern)
|
|
||||||
|
|
||||||
var mg = new Glob(pattern, {mark: true}, function (er, matches) {
|
|
||||||
console.log("matches", matches)
|
|
||||||
})
|
|
||||||
console.log("after")
|
|
728
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/glob.js
generated
vendored
728
node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob/glob.js
generated
vendored
@ -1,728 +0,0 @@
|
|||||||
// Approach:
|
|
||||||
//
|
|
||||||
// 1. Get the minimatch set
|
|
||||||
// 2. For each pattern in the set, PROCESS(pattern)
|
|
||||||
// 3. Store matches per-set, then uniq them
|
|
||||||
//
|
|
||||||
// PROCESS(pattern)
|
|
||||||
// Get the first [n] items from pattern that are all strings
|
|
||||||
// Join these together. This is PREFIX.
|
|
||||||
// If there is no more remaining, then stat(PREFIX) and
|
|
||||||
// add to matches if it succeeds. END.
|
|
||||||
// readdir(PREFIX) as ENTRIES
|
|
||||||
// If fails, END
|
|
||||||
// If pattern[n] is GLOBSTAR
|
|
||||||
// // handle the case where the globstar match is empty
|
|
||||||
// // by pruning it out, and testing the resulting pattern
|
|
||||||
// PROCESS(pattern[0..n] + pattern[n+1 .. $])
|
|
||||||
// // handle other cases.
|
|
||||||
// for ENTRY in ENTRIES (not dotfiles)
|
|
||||||
// // attach globstar + tail onto the entry
|
|
||||||
// PROCESS(pattern[0..n] + ENTRY + pattern[n .. $])
|
|
||||||
//
|
|
||||||
// else // not globstar
|
|
||||||
// for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
|
|
||||||
// Test ENTRY against pattern[n]
|
|
||||||
// If fails, continue
|
|
||||||
// If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
|
|
||||||
//
|
|
||||||
// Caveat:
|
|
||||||
// Cache all stats and readdirs results to minimize syscall. Since all
|
|
||||||
// we ever care about is existence and directory-ness, we can just keep
|
|
||||||
// `true` for files, and [children,...] for directories, or `false` for
|
|
||||||
// things that don't exist.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = glob
|
|
||||||
|
|
||||||
var fs = require("fs")
|
|
||||||
, minimatch = require("minimatch")
|
|
||||||
, Minimatch = minimatch.Minimatch
|
|
||||||
, inherits = require("inherits")
|
|
||||||
, EE = require("events").EventEmitter
|
|
||||||
, path = require("path")
|
|
||||||
, isDir = {}
|
|
||||||
, assert = require("assert").ok
|
|
||||||
|
|
||||||
function glob (pattern, options, cb) {
|
|
||||||
if (typeof options === "function") cb = options, options = {}
|
|
||||||
if (!options) options = {}
|
|
||||||
|
|
||||||
if (typeof options === "number") {
|
|
||||||
deprecated()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var g = new Glob(pattern, options, cb)
|
|
||||||
return g.sync ? g.found : g
|
|
||||||
}
|
|
||||||
|
|
||||||
glob.fnmatch = deprecated
|
|
||||||
|
|
||||||
function deprecated () {
|
|
||||||
throw new Error("glob's interface has changed. Please see the docs.")
|
|
||||||
}
|
|
||||||
|
|
||||||
glob.sync = globSync
|
|
||||||
function globSync (pattern, options) {
|
|
||||||
if (typeof options === "number") {
|
|
||||||
deprecated()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
options = options || {}
|
|
||||||
options.sync = true
|
|
||||||
return glob(pattern, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
this._processingEmitQueue = false
|
|
||||||
|
|
||||||
glob.Glob = Glob
|
|
||||||
inherits(Glob, EE)
|
|
||||||
function Glob (pattern, options, cb) {
|
|
||||||
if (!(this instanceof Glob)) {
|
|
||||||
return new Glob(pattern, options, cb)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof options === "function") {
|
|
||||||
cb = options
|
|
||||||
options = null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof cb === "function") {
|
|
||||||
this.on("error", cb)
|
|
||||||
this.on("end", function (matches) {
|
|
||||||
cb(null, matches)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
options = options || {}
|
|
||||||
|
|
||||||
this._endEmitted = false
|
|
||||||
this.EOF = {}
|
|
||||||
this._emitQueue = []
|
|
||||||
|
|
||||||
this.paused = false
|
|
||||||
this._processingEmitQueue = false
|
|
||||||
|
|
||||||
this.maxDepth = options.maxDepth || 1000
|
|
||||||
this.maxLength = options.maxLength || Infinity
|
|
||||||
this.cache = options.cache || {}
|
|
||||||
this.statCache = options.statCache || {}
|
|
||||||
|
|
||||||
this.changedCwd = false
|
|
||||||
var cwd = process.cwd()
|
|
||||||
if (!options.hasOwnProperty("cwd")) this.cwd = cwd
|
|
||||||
else {
|
|
||||||
this.cwd = options.cwd
|
|
||||||
this.changedCwd = path.resolve(options.cwd) !== cwd
|
|
||||||
}
|
|
||||||
|
|
||||||
this.root = options.root || path.resolve(this.cwd, "/")
|
|
||||||
this.root = path.resolve(this.root)
|
|
||||||
if (process.platform === "win32")
|
|
||||||
this.root = this.root.replace(/\\/g, "/")
|
|
||||||
|
|
||||||
this.nomount = !!options.nomount
|
|
||||||
|
|
||||||
if (!pattern) {
|
|
||||||
throw new Error("must provide pattern")
|
|
||||||
}
|
|
||||||
|
|
||||||
// base-matching: just use globstar for that.
|
|
||||||
if (options.matchBase && -1 === pattern.indexOf("/")) {
|
|
||||||
if (options.noglobstar) {
|
|
||||||
throw new Error("base matching requires globstar")
|
|
||||||
}
|
|
||||||
pattern = "**/" + pattern
|
|
||||||
}
|
|
||||||
|
|
||||||
this.strict = options.strict !== false
|
|
||||||
this.dot = !!options.dot
|
|
||||||
this.mark = !!options.mark
|
|
||||||
this.sync = !!options.sync
|
|
||||||
this.nounique = !!options.nounique
|
|
||||||
this.nonull = !!options.nonull
|
|
||||||
this.nosort = !!options.nosort
|
|
||||||
this.nocase = !!options.nocase
|
|
||||||
this.stat = !!options.stat
|
|
||||||
|
|
||||||
this.debug = !!options.debug || !!options.globDebug
|
|
||||||
if (this.debug)
|
|
||||||
this.log = console.error
|
|
||||||
|
|
||||||
this.silent = !!options.silent
|
|
||||||
|
|
||||||
var mm = this.minimatch = new Minimatch(pattern, options)
|
|
||||||
this.options = mm.options
|
|
||||||
pattern = this.pattern = mm.pattern
|
|
||||||
|
|
||||||
this.error = null
|
|
||||||
this.aborted = false
|
|
||||||
|
|
||||||
// list of all the patterns that ** has resolved do, so
|
|
||||||
// we can avoid visiting multiple times.
|
|
||||||
this._globstars = {}
|
|
||||||
|
|
||||||
EE.call(this)
|
|
||||||
|
|
||||||
// process each pattern in the minimatch set
|
|
||||||
var n = this.minimatch.set.length
|
|
||||||
|
|
||||||
// The matches are stored as {<filename>: true,...} so that
|
|
||||||
// duplicates are automagically pruned.
|
|
||||||
// Later, we do an Object.keys() on these.
|
|
||||||
// Keep them as a list so we can fill in when nonull is set.
|
|
||||||
this.matches = new Array(n)
|
|
||||||
|
|
||||||
this.minimatch.set.forEach(iterator.bind(this))
|
|
||||||
function iterator (pattern, i, set) {
|
|
||||||
this._process(pattern, 0, i, function (er) {
|
|
||||||
if (er) this.emit("error", er)
|
|
||||||
if (-- n <= 0) this._finish()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype.log = function () {}
|
|
||||||
|
|
||||||
Glob.prototype._finish = function () {
|
|
||||||
assert(this instanceof Glob)
|
|
||||||
|
|
||||||
var nou = this.nounique
|
|
||||||
, all = nou ? [] : {}
|
|
||||||
|
|
||||||
for (var i = 0, l = this.matches.length; i < l; i ++) {
|
|
||||||
var matches = this.matches[i]
|
|
||||||
this.log("matches[%d] =", i, matches)
|
|
||||||
// do like the shell, and spit out the literal glob
|
|
||||||
if (!matches) {
|
|
||||||
if (this.nonull) {
|
|
||||||
var literal = this.minimatch.globSet[i]
|
|
||||||
if (nou) all.push(literal)
|
|
||||||
else all[literal] = true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// had matches
|
|
||||||
var m = Object.keys(matches)
|
|
||||||
if (nou) all.push.apply(all, m)
|
|
||||||
else m.forEach(function (m) {
|
|
||||||
all[m] = true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!nou) all = Object.keys(all)
|
|
||||||
|
|
||||||
if (!this.nosort) {
|
|
||||||
all = all.sort(this.nocase ? alphasorti : alphasort)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.mark) {
|
|
||||||
// at *some* point we statted all of these
|
|
||||||
all = all.map(this._mark, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.log("emitting end", all)
|
|
||||||
|
|
||||||
this.EOF = this.found = all
|
|
||||||
this.emitMatch(this.EOF)
|
|
||||||
}
|
|
||||||
|
|
||||||
function alphasorti (a, b) {
|
|
||||||
a = a.toLowerCase()
|
|
||||||
b = b.toLowerCase()
|
|
||||||
return alphasort(a, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
function alphasort (a, b) {
|
|
||||||
return a > b ? 1 : a < b ? -1 : 0
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype._mark = function (p) {
|
|
||||||
var c = this.cache[p]
|
|
||||||
var m = p
|
|
||||||
if (c) {
|
|
||||||
var isDir = c === 2 || Array.isArray(c)
|
|
||||||
var slash = p.slice(-1) === '/'
|
|
||||||
|
|
||||||
if (isDir && !slash)
|
|
||||||
m += '/'
|
|
||||||
else if (!isDir && slash)
|
|
||||||
m = m.slice(0, -1)
|
|
||||||
|
|
||||||
if (m !== p) {
|
|
||||||
this.statCache[m] = this.statCache[p]
|
|
||||||
this.cache[m] = this.cache[p]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype.abort = function () {
|
|
||||||
this.aborted = true
|
|
||||||
this.emit("abort")
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype.pause = function () {
|
|
||||||
if (this.paused) return
|
|
||||||
if (this.sync)
|
|
||||||
this.emit("error", new Error("Can't pause/resume sync glob"))
|
|
||||||
this.paused = true
|
|
||||||
this.emit("pause")
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype.resume = function () {
|
|
||||||
if (!this.paused) return
|
|
||||||
if (this.sync)
|
|
||||||
this.emit("error", new Error("Can't pause/resume sync glob"))
|
|
||||||
this.paused = false
|
|
||||||
this.emit("resume")
|
|
||||||
this._processEmitQueue()
|
|
||||||
//process.nextTick(this.emit.bind(this, "resume"))
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype.emitMatch = function (m) {
|
|
||||||
this.log('emitMatch', m)
|
|
||||||
this._emitQueue.push(m)
|
|
||||||
this._processEmitQueue()
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype._processEmitQueue = function (m) {
|
|
||||||
this.log("pEQ paused=%j processing=%j m=%j", this.paused,
|
|
||||||
this._processingEmitQueue, m)
|
|
||||||
var done = false
|
|
||||||
while (!this._processingEmitQueue &&
|
|
||||||
!this.paused) {
|
|
||||||
this._processingEmitQueue = true
|
|
||||||
var m = this._emitQueue.shift()
|
|
||||||
this.log(">processEmitQueue", m === this.EOF ? ":EOF:" : m)
|
|
||||||
if (!m) {
|
|
||||||
this.log(">processEmitQueue, falsey m")
|
|
||||||
this._processingEmitQueue = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m === this.EOF || !(this.mark && !this.stat)) {
|
|
||||||
this.log("peq: unmarked, or eof")
|
|
||||||
next.call(this, 0, false)
|
|
||||||
} else if (this.statCache[m]) {
|
|
||||||
var sc = this.statCache[m]
|
|
||||||
var exists
|
|
||||||
if (sc)
|
|
||||||
exists = sc.isDirectory() ? 2 : 1
|
|
||||||
this.log("peq: stat cached")
|
|
||||||
next.call(this, exists, exists === 2)
|
|
||||||
} else {
|
|
||||||
this.log("peq: _stat, then next")
|
|
||||||
this._stat(m, next)
|
|
||||||
}
|
|
||||||
|
|
||||||
function next(exists, isDir) {
|
|
||||||
this.log("next", m, exists, isDir)
|
|
||||||
var ev = m === this.EOF ? "end" : "match"
|
|
||||||
|
|
||||||
// "end" can only happen once.
|
|
||||||
assert(!this._endEmitted)
|
|
||||||
if (ev === "end")
|
|
||||||
this._endEmitted = true
|
|
||||||
|
|
||||||
if (exists) {
|
|
||||||
// Doesn't mean it necessarily doesn't exist, it's possible
|
|
||||||
// we just didn't check because we don't care that much, or
|
|
||||||
// this is EOF anyway.
|
|
||||||
if (isDir && !m.match(/\/$/)) {
|
|
||||||
m = m + "/"
|
|
||||||
} else if (!isDir && m.match(/\/$/)) {
|
|
||||||
m = m.replace(/\/+$/, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.log("emit", ev, m)
|
|
||||||
this.emit(ev, m)
|
|
||||||
this._processingEmitQueue = false
|
|
||||||
if (done && m !== this.EOF && !this.paused)
|
|
||||||
this._processEmitQueue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
done = true
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype._process = function (pattern, depth, index, cb_) {
|
|
||||||
assert(this instanceof Glob)
|
|
||||||
|
|
||||||
var cb = function cb (er, res) {
|
|
||||||
assert(this instanceof Glob)
|
|
||||||
if (this.paused) {
|
|
||||||
if (!this._processQueue) {
|
|
||||||
this._processQueue = []
|
|
||||||
this.once("resume", function () {
|
|
||||||
var q = this._processQueue
|
|
||||||
this._processQueue = null
|
|
||||||
q.forEach(function (cb) { cb() })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this._processQueue.push(cb_.bind(this, er, res))
|
|
||||||
} else {
|
|
||||||
cb_.call(this, er, res)
|
|
||||||
}
|
|
||||||
}.bind(this)
|
|
||||||
|
|
||||||
if (this.aborted) return cb()
|
|
||||||
|
|
||||||
if (depth > this.maxDepth) return cb()
|
|
||||||
|
|
||||||
// Get the first [n] parts of pattern that are all strings.
|
|
||||||
var n = 0
|
|
||||||
while (typeof pattern[n] === "string") {
|
|
||||||
n ++
|
|
||||||
}
|
|
||||||
// now n is the index of the first one that is *not* a string.
|
|
||||||
|
|
||||||
// see if there's anything else
|
|
||||||
var prefix
|
|
||||||
switch (n) {
|
|
||||||
// if not, then this is rather simple
|
|
||||||
case pattern.length:
|
|
||||||
prefix = pattern.join("/")
|
|
||||||
this._stat(prefix, function (exists, isDir) {
|
|
||||||
// either it's there, or it isn't.
|
|
||||||
// nothing more to do, either way.
|
|
||||||
if (exists) {
|
|
||||||
if (prefix && isAbsolute(prefix) && !this.nomount) {
|
|
||||||
if (prefix.charAt(0) === "/") {
|
|
||||||
prefix = path.join(this.root, prefix)
|
|
||||||
} else {
|
|
||||||
prefix = path.resolve(this.root, prefix)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.platform === "win32")
|
|
||||||
prefix = prefix.replace(/\\/g, "/")
|
|
||||||
|
|
||||||
this.matches[index] = this.matches[index] || {}
|
|
||||||
this.matches[index][prefix] = true
|
|
||||||
this.emitMatch(prefix)
|
|
||||||
}
|
|
||||||
return cb()
|
|
||||||
})
|
|
||||||
return
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
// pattern *starts* with some non-trivial item.
|
|
||||||
// going to readdir(cwd), but not include the prefix in matches.
|
|
||||||
prefix = null
|
|
||||||
break
|
|
||||||
|
|
||||||
default:
|
|
||||||
// pattern has some string bits in the front.
|
|
||||||
// whatever it starts with, whether that's "absolute" like /foo/bar,
|
|
||||||
// or "relative" like "../baz"
|
|
||||||
prefix = pattern.slice(0, n)
|
|
||||||
prefix = prefix.join("/")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the list of entries.
|
|
||||||
var read
|
|
||||||
if (prefix === null) read = "."
|
|
||||||
else if (isAbsolute(prefix) || isAbsolute(pattern.join("/"))) {
|
|
||||||
if (!prefix || !isAbsolute(prefix)) {
|
|
||||||
prefix = path.join("/", prefix)
|
|
||||||
}
|
|
||||||
read = prefix = path.resolve(prefix)
|
|
||||||
|
|
||||||
// if (process.platform === "win32")
|
|
||||||
// read = prefix = prefix.replace(/^[a-zA-Z]:|\\/g, "/")
|
|
||||||
|
|
||||||
this.log('absolute: ', prefix, this.root, pattern, read)
|
|
||||||
} else {
|
|
||||||
read = prefix
|
|
||||||
}
|
|
||||||
|
|
||||||
this.log('readdir(%j)', read, this.cwd, this.root)
|
|
||||||
|
|
||||||
return this._readdir(read, function (er, entries) {
|
|
||||||
if (er) {
|
|
||||||
// not a directory!
|
|
||||||
// this means that, whatever else comes after this, it can never match
|
|
||||||
return cb()
|
|
||||||
}
|
|
||||||
|
|
||||||
// globstar is special
|
|
||||||
if (pattern[n] === minimatch.GLOBSTAR) {
|
|
||||||
// test without the globstar, and with every child both below
|
|
||||||
// and replacing the globstar.
|
|
||||||
var s = [ pattern.slice(0, n).concat(pattern.slice(n + 1)) ]
|
|
||||||
entries.forEach(function (e) {
|
|
||||||
if (e.charAt(0) === "." && !this.dot) return
|
|
||||||
// instead of the globstar
|
|
||||||
s.push(pattern.slice(0, n).concat(e).concat(pattern.slice(n + 1)))
|
|
||||||
// below the globstar
|
|
||||||
s.push(pattern.slice(0, n).concat(e).concat(pattern.slice(n)))
|
|
||||||
}, this)
|
|
||||||
|
|
||||||
s = s.filter(function (pattern) {
|
|
||||||
var key = gsKey(pattern)
|
|
||||||
var seen = !this._globstars[key]
|
|
||||||
this._globstars[key] = true
|
|
||||||
return seen
|
|
||||||
}, this)
|
|
||||||
|
|
||||||
if (!s.length)
|
|
||||||
return cb()
|
|
||||||
|
|
||||||
// now asyncForEach over this
|
|
||||||
var l = s.length
|
|
||||||
, errState = null
|
|
||||||
s.forEach(function (gsPattern) {
|
|
||||||
this._process(gsPattern, depth + 1, index, function (er) {
|
|
||||||
if (errState) return
|
|
||||||
if (er) return cb(errState = er)
|
|
||||||
if (--l <= 0) return cb()
|
|
||||||
})
|
|
||||||
}, this)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// not a globstar
|
|
||||||
// It will only match dot entries if it starts with a dot, or if
|
|
||||||
// dot is set. Stuff like @(.foo|.bar) isn't allowed.
|
|
||||||
var pn = pattern[n]
|
|
||||||
var rawGlob = pattern[n]._glob
|
|
||||||
, dotOk = this.dot || rawGlob.charAt(0) === "."
|
|
||||||
|
|
||||||
entries = entries.filter(function (e) {
|
|
||||||
return (e.charAt(0) !== "." || dotOk) &&
|
|
||||||
e.match(pattern[n])
|
|
||||||
})
|
|
||||||
|
|
||||||
// If n === pattern.length - 1, then there's no need for the extra stat
|
|
||||||
// *unless* the user has specified "mark" or "stat" explicitly.
|
|
||||||
// We know that they exist, since the readdir returned them.
|
|
||||||
if (n === pattern.length - 1 &&
|
|
||||||
!this.mark &&
|
|
||||||
!this.stat) {
|
|
||||||
entries.forEach(function (e) {
|
|
||||||
if (prefix) {
|
|
||||||
if (prefix !== "/") e = prefix + "/" + e
|
|
||||||
else e = prefix + e
|
|
||||||
}
|
|
||||||
if (e.charAt(0) === "/" && !this.nomount) {
|
|
||||||
e = path.join(this.root, e)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.platform === "win32")
|
|
||||||
e = e.replace(/\\/g, "/")
|
|
||||||
|
|
||||||
this.matches[index] = this.matches[index] || {}
|
|
||||||
this.matches[index][e] = true
|
|
||||||
this.emitMatch(e)
|
|
||||||
}, this)
|
|
||||||
return cb.call(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// now test all the remaining entries as stand-ins for that part
|
|
||||||
// of the pattern.
|
|
||||||
var l = entries.length
|
|
||||||
, errState = null
|
|
||||||
if (l === 0) return cb() // no matches possible
|
|
||||||
entries.forEach(function (e) {
|
|
||||||
var p = pattern.slice(0, n).concat(e).concat(pattern.slice(n + 1))
|
|
||||||
this._process(p, depth + 1, index, function (er) {
|
|
||||||
if (errState) return
|
|
||||||
if (er) return cb(errState = er)
|
|
||||||
if (--l === 0) return cb.call(this)
|
|
||||||
})
|
|
||||||
}, this)
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function gsKey (pattern) {
|
|
||||||
return '**' + pattern.map(function (p) {
|
|
||||||
return (p === minimatch.GLOBSTAR) ? '**' : (''+p)
|
|
||||||
}).join('/')
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype._stat = function (f, cb) {
|
|
||||||
assert(this instanceof Glob)
|
|
||||||
var abs = f
|
|
||||||
if (f.charAt(0) === "/") {
|
|
||||||
abs = path.join(this.root, f)
|
|
||||||
} else if (this.changedCwd) {
|
|
||||||
abs = path.resolve(this.cwd, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f.length > this.maxLength) {
|
|
||||||
var er = new Error("Path name too long")
|
|
||||||
er.code = "ENAMETOOLONG"
|
|
||||||
er.path = f
|
|
||||||
return this._afterStat(f, abs, cb, er)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.log('stat', [this.cwd, f, '=', abs])
|
|
||||||
|
|
||||||
if (!this.stat && this.cache.hasOwnProperty(f)) {
|
|
||||||
var exists = this.cache[f]
|
|
||||||
, isDir = exists && (Array.isArray(exists) || exists === 2)
|
|
||||||
if (this.sync) return cb.call(this, !!exists, isDir)
|
|
||||||
return process.nextTick(cb.bind(this, !!exists, isDir))
|
|
||||||
}
|
|
||||||
|
|
||||||
var stat = this.statCache[abs]
|
|
||||||
if (this.sync || stat) {
|
|
||||||
var er
|
|
||||||
try {
|
|
||||||
stat = fs.statSync(abs)
|
|
||||||
} catch (e) {
|
|
||||||
er = e
|
|
||||||
}
|
|
||||||
this._afterStat(f, abs, cb, er, stat)
|
|
||||||
} else {
|
|
||||||
fs.stat(abs, this._afterStat.bind(this, f, abs, cb))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype._afterStat = function (f, abs, cb, er, stat) {
|
|
||||||
var exists
|
|
||||||
assert(this instanceof Glob)
|
|
||||||
|
|
||||||
if (abs.slice(-1) === "/" && stat && !stat.isDirectory()) {
|
|
||||||
this.log("should be ENOTDIR, fake it")
|
|
||||||
|
|
||||||
er = new Error("ENOTDIR, not a directory '" + abs + "'")
|
|
||||||
er.path = abs
|
|
||||||
er.code = "ENOTDIR"
|
|
||||||
stat = null
|
|
||||||
}
|
|
||||||
|
|
||||||
var emit = !this.statCache[abs]
|
|
||||||
this.statCache[abs] = stat
|
|
||||||
|
|
||||||
if (er || !stat) {
|
|
||||||
exists = false
|
|
||||||
} else {
|
|
||||||
exists = stat.isDirectory() ? 2 : 1
|
|
||||||
if (emit)
|
|
||||||
this.emit('stat', f, stat)
|
|
||||||
}
|
|
||||||
this.cache[f] = this.cache[f] || exists
|
|
||||||
cb.call(this, !!exists, exists === 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype._readdir = function (f, cb) {
|
|
||||||
assert(this instanceof Glob)
|
|
||||||
var abs = f
|
|
||||||
if (f.charAt(0) === "/") {
|
|
||||||
abs = path.join(this.root, f)
|
|
||||||
} else if (isAbsolute(f)) {
|
|
||||||
abs = f
|
|
||||||
} else if (this.changedCwd) {
|
|
||||||
abs = path.resolve(this.cwd, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f.length > this.maxLength) {
|
|
||||||
var er = new Error("Path name too long")
|
|
||||||
er.code = "ENAMETOOLONG"
|
|
||||||
er.path = f
|
|
||||||
return this._afterReaddir(f, abs, cb, er)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.log('readdir', [this.cwd, f, abs])
|
|
||||||
if (this.cache.hasOwnProperty(f)) {
|
|
||||||
var c = this.cache[f]
|
|
||||||
if (Array.isArray(c)) {
|
|
||||||
if (this.sync) return cb.call(this, null, c)
|
|
||||||
return process.nextTick(cb.bind(this, null, c))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!c || c === 1) {
|
|
||||||
// either ENOENT or ENOTDIR
|
|
||||||
var code = c ? "ENOTDIR" : "ENOENT"
|
|
||||||
, er = new Error((c ? "Not a directory" : "Not found") + ": " + f)
|
|
||||||
er.path = f
|
|
||||||
er.code = code
|
|
||||||
this.log(f, er)
|
|
||||||
if (this.sync) return cb.call(this, er)
|
|
||||||
return process.nextTick(cb.bind(this, er))
|
|
||||||
}
|
|
||||||
|
|
||||||
// at this point, c === 2, meaning it's a dir, but we haven't
|
|
||||||
// had to read it yet, or c === true, meaning it's *something*
|
|
||||||
// but we don't have any idea what. Need to read it, either way.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.sync) {
|
|
||||||
var er, entries
|
|
||||||
try {
|
|
||||||
entries = fs.readdirSync(abs)
|
|
||||||
} catch (e) {
|
|
||||||
er = e
|
|
||||||
}
|
|
||||||
return this._afterReaddir(f, abs, cb, er, entries)
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.readdir(abs, this._afterReaddir.bind(this, f, abs, cb))
|
|
||||||
}
|
|
||||||
|
|
||||||
Glob.prototype._afterReaddir = function (f, abs, cb, er, entries) {
|
|
||||||
assert(this instanceof Glob)
|
|
||||||
if (entries && !er) {
|
|
||||||
this.cache[f] = entries
|
|
||||||
// if we haven't asked to stat everything for suresies, then just
|
|
||||||
// assume that everything in there exists, so we can avoid
|
|
||||||
// having to stat it a second time. This also gets us one step
|
|
||||||
// further into ELOOP territory.
|
|
||||||
if (!this.mark && !this.stat) {
|
|
||||||
entries.forEach(function (e) {
|
|
||||||
if (f === "/") e = f + e
|
|
||||||
else e = f + "/" + e
|
|
||||||
this.cache[e] = true
|
|
||||||
}, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
return cb.call(this, er, entries)
|
|
||||||
}
|
|
||||||
|
|
||||||
// now handle errors, and cache the information
|
|
||||||
if (er) switch (er.code) {
|
|
||||||
case "ENOTDIR": // totally normal. means it *does* exist.
|
|
||||||
this.cache[f] = 1
|
|
||||||
return cb.call(this, er)
|
|
||||||
case "ENOENT": // not terribly unusual
|
|
||||||
case "ELOOP":
|
|
||||||
case "ENAMETOOLONG":
|
|
||||||
case "UNKNOWN":
|
|
||||||
this.cache[f] = false
|
|
||||||
return cb.call(this, er)
|
|
||||||
default: // some unusual error. Treat as failure.
|
|
||||||
this.cache[f] = false
|
|
||||||
if (this.strict) this.emit("error", er)
|
|
||||||
if (!this.silent) console.error("glob error", er)
|
|
||||||
return cb.call(this, er)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var isAbsolute = process.platform === "win32" ? absWin : absUnix
|
|
||||||
|
|
||||||
function absWin (p) {
|
|
||||||
if (absUnix(p)) return true
|
|
||||||
// pull off the device/UNC bit from a windows path.
|
|
||||||
// from node's lib/path.js
|
|
||||||
var splitDeviceRe =
|
|
||||||
/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/
|
|
||||||
, result = splitDeviceRe.exec(p)
|
|
||||||
, device = result[1] || ''
|
|
||||||
, isUnc = device && device.charAt(1) !== ':'
|
|
||||||
, isAbsolute = !!result[2] || isUnc // UNC paths are always absolute
|
|
||||||
|
|
||||||
return isAbsolute
|
|
||||||
}
|
|
||||||
|
|
||||||
function absUnix (p) {
|
|
||||||
return p.charAt(0) === "/" || p === ""
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
The ISC License
|
|
||||||
|
|
||||||
Copyright (c) Isaac Z. Schlueter
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
||||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
||||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
||||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
||||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
||||||
PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
|||||||
Browser-friendly inheritance fully compatible with standard node.js
|
|
||||||
[inherits](http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor).
|
|
||||||
|
|
||||||
This package exports standard `inherits` from node.js `util` module in
|
|
||||||
node environment, but also provides alternative browser-friendly
|
|
||||||
implementation through [browser
|
|
||||||
field](https://gist.github.com/shtylman/4339901). Alternative
|
|
||||||
implementation is a literal copy of standard one located in standalone
|
|
||||||
module to avoid requiring of `util`. It also has a shim for old
|
|
||||||
browsers with no `Object.create` support.
|
|
||||||
|
|
||||||
While keeping you sure you are using standard `inherits`
|
|
||||||
implementation in node.js environment, it allows bundlers such as
|
|
||||||
[browserify](https://github.com/substack/node-browserify) to not
|
|
||||||
include full `util` package to your client code if all you need is
|
|
||||||
just `inherits` function. It worth, because browser shim for `util`
|
|
||||||
package is large and `inherits` is often the single function you need
|
|
||||||
from it.
|
|
||||||
|
|
||||||
It's recommended to use this package instead of
|
|
||||||
`require('util').inherits` for any code that has chances to be used
|
|
||||||
not only in node.js but in browser too.
|
|
||||||
|
|
||||||
## usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
var inherits = require('inherits');
|
|
||||||
// then use exactly as the standard one
|
|
||||||
```
|
|
||||||
|
|
||||||
## note on version ~1.0
|
|
||||||
|
|
||||||
Version ~1.0 had completely different motivation and is not compatible
|
|
||||||
neither with 2.0 nor with standard node.js `inherits`.
|
|
||||||
|
|
||||||
If you are using version ~1.0 and planning to switch to ~2.0, be
|
|
||||||
careful:
|
|
||||||
|
|
||||||
* new version uses `super_` instead of `super` for referencing
|
|
||||||
superclass
|
|
||||||
* new version overwrites current prototype while old one preserves any
|
|
||||||
existing fields on it
|
|
@ -1 +0,0 @@
|
|||||||
module.exports = require('util').inherits
|
|
@ -1,23 +0,0 @@
|
|||||||
if (typeof Object.create === 'function') {
|
|
||||||
// implementation from standard node.js 'util' module
|
|
||||||
module.exports = function inherits(ctor, superCtor) {
|
|
||||||
ctor.super_ = superCtor
|
|
||||||
ctor.prototype = Object.create(superCtor.prototype, {
|
|
||||||
constructor: {
|
|
||||||
value: ctor,
|
|
||||||
enumerable: false,
|
|
||||||
writable: true,
|
|
||||||
configurable: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
// old school shim for old browsers
|
|
||||||
module.exports = function inherits(ctor, superCtor) {
|
|
||||||
ctor.super_ = superCtor
|
|
||||||
var TempCtor = function () {}
|
|
||||||
TempCtor.prototype = superCtor.prototype
|
|
||||||
ctor.prototype = new TempCtor()
|
|
||||||
ctor.prototype.constructor = ctor
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "inherits",
|
|
||||||
"description": "Browser-friendly inheritance fully compatible with standard node.js inherits()",
|
|
||||||
"version": "2.0.1",
|
|
||||||
"keywords": [
|
|
||||||
"inheritance",
|
|
||||||
"class",
|
|
||||||
"klass",
|
|
||||||
"oop",
|
|
||||||
"object-oriented",
|
|
||||||
"inherits",
|
|
||||||
"browser",
|
|
||||||
"browserify"
|
|
||||||
],
|
|
||||||
"main": "./inherits.js",
|
|
||||||
"browser": "./inherits_browser.js",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/isaacs/inherits"
|
|
||||||
},
|
|
||||||
"license": "ISC",
|
|
||||||
"scripts": {
|
|
||||||
"test": "node test"
|
|
||||||
},
|
|
||||||
"readme": "Browser-friendly inheritance fully compatible with standard node.js\n[inherits](http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor).\n\nThis package exports standard `inherits` from node.js `util` module in\nnode environment, but also provides alternative browser-friendly\nimplementation through [browser\nfield](https://gist.github.com/shtylman/4339901). Alternative\nimplementation is a literal copy of standard one located in standalone\nmodule to avoid requiring of `util`. It also has a shim for old\nbrowsers with no `Object.create` support.\n\nWhile keeping you sure you are using standard `inherits`\nimplementation in node.js environment, it allows bundlers such as\n[browserify](https://github.com/substack/node-browserify) to not\ninclude full `util` package to your client code if all you need is\njust `inherits` function. It worth, because browser shim for `util`\npackage is large and `inherits` is often the single function you need\nfrom it.\n\nIt's recommended to use this package instead of\n`require('util').inherits` for any code that has chances to be used\nnot only in node.js but in browser too.\n\n## usage\n\n```js\nvar inherits = require('inherits');\n// then use exactly as the standard one\n```\n\n## note on version ~1.0\n\nVersion ~1.0 had completely different motivation and is not compatible\nneither with 2.0 nor with standard node.js `inherits`.\n\nIf you are using version ~1.0 and planning to switch to ~2.0, be\ncareful:\n\n* new version uses `super_` instead of `super` for referencing\n superclass\n* new version overwrites current prototype while old one preserves any\n existing fields on it\n",
|
|
||||||
"readmeFilename": "README.md",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/isaacs/inherits/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/isaacs/inherits",
|
|
||||||
"_id": "inherits@2.0.1",
|
|
||||||
"_from": "inherits@2"
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
var inherits = require('./inherits.js')
|
|
||||||
var assert = require('assert')
|
|
||||||
|
|
||||||
function test(c) {
|
|
||||||
assert(c.constructor === Child)
|
|
||||||
assert(c.constructor.super_ === Parent)
|
|
||||||
assert(Object.getPrototypeOf(c) === Child.prototype)
|
|
||||||
assert(Object.getPrototypeOf(Object.getPrototypeOf(c)) === Parent.prototype)
|
|
||||||
assert(c instanceof Child)
|
|
||||||
assert(c instanceof Parent)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Child() {
|
|
||||||
Parent.call(this)
|
|
||||||
test(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Parent() {}
|
|
||||||
|
|
||||||
inherits(Child, Parent)
|
|
||||||
|
|
||||||
var c = new Child
|
|
||||||
test(c)
|
|
||||||
|
|
||||||
console.log('ok')
|
|
@ -1 +0,0 @@
|
|||||||
node_modules
|
|
@ -1,23 +0,0 @@
|
|||||||
Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,218 +0,0 @@
|
|||||||
# minimatch
|
|
||||||
|
|
||||||
A minimal matching utility.
|
|
||||||
|
|
||||||
[![Build Status](https://secure.travis-ci.org/isaacs/minimatch.png)](http://travis-ci.org/isaacs/minimatch)
|
|
||||||
|
|
||||||
|
|
||||||
This is the matching library used internally by npm.
|
|
||||||
|
|
||||||
Eventually, it will replace the C binding in node-glob.
|
|
||||||
|
|
||||||
It works by converting glob expressions into JavaScript `RegExp`
|
|
||||||
objects.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var minimatch = require("minimatch")
|
|
||||||
|
|
||||||
minimatch("bar.foo", "*.foo") // true!
|
|
||||||
minimatch("bar.foo", "*.bar") // false!
|
|
||||||
minimatch("bar.foo", "*.+(bar|foo)", { debug: true }) // true, and noisy!
|
|
||||||
```
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
Supports these glob features:
|
|
||||||
|
|
||||||
* Brace Expansion
|
|
||||||
* Extended glob matching
|
|
||||||
* "Globstar" `**` matching
|
|
||||||
|
|
||||||
See:
|
|
||||||
|
|
||||||
* `man sh`
|
|
||||||
* `man bash`
|
|
||||||
* `man 3 fnmatch`
|
|
||||||
* `man 5 gitignore`
|
|
||||||
|
|
||||||
## Minimatch Class
|
|
||||||
|
|
||||||
Create a minimatch object by instanting the `minimatch.Minimatch` class.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var Minimatch = require("minimatch").Minimatch
|
|
||||||
var mm = new Minimatch(pattern, options)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Properties
|
|
||||||
|
|
||||||
* `pattern` The original pattern the minimatch object represents.
|
|
||||||
* `options` The options supplied to the constructor.
|
|
||||||
* `set` A 2-dimensional array of regexp or string expressions.
|
|
||||||
Each row in the
|
|
||||||
array corresponds to a brace-expanded pattern. Each item in the row
|
|
||||||
corresponds to a single path-part. For example, the pattern
|
|
||||||
`{a,b/c}/d` would expand to a set of patterns like:
|
|
||||||
|
|
||||||
[ [ a, d ]
|
|
||||||
, [ b, c, d ] ]
|
|
||||||
|
|
||||||
If a portion of the pattern doesn't have any "magic" in it
|
|
||||||
(that is, it's something like `"foo"` rather than `fo*o?`), then it
|
|
||||||
will be left as a string rather than converted to a regular
|
|
||||||
expression.
|
|
||||||
|
|
||||||
* `regexp` Created by the `makeRe` method. A single regular expression
|
|
||||||
expressing the entire pattern. This is useful in cases where you wish
|
|
||||||
to use the pattern somewhat like `fnmatch(3)` with `FNM_PATH` enabled.
|
|
||||||
* `negate` True if the pattern is negated.
|
|
||||||
* `comment` True if the pattern is a comment.
|
|
||||||
* `empty` True if the pattern is `""`.
|
|
||||||
|
|
||||||
### Methods
|
|
||||||
|
|
||||||
* `makeRe` Generate the `regexp` member if necessary, and return it.
|
|
||||||
Will return `false` if the pattern is invalid.
|
|
||||||
* `match(fname)` Return true if the filename matches the pattern, or
|
|
||||||
false otherwise.
|
|
||||||
* `matchOne(fileArray, patternArray, partial)` Take a `/`-split
|
|
||||||
filename, and match it against a single row in the `regExpSet`. This
|
|
||||||
method is mainly for internal use, but is exposed so that it can be
|
|
||||||
used by a glob-walker that needs to avoid excessive filesystem calls.
|
|
||||||
|
|
||||||
All other methods are internal, and will be called as necessary.
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
The top-level exported function has a `cache` property, which is an LRU
|
|
||||||
cache set to store 100 items. So, calling these methods repeatedly
|
|
||||||
with the same pattern and options will use the same Minimatch object,
|
|
||||||
saving the cost of parsing it multiple times.
|
|
||||||
|
|
||||||
### minimatch(path, pattern, options)
|
|
||||||
|
|
||||||
Main export. Tests a path against the pattern using the options.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var isJS = minimatch(file, "*.js", { matchBase: true })
|
|
||||||
```
|
|
||||||
|
|
||||||
### minimatch.filter(pattern, options)
|
|
||||||
|
|
||||||
Returns a function that tests its
|
|
||||||
supplied argument, suitable for use with `Array.filter`. Example:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var javascripts = fileList.filter(minimatch.filter("*.js", {matchBase: true}))
|
|
||||||
```
|
|
||||||
|
|
||||||
### minimatch.match(list, pattern, options)
|
|
||||||
|
|
||||||
Match against the list of
|
|
||||||
files, in the style of fnmatch or glob. If nothing is matched, and
|
|
||||||
options.nonull is set, then return a list containing the pattern itself.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var javascripts = minimatch.match(fileList, "*.js", {matchBase: true}))
|
|
||||||
```
|
|
||||||
|
|
||||||
### minimatch.makeRe(pattern, options)
|
|
||||||
|
|
||||||
Make a regular expression object from the pattern.
|
|
||||||
|
|
||||||
## Options
|
|
||||||
|
|
||||||
All options are `false` by default.
|
|
||||||
|
|
||||||
### debug
|
|
||||||
|
|
||||||
Dump a ton of stuff to stderr.
|
|
||||||
|
|
||||||
### nobrace
|
|
||||||
|
|
||||||
Do not expand `{a,b}` and `{1..3}` brace sets.
|
|
||||||
|
|
||||||
### noglobstar
|
|
||||||
|
|
||||||
Disable `**` matching against multiple folder names.
|
|
||||||
|
|
||||||
### dot
|
|
||||||
|
|
||||||
Allow patterns to match filenames starting with a period, even if
|
|
||||||
the pattern does not explicitly have a period in that spot.
|
|
||||||
|
|
||||||
Note that by default, `a/**/b` will **not** match `a/.d/b`, unless `dot`
|
|
||||||
is set.
|
|
||||||
|
|
||||||
### noext
|
|
||||||
|
|
||||||
Disable "extglob" style patterns like `+(a|b)`.
|
|
||||||
|
|
||||||
### nocase
|
|
||||||
|
|
||||||
Perform a case-insensitive match.
|
|
||||||
|
|
||||||
### nonull
|
|
||||||
|
|
||||||
When a match is not found by `minimatch.match`, return a list containing
|
|
||||||
the pattern itself if this option is set. When not set, an empty list
|
|
||||||
is returned if there are no matches.
|
|
||||||
|
|
||||||
### matchBase
|
|
||||||
|
|
||||||
If set, then patterns without slashes will be matched
|
|
||||||
against the basename of the path if it contains slashes. For example,
|
|
||||||
`a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`.
|
|
||||||
|
|
||||||
### nocomment
|
|
||||||
|
|
||||||
Suppress the behavior of treating `#` at the start of a pattern as a
|
|
||||||
comment.
|
|
||||||
|
|
||||||
### nonegate
|
|
||||||
|
|
||||||
Suppress the behavior of treating a leading `!` character as negation.
|
|
||||||
|
|
||||||
### flipNegate
|
|
||||||
|
|
||||||
Returns from negate expressions the same as if they were not negated.
|
|
||||||
(Ie, true on a hit, false on a miss.)
|
|
||||||
|
|
||||||
|
|
||||||
## Comparisons to other fnmatch/glob implementations
|
|
||||||
|
|
||||||
While strict compliance with the existing standards is a worthwhile
|
|
||||||
goal, some discrepancies exist between minimatch and other
|
|
||||||
implementations, and are intentional.
|
|
||||||
|
|
||||||
If the pattern starts with a `!` character, then it is negated. Set the
|
|
||||||
`nonegate` flag to suppress this behavior, and treat leading `!`
|
|
||||||
characters normally. This is perhaps relevant if you wish to start the
|
|
||||||
pattern with a negative extglob pattern like `!(a|B)`. Multiple `!`
|
|
||||||
characters at the start of a pattern will negate the pattern multiple
|
|
||||||
times.
|
|
||||||
|
|
||||||
If a pattern starts with `#`, then it is treated as a comment, and
|
|
||||||
will not match anything. Use `\#` to match a literal `#` at the
|
|
||||||
start of a line, or set the `nocomment` flag to suppress this behavior.
|
|
||||||
|
|
||||||
The double-star character `**` is supported by default, unless the
|
|
||||||
`noglobstar` flag is set. This is supported in the manner of bsdglob
|
|
||||||
and bash 4.1, where `**` only has special significance if it is the only
|
|
||||||
thing in a path part. That is, `a/**/b` will match `a/x/y/b`, but
|
|
||||||
`a/**b` will not.
|
|
||||||
|
|
||||||
If an escaped pattern has no matches, and the `nonull` flag is set,
|
|
||||||
then minimatch.match returns the pattern as-provided, rather than
|
|
||||||
interpreting the character escapes. For example,
|
|
||||||
`minimatch.match([], "\\*a\\?")` will return `"\\*a\\?"` rather than
|
|
||||||
`"*a?"`. This is akin to setting the `nullglob` option in bash, except
|
|
||||||
that it does not resolve escaped pattern characters.
|
|
||||||
|
|
||||||
If brace expansion is not disabled, then it is performed before any
|
|
||||||
other interpretation of the glob pattern. Thus, a pattern like
|
|
||||||
`+(a|{b),c)}`, which would not be valid in bash or zsh, is expanded
|
|
||||||
**first** into the set of `+(a|b)` and `+(a|c)`, and those patterns are
|
|
||||||
checked for validity. Since those two are valid, matching proceeds.
|
|
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
|||||||
/node_modules
|
|
@ -1,14 +0,0 @@
|
|||||||
# Authors, sorted by whether or not they are me
|
|
||||||
Isaac Z. Schlueter <i@izs.me>
|
|
||||||
Brian Cottingham <spiffytech@gmail.com>
|
|
||||||
Carlos Brito Lage <carlos@carloslage.net>
|
|
||||||
Jesse Dailey <jesse.dailey@gmail.com>
|
|
||||||
Kevin O'Hara <kevinohara80@gmail.com>
|
|
||||||
Marco Rogers <marco.rogers@gmail.com>
|
|
||||||
Mark Cavage <mcavage@gmail.com>
|
|
||||||
Marko Mikulicic <marko.mikulicic@isti.cnr.it>
|
|
||||||
Nathan Rajlich <nathan@tootallnate.net>
|
|
||||||
Satheesh Natesan <snateshan@myspace-inc.com>
|
|
||||||
Trent Mick <trentm@gmail.com>
|
|
||||||
ashleybrener <ashley@starlogik.com>
|
|
||||||
n4kz <n4kz@n4kz.com>
|
|
@ -1,23 +0,0 @@
|
|||||||
Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
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.
|
|
@ -1,97 +0,0 @@
|
|||||||
# lru cache
|
|
||||||
|
|
||||||
A cache object that deletes the least-recently-used items.
|
|
||||||
|
|
||||||
## Usage:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var LRU = require("lru-cache")
|
|
||||||
, options = { max: 500
|
|
||||||
, length: function (n) { return n * 2 }
|
|
||||||
, dispose: function (key, n) { n.close() }
|
|
||||||
, maxAge: 1000 * 60 * 60 }
|
|
||||||
, cache = LRU(options)
|
|
||||||
, otherCache = LRU(50) // sets just the max size
|
|
||||||
|
|
||||||
cache.set("key", "value")
|
|
||||||
cache.get("key") // "value"
|
|
||||||
|
|
||||||
cache.reset() // empty the cache
|
|
||||||
```
|
|
||||||
|
|
||||||
If you put more stuff in it, then items will fall out.
|
|
||||||
|
|
||||||
If you try to put an oversized thing in it, then it'll fall out right
|
|
||||||
away.
|
|
||||||
|
|
||||||
## Options
|
|
||||||
|
|
||||||
* `max` The maximum size of the cache, checked by applying the length
|
|
||||||
function to all values in the cache. Not setting this is kind of
|
|
||||||
silly, since that's the whole purpose of this lib, but it defaults
|
|
||||||
to `Infinity`.
|
|
||||||
* `maxAge` Maximum age in ms. Items are not pro-actively pruned out
|
|
||||||
as they age, but if you try to get an item that is too old, it'll
|
|
||||||
drop it and return undefined instead of giving it to you.
|
|
||||||
* `length` Function that is used to calculate the length of stored
|
|
||||||
items. If you're storing strings or buffers, then you probably want
|
|
||||||
to do something like `function(n){return n.length}`. The default is
|
|
||||||
`function(n){return 1}`, which is fine if you want to store `n`
|
|
||||||
like-sized things.
|
|
||||||
* `dispose` Function that is called on items when they are dropped
|
|
||||||
from the cache. This can be handy if you want to close file
|
|
||||||
descriptors or do other cleanup tasks when items are no longer
|
|
||||||
accessible. Called with `key, value`. It's called *before*
|
|
||||||
actually removing the item from the internal cache, so if you want
|
|
||||||
to immediately put it back in, you'll have to do that in a
|
|
||||||
`nextTick` or `setTimeout` callback or it won't do anything.
|
|
||||||
* `stale` By default, if you set a `maxAge`, it'll only actually pull
|
|
||||||
stale items out of the cache when you `get(key)`. (That is, it's
|
|
||||||
not pre-emptively doing a `setTimeout` or anything.) If you set
|
|
||||||
`stale:true`, it'll return the stale value before deleting it. If
|
|
||||||
you don't set this, then it'll return `undefined` when you try to
|
|
||||||
get a stale entry, as if it had already been deleted.
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
* `set(key, value)`
|
|
||||||
* `get(key) => value`
|
|
||||||
|
|
||||||
Both of these will update the "recently used"-ness of the key.
|
|
||||||
They do what you think.
|
|
||||||
|
|
||||||
* `peek(key)`
|
|
||||||
|
|
||||||
Returns the key value (or `undefined` if not found) without
|
|
||||||
updating the "recently used"-ness of the key.
|
|
||||||
|
|
||||||
(If you find yourself using this a lot, you *might* be using the
|
|
||||||
wrong sort of data structure, but there are some use cases where
|
|
||||||
it's handy.)
|
|
||||||
|
|
||||||
* `del(key)`
|
|
||||||
|
|
||||||
Deletes a key out of the cache.
|
|
||||||
|
|
||||||
* `reset()`
|
|
||||||
|
|
||||||
Clear the cache entirely, throwing away all values.
|
|
||||||
|
|
||||||
* `has(key)`
|
|
||||||
|
|
||||||
Check if a key is in the cache, without updating the recent-ness
|
|
||||||
or deleting it for being stale.
|
|
||||||
|
|
||||||
* `forEach(function(value,key,cache), [thisp])`
|
|
||||||
|
|
||||||
Just like `Array.prototype.forEach`. Iterates over all the keys
|
|
||||||
in the cache, in order of recent-ness. (Ie, more recently used
|
|
||||||
items are iterated over first.)
|
|
||||||
|
|
||||||
* `keys()`
|
|
||||||
|
|
||||||
Return an array of the keys in the cache.
|
|
||||||
|
|
||||||
* `values()`
|
|
||||||
|
|
||||||
Return an array of the values in the cache.
|
|
@ -1,252 +0,0 @@
|
|||||||
;(function () { // closure for web browsers
|
|
||||||
|
|
||||||
if (typeof module === 'object' && module.exports) {
|
|
||||||
module.exports = LRUCache
|
|
||||||
} else {
|
|
||||||
// just set the global for non-node platforms.
|
|
||||||
this.LRUCache = LRUCache
|
|
||||||
}
|
|
||||||
|
|
||||||
function hOP (obj, key) {
|
|
||||||
return Object.prototype.hasOwnProperty.call(obj, key)
|
|
||||||
}
|
|
||||||
|
|
||||||
function naiveLength () { return 1 }
|
|
||||||
|
|
||||||
function LRUCache (options) {
|
|
||||||
if (!(this instanceof LRUCache))
|
|
||||||
return new LRUCache(options)
|
|
||||||
|
|
||||||
if (typeof options === 'number')
|
|
||||||
options = { max: options }
|
|
||||||
|
|
||||||
if (!options)
|
|
||||||
options = {}
|
|
||||||
|
|
||||||
this._max = options.max
|
|
||||||
// Kind of weird to have a default max of Infinity, but oh well.
|
|
||||||
if (!this._max || !(typeof this._max === "number") || this._max <= 0 )
|
|
||||||
this._max = Infinity
|
|
||||||
|
|
||||||
this._lengthCalculator = options.length || naiveLength
|
|
||||||
if (typeof this._lengthCalculator !== "function")
|
|
||||||
this._lengthCalculator = naiveLength
|
|
||||||
|
|
||||||
this._allowStale = options.stale || false
|
|
||||||
this._maxAge = options.maxAge || null
|
|
||||||
this._dispose = options.dispose
|
|
||||||
this.reset()
|
|
||||||
}
|
|
||||||
|
|
||||||
// resize the cache when the max changes.
|
|
||||||
Object.defineProperty(LRUCache.prototype, "max",
|
|
||||||
{ set : function (mL) {
|
|
||||||
if (!mL || !(typeof mL === "number") || mL <= 0 ) mL = Infinity
|
|
||||||
this._max = mL
|
|
||||||
if (this._length > this._max) trim(this)
|
|
||||||
}
|
|
||||||
, get : function () { return this._max }
|
|
||||||
, enumerable : true
|
|
||||||
})
|
|
||||||
|
|
||||||
// resize the cache when the lengthCalculator changes.
|
|
||||||
Object.defineProperty(LRUCache.prototype, "lengthCalculator",
|
|
||||||
{ set : function (lC) {
|
|
||||||
if (typeof lC !== "function") {
|
|
||||||
this._lengthCalculator = naiveLength
|
|
||||||
this._length = this._itemCount
|
|
||||||
for (var key in this._cache) {
|
|
||||||
this._cache[key].length = 1
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this._lengthCalculator = lC
|
|
||||||
this._length = 0
|
|
||||||
for (var key in this._cache) {
|
|
||||||
this._cache[key].length = this._lengthCalculator(this._cache[key].value)
|
|
||||||
this._length += this._cache[key].length
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._length > this._max) trim(this)
|
|
||||||
}
|
|
||||||
, get : function () { return this._lengthCalculator }
|
|
||||||
, enumerable : true
|
|
||||||
})
|
|
||||||
|
|
||||||
Object.defineProperty(LRUCache.prototype, "length",
|
|
||||||
{ get : function () { return this._length }
|
|
||||||
, enumerable : true
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
Object.defineProperty(LRUCache.prototype, "itemCount",
|
|
||||||
{ get : function () { return this._itemCount }
|
|
||||||
, enumerable : true
|
|
||||||
})
|
|
||||||
|
|
||||||
LRUCache.prototype.forEach = function (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
var i = 0;
|
|
||||||
for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
|
|
||||||
i++
|
|
||||||
var hit = this._lruList[k]
|
|
||||||
if (this._maxAge && (Date.now() - hit.now > this._maxAge)) {
|
|
||||||
del(this, hit)
|
|
||||||
if (!this._allowStale) hit = undefined
|
|
||||||
}
|
|
||||||
if (hit) {
|
|
||||||
fn.call(thisp, hit.value, hit.key, this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LRUCache.prototype.keys = function () {
|
|
||||||
var keys = new Array(this._itemCount)
|
|
||||||
var i = 0
|
|
||||||
for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
|
|
||||||
var hit = this._lruList[k]
|
|
||||||
keys[i++] = hit.key
|
|
||||||
}
|
|
||||||
return keys
|
|
||||||
}
|
|
||||||
|
|
||||||
LRUCache.prototype.values = function () {
|
|
||||||
var values = new Array(this._itemCount)
|
|
||||||
var i = 0
|
|
||||||
for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
|
|
||||||
var hit = this._lruList[k]
|
|
||||||
values[i++] = hit.value
|
|
||||||
}
|
|
||||||
return values
|
|
||||||
}
|
|
||||||
|
|
||||||
LRUCache.prototype.reset = function () {
|
|
||||||
if (this._dispose && this._cache) {
|
|
||||||
for (var k in this._cache) {
|
|
||||||
this._dispose(k, this._cache[k].value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._cache = Object.create(null) // hash of items by key
|
|
||||||
this._lruList = Object.create(null) // list of items in order of use recency
|
|
||||||
this._mru = 0 // most recently used
|
|
||||||
this._lru = 0 // least recently used
|
|
||||||
this._length = 0 // number of items in the list
|
|
||||||
this._itemCount = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Provided for debugging/dev purposes only. No promises whatsoever that
|
|
||||||
// this API stays stable.
|
|
||||||
LRUCache.prototype.dump = function () {
|
|
||||||
return this._cache
|
|
||||||
}
|
|
||||||
|
|
||||||
LRUCache.prototype.dumpLru = function () {
|
|
||||||
return this._lruList
|
|
||||||
}
|
|
||||||
|
|
||||||
LRUCache.prototype.set = function (key, value) {
|
|
||||||
if (hOP(this._cache, key)) {
|
|
||||||
// dispose of the old one before overwriting
|
|
||||||
if (this._dispose) this._dispose(key, this._cache[key].value)
|
|
||||||
if (this._maxAge) this._cache[key].now = Date.now()
|
|
||||||
this._cache[key].value = value
|
|
||||||
this.get(key)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
var len = this._lengthCalculator(value)
|
|
||||||
var age = this._maxAge ? Date.now() : 0
|
|
||||||
var hit = new Entry(key, value, this._mru++, len, age)
|
|
||||||
|
|
||||||
// oversized objects fall out of cache automatically.
|
|
||||||
if (hit.length > this._max) {
|
|
||||||
if (this._dispose) this._dispose(key, value)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
this._length += hit.length
|
|
||||||
this._lruList[hit.lu] = this._cache[key] = hit
|
|
||||||
this._itemCount ++
|
|
||||||
|
|
||||||
if (this._length > this._max) trim(this)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
LRUCache.prototype.has = function (key) {
|
|
||||||
if (!hOP(this._cache, key)) return false
|
|
||||||
var hit = this._cache[key]
|
|
||||||
if (this._maxAge && (Date.now() - hit.now > this._maxAge)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
LRUCache.prototype.get = function (key) {
|
|
||||||
return get(this, key, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
LRUCache.prototype.peek = function (key) {
|
|
||||||
return get(this, key, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
LRUCache.prototype.pop = function () {
|
|
||||||
var hit = this._lruList[this._lru]
|
|
||||||
del(this, hit)
|
|
||||||
return hit || null
|
|
||||||
}
|
|
||||||
|
|
||||||
LRUCache.prototype.del = function (key) {
|
|
||||||
del(this, this._cache[key])
|
|
||||||
}
|
|
||||||
|
|
||||||
function get (self, key, doUse) {
|
|
||||||
var hit = self._cache[key]
|
|
||||||
if (hit) {
|
|
||||||
if (self._maxAge && (Date.now() - hit.now > self._maxAge)) {
|
|
||||||
del(self, hit)
|
|
||||||
if (!self._allowStale) hit = undefined
|
|
||||||
} else {
|
|
||||||
if (doUse) use(self, hit)
|
|
||||||
}
|
|
||||||
if (hit) hit = hit.value
|
|
||||||
}
|
|
||||||
return hit
|
|
||||||
}
|
|
||||||
|
|
||||||
function use (self, hit) {
|
|
||||||
shiftLU(self, hit)
|
|
||||||
hit.lu = self._mru ++
|
|
||||||
self._lruList[hit.lu] = hit
|
|
||||||
}
|
|
||||||
|
|
||||||
function trim (self) {
|
|
||||||
while (self._lru < self._mru && self._length > self._max)
|
|
||||||
del(self, self._lruList[self._lru])
|
|
||||||
}
|
|
||||||
|
|
||||||
function shiftLU (self, hit) {
|
|
||||||
delete self._lruList[ hit.lu ]
|
|
||||||
while (self._lru < self._mru && !self._lruList[self._lru]) self._lru ++
|
|
||||||
}
|
|
||||||
|
|
||||||
function del (self, hit) {
|
|
||||||
if (hit) {
|
|
||||||
if (self._dispose) self._dispose(hit.key, hit.value)
|
|
||||||
self._length -= hit.length
|
|
||||||
self._itemCount --
|
|
||||||
delete self._cache[ hit.key ]
|
|
||||||
shiftLU(self, hit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// classy, since V8 prefers predictable objects.
|
|
||||||
function Entry (key, value, lu, length, now) {
|
|
||||||
this.key = key
|
|
||||||
this.value = value
|
|
||||||
this.lu = lu
|
|
||||||
this.length = length
|
|
||||||
this.now = now
|
|
||||||
}
|
|
||||||
|
|
||||||
})()
|
|
@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "lru-cache",
|
|
||||||
"description": "A cache object that deletes the least-recently-used items.",
|
|
||||||
"version": "2.5.0",
|
|
||||||
"author": {
|
|
||||||
"name": "Isaac Z. Schlueter",
|
|
||||||
"email": "i@izs.me"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "tap test --gc"
|
|
||||||
},
|
|
||||||
"main": "lib/lru-cache.js",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/isaacs/node-lru-cache.git"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"tap": "",
|
|
||||||
"weak": ""
|
|
||||||
},
|
|
||||||
"license": {
|
|
||||||
"type": "MIT",
|
|
||||||
"url": "http://github.com/isaacs/node-lru-cache/raw/master/LICENSE"
|
|
||||||
},
|
|
||||||
"readme": "# lru cache\n\nA cache object that deletes the least-recently-used items.\n\n## Usage:\n\n```javascript\nvar LRU = require(\"lru-cache\")\n , options = { max: 500\n , length: function (n) { return n * 2 }\n , dispose: function (key, n) { n.close() }\n , maxAge: 1000 * 60 * 60 }\n , cache = LRU(options)\n , otherCache = LRU(50) // sets just the max size\n\ncache.set(\"key\", \"value\")\ncache.get(\"key\") // \"value\"\n\ncache.reset() // empty the cache\n```\n\nIf you put more stuff in it, then items will fall out.\n\nIf you try to put an oversized thing in it, then it'll fall out right\naway.\n\n## Options\n\n* `max` The maximum size of the cache, checked by applying the length\n function to all values in the cache. Not setting this is kind of\n silly, since that's the whole purpose of this lib, but it defaults\n to `Infinity`.\n* `maxAge` Maximum age in ms. Items are not pro-actively pruned out\n as they age, but if you try to get an item that is too old, it'll\n drop it and return undefined instead of giving it to you.\n* `length` Function that is used to calculate the length of stored\n items. If you're storing strings or buffers, then you probably want\n to do something like `function(n){return n.length}`. The default is\n `function(n){return 1}`, which is fine if you want to store `n`\n like-sized things.\n* `dispose` Function that is called on items when they are dropped\n from the cache. This can be handy if you want to close file\n descriptors or do other cleanup tasks when items are no longer\n accessible. Called with `key, value`. It's called *before*\n actually removing the item from the internal cache, so if you want\n to immediately put it back in, you'll have to do that in a\n `nextTick` or `setTimeout` callback or it won't do anything.\n* `stale` By default, if you set a `maxAge`, it'll only actually pull\n stale items out of the cache when you `get(key)`. (That is, it's\n not pre-emptively doing a `setTimeout` or anything.) If you set\n `stale:true`, it'll return the stale value before deleting it. If\n you don't set this, then it'll return `undefined` when you try to\n get a stale entry, as if it had already been deleted.\n\n## API\n\n* `set(key, value)`\n* `get(key) => value`\n\n Both of these will update the \"recently used\"-ness of the key.\n They do what you think.\n\n* `peek(key)`\n\n Returns the key value (or `undefined` if not found) without\n updating the \"recently used\"-ness of the key.\n\n (If you find yourself using this a lot, you *might* be using the\n wrong sort of data structure, but there are some use cases where\n it's handy.)\n\n* `del(key)`\n\n Deletes a key out of the cache.\n\n* `reset()`\n\n Clear the cache entirely, throwing away all values.\n\n* `has(key)`\n\n Check if a key is in the cache, without updating the recent-ness\n or deleting it for being stale.\n\n* `forEach(function(value,key,cache), [thisp])`\n\n Just like `Array.prototype.forEach`. Iterates over all the keys\n in the cache, in order of recent-ness. (Ie, more recently used\n items are iterated over first.)\n\n* `keys()`\n\n Return an array of the keys in the cache.\n\n* `values()`\n\n Return an array of the values in the cache.\n",
|
|
||||||
"readmeFilename": "README.md",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/isaacs/node-lru-cache/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/isaacs/node-lru-cache",
|
|
||||||
"_id": "lru-cache@2.5.0",
|
|
||||||
"_from": "lru-cache@2"
|
|
||||||
}
|
|
@ -1,369 +0,0 @@
|
|||||||
var test = require("tap").test
|
|
||||||
, LRU = require("../")
|
|
||||||
|
|
||||||
test("basic", function (t) {
|
|
||||||
var cache = new LRU({max: 10})
|
|
||||||
cache.set("key", "value")
|
|
||||||
t.equal(cache.get("key"), "value")
|
|
||||||
t.equal(cache.get("nada"), undefined)
|
|
||||||
t.equal(cache.length, 1)
|
|
||||||
t.equal(cache.max, 10)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("least recently set", function (t) {
|
|
||||||
var cache = new LRU(2)
|
|
||||||
cache.set("a", "A")
|
|
||||||
cache.set("b", "B")
|
|
||||||
cache.set("c", "C")
|
|
||||||
t.equal(cache.get("c"), "C")
|
|
||||||
t.equal(cache.get("b"), "B")
|
|
||||||
t.equal(cache.get("a"), undefined)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("lru recently gotten", function (t) {
|
|
||||||
var cache = new LRU(2)
|
|
||||||
cache.set("a", "A")
|
|
||||||
cache.set("b", "B")
|
|
||||||
cache.get("a")
|
|
||||||
cache.set("c", "C")
|
|
||||||
t.equal(cache.get("c"), "C")
|
|
||||||
t.equal(cache.get("b"), undefined)
|
|
||||||
t.equal(cache.get("a"), "A")
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("del", function (t) {
|
|
||||||
var cache = new LRU(2)
|
|
||||||
cache.set("a", "A")
|
|
||||||
cache.del("a")
|
|
||||||
t.equal(cache.get("a"), undefined)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("max", function (t) {
|
|
||||||
var cache = new LRU(3)
|
|
||||||
|
|
||||||
// test changing the max, verify that the LRU items get dropped.
|
|
||||||
cache.max = 100
|
|
||||||
for (var i = 0; i < 100; i ++) cache.set(i, i)
|
|
||||||
t.equal(cache.length, 100)
|
|
||||||
for (var i = 0; i < 100; i ++) {
|
|
||||||
t.equal(cache.get(i), i)
|
|
||||||
}
|
|
||||||
cache.max = 3
|
|
||||||
t.equal(cache.length, 3)
|
|
||||||
for (var i = 0; i < 97; i ++) {
|
|
||||||
t.equal(cache.get(i), undefined)
|
|
||||||
}
|
|
||||||
for (var i = 98; i < 100; i ++) {
|
|
||||||
t.equal(cache.get(i), i)
|
|
||||||
}
|
|
||||||
|
|
||||||
// now remove the max restriction, and try again.
|
|
||||||
cache.max = "hello"
|
|
||||||
for (var i = 0; i < 100; i ++) cache.set(i, i)
|
|
||||||
t.equal(cache.length, 100)
|
|
||||||
for (var i = 0; i < 100; i ++) {
|
|
||||||
t.equal(cache.get(i), i)
|
|
||||||
}
|
|
||||||
// should trigger an immediate resize
|
|
||||||
cache.max = 3
|
|
||||||
t.equal(cache.length, 3)
|
|
||||||
for (var i = 0; i < 97; i ++) {
|
|
||||||
t.equal(cache.get(i), undefined)
|
|
||||||
}
|
|
||||||
for (var i = 98; i < 100; i ++) {
|
|
||||||
t.equal(cache.get(i), i)
|
|
||||||
}
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("reset", function (t) {
|
|
||||||
var cache = new LRU(10)
|
|
||||||
cache.set("a", "A")
|
|
||||||
cache.set("b", "B")
|
|
||||||
cache.reset()
|
|
||||||
t.equal(cache.length, 0)
|
|
||||||
t.equal(cache.max, 10)
|
|
||||||
t.equal(cache.get("a"), undefined)
|
|
||||||
t.equal(cache.get("b"), undefined)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
// Note: `<cache>.dump()` is a debugging tool only. No guarantees are made
|
|
||||||
// about the format/layout of the response.
|
|
||||||
test("dump", function (t) {
|
|
||||||
var cache = new LRU(10)
|
|
||||||
var d = cache.dump();
|
|
||||||
t.equal(Object.keys(d).length, 0, "nothing in dump for empty cache")
|
|
||||||
cache.set("a", "A")
|
|
||||||
var d = cache.dump() // { a: { key: "a", value: "A", lu: 0 } }
|
|
||||||
t.ok(d.a)
|
|
||||||
t.equal(d.a.key, "a")
|
|
||||||
t.equal(d.a.value, "A")
|
|
||||||
t.equal(d.a.lu, 0)
|
|
||||||
|
|
||||||
cache.set("b", "B")
|
|
||||||
cache.get("b")
|
|
||||||
d = cache.dump()
|
|
||||||
t.ok(d.b)
|
|
||||||
t.equal(d.b.key, "b")
|
|
||||||
t.equal(d.b.value, "B")
|
|
||||||
t.equal(d.b.lu, 2)
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
test("basic with weighed length", function (t) {
|
|
||||||
var cache = new LRU({
|
|
||||||
max: 100,
|
|
||||||
length: function (item) { return item.size }
|
|
||||||
})
|
|
||||||
cache.set("key", {val: "value", size: 50})
|
|
||||||
t.equal(cache.get("key").val, "value")
|
|
||||||
t.equal(cache.get("nada"), undefined)
|
|
||||||
t.equal(cache.lengthCalculator(cache.get("key")), 50)
|
|
||||||
t.equal(cache.length, 50)
|
|
||||||
t.equal(cache.max, 100)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
test("weighed length item too large", function (t) {
|
|
||||||
var cache = new LRU({
|
|
||||||
max: 10,
|
|
||||||
length: function (item) { return item.size }
|
|
||||||
})
|
|
||||||
t.equal(cache.max, 10)
|
|
||||||
|
|
||||||
// should fall out immediately
|
|
||||||
cache.set("key", {val: "value", size: 50})
|
|
||||||
|
|
||||||
t.equal(cache.length, 0)
|
|
||||||
t.equal(cache.get("key"), undefined)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("least recently set with weighed length", function (t) {
|
|
||||||
var cache = new LRU({
|
|
||||||
max:8,
|
|
||||||
length: function (item) { return item.length }
|
|
||||||
})
|
|
||||||
cache.set("a", "A")
|
|
||||||
cache.set("b", "BB")
|
|
||||||
cache.set("c", "CCC")
|
|
||||||
cache.set("d", "DDDD")
|
|
||||||
t.equal(cache.get("d"), "DDDD")
|
|
||||||
t.equal(cache.get("c"), "CCC")
|
|
||||||
t.equal(cache.get("b"), undefined)
|
|
||||||
t.equal(cache.get("a"), undefined)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("lru recently gotten with weighed length", function (t) {
|
|
||||||
var cache = new LRU({
|
|
||||||
max: 8,
|
|
||||||
length: function (item) { return item.length }
|
|
||||||
})
|
|
||||||
cache.set("a", "A")
|
|
||||||
cache.set("b", "BB")
|
|
||||||
cache.set("c", "CCC")
|
|
||||||
cache.get("a")
|
|
||||||
cache.get("b")
|
|
||||||
cache.set("d", "DDDD")
|
|
||||||
t.equal(cache.get("c"), undefined)
|
|
||||||
t.equal(cache.get("d"), "DDDD")
|
|
||||||
t.equal(cache.get("b"), "BB")
|
|
||||||
t.equal(cache.get("a"), "A")
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("set returns proper booleans", function(t) {
|
|
||||||
var cache = new LRU({
|
|
||||||
max: 5,
|
|
||||||
length: function (item) { return item.length }
|
|
||||||
})
|
|
||||||
|
|
||||||
t.equal(cache.set("a", "A"), true)
|
|
||||||
|
|
||||||
// should return false for max exceeded
|
|
||||||
t.equal(cache.set("b", "donuts"), false)
|
|
||||||
|
|
||||||
t.equal(cache.set("b", "B"), true)
|
|
||||||
t.equal(cache.set("c", "CCCC"), true)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("drop the old items", function(t) {
|
|
||||||
var cache = new LRU({
|
|
||||||
max: 5,
|
|
||||||
maxAge: 50
|
|
||||||
})
|
|
||||||
|
|
||||||
cache.set("a", "A")
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
cache.set("b", "b")
|
|
||||||
t.equal(cache.get("a"), "A")
|
|
||||||
}, 25)
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
cache.set("c", "C")
|
|
||||||
// timed out
|
|
||||||
t.notOk(cache.get("a"))
|
|
||||||
}, 60)
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
t.notOk(cache.get("b"))
|
|
||||||
t.equal(cache.get("c"), "C")
|
|
||||||
}, 90)
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
t.notOk(cache.get("c"))
|
|
||||||
t.end()
|
|
||||||
}, 155)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("disposal function", function(t) {
|
|
||||||
var disposed = false
|
|
||||||
var cache = new LRU({
|
|
||||||
max: 1,
|
|
||||||
dispose: function (k, n) {
|
|
||||||
disposed = n
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
cache.set(1, 1)
|
|
||||||
cache.set(2, 2)
|
|
||||||
t.equal(disposed, 1)
|
|
||||||
cache.set(3, 3)
|
|
||||||
t.equal(disposed, 2)
|
|
||||||
cache.reset()
|
|
||||||
t.equal(disposed, 3)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("disposal function on too big of item", function(t) {
|
|
||||||
var disposed = false
|
|
||||||
var cache = new LRU({
|
|
||||||
max: 1,
|
|
||||||
length: function (k) {
|
|
||||||
return k.length
|
|
||||||
},
|
|
||||||
dispose: function (k, n) {
|
|
||||||
disposed = n
|
|
||||||
}
|
|
||||||
})
|
|
||||||
var obj = [ 1, 2 ]
|
|
||||||
|
|
||||||
t.equal(disposed, false)
|
|
||||||
cache.set("obj", obj)
|
|
||||||
t.equal(disposed, obj)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("has()", function(t) {
|
|
||||||
var cache = new LRU({
|
|
||||||
max: 1,
|
|
||||||
maxAge: 10
|
|
||||||
})
|
|
||||||
|
|
||||||
cache.set('foo', 'bar')
|
|
||||||
t.equal(cache.has('foo'), true)
|
|
||||||
cache.set('blu', 'baz')
|
|
||||||
t.equal(cache.has('foo'), false)
|
|
||||||
t.equal(cache.has('blu'), true)
|
|
||||||
setTimeout(function() {
|
|
||||||
t.equal(cache.has('blu'), false)
|
|
||||||
t.end()
|
|
||||||
}, 15)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("stale", function(t) {
|
|
||||||
var cache = new LRU({
|
|
||||||
maxAge: 10,
|
|
||||||
stale: true
|
|
||||||
})
|
|
||||||
|
|
||||||
cache.set('foo', 'bar')
|
|
||||||
t.equal(cache.get('foo'), 'bar')
|
|
||||||
t.equal(cache.has('foo'), true)
|
|
||||||
setTimeout(function() {
|
|
||||||
t.equal(cache.has('foo'), false)
|
|
||||||
t.equal(cache.get('foo'), 'bar')
|
|
||||||
t.equal(cache.get('foo'), undefined)
|
|
||||||
t.end()
|
|
||||||
}, 15)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("lru update via set", function(t) {
|
|
||||||
var cache = LRU({ max: 2 });
|
|
||||||
|
|
||||||
cache.set('foo', 1);
|
|
||||||
cache.set('bar', 2);
|
|
||||||
cache.del('bar');
|
|
||||||
cache.set('baz', 3);
|
|
||||||
cache.set('qux', 4);
|
|
||||||
|
|
||||||
t.equal(cache.get('foo'), undefined)
|
|
||||||
t.equal(cache.get('bar'), undefined)
|
|
||||||
t.equal(cache.get('baz'), 3)
|
|
||||||
t.equal(cache.get('qux'), 4)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("least recently set w/ peek", function (t) {
|
|
||||||
var cache = new LRU(2)
|
|
||||||
cache.set("a", "A")
|
|
||||||
cache.set("b", "B")
|
|
||||||
t.equal(cache.peek("a"), "A")
|
|
||||||
cache.set("c", "C")
|
|
||||||
t.equal(cache.get("c"), "C")
|
|
||||||
t.equal(cache.get("b"), "B")
|
|
||||||
t.equal(cache.get("a"), undefined)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("pop the least used item", function (t) {
|
|
||||||
var cache = new LRU(3)
|
|
||||||
, last
|
|
||||||
|
|
||||||
cache.set("a", "A")
|
|
||||||
cache.set("b", "B")
|
|
||||||
cache.set("c", "C")
|
|
||||||
|
|
||||||
t.equal(cache.length, 3)
|
|
||||||
t.equal(cache.max, 3)
|
|
||||||
|
|
||||||
// Ensure we pop a, c, b
|
|
||||||
cache.get("b", "B")
|
|
||||||
|
|
||||||
last = cache.pop()
|
|
||||||
t.equal(last.key, "a")
|
|
||||||
t.equal(last.value, "A")
|
|
||||||
t.equal(cache.length, 2)
|
|
||||||
t.equal(cache.max, 3)
|
|
||||||
|
|
||||||
last = cache.pop()
|
|
||||||
t.equal(last.key, "c")
|
|
||||||
t.equal(last.value, "C")
|
|
||||||
t.equal(cache.length, 1)
|
|
||||||
t.equal(cache.max, 3)
|
|
||||||
|
|
||||||
last = cache.pop()
|
|
||||||
t.equal(last.key, "b")
|
|
||||||
t.equal(last.value, "B")
|
|
||||||
t.equal(cache.length, 0)
|
|
||||||
t.equal(cache.max, 3)
|
|
||||||
|
|
||||||
last = cache.pop()
|
|
||||||
t.equal(last, null)
|
|
||||||
t.equal(cache.length, 0)
|
|
||||||
t.equal(cache.max, 3)
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,52 +0,0 @@
|
|||||||
var test = require('tap').test
|
|
||||||
var LRU = require('../')
|
|
||||||
|
|
||||||
test('forEach', function (t) {
|
|
||||||
var l = new LRU(5)
|
|
||||||
for (var i = 0; i < 10; i ++) {
|
|
||||||
l.set(i.toString(), i.toString(2))
|
|
||||||
}
|
|
||||||
|
|
||||||
var i = 9
|
|
||||||
l.forEach(function (val, key, cache) {
|
|
||||||
t.equal(cache, l)
|
|
||||||
t.equal(key, i.toString())
|
|
||||||
t.equal(val, i.toString(2))
|
|
||||||
i -= 1
|
|
||||||
})
|
|
||||||
|
|
||||||
// get in order of most recently used
|
|
||||||
l.get(6)
|
|
||||||
l.get(8)
|
|
||||||
|
|
||||||
var order = [ 8, 6, 9, 7, 5 ]
|
|
||||||
var i = 0
|
|
||||||
|
|
||||||
l.forEach(function (val, key, cache) {
|
|
||||||
var j = order[i ++]
|
|
||||||
t.equal(cache, l)
|
|
||||||
t.equal(key, j.toString())
|
|
||||||
t.equal(val, j.toString(2))
|
|
||||||
})
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('keys() and values()', function (t) {
|
|
||||||
var l = new LRU(5)
|
|
||||||
for (var i = 0; i < 10; i ++) {
|
|
||||||
l.set(i.toString(), i.toString(2))
|
|
||||||
}
|
|
||||||
|
|
||||||
t.similar(l.keys(), ['9', '8', '7', '6', '5'])
|
|
||||||
t.similar(l.values(), ['1001', '1000', '111', '110', '101'])
|
|
||||||
|
|
||||||
// get in order of most recently used
|
|
||||||
l.get(6)
|
|
||||||
l.get(8)
|
|
||||||
|
|
||||||
t.similar(l.keys(), ['8', '6', '9', '7', '5'])
|
|
||||||
t.similar(l.values(), ['1000', '110', '1001', '111', '101'])
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,50 +0,0 @@
|
|||||||
#!/usr/bin/env node --expose_gc
|
|
||||||
|
|
||||||
var weak = require('weak');
|
|
||||||
var test = require('tap').test
|
|
||||||
var LRU = require('../')
|
|
||||||
var l = new LRU({ max: 10 })
|
|
||||||
var refs = 0
|
|
||||||
function X() {
|
|
||||||
refs ++
|
|
||||||
weak(this, deref)
|
|
||||||
}
|
|
||||||
|
|
||||||
function deref() {
|
|
||||||
refs --
|
|
||||||
}
|
|
||||||
|
|
||||||
test('no leaks', function (t) {
|
|
||||||
// fill up the cache
|
|
||||||
for (var i = 0; i < 100; i++) {
|
|
||||||
l.set(i, new X);
|
|
||||||
// throw some gets in there, too.
|
|
||||||
if (i % 2 === 0)
|
|
||||||
l.get(i / 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
gc()
|
|
||||||
|
|
||||||
var start = process.memoryUsage()
|
|
||||||
|
|
||||||
// capture the memory
|
|
||||||
var startRefs = refs
|
|
||||||
|
|
||||||
// do it again, but more
|
|
||||||
for (var i = 0; i < 10000; i++) {
|
|
||||||
l.set(i, new X);
|
|
||||||
// throw some gets in there, too.
|
|
||||||
if (i % 2 === 0)
|
|
||||||
l.get(i / 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
gc()
|
|
||||||
|
|
||||||
var end = process.memoryUsage()
|
|
||||||
t.equal(refs, startRefs, 'no leaky refs')
|
|
||||||
|
|
||||||
console.error('start: %j\n' +
|
|
||||||
'end: %j', start, end);
|
|
||||||
t.pass();
|
|
||||||
t.end();
|
|
||||||
})
|
|
@ -1,27 +0,0 @@
|
|||||||
Copyright (c) Isaac Z. Schlueter ("Author")
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
The BSD License
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
|
|
||||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
||||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
||||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
|
||||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,53 +0,0 @@
|
|||||||
# sigmund
|
|
||||||
|
|
||||||
Quick and dirty signatures for Objects.
|
|
||||||
|
|
||||||
This is like a much faster `deepEquals` comparison, which returns a
|
|
||||||
string key suitable for caches and the like.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function doSomething (someObj) {
|
|
||||||
var key = sigmund(someObj, maxDepth) // max depth defaults to 10
|
|
||||||
var cached = cache.get(key)
|
|
||||||
if (cached) return cached)
|
|
||||||
|
|
||||||
var result = expensiveCalculation(someObj)
|
|
||||||
cache.set(key, result)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The resulting key will be as unique and reproducible as calling
|
|
||||||
`JSON.stringify` or `util.inspect` on the object, but is much faster.
|
|
||||||
In order to achieve this speed, some differences are glossed over.
|
|
||||||
For example, the object `{0:'foo'}` will be treated identically to the
|
|
||||||
array `['foo']`.
|
|
||||||
|
|
||||||
Also, just as there is no way to summon the soul from the scribblings
|
|
||||||
of a cocain-addled psychoanalyst, there is no way to revive the object
|
|
||||||
from the signature string that sigmund gives you. In fact, it's
|
|
||||||
barely even readable.
|
|
||||||
|
|
||||||
As with `sys.inspect` and `JSON.stringify`, larger objects will
|
|
||||||
produce larger signature strings.
|
|
||||||
|
|
||||||
Because sigmund is a bit less strict than the more thorough
|
|
||||||
alternatives, the strings will be shorter, and also there is a
|
|
||||||
slightly higher chance for collisions. For example, these objects
|
|
||||||
have the same signature:
|
|
||||||
|
|
||||||
var obj1 = {a:'b',c:/def/,g:['h','i',{j:'',k:'l'}]}
|
|
||||||
var obj2 = {a:'b',c:'/def/',g:['h','i','{jkl']}
|
|
||||||
|
|
||||||
Like a good Freudian, sigmund is most effective when you already have
|
|
||||||
some understanding of what you're looking for. It can help you help
|
|
||||||
yourself, but you must be willing to do some work as well.
|
|
||||||
|
|
||||||
Cycles are handled, and cyclical objects are silently omitted (though
|
|
||||||
the key is included in the signature output.)
|
|
||||||
|
|
||||||
The second argument is the maximum depth, which defaults to 10,
|
|
||||||
because that is the maximum object traversal depth covered by most
|
|
||||||
insurance carriers.
|
|
@ -1,283 +0,0 @@
|
|||||||
// different ways to id objects
|
|
||||||
// use a req/res pair, since it's crazy deep and cyclical
|
|
||||||
|
|
||||||
// sparseFE10 and sigmund are usually pretty close, which is to be expected,
|
|
||||||
// since they are essentially the same algorithm, except that sigmund handles
|
|
||||||
// regular expression objects properly.
|
|
||||||
|
|
||||||
|
|
||||||
var http = require('http')
|
|
||||||
var util = require('util')
|
|
||||||
var sigmund = require('./sigmund.js')
|
|
||||||
var sreq, sres, creq, cres, test
|
|
||||||
|
|
||||||
http.createServer(function (q, s) {
|
|
||||||
sreq = q
|
|
||||||
sres = s
|
|
||||||
sres.end('ok')
|
|
||||||
this.close(function () { setTimeout(function () {
|
|
||||||
start()
|
|
||||||
}, 200) })
|
|
||||||
}).listen(1337, function () {
|
|
||||||
creq = http.get({ port: 1337 })
|
|
||||||
creq.on('response', function (s) { cres = s })
|
|
||||||
})
|
|
||||||
|
|
||||||
function start () {
|
|
||||||
test = [sreq, sres, creq, cres]
|
|
||||||
// test = sreq
|
|
||||||
// sreq.sres = sres
|
|
||||||
// sreq.creq = creq
|
|
||||||
// sreq.cres = cres
|
|
||||||
|
|
||||||
for (var i in exports.compare) {
|
|
||||||
console.log(i)
|
|
||||||
var hash = exports.compare[i]()
|
|
||||||
console.log(hash)
|
|
||||||
console.log(hash.length)
|
|
||||||
console.log('')
|
|
||||||
}
|
|
||||||
|
|
||||||
require('bench').runMain()
|
|
||||||
}
|
|
||||||
|
|
||||||
function customWs (obj, md, d) {
|
|
||||||
d = d || 0
|
|
||||||
var to = typeof obj
|
|
||||||
if (to === 'undefined' || to === 'function' || to === null) return ''
|
|
||||||
if (d > md || !obj || to !== 'object') return ('' + obj).replace(/[\n ]+/g, '')
|
|
||||||
|
|
||||||
if (Array.isArray(obj)) {
|
|
||||||
return obj.map(function (i, _, __) {
|
|
||||||
return customWs(i, md, d + 1)
|
|
||||||
}).reduce(function (a, b) { return a + b }, '')
|
|
||||||
}
|
|
||||||
|
|
||||||
var keys = Object.keys(obj)
|
|
||||||
return keys.map(function (k, _, __) {
|
|
||||||
return k + ':' + customWs(obj[k], md, d + 1)
|
|
||||||
}).reduce(function (a, b) { return a + b }, '')
|
|
||||||
}
|
|
||||||
|
|
||||||
function custom (obj, md, d) {
|
|
||||||
d = d || 0
|
|
||||||
var to = typeof obj
|
|
||||||
if (to === 'undefined' || to === 'function' || to === null) return ''
|
|
||||||
if (d > md || !obj || to !== 'object') return '' + obj
|
|
||||||
|
|
||||||
if (Array.isArray(obj)) {
|
|
||||||
return obj.map(function (i, _, __) {
|
|
||||||
return custom(i, md, d + 1)
|
|
||||||
}).reduce(function (a, b) { return a + b }, '')
|
|
||||||
}
|
|
||||||
|
|
||||||
var keys = Object.keys(obj)
|
|
||||||
return keys.map(function (k, _, __) {
|
|
||||||
return k + ':' + custom(obj[k], md, d + 1)
|
|
||||||
}).reduce(function (a, b) { return a + b }, '')
|
|
||||||
}
|
|
||||||
|
|
||||||
function sparseFE2 (obj, maxDepth) {
|
|
||||||
var seen = []
|
|
||||||
var soFar = ''
|
|
||||||
function ch (v, depth) {
|
|
||||||
if (depth > maxDepth) return
|
|
||||||
if (typeof v === 'function' || typeof v === 'undefined') return
|
|
||||||
if (typeof v !== 'object' || !v) {
|
|
||||||
soFar += v
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
|
||||||
seen.push(v)
|
|
||||||
soFar += '{'
|
|
||||||
Object.keys(v).forEach(function (k, _, __) {
|
|
||||||
// pseudo-private values. skip those.
|
|
||||||
if (k.charAt(0) === '_') return
|
|
||||||
var to = typeof v[k]
|
|
||||||
if (to === 'function' || to === 'undefined') return
|
|
||||||
soFar += k + ':'
|
|
||||||
ch(v[k], depth + 1)
|
|
||||||
})
|
|
||||||
soFar += '}'
|
|
||||||
}
|
|
||||||
ch(obj, 0)
|
|
||||||
return soFar
|
|
||||||
}
|
|
||||||
|
|
||||||
function sparseFE (obj, maxDepth) {
|
|
||||||
var seen = []
|
|
||||||
var soFar = ''
|
|
||||||
function ch (v, depth) {
|
|
||||||
if (depth > maxDepth) return
|
|
||||||
if (typeof v === 'function' || typeof v === 'undefined') return
|
|
||||||
if (typeof v !== 'object' || !v) {
|
|
||||||
soFar += v
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
|
||||||
seen.push(v)
|
|
||||||
soFar += '{'
|
|
||||||
Object.keys(v).forEach(function (k, _, __) {
|
|
||||||
// pseudo-private values. skip those.
|
|
||||||
if (k.charAt(0) === '_') return
|
|
||||||
var to = typeof v[k]
|
|
||||||
if (to === 'function' || to === 'undefined') return
|
|
||||||
soFar += k
|
|
||||||
ch(v[k], depth + 1)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
ch(obj, 0)
|
|
||||||
return soFar
|
|
||||||
}
|
|
||||||
|
|
||||||
function sparse (obj, maxDepth) {
|
|
||||||
var seen = []
|
|
||||||
var soFar = ''
|
|
||||||
function ch (v, depth) {
|
|
||||||
if (depth > maxDepth) return
|
|
||||||
if (typeof v === 'function' || typeof v === 'undefined') return
|
|
||||||
if (typeof v !== 'object' || !v) {
|
|
||||||
soFar += v
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
|
||||||
seen.push(v)
|
|
||||||
soFar += '{'
|
|
||||||
for (var k in v) {
|
|
||||||
// pseudo-private values. skip those.
|
|
||||||
if (k.charAt(0) === '_') continue
|
|
||||||
var to = typeof v[k]
|
|
||||||
if (to === 'function' || to === 'undefined') continue
|
|
||||||
soFar += k
|
|
||||||
ch(v[k], depth + 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ch(obj, 0)
|
|
||||||
return soFar
|
|
||||||
}
|
|
||||||
|
|
||||||
function noCommas (obj, maxDepth) {
|
|
||||||
var seen = []
|
|
||||||
var soFar = ''
|
|
||||||
function ch (v, depth) {
|
|
||||||
if (depth > maxDepth) return
|
|
||||||
if (typeof v === 'function' || typeof v === 'undefined') return
|
|
||||||
if (typeof v !== 'object' || !v) {
|
|
||||||
soFar += v
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
|
||||||
seen.push(v)
|
|
||||||
soFar += '{'
|
|
||||||
for (var k in v) {
|
|
||||||
// pseudo-private values. skip those.
|
|
||||||
if (k.charAt(0) === '_') continue
|
|
||||||
var to = typeof v[k]
|
|
||||||
if (to === 'function' || to === 'undefined') continue
|
|
||||||
soFar += k + ':'
|
|
||||||
ch(v[k], depth + 1)
|
|
||||||
}
|
|
||||||
soFar += '}'
|
|
||||||
}
|
|
||||||
ch(obj, 0)
|
|
||||||
return soFar
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function flatten (obj, maxDepth) {
|
|
||||||
var seen = []
|
|
||||||
var soFar = ''
|
|
||||||
function ch (v, depth) {
|
|
||||||
if (depth > maxDepth) return
|
|
||||||
if (typeof v === 'function' || typeof v === 'undefined') return
|
|
||||||
if (typeof v !== 'object' || !v) {
|
|
||||||
soFar += v
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (seen.indexOf(v) !== -1 || depth === maxDepth) return
|
|
||||||
seen.push(v)
|
|
||||||
soFar += '{'
|
|
||||||
for (var k in v) {
|
|
||||||
// pseudo-private values. skip those.
|
|
||||||
if (k.charAt(0) === '_') continue
|
|
||||||
var to = typeof v[k]
|
|
||||||
if (to === 'function' || to === 'undefined') continue
|
|
||||||
soFar += k + ':'
|
|
||||||
ch(v[k], depth + 1)
|
|
||||||
soFar += ','
|
|
||||||
}
|
|
||||||
soFar += '}'
|
|
||||||
}
|
|
||||||
ch(obj, 0)
|
|
||||||
return soFar
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.compare =
|
|
||||||
{
|
|
||||||
// 'custom 2': function () {
|
|
||||||
// return custom(test, 2, 0)
|
|
||||||
// },
|
|
||||||
// 'customWs 2': function () {
|
|
||||||
// return customWs(test, 2, 0)
|
|
||||||
// },
|
|
||||||
'JSON.stringify (guarded)': function () {
|
|
||||||
var seen = []
|
|
||||||
return JSON.stringify(test, function (k, v) {
|
|
||||||
if (typeof v !== 'object' || !v) return v
|
|
||||||
if (seen.indexOf(v) !== -1) return undefined
|
|
||||||
seen.push(v)
|
|
||||||
return v
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
'flatten 10': function () {
|
|
||||||
return flatten(test, 10)
|
|
||||||
},
|
|
||||||
|
|
||||||
// 'flattenFE 10': function () {
|
|
||||||
// return flattenFE(test, 10)
|
|
||||||
// },
|
|
||||||
|
|
||||||
'noCommas 10': function () {
|
|
||||||
return noCommas(test, 10)
|
|
||||||
},
|
|
||||||
|
|
||||||
'sparse 10': function () {
|
|
||||||
return sparse(test, 10)
|
|
||||||
},
|
|
||||||
|
|
||||||
'sparseFE 10': function () {
|
|
||||||
return sparseFE(test, 10)
|
|
||||||
},
|
|
||||||
|
|
||||||
'sparseFE2 10': function () {
|
|
||||||
return sparseFE2(test, 10)
|
|
||||||
},
|
|
||||||
|
|
||||||
sigmund: function() {
|
|
||||||
return sigmund(test, 10)
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
// 'util.inspect 1': function () {
|
|
||||||
// return util.inspect(test, false, 1, false)
|
|
||||||
// },
|
|
||||||
// 'util.inspect undefined': function () {
|
|
||||||
// util.inspect(test)
|
|
||||||
// },
|
|
||||||
// 'util.inspect 2': function () {
|
|
||||||
// util.inspect(test, false, 2, false)
|
|
||||||
// },
|
|
||||||
// 'util.inspect 3': function () {
|
|
||||||
// util.inspect(test, false, 3, false)
|
|
||||||
// },
|
|
||||||
// 'util.inspect 4': function () {
|
|
||||||
// util.inspect(test, false, 4, false)
|
|
||||||
// },
|
|
||||||
// 'util.inspect Infinity': function () {
|
|
||||||
// util.inspect(test, false, Infinity, false)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
/** results
|
|
||||||
**/
|
|
@ -1,42 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "sigmund",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "Quick and dirty signatures for Objects.",
|
|
||||||
"main": "sigmund.js",
|
|
||||||
"directories": {
|
|
||||||
"test": "test"
|
|
||||||
},
|
|
||||||
"dependencies": {},
|
|
||||||
"devDependencies": {
|
|
||||||
"tap": "~0.3.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "tap test/*.js",
|
|
||||||
"bench": "node bench.js"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/isaacs/sigmund"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"object",
|
|
||||||
"signature",
|
|
||||||
"key",
|
|
||||||
"data",
|
|
||||||
"psychoanalysis"
|
|
||||||
],
|
|
||||||
"author": {
|
|
||||||
"name": "Isaac Z. Schlueter",
|
|
||||||
"email": "i@izs.me",
|
|
||||||
"url": "http://blog.izs.me/"
|
|
||||||
},
|
|
||||||
"license": "BSD",
|
|
||||||
"readme": "# sigmund\n\nQuick and dirty signatures for Objects.\n\nThis is like a much faster `deepEquals` comparison, which returns a\nstring key suitable for caches and the like.\n\n## Usage\n\n```javascript\nfunction doSomething (someObj) {\n var key = sigmund(someObj, maxDepth) // max depth defaults to 10\n var cached = cache.get(key)\n if (cached) return cached)\n\n var result = expensiveCalculation(someObj)\n cache.set(key, result)\n return result\n}\n```\n\nThe resulting key will be as unique and reproducible as calling\n`JSON.stringify` or `util.inspect` on the object, but is much faster.\nIn order to achieve this speed, some differences are glossed over.\nFor example, the object `{0:'foo'}` will be treated identically to the\narray `['foo']`.\n\nAlso, just as there is no way to summon the soul from the scribblings\nof a cocain-addled psychoanalyst, there is no way to revive the object\nfrom the signature string that sigmund gives you. In fact, it's\nbarely even readable.\n\nAs with `sys.inspect` and `JSON.stringify`, larger objects will\nproduce larger signature strings.\n\nBecause sigmund is a bit less strict than the more thorough\nalternatives, the strings will be shorter, and also there is a\nslightly higher chance for collisions. For example, these objects\nhave the same signature:\n\n var obj1 = {a:'b',c:/def/,g:['h','i',{j:'',k:'l'}]}\n var obj2 = {a:'b',c:'/def/',g:['h','i','{jkl']}\n\nLike a good Freudian, sigmund is most effective when you already have\nsome understanding of what you're looking for. It can help you help\nyourself, but you must be willing to do some work as well.\n\nCycles are handled, and cyclical objects are silently omitted (though\nthe key is included in the signature output.)\n\nThe second argument is the maximum depth, which defaults to 10,\nbecause that is the maximum object traversal depth covered by most\ninsurance carriers.\n",
|
|
||||||
"readmeFilename": "README.md",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/isaacs/sigmund/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/isaacs/sigmund",
|
|
||||||
"_id": "sigmund@1.0.0",
|
|
||||||
"_from": "sigmund@~1.0.0"
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
module.exports = sigmund
|
|
||||||
function sigmund (subject, maxSessions) {
|
|
||||||
maxSessions = maxSessions || 10;
|
|
||||||
var notes = [];
|
|
||||||
var analysis = '';
|
|
||||||
var RE = RegExp;
|
|
||||||
|
|
||||||
function psychoAnalyze (subject, session) {
|
|
||||||
if (session > maxSessions) return;
|
|
||||||
|
|
||||||
if (typeof subject === 'function' ||
|
|
||||||
typeof subject === 'undefined') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof subject !== 'object' || !subject ||
|
|
||||||
(subject instanceof RE)) {
|
|
||||||
analysis += subject;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
|
|
||||||
|
|
||||||
notes.push(subject);
|
|
||||||
analysis += '{';
|
|
||||||
Object.keys(subject).forEach(function (issue, _, __) {
|
|
||||||
// pseudo-private values. skip those.
|
|
||||||
if (issue.charAt(0) === '_') return;
|
|
||||||
var to = typeof subject[issue];
|
|
||||||
if (to === 'function' || to === 'undefined') return;
|
|
||||||
analysis += issue;
|
|
||||||
psychoAnalyze(subject[issue], session + 1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
psychoAnalyze(subject, 0);
|
|
||||||
return analysis;
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: set softtabstop=4 shiftwidth=4:
|
|
@ -1,24 +0,0 @@
|
|||||||
var test = require('tap').test
|
|
||||||
var sigmund = require('../sigmund.js')
|
|
||||||
|
|
||||||
|
|
||||||
// occasionally there are duplicates
|
|
||||||
// that's an acceptable edge-case. JSON.stringify and util.inspect
|
|
||||||
// have some collision potential as well, though less, and collision
|
|
||||||
// detection is expensive.
|
|
||||||
var hash = '{abc/def/g{0h1i2{jkl'
|
|
||||||
var obj1 = {a:'b',c:/def/,g:['h','i',{j:'',k:'l'}]}
|
|
||||||
var obj2 = {a:'b',c:'/def/',g:['h','i','{jkl']}
|
|
||||||
|
|
||||||
var obj3 = JSON.parse(JSON.stringify(obj1))
|
|
||||||
obj3.c = /def/
|
|
||||||
obj3.g[2].cycle = obj3
|
|
||||||
var cycleHash = '{abc/def/g{0h1i2{jklcycle'
|
|
||||||
|
|
||||||
test('basic', function (t) {
|
|
||||||
t.equal(sigmund(obj1), hash)
|
|
||||||
t.equal(sigmund(obj2), hash)
|
|
||||||
t.equal(sigmund(obj3), cycleHash)
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
|||||||
{
|
|
||||||
"author": {
|
|
||||||
"name": "Isaac Z. Schlueter",
|
|
||||||
"email": "i@izs.me",
|
|
||||||
"url": "http://blog.izs.me"
|
|
||||||
},
|
|
||||||
"name": "minimatch",
|
|
||||||
"description": "a glob matcher in javascript",
|
|
||||||
"version": "0.3.0",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/isaacs/minimatch.git"
|
|
||||||
},
|
|
||||||
"main": "minimatch.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "tap test/*.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"lru-cache": "2",
|
|
||||||
"sigmund": "~1.0.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"tap": ""
|
|
||||||
},
|
|
||||||
"license": {
|
|
||||||
"type": "MIT",
|
|
||||||
"url": "http://github.com/isaacs/minimatch/raw/master/LICENSE"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/isaacs/minimatch/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/isaacs/minimatch",
|
|
||||||
"_id": "minimatch@0.3.0",
|
|
||||||
"_shasum": "275d8edaac4f1bb3326472089e7949c8394699dd",
|
|
||||||
"_from": "minimatch@0.3",
|
|
||||||
"_npmVersion": "1.4.10",
|
|
||||||
"_npmUser": {
|
|
||||||
"name": "isaacs",
|
|
||||||
"email": "i@izs.me"
|
|
||||||
},
|
|
||||||
"maintainers": [
|
|
||||||
{
|
|
||||||
"name": "isaacs",
|
|
||||||
"email": "i@izs.me"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dist": {
|
|
||||||
"shasum": "275d8edaac4f1bb3326472089e7949c8394699dd",
|
|
||||||
"tarball": "http://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz"
|
|
||||||
},
|
|
||||||
"directories": {},
|
|
||||||
"_resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz",
|
|
||||||
"readme": "ERROR: No README data found!"
|
|
||||||
}
|
|
@ -1,399 +0,0 @@
|
|||||||
// http://www.bashcookbook.com/bashinfo/source/bash-1.14.7/tests/glob-test
|
|
||||||
//
|
|
||||||
// TODO: Some of these tests do very bad things with backslashes, and will
|
|
||||||
// most likely fail badly on windows. They should probably be skipped.
|
|
||||||
|
|
||||||
var tap = require("tap")
|
|
||||||
, globalBefore = Object.keys(global)
|
|
||||||
, mm = require("../")
|
|
||||||
, files = [ "a", "b", "c", "d", "abc"
|
|
||||||
, "abd", "abe", "bb", "bcd"
|
|
||||||
, "ca", "cb", "dd", "de"
|
|
||||||
, "bdir/", "bdir/cfile"]
|
|
||||||
, next = files.concat([ "a-b", "aXb"
|
|
||||||
, ".x", ".y" ])
|
|
||||||
|
|
||||||
|
|
||||||
var patterns =
|
|
||||||
[ "http://www.bashcookbook.com/bashinfo/source/bash-1.14.7/tests/glob-test"
|
|
||||||
, ["a*", ["a", "abc", "abd", "abe"]]
|
|
||||||
, ["X*", ["X*"], {nonull: true}]
|
|
||||||
|
|
||||||
// allow null glob expansion
|
|
||||||
, ["X*", []]
|
|
||||||
|
|
||||||
// isaacs: Slightly different than bash/sh/ksh
|
|
||||||
// \\* is not un-escaped to literal "*" in a failed match,
|
|
||||||
// but it does make it get treated as a literal star
|
|
||||||
, ["\\*", ["\\*"], {nonull: true}]
|
|
||||||
, ["\\**", ["\\**"], {nonull: true}]
|
|
||||||
, ["\\*\\*", ["\\*\\*"], {nonull: true}]
|
|
||||||
|
|
||||||
, ["b*/", ["bdir/"]]
|
|
||||||
, ["c*", ["c", "ca", "cb"]]
|
|
||||||
, ["**", files]
|
|
||||||
|
|
||||||
, ["\\.\\./*/", ["\\.\\./*/"], {nonull: true}]
|
|
||||||
, ["s/\\..*//", ["s/\\..*//"], {nonull: true}]
|
|
||||||
|
|
||||||
, "legendary larry crashes bashes"
|
|
||||||
, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"
|
|
||||||
, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"], {nonull: true}]
|
|
||||||
, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"
|
|
||||||
, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"], {nonull: true}]
|
|
||||||
|
|
||||||
, "character classes"
|
|
||||||
, ["[a-c]b*", ["abc", "abd", "abe", "bb", "cb"]]
|
|
||||||
, ["[a-y]*[^c]", ["abd", "abe", "bb", "bcd",
|
|
||||||
"bdir/", "ca", "cb", "dd", "de"]]
|
|
||||||
, ["a*[^c]", ["abd", "abe"]]
|
|
||||||
, function () { files.push("a-b", "aXb") }
|
|
||||||
, ["a[X-]b", ["a-b", "aXb"]]
|
|
||||||
, function () { files.push(".x", ".y") }
|
|
||||||
, ["[^a-c]*", ["d", "dd", "de"]]
|
|
||||||
, function () { files.push("a*b/", "a*b/ooo") }
|
|
||||||
, ["a\\*b/*", ["a*b/ooo"]]
|
|
||||||
, ["a\\*?/*", ["a*b/ooo"]]
|
|
||||||
, ["*\\\\!*", [], {null: true}, ["echo !7"]]
|
|
||||||
, ["*\\!*", ["echo !7"], null, ["echo !7"]]
|
|
||||||
, ["*.\\*", ["r.*"], null, ["r.*"]]
|
|
||||||
, ["a[b]c", ["abc"]]
|
|
||||||
, ["a[\\b]c", ["abc"]]
|
|
||||||
, ["a?c", ["abc"]]
|
|
||||||
, ["a\\*c", [], {null: true}, ["abc"]]
|
|
||||||
, ["", [""], { null: true }, [""]]
|
|
||||||
|
|
||||||
, "http://www.opensource.apple.com/source/bash/bash-23/" +
|
|
||||||
"bash/tests/glob-test"
|
|
||||||
, function () { files.push("man/", "man/man1/", "man/man1/bash.1") }
|
|
||||||
, ["*/man*/bash.*", ["man/man1/bash.1"]]
|
|
||||||
, ["man/man1/bash.1", ["man/man1/bash.1"]]
|
|
||||||
, ["a***c", ["abc"], null, ["abc"]]
|
|
||||||
, ["a*****?c", ["abc"], null, ["abc"]]
|
|
||||||
, ["?*****??", ["abc"], null, ["abc"]]
|
|
||||||
, ["*****??", ["abc"], null, ["abc"]]
|
|
||||||
, ["?*****?c", ["abc"], null, ["abc"]]
|
|
||||||
, ["?***?****c", ["abc"], null, ["abc"]]
|
|
||||||
, ["?***?****?", ["abc"], null, ["abc"]]
|
|
||||||
, ["?***?****", ["abc"], null, ["abc"]]
|
|
||||||
, ["*******c", ["abc"], null, ["abc"]]
|
|
||||||
, ["*******?", ["abc"], null, ["abc"]]
|
|
||||||
, ["a*cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["a**?**cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["a**?**cd**?**??k***", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["a**?**cd**?**??***k", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["a**?**cd**?**??***k**", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["a****c**?**??*****", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["[-abc]", ["-"], null, ["-"]]
|
|
||||||
, ["[abc-]", ["-"], null, ["-"]]
|
|
||||||
, ["\\", ["\\"], null, ["\\"]]
|
|
||||||
, ["[\\\\]", ["\\"], null, ["\\"]]
|
|
||||||
, ["[[]", ["["], null, ["["]]
|
|
||||||
, ["[", ["["], null, ["["]]
|
|
||||||
, ["[*", ["[abc"], null, ["[abc"]]
|
|
||||||
, "a right bracket shall lose its special meaning and\n" +
|
|
||||||
"represent itself in a bracket expression if it occurs\n" +
|
|
||||||
"first in the list. -- POSIX.2 2.8.3.2"
|
|
||||||
, ["[]]", ["]"], null, ["]"]]
|
|
||||||
, ["[]-]", ["]"], null, ["]"]]
|
|
||||||
, ["[a-\z]", ["p"], null, ["p"]]
|
|
||||||
, ["??**********?****?", [], { null: true }, ["abc"]]
|
|
||||||
, ["??**********?****c", [], { null: true }, ["abc"]]
|
|
||||||
, ["?************c****?****", [], { null: true }, ["abc"]]
|
|
||||||
, ["*c*?**", [], { null: true }, ["abc"]]
|
|
||||||
, ["a*****c*?**", [], { null: true }, ["abc"]]
|
|
||||||
, ["a********???*******", [], { null: true }, ["abc"]]
|
|
||||||
, ["[]", [], { null: true }, ["a"]]
|
|
||||||
, ["[abc", [], { null: true }, ["["]]
|
|
||||||
|
|
||||||
, "nocase tests"
|
|
||||||
, ["XYZ", ["xYz"], { nocase: true, null: true }
|
|
||||||
, ["xYz", "ABC", "IjK"]]
|
|
||||||
, ["ab*", ["ABC"], { nocase: true, null: true }
|
|
||||||
, ["xYz", "ABC", "IjK"]]
|
|
||||||
, ["[ia]?[ck]", ["ABC", "IjK"], { nocase: true, null: true }
|
|
||||||
, ["xYz", "ABC", "IjK"]]
|
|
||||||
|
|
||||||
// [ pattern, [matches], MM opts, files, TAP opts]
|
|
||||||
, "onestar/twostar"
|
|
||||||
, ["{/*,*}", [], {null: true}, ["/asdf/asdf/asdf"]]
|
|
||||||
, ["{/?,*}", ["/a", "bb"], {null: true}
|
|
||||||
, ["/a", "/b/b", "/a/b/c", "bb"]]
|
|
||||||
|
|
||||||
, "dots should not match unless requested"
|
|
||||||
, ["**", ["a/b"], {}, ["a/b", "a/.d", ".a/.d"]]
|
|
||||||
|
|
||||||
// .. and . can only match patterns starting with .,
|
|
||||||
// even when options.dot is set.
|
|
||||||
, function () {
|
|
||||||
files = ["a/./b", "a/../b", "a/c/b", "a/.d/b"]
|
|
||||||
}
|
|
||||||
, ["a/*/b", ["a/c/b", "a/.d/b"], {dot: true}]
|
|
||||||
, ["a/.*/b", ["a/./b", "a/../b", "a/.d/b"], {dot: true}]
|
|
||||||
, ["a/*/b", ["a/c/b"], {dot:false}]
|
|
||||||
, ["a/.*/b", ["a/./b", "a/../b", "a/.d/b"], {dot: false}]
|
|
||||||
|
|
||||||
|
|
||||||
// this also tests that changing the options needs
|
|
||||||
// to change the cache key, even if the pattern is
|
|
||||||
// the same!
|
|
||||||
, ["**", ["a/b","a/.d",".a/.d"], { dot: true }
|
|
||||||
, [ ".a/.d", "a/.d", "a/b"]]
|
|
||||||
|
|
||||||
, "paren sets cannot contain slashes"
|
|
||||||
, ["*(a/b)", ["*(a/b)"], {nonull: true}, ["a/b"]]
|
|
||||||
|
|
||||||
// brace sets trump all else.
|
|
||||||
//
|
|
||||||
// invalid glob pattern. fails on bash4 and bsdglob.
|
|
||||||
// however, in this implementation, it's easier just
|
|
||||||
// to do the intuitive thing, and let brace-expansion
|
|
||||||
// actually come before parsing any extglob patterns,
|
|
||||||
// like the documentation seems to say.
|
|
||||||
//
|
|
||||||
// XXX: if anyone complains about this, either fix it
|
|
||||||
// or tell them to grow up and stop complaining.
|
|
||||||
//
|
|
||||||
// bash/bsdglob says this:
|
|
||||||
// , ["*(a|{b),c)}", ["*(a|{b),c)}"], {}, ["a", "ab", "ac", "ad"]]
|
|
||||||
// but we do this instead:
|
|
||||||
, ["*(a|{b),c)}", ["a", "ab", "ac"], {}, ["a", "ab", "ac", "ad"]]
|
|
||||||
|
|
||||||
// test partial parsing in the presence of comment/negation chars
|
|
||||||
, ["[!a*", ["[!ab"], {}, ["[!ab", "[ab"]]
|
|
||||||
, ["[#a*", ["[#ab"], {}, ["[#ab", "[ab"]]
|
|
||||||
|
|
||||||
// like: {a,b|c\\,d\\\|e} except it's unclosed, so it has to be escaped.
|
|
||||||
, ["+(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g"
|
|
||||||
, ["+(a|b\\|c\\\\|d\\\\|e\\\\\\\\|f\\\\\\\\|g"]
|
|
||||||
, {}
|
|
||||||
, ["+(a|b\\|c\\\\|d\\\\|e\\\\\\\\|f\\\\\\\\|g", "a", "b\\c"]]
|
|
||||||
|
|
||||||
|
|
||||||
// crazy nested {,,} and *(||) tests.
|
|
||||||
, function () {
|
|
||||||
files = [ "a", "b", "c", "d"
|
|
||||||
, "ab", "ac", "ad"
|
|
||||||
, "bc", "cb"
|
|
||||||
, "bc,d", "c,db", "c,d"
|
|
||||||
, "d)", "(b|c", "*(b|c"
|
|
||||||
, "b|c", "b|cc", "cb|c"
|
|
||||||
, "x(a|b|c)", "x(a|c)"
|
|
||||||
, "(a|b|c)", "(a|c)"]
|
|
||||||
}
|
|
||||||
, ["*(a|{b,c})", ["a", "b", "c", "ab", "ac"]]
|
|
||||||
, ["{a,*(b|c,d)}", ["a","(b|c", "*(b|c", "d)"]]
|
|
||||||
// a
|
|
||||||
// *(b|c)
|
|
||||||
// *(b|d)
|
|
||||||
, ["{a,*(b|{c,d})}", ["a","b", "bc", "cb", "c", "d"]]
|
|
||||||
, ["*(a|{b|c,c})", ["a", "b", "c", "ab", "ac", "bc", "cb"]]
|
|
||||||
|
|
||||||
|
|
||||||
// test various flag settings.
|
|
||||||
, [ "*(a|{b|c,c})", ["x(a|b|c)", "x(a|c)", "(a|b|c)", "(a|c)"]
|
|
||||||
, { noext: true } ]
|
|
||||||
, ["a?b", ["x/y/acb", "acb/"], {matchBase: true}
|
|
||||||
, ["x/y/acb", "acb/", "acb/d/e", "x/y/acb/d"] ]
|
|
||||||
, ["#*", ["#a", "#b"], {nocomment: true}, ["#a", "#b", "c#d"]]
|
|
||||||
|
|
||||||
|
|
||||||
// begin channelling Boole and deMorgan...
|
|
||||||
, "negation tests"
|
|
||||||
, function () {
|
|
||||||
files = ["d", "e", "!ab", "!abc", "a!b", "\\!a"]
|
|
||||||
}
|
|
||||||
|
|
||||||
// anything that is NOT a* matches.
|
|
||||||
, ["!a*", ["\\!a", "d", "e", "!ab", "!abc"]]
|
|
||||||
|
|
||||||
// anything that IS !a* matches.
|
|
||||||
, ["!a*", ["!ab", "!abc"], {nonegate: true}]
|
|
||||||
|
|
||||||
// anything that IS a* matches
|
|
||||||
, ["!!a*", ["a!b"]]
|
|
||||||
|
|
||||||
// anything that is NOT !a* matches
|
|
||||||
, ["!\\!a*", ["a!b", "d", "e", "\\!a"]]
|
|
||||||
|
|
||||||
// negation nestled within a pattern
|
|
||||||
, function () {
|
|
||||||
files = [ "foo.js"
|
|
||||||
, "foo.bar"
|
|
||||||
// can't match this one without negative lookbehind.
|
|
||||||
, "foo.js.js"
|
|
||||||
, "blar.js"
|
|
||||||
, "foo."
|
|
||||||
, "boo.js.boo" ]
|
|
||||||
}
|
|
||||||
, ["*.!(js)", ["foo.bar", "foo.", "boo.js.boo"] ]
|
|
||||||
|
|
||||||
// https://github.com/isaacs/minimatch/issues/5
|
|
||||||
, function () {
|
|
||||||
files = [ 'a/b/.x/c'
|
|
||||||
, 'a/b/.x/c/d'
|
|
||||||
, 'a/b/.x/c/d/e'
|
|
||||||
, 'a/b/.x'
|
|
||||||
, 'a/b/.x/'
|
|
||||||
, 'a/.x/b'
|
|
||||||
, '.x'
|
|
||||||
, '.x/'
|
|
||||||
, '.x/a'
|
|
||||||
, '.x/a/b'
|
|
||||||
, 'a/.x/b/.x/c'
|
|
||||||
, '.x/.x' ]
|
|
||||||
}
|
|
||||||
, ["**/.x/**", [ '.x/'
|
|
||||||
, '.x/a'
|
|
||||||
, '.x/a/b'
|
|
||||||
, 'a/.x/b'
|
|
||||||
, 'a/b/.x/'
|
|
||||||
, 'a/b/.x/c'
|
|
||||||
, 'a/b/.x/c/d'
|
|
||||||
, 'a/b/.x/c/d/e' ] ]
|
|
||||||
|
|
||||||
]
|
|
||||||
|
|
||||||
var regexps =
|
|
||||||
[ '/^(?:(?=.)a[^/]*?)$/',
|
|
||||||
'/^(?:(?=.)X[^/]*?)$/',
|
|
||||||
'/^(?:(?=.)X[^/]*?)$/',
|
|
||||||
'/^(?:\\*)$/',
|
|
||||||
'/^(?:(?=.)\\*[^/]*?)$/',
|
|
||||||
'/^(?:\\*\\*)$/',
|
|
||||||
'/^(?:(?=.)b[^/]*?\\/)$/',
|
|
||||||
'/^(?:(?=.)c[^/]*?)$/',
|
|
||||||
'/^(?:(?:(?!(?:\\/|^)\\.).)*?)$/',
|
|
||||||
'/^(?:\\.\\.\\/(?!\\.)(?=.)[^/]*?\\/)$/',
|
|
||||||
'/^(?:s\\/(?=.)\\.\\.[^/]*?\\/)$/',
|
|
||||||
'/^(?:\\/\\^root:\\/\\{s\\/(?=.)\\^[^:][^/]*?:[^:][^/]*?:\\([^:]\\)[^/]*?\\.[^/]*?\\$\\/1\\/)$/',
|
|
||||||
'/^(?:\\/\\^root:\\/\\{s\\/(?=.)\\^[^:][^/]*?:[^:][^/]*?:\\([^:]\\)[^/]*?\\.[^/]*?\\$\\/\u0001\\/)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[a-c]b[^/]*?)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[a-y][^/]*?[^c])$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?[^c])$/',
|
|
||||||
'/^(?:(?=.)a[X-]b)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^a-c][^/]*?)$/',
|
|
||||||
'/^(?:a\\*b\\/(?!\\.)(?=.)[^/]*?)$/',
|
|
||||||
'/^(?:(?=.)a\\*[^/]\\/(?!\\.)(?=.)[^/]*?)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?\\\\\\![^/]*?)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?\\![^/]*?)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?\\.\\*)$/',
|
|
||||||
'/^(?:(?=.)a[b]c)$/',
|
|
||||||
'/^(?:(?=.)a[b]c)$/',
|
|
||||||
'/^(?:(?=.)a[^/]c)$/',
|
|
||||||
'/^(?:a\\*c)$/',
|
|
||||||
'false',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?\\/(?=.)man[^/]*?\\/(?=.)bash\\.[^/]*?)$/',
|
|
||||||
'/^(?:man\\/man1\\/bash\\.1)$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?c)$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?c)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/])$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/])$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k)$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k)$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k[^/]*?[^/]*?[^/]*?)$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?k)$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?k[^/]*?[^/]*?)$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[-abc])$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[abc-])$/',
|
|
||||||
'/^(?:\\\\)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[\\\\])$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[\\[])$/',
|
|
||||||
'/^(?:\\[)$/',
|
|
||||||
'/^(?:(?=.)\\[(?!\\.)(?=.)[^/]*?)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[\\]])$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[\\]-])$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[a-z])$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/])$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?c)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?c[^/]*?[^/][^/]*?[^/]*?)$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/][^/]*?[^/]*?)$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?)$/',
|
|
||||||
'/^(?:\\[\\])$/',
|
|
||||||
'/^(?:\\[abc)$/',
|
|
||||||
'/^(?:(?=.)XYZ)$/i',
|
|
||||||
'/^(?:(?=.)ab[^/]*?)$/i',
|
|
||||||
'/^(?:(?!\\.)(?=.)[ia][^/][ck])$/i',
|
|
||||||
'/^(?:\\/(?!\\.)(?=.)[^/]*?|(?!\\.)(?=.)[^/]*?)$/',
|
|
||||||
'/^(?:\\/(?!\\.)(?=.)[^/]|(?!\\.)(?=.)[^/]*?)$/',
|
|
||||||
'/^(?:(?:(?!(?:\\/|^)\\.).)*?)$/',
|
|
||||||
'/^(?:a\\/(?!(?:^|\\/)\\.{1,2}(?:$|\\/))(?=.)[^/]*?\\/b)$/',
|
|
||||||
'/^(?:a\\/(?=.)\\.[^/]*?\\/b)$/',
|
|
||||||
'/^(?:a\\/(?!\\.)(?=.)[^/]*?\\/b)$/',
|
|
||||||
'/^(?:a\\/(?=.)\\.[^/]*?\\/b)$/',
|
|
||||||
'/^(?:(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?\\(a\\/b\\))$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)(?:a|b)*|(?!\\.)(?=.)(?:a|c)*)$/',
|
|
||||||
'/^(?:(?=.)\\[(?=.)\\!a[^/]*?)$/',
|
|
||||||
'/^(?:(?=.)\\[(?=.)#a[^/]*?)$/',
|
|
||||||
'/^(?:(?=.)\\+\\(a\\|[^/]*?\\|c\\\\\\\\\\|d\\\\\\\\\\|e\\\\\\\\\\\\\\\\\\|f\\\\\\\\\\\\\\\\\\|g)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)(?:a|b)*|(?!\\.)(?=.)(?:a|c)*)$/',
|
|
||||||
'/^(?:a|(?!\\.)(?=.)[^/]*?\\(b\\|c|d\\))$/',
|
|
||||||
'/^(?:a|(?!\\.)(?=.)(?:b|c)*|(?!\\.)(?=.)(?:b|d)*)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)(?:a|b|c)*|(?!\\.)(?=.)(?:a|c)*)$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?\\(a\\|b\\|c\\)|(?!\\.)(?=.)[^/]*?\\(a\\|c\\))$/',
|
|
||||||
'/^(?:(?=.)a[^/]b)$/',
|
|
||||||
'/^(?:(?=.)#[^/]*?)$/',
|
|
||||||
'/^(?!^(?:(?=.)a[^/]*?)$).*$/',
|
|
||||||
'/^(?:(?=.)\\!a[^/]*?)$/',
|
|
||||||
'/^(?:(?=.)a[^/]*?)$/',
|
|
||||||
'/^(?!^(?:(?=.)\\!a[^/]*?)$).*$/',
|
|
||||||
'/^(?:(?!\\.)(?=.)[^/]*?\\.(?:(?!js)[^/]*?))$/',
|
|
||||||
'/^(?:(?:(?!(?:\\/|^)\\.).)*?\\/\\.x\\/(?:(?!(?:\\/|^)\\.).)*?)$/' ]
|
|
||||||
var re = 0;
|
|
||||||
|
|
||||||
tap.test("basic tests", function (t) {
|
|
||||||
var start = Date.now()
|
|
||||||
|
|
||||||
// [ pattern, [matches], MM opts, files, TAP opts]
|
|
||||||
patterns.forEach(function (c) {
|
|
||||||
if (typeof c === "function") return c()
|
|
||||||
if (typeof c === "string") return t.comment(c)
|
|
||||||
|
|
||||||
var pattern = c[0]
|
|
||||||
, expect = c[1].sort(alpha)
|
|
||||||
, options = c[2] || {}
|
|
||||||
, f = c[3] || files
|
|
||||||
, tapOpts = c[4] || {}
|
|
||||||
|
|
||||||
// options.debug = true
|
|
||||||
var m = new mm.Minimatch(pattern, options)
|
|
||||||
var r = m.makeRe()
|
|
||||||
var expectRe = regexps[re++]
|
|
||||||
tapOpts.re = String(r) || JSON.stringify(r)
|
|
||||||
tapOpts.files = JSON.stringify(f)
|
|
||||||
tapOpts.pattern = pattern
|
|
||||||
tapOpts.set = m.set
|
|
||||||
tapOpts.negated = m.negate
|
|
||||||
|
|
||||||
var actual = mm.match(f, pattern, options)
|
|
||||||
actual.sort(alpha)
|
|
||||||
|
|
||||||
t.equivalent( actual, expect
|
|
||||||
, JSON.stringify(pattern) + " " + JSON.stringify(expect)
|
|
||||||
, tapOpts )
|
|
||||||
|
|
||||||
t.equal(tapOpts.re, expectRe, tapOpts)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.comment("time=" + (Date.now() - start) + "ms")
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tap.test("global leak test", function (t) {
|
|
||||||
var globalAfter = Object.keys(global)
|
|
||||||
t.equivalent(globalAfter, globalBefore, "no new globals, please")
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
function alpha (a, b) {
|
|
||||||
return a > b ? 1 : -1
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
var tap = require("tap")
|
|
||||||
, minimatch = require("../")
|
|
||||||
|
|
||||||
tap.test("brace expansion", function (t) {
|
|
||||||
// [ pattern, [expanded] ]
|
|
||||||
; [ [ "a{b,c{d,e},{f,g}h}x{y,z}"
|
|
||||||
, [ "abxy"
|
|
||||||
, "abxz"
|
|
||||||
, "acdxy"
|
|
||||||
, "acdxz"
|
|
||||||
, "acexy"
|
|
||||||
, "acexz"
|
|
||||||
, "afhxy"
|
|
||||||
, "afhxz"
|
|
||||||
, "aghxy"
|
|
||||||
, "aghxz" ] ]
|
|
||||||
, [ "a{1..5}b"
|
|
||||||
, [ "a1b"
|
|
||||||
, "a2b"
|
|
||||||
, "a3b"
|
|
||||||
, "a4b"
|
|
||||||
, "a5b" ] ]
|
|
||||||
, [ "a{b}c", ["a{b}c"] ]
|
|
||||||
].forEach(function (tc) {
|
|
||||||
var p = tc[0]
|
|
||||||
, expect = tc[1]
|
|
||||||
t.equivalent(minimatch.braceExpand(p), expect, p)
|
|
||||||
})
|
|
||||||
console.error("ending")
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
|||||||
var Minimatch = require("../minimatch.js").Minimatch
|
|
||||||
var tap = require("tap")
|
|
||||||
tap.test("cache test", function (t) {
|
|
||||||
var mm1 = new Minimatch("a?b")
|
|
||||||
var mm2 = new Minimatch("a?b")
|
|
||||||
t.equal(mm1, mm2, "should get the same object")
|
|
||||||
// the lru should drop it after 100 entries
|
|
||||||
for (var i = 0; i < 100; i ++) {
|
|
||||||
new Minimatch("a"+i)
|
|
||||||
}
|
|
||||||
mm2 = new Minimatch("a?b")
|
|
||||||
t.notEqual(mm1, mm2, "cache should have dropped")
|
|
||||||
t.end()
|
|
||||||
})
|
|
@ -1,274 +0,0 @@
|
|||||||
// http://www.bashcookbook.com/bashinfo/source/bash-1.14.7/tests/glob-test
|
|
||||||
//
|
|
||||||
// TODO: Some of these tests do very bad things with backslashes, and will
|
|
||||||
// most likely fail badly on windows. They should probably be skipped.
|
|
||||||
|
|
||||||
var tap = require("tap")
|
|
||||||
, globalBefore = Object.keys(global)
|
|
||||||
, mm = require("../")
|
|
||||||
, files = [ "a", "b", "c", "d", "abc"
|
|
||||||
, "abd", "abe", "bb", "bcd"
|
|
||||||
, "ca", "cb", "dd", "de"
|
|
||||||
, "bdir/", "bdir/cfile"]
|
|
||||||
, next = files.concat([ "a-b", "aXb"
|
|
||||||
, ".x", ".y" ])
|
|
||||||
|
|
||||||
tap.test("basic tests", function (t) {
|
|
||||||
var start = Date.now()
|
|
||||||
|
|
||||||
// [ pattern, [matches], MM opts, files, TAP opts]
|
|
||||||
; [ "http://www.bashcookbook.com/bashinfo" +
|
|
||||||
"/source/bash-1.14.7/tests/glob-test"
|
|
||||||
, ["a*", ["a", "abc", "abd", "abe"]]
|
|
||||||
, ["X*", ["X*"], {nonull: true}]
|
|
||||||
|
|
||||||
// allow null glob expansion
|
|
||||||
, ["X*", []]
|
|
||||||
|
|
||||||
// isaacs: Slightly different than bash/sh/ksh
|
|
||||||
// \\* is not un-escaped to literal "*" in a failed match,
|
|
||||||
// but it does make it get treated as a literal star
|
|
||||||
, ["\\*", ["\\*"], {nonull: true}]
|
|
||||||
, ["\\**", ["\\**"], {nonull: true}]
|
|
||||||
, ["\\*\\*", ["\\*\\*"], {nonull: true}]
|
|
||||||
|
|
||||||
, ["b*/", ["bdir/"]]
|
|
||||||
, ["c*", ["c", "ca", "cb"]]
|
|
||||||
, ["**", files]
|
|
||||||
|
|
||||||
, ["\\.\\./*/", ["\\.\\./*/"], {nonull: true}]
|
|
||||||
, ["s/\\..*//", ["s/\\..*//"], {nonull: true}]
|
|
||||||
|
|
||||||
, "legendary larry crashes bashes"
|
|
||||||
, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"
|
|
||||||
, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"], {nonull: true}]
|
|
||||||
, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"
|
|
||||||
, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"], {nonull: true}]
|
|
||||||
|
|
||||||
, "character classes"
|
|
||||||
, ["[a-c]b*", ["abc", "abd", "abe", "bb", "cb"]]
|
|
||||||
, ["[a-y]*[^c]", ["abd", "abe", "bb", "bcd",
|
|
||||||
"bdir/", "ca", "cb", "dd", "de"]]
|
|
||||||
, ["a*[^c]", ["abd", "abe"]]
|
|
||||||
, function () { files.push("a-b", "aXb") }
|
|
||||||
, ["a[X-]b", ["a-b", "aXb"]]
|
|
||||||
, function () { files.push(".x", ".y") }
|
|
||||||
, ["[^a-c]*", ["d", "dd", "de"]]
|
|
||||||
, function () { files.push("a*b/", "a*b/ooo") }
|
|
||||||
, ["a\\*b/*", ["a*b/ooo"]]
|
|
||||||
, ["a\\*?/*", ["a*b/ooo"]]
|
|
||||||
, ["*\\\\!*", [], {null: true}, ["echo !7"]]
|
|
||||||
, ["*\\!*", ["echo !7"], null, ["echo !7"]]
|
|
||||||
, ["*.\\*", ["r.*"], null, ["r.*"]]
|
|
||||||
, ["a[b]c", ["abc"]]
|
|
||||||
, ["a[\\b]c", ["abc"]]
|
|
||||||
, ["a?c", ["abc"]]
|
|
||||||
, ["a\\*c", [], {null: true}, ["abc"]]
|
|
||||||
, ["", [""], { null: true }, [""]]
|
|
||||||
|
|
||||||
, "http://www.opensource.apple.com/source/bash/bash-23/" +
|
|
||||||
"bash/tests/glob-test"
|
|
||||||
, function () { files.push("man/", "man/man1/", "man/man1/bash.1") }
|
|
||||||
, ["*/man*/bash.*", ["man/man1/bash.1"]]
|
|
||||||
, ["man/man1/bash.1", ["man/man1/bash.1"]]
|
|
||||||
, ["a***c", ["abc"], null, ["abc"]]
|
|
||||||
, ["a*****?c", ["abc"], null, ["abc"]]
|
|
||||||
, ["?*****??", ["abc"], null, ["abc"]]
|
|
||||||
, ["*****??", ["abc"], null, ["abc"]]
|
|
||||||
, ["?*****?c", ["abc"], null, ["abc"]]
|
|
||||||
, ["?***?****c", ["abc"], null, ["abc"]]
|
|
||||||
, ["?***?****?", ["abc"], null, ["abc"]]
|
|
||||||
, ["?***?****", ["abc"], null, ["abc"]]
|
|
||||||
, ["*******c", ["abc"], null, ["abc"]]
|
|
||||||
, ["*******?", ["abc"], null, ["abc"]]
|
|
||||||
, ["a*cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["a**?**cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["a**?**cd**?**??k***", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["a**?**cd**?**??***k", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["a**?**cd**?**??***k**", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["a****c**?**??*****", ["abcdecdhjk"], null, ["abcdecdhjk"]]
|
|
||||||
, ["[-abc]", ["-"], null, ["-"]]
|
|
||||||
, ["[abc-]", ["-"], null, ["-"]]
|
|
||||||
, ["\\", ["\\"], null, ["\\"]]
|
|
||||||
, ["[\\\\]", ["\\"], null, ["\\"]]
|
|
||||||
, ["[[]", ["["], null, ["["]]
|
|
||||||
, ["[", ["["], null, ["["]]
|
|
||||||
, ["[*", ["[abc"], null, ["[abc"]]
|
|
||||||
, "a right bracket shall lose its special meaning and\n" +
|
|
||||||
"represent itself in a bracket expression if it occurs\n" +
|
|
||||||
"first in the list. -- POSIX.2 2.8.3.2"
|
|
||||||
, ["[]]", ["]"], null, ["]"]]
|
|
||||||
, ["[]-]", ["]"], null, ["]"]]
|
|
||||||
, ["[a-\z]", ["p"], null, ["p"]]
|
|
||||||
, ["??**********?****?", [], { null: true }, ["abc"]]
|
|
||||||
, ["??**********?****c", [], { null: true }, ["abc"]]
|
|
||||||
, ["?************c****?****", [], { null: true }, ["abc"]]
|
|
||||||
, ["*c*?**", [], { null: true }, ["abc"]]
|
|
||||||
, ["a*****c*?**", [], { null: true }, ["abc"]]
|
|
||||||
, ["a********???*******", [], { null: true }, ["abc"]]
|
|
||||||
, ["[]", [], { null: true }, ["a"]]
|
|
||||||
, ["[abc", [], { null: true }, ["["]]
|
|
||||||
|
|
||||||
, "nocase tests"
|
|
||||||
, ["XYZ", ["xYz"], { nocase: true, null: true }
|
|
||||||
, ["xYz", "ABC", "IjK"]]
|
|
||||||
, ["ab*", ["ABC"], { nocase: true, null: true }
|
|
||||||
, ["xYz", "ABC", "IjK"]]
|
|
||||||
, ["[ia]?[ck]", ["ABC", "IjK"], { nocase: true, null: true }
|
|
||||||
, ["xYz", "ABC", "IjK"]]
|
|
||||||
|
|
||||||
// [ pattern, [matches], MM opts, files, TAP opts]
|
|
||||||
, "onestar/twostar"
|
|
||||||
, ["{/*,*}", [], {null: true}, ["/asdf/asdf/asdf"]]
|
|
||||||
, ["{/?,*}", ["/a", "bb"], {null: true}
|
|
||||||
, ["/a", "/b/b", "/a/b/c", "bb"]]
|
|
||||||
|
|
||||||
, "dots should not match unless requested"
|
|
||||||
, ["**", ["a/b"], {}, ["a/b", "a/.d", ".a/.d"]]
|
|
||||||
|
|
||||||
// .. and . can only match patterns starting with .,
|
|
||||||
// even when options.dot is set.
|
|
||||||
, function () {
|
|
||||||
files = ["a/./b", "a/../b", "a/c/b", "a/.d/b"]
|
|
||||||
}
|
|
||||||
, ["a/*/b", ["a/c/b", "a/.d/b"], {dot: true}]
|
|
||||||
, ["a/.*/b", ["a/./b", "a/../b", "a/.d/b"], {dot: true}]
|
|
||||||
, ["a/*/b", ["a/c/b"], {dot:false}]
|
|
||||||
, ["a/.*/b", ["a/./b", "a/../b", "a/.d/b"], {dot: false}]
|
|
||||||
|
|
||||||
|
|
||||||
// this also tests that changing the options needs
|
|
||||||
// to change the cache key, even if the pattern is
|
|
||||||
// the same!
|
|
||||||
, ["**", ["a/b","a/.d",".a/.d"], { dot: true }
|
|
||||||
, [ ".a/.d", "a/.d", "a/b"]]
|
|
||||||
|
|
||||||
, "paren sets cannot contain slashes"
|
|
||||||
, ["*(a/b)", ["*(a/b)"], {nonull: true}, ["a/b"]]
|
|
||||||
|
|
||||||
// brace sets trump all else.
|
|
||||||
//
|
|
||||||
// invalid glob pattern. fails on bash4 and bsdglob.
|
|
||||||
// however, in this implementation, it's easier just
|
|
||||||
// to do the intuitive thing, and let brace-expansion
|
|
||||||
// actually come before parsing any extglob patterns,
|
|
||||||
// like the documentation seems to say.
|
|
||||||
//
|
|
||||||
// XXX: if anyone complains about this, either fix it
|
|
||||||
// or tell them to grow up and stop complaining.
|
|
||||||
//
|
|
||||||
// bash/bsdglob says this:
|
|
||||||
// , ["*(a|{b),c)}", ["*(a|{b),c)}"], {}, ["a", "ab", "ac", "ad"]]
|
|
||||||
// but we do this instead:
|
|
||||||
, ["*(a|{b),c)}", ["a", "ab", "ac"], {}, ["a", "ab", "ac", "ad"]]
|
|
||||||
|
|
||||||
// test partial parsing in the presence of comment/negation chars
|
|
||||||
, ["[!a*", ["[!ab"], {}, ["[!ab", "[ab"]]
|
|
||||||
, ["[#a*", ["[#ab"], {}, ["[#ab", "[ab"]]
|
|
||||||
|
|
||||||
// like: {a,b|c\\,d\\\|e} except it's unclosed, so it has to be escaped.
|
|
||||||
, ["+(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g"
|
|
||||||
, ["+(a|b\\|c\\\\|d\\\\|e\\\\\\\\|f\\\\\\\\|g"]
|
|
||||||
, {}
|
|
||||||
, ["+(a|b\\|c\\\\|d\\\\|e\\\\\\\\|f\\\\\\\\|g", "a", "b\\c"]]
|
|
||||||
|
|
||||||
|
|
||||||
// crazy nested {,,} and *(||) tests.
|
|
||||||
, function () {
|
|
||||||
files = [ "a", "b", "c", "d"
|
|
||||||
, "ab", "ac", "ad"
|
|
||||||
, "bc", "cb"
|
|
||||||
, "bc,d", "c,db", "c,d"
|
|
||||||
, "d)", "(b|c", "*(b|c"
|
|
||||||
, "b|c", "b|cc", "cb|c"
|
|
||||||
, "x(a|b|c)", "x(a|c)"
|
|
||||||
, "(a|b|c)", "(a|c)"]
|
|
||||||
}
|
|
||||||
, ["*(a|{b,c})", ["a", "b", "c", "ab", "ac"]]
|
|
||||||
, ["{a,*(b|c,d)}", ["a","(b|c", "*(b|c", "d)"]]
|
|
||||||
// a
|
|
||||||
// *(b|c)
|
|
||||||
// *(b|d)
|
|
||||||
, ["{a,*(b|{c,d})}", ["a","b", "bc", "cb", "c", "d"]]
|
|
||||||
, ["*(a|{b|c,c})", ["a", "b", "c", "ab", "ac", "bc", "cb"]]
|
|
||||||
|
|
||||||
|
|
||||||
// test various flag settings.
|
|
||||||
, [ "*(a|{b|c,c})", ["x(a|b|c)", "x(a|c)", "(a|b|c)", "(a|c)"]
|
|
||||||
, { noext: true } ]
|
|
||||||
, ["a?b", ["x/y/acb", "acb/"], {matchBase: true}
|
|
||||||
, ["x/y/acb", "acb/", "acb/d/e", "x/y/acb/d"] ]
|
|
||||||
, ["#*", ["#a", "#b"], {nocomment: true}, ["#a", "#b", "c#d"]]
|
|
||||||
|
|
||||||
|
|
||||||
// begin channelling Boole and deMorgan...
|
|
||||||
, "negation tests"
|
|
||||||
, function () {
|
|
||||||
files = ["d", "e", "!ab", "!abc", "a!b", "\\!a"]
|
|
||||||
}
|
|
||||||
|
|
||||||
// anything that is NOT a* matches.
|
|
||||||
, ["!a*", ["\\!a", "d", "e", "!ab", "!abc"]]
|
|
||||||
|
|
||||||
// anything that IS !a* matches.
|
|
||||||
, ["!a*", ["!ab", "!abc"], {nonegate: true}]
|
|
||||||
|
|
||||||
// anything that IS a* matches
|
|
||||||
, ["!!a*", ["a!b"]]
|
|
||||||
|
|
||||||
// anything that is NOT !a* matches
|
|
||||||
, ["!\\!a*", ["a!b", "d", "e", "\\!a"]]
|
|
||||||
|
|
||||||
// negation nestled within a pattern
|
|
||||||
, function () {
|
|
||||||
files = [ "foo.js"
|
|
||||||
, "foo.bar"
|
|
||||||
// can't match this one without negative lookbehind.
|
|
||||||
, "foo.js.js"
|
|
||||||
, "blar.js"
|
|
||||||
, "foo."
|
|
||||||
, "boo.js.boo" ]
|
|
||||||
}
|
|
||||||
, ["*.!(js)", ["foo.bar", "foo.", "boo.js.boo"] ]
|
|
||||||
|
|
||||||
].forEach(function (c) {
|
|
||||||
if (typeof c === "function") return c()
|
|
||||||
if (typeof c === "string") return t.comment(c)
|
|
||||||
|
|
||||||
var pattern = c[0]
|
|
||||||
, expect = c[1].sort(alpha)
|
|
||||||
, options = c[2]
|
|
||||||
, f = c[3] || files
|
|
||||||
, tapOpts = c[4] || {}
|
|
||||||
|
|
||||||
// options.debug = true
|
|
||||||
var Class = mm.defaults(options).Minimatch
|
|
||||||
var m = new Class(pattern, {})
|
|
||||||
var r = m.makeRe()
|
|
||||||
tapOpts.re = String(r) || JSON.stringify(r)
|
|
||||||
tapOpts.files = JSON.stringify(f)
|
|
||||||
tapOpts.pattern = pattern
|
|
||||||
tapOpts.set = m.set
|
|
||||||
tapOpts.negated = m.negate
|
|
||||||
|
|
||||||
var actual = mm.match(f, pattern, options)
|
|
||||||
actual.sort(alpha)
|
|
||||||
|
|
||||||
t.equivalent( actual, expect
|
|
||||||
, JSON.stringify(pattern) + " " + JSON.stringify(expect)
|
|
||||||
, tapOpts )
|
|
||||||
})
|
|
||||||
|
|
||||||
t.comment("time=" + (Date.now() - start) + "ms")
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
tap.test("global leak test", function (t) {
|
|
||||||
var globalAfter = Object.keys(global)
|
|
||||||
t.equivalent(globalAfter, globalBefore, "no new globals, please")
|
|
||||||
t.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
function alpha (a, b) {
|
|
||||||
return a > b ? 1 : -1
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
var test = require('tap').test
|
|
||||||
var minimatch = require('../')
|
|
||||||
|
|
||||||
test('extglob ending with statechar', function(t) {
|
|
||||||
t.notOk(minimatch('ax', 'a?(b*)'))
|
|
||||||
t.ok(minimatch('ax', '?(a*|b)'))
|
|
||||||
t.end()
|
|
||||||
})
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user