updated sys and created publi
This commit is contained in:
+184
@@ -0,0 +1,184 @@
|
||||
## v4.6.1
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v4.6.1
|
||||
|
||||
## v4.6.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v4.6.0
|
||||
|
||||
## v4.5.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v4.5.0
|
||||
|
||||
## v4.4.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v4.4.0
|
||||
|
||||
## v4.3.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v4.3.0
|
||||
|
||||
## v4.2.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v4.2.0
|
||||
|
||||
## v4.1.1
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v4.1.1
|
||||
|
||||
## v4.1.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v4.1.0
|
||||
|
||||
## v4.0.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v4.0.0
|
||||
|
||||
## v3.13.1
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.13.1
|
||||
|
||||
## v3.13.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.13.0
|
||||
|
||||
## v3.12.5
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.12.5
|
||||
|
||||
## v3.12.4
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.12.4
|
||||
|
||||
## v3.12.3
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.12.3
|
||||
|
||||
## v3.12.2
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.12.2
|
||||
|
||||
## v3.12.1
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.12.1
|
||||
|
||||
## v3.12.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.12.0
|
||||
|
||||
## v3.11.3
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.11.3
|
||||
|
||||
## v3.11.2
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.11.2
|
||||
|
||||
## v3.11.1
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.11.1
|
||||
|
||||
## v3.11.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.11.0
|
||||
|
||||
## v3.10.1
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.10.1
|
||||
|
||||
## v3.10.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.10.0
|
||||
|
||||
## v3.9.3
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.9.3
|
||||
|
||||
## v3.9.2
|
||||
|
||||
(removed)
|
||||
|
||||
## v3.9.1
|
||||
|
||||
(removed)
|
||||
|
||||
## v3.9.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.9.0
|
||||
|
||||
## v3.8.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.8.0
|
||||
|
||||
## v3.7.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.7.0
|
||||
|
||||
## v3.6.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.6.0
|
||||
|
||||
## v3.5.3
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.5.3
|
||||
|
||||
## v3.5.2
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.5.2
|
||||
|
||||
## v3.5.1
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.5.1
|
||||
|
||||
## v3.5.0
|
||||
|
||||
(removed)
|
||||
|
||||
## v3.4.2
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.4.2
|
||||
|
||||
## v3.4.1
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.4.1
|
||||
|
||||
## v3.4.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.4.0
|
||||
|
||||
## v3.3.3
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.3.3
|
||||
|
||||
## v3.3.2
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.3.2
|
||||
|
||||
## v3.3.1
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.3.1
|
||||
|
||||
## v3.3.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.3.0
|
||||
|
||||
## v3.2.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.2.0
|
||||
|
||||
## v3.1.2
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.1.2
|
||||
|
||||
## v3.1.1
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.1.1
|
||||
|
||||
## v3.1.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.1.0
|
||||
|
||||
## v3.0.0
|
||||
|
||||
https://github.com/sass/node-sass/releases/tag/v3.0.0
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
Copyright (c) 2013-2016 Andrew Nesbitt
|
||||
|
||||
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.
|
||||
+613
@@ -0,0 +1,613 @@
|
||||
# node-sass
|
||||
|
||||
#### Supported Node.js versions vary by release, please consult the [releases page](https://github.com/sass/node-sass/releases)
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<img width="77px" alt="Sass logo" src="https://rawgit.com/sass/node-sass/master/media/logo.svg" />
|
||||
</td>
|
||||
<td valign="bottom" align="right">
|
||||
<a href="https://www.npmjs.com/package/node-sass">
|
||||
<img width="100%" src="https://nodei.co/npm/node-sass.png?downloads=true&downloadRank=true&stars=true">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
[](https://travis-ci.org/sass/node-sass)
|
||||
[](https://ci.appveyor.com/project/sass/node-sass/branch/master)
|
||||
[](http://badge.fury.io/js/node-sass)
|
||||
[](https://david-dm.org/sass/node-sass)
|
||||
[](https://david-dm.org/sass/node-sass#info=devDependencies)
|
||||
[](https://coveralls.io/r/sass/node-sass?branch=master)
|
||||
[](http://inch-ci.org/github/sass/node-sass)
|
||||
[](https://libsass-slack.herokuapp.com/)
|
||||
|
||||
Node-sass is a library that provides binding for Node.js to [LibSass], the C version of the popular stylesheet preprocessor, Sass.
|
||||
|
||||
It allows you to natively compile .scss files to css at incredible speed and automatically via a connect middleware.
|
||||
|
||||
Find it on npm: <https://www.npmjs.com/package/node-sass>
|
||||
|
||||
Follow @nodesass on twitter for release updates: <https://twitter.com/nodesass>
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm install node-sass
|
||||
```
|
||||
|
||||
Some users have reported issues installing on Ubuntu due to `node` being registered to another package. [Follow the official NodeJS docs](https://github.com/nodejs/node-v0.x-archive/wiki/Installing-Node.js-via-package-manager) to install NodeJS so that `#!/usr/bin/env node` correctly resolves.
|
||||
|
||||
Compiling on Windows machines requires the [node-gyp prerequisites](https://github.com/nodejs/node-gyp#on-windows).
|
||||
|
||||
Are you seeing the following error? Check out our [Troubleshooting guide](/TROUBLESHOOTING.md#installing-node-sass-4x-with-node--4).**
|
||||
|
||||
```
|
||||
SyntaxError: Use of const in strict mode.
|
||||
```
|
||||
|
||||
**Having installation troubles? Check out our [Troubleshooting guide](/TROUBLESHOOTING.md).**
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var sass = require('node-sass');
|
||||
sass.render({
|
||||
file: scss_filename,
|
||||
[, options..]
|
||||
}, function(err, result) { /*...*/ });
|
||||
// OR
|
||||
var result = sass.renderSync({
|
||||
data: scss_content
|
||||
[, options..]
|
||||
});
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
### file
|
||||
|
||||
* Type: `String`
|
||||
* Default: `null`
|
||||
|
||||
**Special**: `file` or `data` must be specified
|
||||
|
||||
Path to a file for [LibSass] to compile.
|
||||
|
||||
### data
|
||||
|
||||
* Type: `String`
|
||||
* Default: `null`
|
||||
|
||||
**Special**: `file` or `data` must be specified
|
||||
|
||||
A string to pass to [LibSass] to compile. It is recommended that you use `includePaths` in conjunction with this so that [LibSass] can find files when using the `@import` directive.
|
||||
|
||||
### importer (>= v2.0.0) - _experimental_
|
||||
|
||||
**This is an experimental LibSass feature. Use with caution.**
|
||||
|
||||
* Type: `Function | Function[]` signature `function(url, prev, done)`
|
||||
* Default: `undefined`
|
||||
|
||||
Function Parameters and Information:
|
||||
|
||||
* `url (String)` - the path in import **as-is**, which [LibSass] encountered
|
||||
* `prev (String)` - the previously resolved path
|
||||
* `done (Function)` - a callback function to invoke on async completion, takes an object literal containing
|
||||
* `file (String)` - an alternate path for [LibSass] to use **OR**
|
||||
* `contents (String)` - the imported contents (for example, read from memory or the file system)
|
||||
|
||||
Handles when [LibSass] encounters the `@import` directive. A custom importer allows extension of the [LibSass] engine in both a synchronous and asynchronous manner. In both cases, the goal is to either `return` or call `done()` with an object literal. Depending on the value of the object literal, one of two things will happen.
|
||||
|
||||
When returning or calling `done()` with `{ file: "String" }`, the new file path will be assumed for the `@import`. It's recommended to be mindful of the value of `prev` in instances where relative path resolution may be required.
|
||||
|
||||
When returning or calling `done()` with `{ contents: "String" }`, the string value will be used as if the file was read in through an external source.
|
||||
|
||||
Starting from v3.0.0:
|
||||
|
||||
* `this` refers to a contextual scope for the immediate run of `sass.render` or `sass.renderSync`
|
||||
|
||||
* importers can return error and LibSass will emit that error in response. For instance:
|
||||
|
||||
```javascript
|
||||
done(new Error('doesn\'t exist!'));
|
||||
// or return synchronously
|
||||
return new Error('nothing to do here');
|
||||
```
|
||||
|
||||
* importer can be an array of functions, which will be called by LibSass in the order of their occurrence in array. This helps user specify special importer for particular kind of path (filesystem, http). If an importer does not want to handle a particular path, it should return `null`. See [functions section](#functions--v300---experimental) for more details on Sass types.
|
||||
|
||||
### functions (>= v3.0.0) - _experimental_
|
||||
|
||||
**This is an experimental LibSass feature. Use with caution.**
|
||||
|
||||
`functions` is an `Object` that holds a collection of custom functions that may be invoked by the sass files being compiled. They may take zero or more input parameters and must return a value either synchronously (`return ...;`) or asynchronously (`done();`). Those parameters will be instances of one of the constructors contained in the `require('node-sass').types` hash. The return value must be of one of these types as well. See the list of available types below:
|
||||
|
||||
#### types.Number(value [, unit = ""])
|
||||
|
||||
* `getValue()`/ `setValue(value)` : gets / sets the numerical portion of the number
|
||||
* `getUnit()` / `setUnit(unit)` : gets / sets the unit portion of the number
|
||||
|
||||
#### types.String(value)
|
||||
|
||||
* `getValue()` / `setValue(value)` : gets / sets the enclosed string
|
||||
|
||||
#### types.Color(r, g, b [, a = 1.0]) or types.Color(argb)
|
||||
|
||||
* `getR()` / `setR(value)` : red component (integer from `0` to `255`)
|
||||
* `getG()` / `setG(value)` : green component (integer from `0` to `255`)
|
||||
* `getB()` / `setB(value)` : blue component (integer from `0` to `255`)
|
||||
* `getA()` / `setA(value)` : alpha component (number from `0` to `1.0`)
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var Color = require('node-sass').types.Color,
|
||||
c1 = new Color(255, 0, 0),
|
||||
c2 = new Color(0xff0088cc);
|
||||
```
|
||||
|
||||
#### types.Boolean(value)
|
||||
|
||||
* `getValue()` : gets the enclosed boolean
|
||||
* `types.Boolean.TRUE` : Singleton instance of `types.Boolean` that holds "true"
|
||||
* `types.Boolean.FALSE` : Singleton instance of `types.Boolean` that holds "false"
|
||||
|
||||
#### types.List(length [, commaSeparator = true])
|
||||
|
||||
* `getValue(index)` / `setValue(index, value)` : `value` must itself be an instance of one of the constructors in `sass.types`.
|
||||
* `getSeparator()` / `setSeparator(isComma)` : whether to use commas as a separator
|
||||
* `getLength()`
|
||||
|
||||
#### types.Map(length)
|
||||
|
||||
* `getKey(index)` / `setKey(index, value)`
|
||||
* `getValue(index)` / `setValue(index, value)`
|
||||
* `getLength()`
|
||||
|
||||
#### types.Null()
|
||||
|
||||
* `types.Null.NULL` : Singleton instance of `types.Null`.
|
||||
|
||||
#### Example
|
||||
|
||||
```javascript
|
||||
sass.renderSync({
|
||||
data: '#{headings(2,5)} { color: #08c; }',
|
||||
functions: {
|
||||
'headings($from: 0, $to: 6)': function(from, to) {
|
||||
var i, f = from.getValue(), t = to.getValue(),
|
||||
list = new sass.types.List(t - f + 1);
|
||||
|
||||
for (i = f; i <= t; i++) {
|
||||
list.setValue(i - f, new sass.types.String('h' + i));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### includePaths
|
||||
|
||||
* Type: `Array<String>`
|
||||
* Default: `[]`
|
||||
|
||||
An array of paths that [LibSass] can look in to attempt to resolve your `@import` declarations. When using `data`, it is recommended that you use this.
|
||||
|
||||
### indentedSyntax
|
||||
|
||||
* Type: `Boolean`
|
||||
* Default: `false`
|
||||
|
||||
`true` values enable [Sass Indented Syntax](http://sass-lang.com/documentation/file.INDENTED_SYNTAX.html) for parsing the data string or file.
|
||||
|
||||
__Note:__ node-sass/libsass will compile a mixed library of scss and indented syntax (.sass) files with the Default setting (false) as long as .sass and .scss extensions are used in filenames.
|
||||
|
||||
### indentType (>= v3.0.0)
|
||||
|
||||
* Type: `String`
|
||||
* Default: `space`
|
||||
|
||||
Used to determine whether to use space or tab character for indentation.
|
||||
|
||||
### indentWidth (>= v3.0.0)
|
||||
|
||||
* Type: `Number`
|
||||
* Default: `2`
|
||||
* Maximum: `10`
|
||||
|
||||
Used to determine the number of spaces or tabs to be used for indentation.
|
||||
|
||||
### linefeed (>= v3.0.0)
|
||||
|
||||
* Type: `String`
|
||||
* Default: `lf`
|
||||
|
||||
Used to determine whether to use `cr`, `crlf`, `lf` or `lfcr` sequence for line break.
|
||||
|
||||
### omitSourceMapUrl
|
||||
|
||||
* Type: `Boolean`
|
||||
* Default: `false`
|
||||
|
||||
**Special:** When using this, you should also specify `outFile` to avoid unexpected behavior.
|
||||
|
||||
`true` values disable the inclusion of source map information in the output file.
|
||||
|
||||
### outFile
|
||||
|
||||
* Type: `String | null`
|
||||
* Default: `null`
|
||||
|
||||
**Special:** Required when `sourceMap` is a truthy value
|
||||
|
||||
Specify the intended location of the output file. Strongly recommended when outputting source maps so that they can properly refer back to their intended files.
|
||||
|
||||
**Attention** enabling this option will **not** write the file on disk for you, it's for internal reference purpose only (to generate the map for example).
|
||||
|
||||
Example on how to write it on the disk
|
||||
|
||||
```javascript
|
||||
sass.render({
|
||||
...
|
||||
outFile: yourPathTotheFile,
|
||||
}, function(error, result) { // node-style callback from v3.0.0 onwards
|
||||
if(!error){
|
||||
// No errors during the compilation, write this result on the disk
|
||||
fs.writeFile(yourPathTotheFile, result.css, function(err){
|
||||
if(!err){
|
||||
//file written on disk
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### outputStyle
|
||||
|
||||
* Type: `String`
|
||||
* Default: `nested`
|
||||
* Values: `nested`, `expanded`, `compact`, `compressed`
|
||||
|
||||
Determines the output format of the final CSS style.
|
||||
|
||||
### precision
|
||||
|
||||
* Type: `Integer`
|
||||
* Default: `5`
|
||||
|
||||
Used to determine how many digits after the decimal will be allowed. For instance, if you had a decimal number of `1.23456789` and a precision of `5`, the result will be `1.23457` in the final CSS.
|
||||
|
||||
### sourceComments
|
||||
|
||||
* Type: `Boolean`
|
||||
* Default: `false`
|
||||
|
||||
`true` Enables the line number and file where a selector is defined to be emitted into the compiled CSS as a comment. Useful for debugging, especially when using imports and mixins.
|
||||
|
||||
### sourceMap
|
||||
|
||||
* Type: `Boolean | String | undefined`
|
||||
* Default: `undefined`
|
||||
|
||||
**Special:** Setting the `sourceMap` option requires also setting the `outFile` option
|
||||
|
||||
Enables the outputting of a source map during `render` and `renderSync`. When `sourceMap === true`, the value of `outFile` is used as the target output location for the source map. When `typeof sourceMap === "string"`, the value of `sourceMap` will be used as the writing location for the file.
|
||||
|
||||
### sourceMapContents
|
||||
|
||||
* Type: `Boolean`
|
||||
* Default: `false`
|
||||
|
||||
`true` includes the `contents` in the source map information
|
||||
|
||||
### sourceMapEmbed
|
||||
|
||||
* Type: `Boolean`
|
||||
* Default: `false`
|
||||
|
||||
`true` embeds the source map as a data URI
|
||||
|
||||
### sourceMapRoot
|
||||
|
||||
* Type: `String`
|
||||
* Default: `undefined`
|
||||
|
||||
the value will be emitted as `sourceRoot` in the source map information
|
||||
|
||||
## `render` Callback (>= v3.0.0)
|
||||
|
||||
node-sass supports standard node style asynchronous callbacks with the signature of `function(err, result)`. In error conditions, the `error` argument is populated with the error object. In success conditions, the `result` object is populated with an object describing the result of the render call.
|
||||
|
||||
### Error Object
|
||||
|
||||
* `message` (String) - The error message.
|
||||
* `line` (Number) - The line number of error.
|
||||
* `column` (Number) - The column number of error.
|
||||
* `status` (Number) - The status code.
|
||||
* `file` (String) - The filename of error. In case `file` option was not set (in favour of `data`), this will reflect the value `stdin`.
|
||||
|
||||
### Result Object
|
||||
|
||||
* `css` (Buffer) - The compiled CSS. Write this to a file, or serve it out as needed.
|
||||
* `map` (Buffer) - The source map
|
||||
* `stats` (Object) - An object containing information about the compile. It contains the following keys:
|
||||
* `entry` (String) - The path to the scss file, or `data` if the source was not a file
|
||||
* `start` (Number) - Date.now() before the compilation
|
||||
* `end` (Number) - Date.now() after the compilation
|
||||
* `duration` (Number) - *end* - *start*
|
||||
* `includedFiles` (Array) - Absolute paths to all related scss files in no particular order.
|
||||
|
||||
### Examples
|
||||
|
||||
```javascript
|
||||
var sass = require('node-sass');
|
||||
sass.render({
|
||||
file: '/path/to/myFile.scss',
|
||||
data: 'body{background:blue; a{color:black;}}',
|
||||
importer: function(url, prev, done) {
|
||||
// url is the path in import as is, which LibSass encountered.
|
||||
// prev is the previously resolved path.
|
||||
// done is an optional callback, either consume it or return value synchronously.
|
||||
// this.options contains this options hash, this.callback contains the node-style callback
|
||||
someAsyncFunction(url, prev, function(result){
|
||||
done({
|
||||
file: result.path, // only one of them is required, see section Special Behaviours.
|
||||
contents: result.data
|
||||
});
|
||||
});
|
||||
// OR
|
||||
var result = someSyncFunction(url, prev);
|
||||
return {file: result.path, contents: result.data};
|
||||
},
|
||||
includePaths: [ 'lib/', 'mod/' ],
|
||||
outputStyle: 'compressed'
|
||||
}, function(error, result) { // node-style callback from v3.0.0 onwards
|
||||
if (error) {
|
||||
console.log(error.status); // used to be "code" in v2x and below
|
||||
console.log(error.column);
|
||||
console.log(error.message);
|
||||
console.log(error.line);
|
||||
}
|
||||
else {
|
||||
console.log(result.css.toString());
|
||||
|
||||
console.log(result.stats);
|
||||
|
||||
console.log(result.map.toString());
|
||||
// or better
|
||||
console.log(JSON.stringify(result.map)); // note, JSON.stringify accepts Buffer too
|
||||
}
|
||||
});
|
||||
// OR
|
||||
var result = sass.renderSync({
|
||||
file: '/path/to/file.scss',
|
||||
data: 'body{background:blue; a{color:black;}}',
|
||||
outputStyle: 'compressed',
|
||||
outFile: '/to/my/output.css',
|
||||
sourceMap: true, // or an absolute or relative (to outFile) path
|
||||
importer: function(url, prev, done) {
|
||||
// url is the path in import as is, which LibSass encountered.
|
||||
// prev is the previously resolved path.
|
||||
// done is an optional callback, either consume it or return value synchronously.
|
||||
// this.options contains this options hash
|
||||
someAsyncFunction(url, prev, function(result){
|
||||
done({
|
||||
file: result.path, // only one of them is required, see section Special Behaviours.
|
||||
contents: result.data
|
||||
});
|
||||
});
|
||||
// OR
|
||||
var result = someSyncFunction(url, prev);
|
||||
return {file: result.path, contents: result.data};
|
||||
}
|
||||
}));
|
||||
|
||||
console.log(result.css);
|
||||
console.log(result.map);
|
||||
console.log(result.stats);
|
||||
```
|
||||
|
||||
### Special behaviours
|
||||
|
||||
* In the case that both `file` and `data` options are set, node-sass will give precedence to `data` and use `file` to calculate paths in sourcemaps.
|
||||
|
||||
### Version information (>= v2.0.0)
|
||||
|
||||
Both `node-sass` and `libsass` version info is now exposed via the `info` method:
|
||||
|
||||
```javascript
|
||||
var sass = require('node-sass');
|
||||
|
||||
console.log(sass.info);
|
||||
|
||||
/*
|
||||
it will output something like:
|
||||
|
||||
node-sass 2.0.1 (Wrapper) [JavaScript]
|
||||
libsass 3.1.0 (Sass Compiler) [C/C++]
|
||||
*/
|
||||
```
|
||||
|
||||
Since node-sass >=v3.0.0 LibSass version is determined at run time.
|
||||
|
||||
## Integrations
|
||||
|
||||
Listing of community uses of node-sass in build tools and frameworks.
|
||||
|
||||
### Brackets extension
|
||||
|
||||
[@jasonsanjose](https://github.com/jasonsanjose) has created a [Brackets](http://brackets.io) extension based on node-sass: <https://github.com/jasonsanjose/brackets-sass>. When editing Sass files, the extension compiles changes on save. The extension also integrates with Live Preview to show Sass changes in the browser without saving or compiling.
|
||||
|
||||
### Brunch plugin
|
||||
|
||||
[Brunch](http://brunch.io)'s official sass plugin uses node-sass by default, and automatically falls back to ruby if use of Compass is detected: <https://github.com/brunch/sass-brunch>
|
||||
|
||||
### Connect/Express middleware
|
||||
|
||||
Recompile `.scss` files automatically for connect and express based http servers.
|
||||
|
||||
This functionality has been moved to [`node-sass-middleware`](https://github.com/sass/node-sass-middleware) in node-sass v1.0.0
|
||||
|
||||
### DocPad Plugin
|
||||
|
||||
[@jking90](https://github.com/jking90) wrote a [DocPad](http://docpad.org/) plugin that compiles `.scss` files using node-sass: <https://github.com/jking90/docpad-plugin-nodesass>
|
||||
|
||||
### Duo.js extension
|
||||
|
||||
[@stephenway](https://github.com/stephenway) has created an extension that transpiles Sass to CSS using node-sass with [duo.js](http://duojs.org/)
|
||||
<https://github.com/duojs/sass>
|
||||
|
||||
### Grunt extension
|
||||
|
||||
[@sindresorhus](https://github.com/sindresorhus/) has created a set of grunt tasks based on node-sass: <https://github.com/sindresorhus/grunt-sass>
|
||||
|
||||
### Gulp extension
|
||||
|
||||
[@dlmanning](https://github.com/dlmanning/) has created a gulp sass plugin based on node-sass: <https://github.com/dlmanning/gulp-sass>
|
||||
|
||||
### Harp
|
||||
|
||||
[@sintaxi](https://github.com/sintaxi)’s Harp web server implicitly compiles `.scss` files using node-sass: <https://github.com/sintaxi/harp>
|
||||
|
||||
### Metalsmith plugin
|
||||
|
||||
[@stevenschobert](https://github.com/stevenschobert/) has created a metalsmith plugin based on node-sass: <https://github.com/stevenschobert/metalsmith-sass>
|
||||
|
||||
### Meteor plugin
|
||||
|
||||
[@fourseven](https://github.com/fourseven) has created a meteor plugin based on node-sass: <https://github.com/fourseven/meteor-scss>
|
||||
|
||||
### Mimosa module
|
||||
|
||||
[@dbashford](https://github.com/dbashford) has created a Mimosa module for sass which includes node-sass: <https://github.com/dbashford/mimosa-sass>
|
||||
|
||||
## Example App
|
||||
|
||||
There is also an example connect app here: <https://github.com/andrew/node-sass-example>
|
||||
|
||||
## Rebuilding binaries
|
||||
|
||||
Node-sass includes pre-compiled binaries for popular platforms, to add a binary for your platform follow these steps:
|
||||
|
||||
Check out the project:
|
||||
|
||||
```bash
|
||||
git clone --recursive https://github.com/sass/node-sass.git
|
||||
cd node-sass
|
||||
npm install
|
||||
node scripts/build -f # use -d switch for debug release
|
||||
# if succeeded, it will generate and move
|
||||
# the binary in vendor directory.
|
||||
```
|
||||
|
||||
## Command Line Interface
|
||||
|
||||
The interface for command-line usage is fairly simplistic at this stage, as seen in the following usage section.
|
||||
|
||||
Output will be sent to stdout if the `--output` flag is omitted.
|
||||
|
||||
### Usage
|
||||
|
||||
`node-sass [options] <input> [output]`
|
||||
Or:
|
||||
`cat <input> | node-sass > output`
|
||||
|
||||
Example:
|
||||
|
||||
`node-sass src/style.scss dest/style.css`
|
||||
|
||||
**Options:**
|
||||
|
||||
```bash
|
||||
-w, --watch Watch a directory or file
|
||||
-r, --recursive Recursively watch directories or files
|
||||
-o, --output Output directory
|
||||
-x, --omit-source-map-url Omit source map URL comment from output
|
||||
-i, --indented-syntax Treat data from stdin as sass code (versus scss)
|
||||
-q, --quiet Suppress log output except on error
|
||||
-v, --version Prints version info
|
||||
--output-style CSS output style (nested | expanded | compact | compressed)
|
||||
--indent-type Indent type for output CSS (space | tab)
|
||||
--indent-width Indent width; number of spaces or tabs (maximum value: 10)
|
||||
--linefeed Linefeed style (cr | crlf | lf | lfcr)
|
||||
--source-comments Include debug info in output
|
||||
--source-map Emit source map
|
||||
--source-map-contents Embed include contents in map
|
||||
--source-map-embed Embed sourceMappingUrl as data URI
|
||||
--source-map-root Base path, will be emitted in source-map as is
|
||||
--include-path Path to look for imported files
|
||||
--follow Follow symlinked directories
|
||||
--precision The amount of precision allowed in decimal numbers
|
||||
--error-bell Output a bell character on errors
|
||||
--importer Path to .js file containing custom importer
|
||||
--functions Path to .js file containing custom functions
|
||||
--help Print usage info
|
||||
```
|
||||
|
||||
The `input` can be either a single `.scss` or `.sass`, or a directory. If the input is a directory the `--output` flag must also be supplied.
|
||||
|
||||
Also, note `--importer` takes the (absolute or relative to pwd) path to a js file, which needs to have a default `module.exports` set to the importer function. See our test [fixtures](https://github.com/sass/node-sass/tree/974f93e76ddd08ea850e3e663cfe64bb6a059dd3/test/fixtures/extras) for example.
|
||||
|
||||
The `--source-map` option accepts a boolean value, in which case it replaces destination extension with `.css.map`. It also accepts path to `.map` file and even path to the desired directory.
|
||||
When compiling a directory `--source-map` can either be a boolean value or a directory.
|
||||
|
||||
## Binary configuration parameters
|
||||
|
||||
node-sass supports different configuration parameters to change settings related to the sass binary such as binary name, binary path or alternative download path. Following parameters are supported by node-sass:
|
||||
|
||||
Variable name | .npmrc parameter | Process argument | Value
|
||||
-----------------|------------------|--------------------|------
|
||||
SASS_BINARY_NAME | sass_binary_name | --sass-binary-name | path
|
||||
SASS_BINARY_SITE | sass_binary_site | --sass-binary-site | URL
|
||||
SASS_BINARY_PATH | sass_binary_path | --sass-binary-path | path
|
||||
|
||||
These parameters can be used as environment variable:
|
||||
|
||||
* E.g. `export SASS_BINARY_SITE=http://example.com/`
|
||||
|
||||
As local or global [.npmrc](https://docs.npmjs.com/misc/config) configuration file:
|
||||
|
||||
* E.g. `sass_binary_site=http://example.com/`
|
||||
|
||||
As a process argument:
|
||||
|
||||
* E.g. `npm install node-sass --sass-binary-site=http://example.com/`
|
||||
|
||||
## Post-install Build
|
||||
|
||||
Install runs only two Mocha tests to see if your machine can use the pre-built [LibSass] which will save some time during install. If any tests fail it will build from source.
|
||||
|
||||
## Maintainers
|
||||
|
||||
This module is brought to you and maintained by the following people:
|
||||
|
||||
* Michael Mifsud - Project Lead ([Github](https://github.com/xzyfer) / [Twitter](https://twitter.com/xzyfer))
|
||||
* Andrew Nesbitt ([Github](https://github.com/andrew) / [Twitter](https://twitter.com/teabass))
|
||||
* Dean Mao ([Github](https://github.com/deanmao) / [Twitter](https://twitter.com/deanmao))
|
||||
* Brett Wilkins ([Github](https://github.com/bwilkins) / [Twitter](https://twitter.com/bjmaz))
|
||||
* Keith Cirkel ([Github](https://github.com/keithamus) / [Twitter](https://twitter.com/Keithamus))
|
||||
* Laurent Goderre ([Github](https://github.com/laurentgoderre) / [Twitter](https://twitter.com/laurentgoderre))
|
||||
* Nick Schonning ([Github](https://github.com/nschonni) / [Twitter](https://twitter.com/nschonni))
|
||||
* Adam Yeats ([Github](https://github.com/adamyeats) / [Twitter](https://twitter.com/adamyeats))
|
||||
* Adeel Mujahid ([Github](https://github.com/am11) / [Twitter](https://twitter.com/adeelbm))
|
||||
|
||||
## Contributors
|
||||
|
||||
We <3 our contributors! A special thanks to all those who have clocked in some dev time on this project, we really appreciate your hard work. You can find [a full list of those people here.](https://github.com/sass/node-sass/graphs/contributors)
|
||||
|
||||
### Note on Patches/Pull Requests
|
||||
|
||||
Check out our [Contributing guide](/.github/CONTRIBUTING.md)
|
||||
|
||||
## Copyright
|
||||
|
||||
Copyright (c) 2015 Andrew Nesbitt. See [LICENSE](https://github.com/sass/node-sass/blob/master/LICENSE) for details.
|
||||
|
||||
[LibSass]: https://github.com/sass/libsass
|
||||
+404
@@ -0,0 +1,404 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var Emitter = require('events').EventEmitter,
|
||||
forEach = require('async-foreach').forEach,
|
||||
Gaze = require('gaze'),
|
||||
meow = require('meow'),
|
||||
util = require('util'),
|
||||
path = require('path'),
|
||||
glob = require('glob'),
|
||||
sass = require('../lib'),
|
||||
render = require('../lib/render'),
|
||||
watcher = require('../lib/watcher'),
|
||||
stdout = require('stdout-stream'),
|
||||
stdin = require('get-stdin'),
|
||||
fs = require('fs');
|
||||
|
||||
/**
|
||||
* Initialize CLI
|
||||
*/
|
||||
|
||||
var cli = meow({
|
||||
pkg: '../package.json',
|
||||
version: sass.info,
|
||||
help: [
|
||||
'Usage:',
|
||||
' node-sass [options] <input.scss>',
|
||||
' cat <input.scss> | node-sass [options] > output.css',
|
||||
'',
|
||||
'Example: Compile foobar.scss to foobar.css',
|
||||
' node-sass --output-style compressed foobar.scss > foobar.css',
|
||||
' cat foobar.scss | node-sass --output-style compressed > foobar.css',
|
||||
'',
|
||||
'Example: Watch the sass directory for changes, compile with sourcemaps to the css directory',
|
||||
' node-sass --watch --recursive --output css',
|
||||
' --source-map true --source-map-contents sass',
|
||||
'',
|
||||
'Options',
|
||||
' -w, --watch Watch a directory or file',
|
||||
' -r, --recursive Recursively watch directories or files',
|
||||
' -o, --output Output directory',
|
||||
' -x, --omit-source-map-url Omit source map URL comment from output',
|
||||
' -i, --indented-syntax Treat data from stdin as sass code (versus scss)',
|
||||
' -q, --quiet Suppress log output except on error',
|
||||
' -v, --version Prints version info',
|
||||
' --output-style CSS output style (nested | expanded | compact | compressed)',
|
||||
' --indent-type Indent type for output CSS (space | tab)',
|
||||
' --indent-width Indent width; number of spaces or tabs (maximum value: 10)',
|
||||
' --linefeed Linefeed style (cr | crlf | lf | lfcr)',
|
||||
' --source-comments Include debug info in output',
|
||||
' --source-map Emit source map',
|
||||
' --source-map-contents Embed include contents in map',
|
||||
' --source-map-embed Embed sourceMappingUrl as data URI',
|
||||
' --source-map-root Base path, will be emitted in source-map as is',
|
||||
' --include-path Path to look for imported files',
|
||||
' --follow Follow symlinked directories',
|
||||
' --precision The amount of precision allowed in decimal numbers',
|
||||
' --error-bell Output a bell character on errors',
|
||||
' --importer Path to .js file containing custom importer',
|
||||
' --functions Path to .js file containing custom functions',
|
||||
' --help Print usage info'
|
||||
].join('\n')
|
||||
}, {
|
||||
boolean: [
|
||||
'error-bell',
|
||||
'follow',
|
||||
'indented-syntax',
|
||||
'omit-source-map-url',
|
||||
'quiet',
|
||||
'recursive',
|
||||
'source-map-embed',
|
||||
'source-map-contents',
|
||||
'source-comments',
|
||||
'watch'
|
||||
],
|
||||
string: [
|
||||
'functions',
|
||||
'importer',
|
||||
'include-path',
|
||||
'indent-type',
|
||||
'linefeed',
|
||||
'output',
|
||||
'output-style',
|
||||
'precision',
|
||||
'source-map-root'
|
||||
],
|
||||
alias: {
|
||||
c: 'source-comments',
|
||||
i: 'indented-syntax',
|
||||
q: 'quiet',
|
||||
o: 'output',
|
||||
r: 'recursive',
|
||||
x: 'omit-source-map-url',
|
||||
v: 'version',
|
||||
w: 'watch'
|
||||
},
|
||||
default: {
|
||||
'include-path': process.cwd(),
|
||||
'indent-type': 'space',
|
||||
'indent-width': 2,
|
||||
linefeed: 'lf',
|
||||
'output-style': 'nested',
|
||||
precision: 5,
|
||||
quiet: false,
|
||||
recursive: true
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Is a Directory
|
||||
*
|
||||
* @param {String} filePath
|
||||
* @returns {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function isDirectory(filePath) {
|
||||
var isDir = false;
|
||||
try {
|
||||
var absolutePath = path.resolve(filePath);
|
||||
isDir = fs.statSync(absolutePath).isDirectory();
|
||||
} catch (e) {
|
||||
isDir = e.code === 'ENOENT';
|
||||
}
|
||||
return isDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get correct glob pattern
|
||||
*
|
||||
* @param {Object} options
|
||||
* @returns {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function globPattern(options) {
|
||||
return options.recursive ? '**/*.{sass,scss}' : '*.{sass,scss}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create emitter
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getEmitter() {
|
||||
var emitter = new Emitter();
|
||||
|
||||
emitter.on('error', function(err) {
|
||||
if (options.errorBell) {
|
||||
err += '\x07';
|
||||
}
|
||||
console.error(err);
|
||||
if (!options.watch) {
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
emitter.on('warn', function(data) {
|
||||
if (!options.quiet) {
|
||||
console.warn(data);
|
||||
}
|
||||
});
|
||||
|
||||
emitter.on('log', stdout.write.bind(stdout));
|
||||
|
||||
return emitter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct options
|
||||
*
|
||||
* @param {Array} arguments
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getOptions(args, options) {
|
||||
var cssDir, sassDir, file, mapDir;
|
||||
options.src = args[0];
|
||||
|
||||
if (args[1]) {
|
||||
options.dest = path.resolve(args[1]);
|
||||
} else if (options.output) {
|
||||
options.dest = path.join(
|
||||
path.resolve(options.output),
|
||||
[path.basename(options.src, path.extname(options.src)), '.css'].join('')); // replace ext.
|
||||
}
|
||||
|
||||
if (options.directory) {
|
||||
sassDir = path.resolve(options.directory);
|
||||
file = path.relative(sassDir, args[0]);
|
||||
cssDir = path.resolve(options.output);
|
||||
options.dest = path.join(cssDir, file).replace(path.extname(file), '.css');
|
||||
}
|
||||
|
||||
if (options.sourceMap) {
|
||||
if(!options.sourceMapOriginal) {
|
||||
options.sourceMapOriginal = options.sourceMap;
|
||||
}
|
||||
|
||||
// check if sourceMap path ends with .map to avoid isDirectory false-positive
|
||||
var sourceMapIsDirectory = options.sourceMapOriginal.indexOf('.map', options.sourceMapOriginal.length - 4) === -1 && isDirectory(options.sourceMapOriginal);
|
||||
|
||||
if (options.sourceMapOriginal === 'true') {
|
||||
options.sourceMap = options.dest + '.map';
|
||||
} else if (!sourceMapIsDirectory) {
|
||||
options.sourceMap = path.resolve(options.sourceMapOriginal);
|
||||
} else if (sourceMapIsDirectory) {
|
||||
if (!options.directory) {
|
||||
options.sourceMap = path.resolve(options.sourceMapOriginal, path.basename(options.dest) + '.map');
|
||||
} else {
|
||||
sassDir = path.resolve(options.directory);
|
||||
file = path.relative(sassDir, args[0]);
|
||||
mapDir = path.resolve(options.sourceMapOriginal);
|
||||
options.sourceMap = path.join(mapDir, file).replace(path.extname(file), '.css.map');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Object} emitter
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function watch(options, emitter) {
|
||||
var handler = function(files) {
|
||||
files.added.forEach(function(file) {
|
||||
var watch = gaze.watched();
|
||||
Object.keys(watch).forEach(function (dir) {
|
||||
if (watch[dir].indexOf(file) !== -1) {
|
||||
gaze.add(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
files.changed.forEach(function(file) {
|
||||
if (path.basename(file)[0] !== '_') {
|
||||
renderFile(file, options, emitter);
|
||||
}
|
||||
});
|
||||
|
||||
files.removed.forEach(function(file) {
|
||||
gaze.remove(file);
|
||||
});
|
||||
};
|
||||
|
||||
var gaze = new Gaze();
|
||||
gaze.add(watcher.reset(options));
|
||||
gaze.on('error', emitter.emit.bind(emitter, 'error'));
|
||||
|
||||
gaze.on('changed', function(file) {
|
||||
handler(watcher.changed(file));
|
||||
});
|
||||
|
||||
gaze.on('added', function(file) {
|
||||
handler(watcher.added(file));
|
||||
});
|
||||
|
||||
gaze.on('deleted', function(file) {
|
||||
handler(watcher.deleted(file));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Object} emitter
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function run(options, emitter) {
|
||||
if (!Array.isArray(options.includePath)) {
|
||||
options.includePath = [options.includePath];
|
||||
}
|
||||
|
||||
if (options.directory) {
|
||||
if (!options.output) {
|
||||
emitter.emit('error', 'An output directory must be specified when compiling a directory');
|
||||
}
|
||||
if (!isDirectory(options.output)) {
|
||||
emitter.emit('error', 'An output directory must be specified when compiling a directory');
|
||||
}
|
||||
}
|
||||
|
||||
if (options.sourceMapOriginal && options.directory && !isDirectory(options.sourceMapOriginal) && options.sourceMapOriginal !== 'true') {
|
||||
emitter.emit('error', 'The --source-map option must be either a boolean or directory when compiling a directory');
|
||||
}
|
||||
|
||||
if (options.importer) {
|
||||
if ((path.resolve(options.importer) === path.normalize(options.importer).replace(/(.+)([\/|\\])$/, '$1'))) {
|
||||
options.importer = require(options.importer);
|
||||
} else {
|
||||
options.importer = require(path.resolve(options.importer));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.functions) {
|
||||
if ((path.resolve(options.functions) === path.normalize(options.functions).replace(/(.+)([\/|\\])$/, '$1'))) {
|
||||
options.functions = require(options.functions);
|
||||
} else {
|
||||
options.functions = require(path.resolve(options.functions));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.watch) {
|
||||
watch(options, emitter);
|
||||
} else if (options.directory) {
|
||||
renderDir(options, emitter);
|
||||
} else {
|
||||
render(options, emitter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a file
|
||||
*
|
||||
* @param {String} file
|
||||
* @param {Object} options
|
||||
* @param {Object} emitter
|
||||
* @api private
|
||||
*/
|
||||
function renderFile(file, options, emitter) {
|
||||
options = getOptions([path.resolve(file)], options);
|
||||
if (options.watch) {
|
||||
emitter.emit('warn', util.format('=> changed: %s', file));
|
||||
}
|
||||
render(options, emitter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render all sass files in a directory
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Object} emitter
|
||||
* @api private
|
||||
*/
|
||||
function renderDir(options, emitter) {
|
||||
var globPath = path.resolve(options.directory, globPattern(options));
|
||||
glob(globPath, { ignore: '**/_*', follow: options.follow }, function(err, files) {
|
||||
if (err) {
|
||||
return emitter.emit('error', util.format('You do not have permission to access this path: %s.', err.path));
|
||||
} else if (!files.length) {
|
||||
return emitter.emit('error', 'No input file was found.');
|
||||
}
|
||||
|
||||
forEach(files, function(subject) {
|
||||
emitter.once('done', this.async());
|
||||
renderFile(subject, options, emitter);
|
||||
}, function(successful, arr) {
|
||||
var outputDir = path.join(process.cwd(), options.output);
|
||||
emitter.emit('warn', util.format('Wrote %s CSS files to %s', arr.length, outputDir));
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Arguments and options
|
||||
*/
|
||||
|
||||
var options = getOptions(cli.input, cli.flags);
|
||||
var emitter = getEmitter();
|
||||
|
||||
/**
|
||||
* Show usage if no arguments are supplied
|
||||
*/
|
||||
|
||||
if (!options.src && process.stdin.isTTY) {
|
||||
emitter.emit('error', [
|
||||
'Provide a Sass file to render',
|
||||
'',
|
||||
'Example: Compile foobar.scss to foobar.css',
|
||||
' node-sass --output-style compressed foobar.scss > foobar.css',
|
||||
' cat foobar.scss | node-sass --output-style compressed > foobar.css',
|
||||
'',
|
||||
'Example: Watch the sass directory for changes, compile with sourcemaps to the css directory',
|
||||
' node-sass --watch --recursive --output css',
|
||||
' --source-map true --source-map-contents sass',
|
||||
].join('\n'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply arguments
|
||||
*/
|
||||
|
||||
if (options.src) {
|
||||
if (isDirectory(options.src)) {
|
||||
options.directory = options.src;
|
||||
}
|
||||
run(options, emitter);
|
||||
} else if (!process.stdin.isTTY) {
|
||||
stdin(function(data) {
|
||||
options.data = data;
|
||||
options.stdin = true;
|
||||
run(options, emitter);
|
||||
});
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
{
|
||||
'variables': {
|
||||
'libsass_ext%': '',
|
||||
},
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'binding',
|
||||
'win_delay_load_hook': 'true',
|
||||
'sources': [
|
||||
'src/binding.cpp',
|
||||
'src/create_string.cpp',
|
||||
'src/custom_function_bridge.cpp',
|
||||
'src/custom_importer_bridge.cpp',
|
||||
'src/sass_context_wrapper.cpp',
|
||||
'src/sass_types/boolean.cpp',
|
||||
'src/sass_types/color.cpp',
|
||||
'src/sass_types/error.cpp',
|
||||
'src/sass_types/factory.cpp',
|
||||
'src/sass_types/list.cpp',
|
||||
'src/sass_types/map.cpp',
|
||||
'src/sass_types/null.cpp',
|
||||
'src/sass_types/number.cpp',
|
||||
'src/sass_types/string.cpp'
|
||||
],
|
||||
'msvs_settings': {
|
||||
'VCLinkerTool': {
|
||||
'SetChecksum': 'true'
|
||||
}
|
||||
},
|
||||
'xcode_settings': {
|
||||
'OTHER_CPLUSPLUSFLAGS': [
|
||||
'-std=c++11'
|
||||
],
|
||||
'OTHER_LDFLAGS': [],
|
||||
'GCC_ENABLE_CPP_EXCEPTIONS': 'NO',
|
||||
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
||||
},
|
||||
'include_dirs': [
|
||||
'<!(node -e "require(\'nan\')")',
|
||||
],
|
||||
'conditions': [
|
||||
['libsass_ext == "" or libsass_ext == "no"', {
|
||||
'dependencies': [
|
||||
'src/libsass.gyp:libsass',
|
||||
]
|
||||
}],
|
||||
['libsass_ext == "auto"', {
|
||||
'cflags_cc': [
|
||||
'<!(pkg-config --cflags libsass)',
|
||||
],
|
||||
'link_settings': {
|
||||
'ldflags': [
|
||||
'<!(pkg-config --libs-only-other --libs-only-L libsass)',
|
||||
],
|
||||
'libraries': [
|
||||
'<!(pkg-config --libs-only-l libsass)',
|
||||
],
|
||||
}
|
||||
}],
|
||||
['libsass_ext == "yes"', {
|
||||
'cflags_cc': [
|
||||
'<(libsass_cflags)',
|
||||
],
|
||||
'link_settings': {
|
||||
'ldflags': [
|
||||
'<(libsass_ldflags)',
|
||||
],
|
||||
'libraries': [
|
||||
'<(libsass_library)',
|
||||
],
|
||||
}
|
||||
}],
|
||||
['OS=="win" and MSVS_VERSION == "2015"', {
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
'AdditionalOptions': [
|
||||
# disable Thread-Safe "Magic" for local static variables
|
||||
'/Zc:threadSafeInit-',
|
||||
],
|
||||
},
|
||||
},
|
||||
}],
|
||||
['OS!="win"', {
|
||||
'cflags_cc+': [
|
||||
'-std=c++0x'
|
||||
]
|
||||
}]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*!
|
||||
* node-sass: lib/binding.js
|
||||
*/
|
||||
|
||||
var errors = require('./errors');
|
||||
|
||||
/**
|
||||
* Require binding
|
||||
*/
|
||||
module.exports = function(ext) {
|
||||
if (!ext.hasBinary(ext.getBinaryPath())) {
|
||||
if (!ext.isSupportedEnvironment()) {
|
||||
throw new Error(errors.unsupportedEnvironment());
|
||||
} else {
|
||||
throw new Error(errors.missingBinary());
|
||||
}
|
||||
}
|
||||
|
||||
return require(ext.getBinaryPath());
|
||||
};
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*!
|
||||
* node-sass: lib/errors.js
|
||||
*/
|
||||
|
||||
var sass = require('./extensions'),
|
||||
pkg = require('../package.json');
|
||||
|
||||
function humanEnvironment() {
|
||||
return sass.getHumanEnvironment(sass.getBinaryName());
|
||||
}
|
||||
|
||||
function foundBinaries() {
|
||||
return [
|
||||
'Found bindings for the following environments:',
|
||||
foundBinariesList(),
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function foundBinariesList() {
|
||||
return sass.getInstalledBinaries().map(function(env) {
|
||||
return ' - ' + sass.getHumanEnvironment(env);
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
function missingBinaryFooter() {
|
||||
return [
|
||||
'This usually happens because your environment has changed since running `npm install`.',
|
||||
'Run `npm rebuild node-sass --force` to build the binding for your current environment.',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
module.exports.unsupportedEnvironment = function() {
|
||||
return [
|
||||
'Node Sass does not yet support your current environment: ' + humanEnvironment(),
|
||||
'For more information on which environments are supported please see:',
|
||||
'https://github.com/sass/node-sass/releases/tag/v' + pkg.version
|
||||
].join('\n');
|
||||
};
|
||||
|
||||
module.exports.missingBinary = function() {
|
||||
return [
|
||||
'Missing binding ' + sass.getBinaryPath(),
|
||||
'Node Sass could not find a binding for your current environment: ' + humanEnvironment(),
|
||||
'',
|
||||
foundBinaries(),
|
||||
'',
|
||||
missingBinaryFooter(),
|
||||
].join('\n');
|
||||
};
|
||||
+424
@@ -0,0 +1,424 @@
|
||||
/*!
|
||||
* node-sass: lib/extensions.js
|
||||
*/
|
||||
|
||||
var eol = require('os').EOL,
|
||||
fs = require('fs'),
|
||||
pkg = require('../package.json'),
|
||||
mkdir = require('mkdirp'),
|
||||
path = require('path'),
|
||||
defaultBinaryPath = path.join(__dirname, '..', 'vendor'),
|
||||
trueCasePathSync = require('true-case-path');
|
||||
|
||||
/**
|
||||
* Get the human readable name of the Platform that is running
|
||||
*
|
||||
* @param {string} platform - An OS platform to match, or null to fallback to
|
||||
* the current process platform
|
||||
* @return {Object} The name of the platform if matched, false otherwise
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
function getHumanPlatform(platform) {
|
||||
switch (platform || process.platform) {
|
||||
case 'darwin': return 'OS X';
|
||||
case 'freebsd': return 'FreeBSD';
|
||||
case 'linux': return 'Linux';
|
||||
case 'linux_musl': return 'Linux/musl';
|
||||
case 'win32': return 'Windows';
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a more readable version of the architecture
|
||||
*
|
||||
* @param {string} arch - An instruction architecture name to match, or null to
|
||||
* lookup the current process architecture
|
||||
* @return {Object} The value of the process architecture, or false if unknown
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
function getHumanArchitecture(arch) {
|
||||
switch (arch || process.arch) {
|
||||
case 'ia32': return '32-bit';
|
||||
case 'x86': return '32-bit';
|
||||
case 'x64': return '64-bit';
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the friendly name of the Node environment being run
|
||||
*
|
||||
* @param {Object} abi - A Node Application Binary Interface value, or null to
|
||||
* fallback to the current Node ABI
|
||||
* @return {Object} Returns a string name of the Node environment or false if
|
||||
* unmatched
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
function getHumanNodeVersion(abi) {
|
||||
switch (parseInt(abi || process.versions.modules, 10)) {
|
||||
case 11: return 'Node 0.10.x';
|
||||
case 14: return 'Node 0.12.x';
|
||||
case 42: return 'io.js 1.x';
|
||||
case 43: return 'io.js 1.1.x';
|
||||
case 44: return 'io.js 2.x';
|
||||
case 45: return 'io.js 3.x';
|
||||
case 46: return 'Node.js 4.x';
|
||||
case 47: return 'Node.js 5.x';
|
||||
case 48: return 'Node.js 6.x';
|
||||
case 49: return 'Electron 1.3.x';
|
||||
case 50: return 'Electron 1.4.x';
|
||||
case 51: return 'Node.js 7.x';
|
||||
case 53: return 'Electron 1.6.x';
|
||||
case 57: return 'Node.js 8.x';
|
||||
case 59: return 'Node.js 9.x';
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a human readable description of where node-sass is running to support
|
||||
* user error reporting when something goes wrong
|
||||
*
|
||||
* @param {string} env - The name of the native bindings that is to be parsed
|
||||
* @return {string} A description of what os, architecture, and Node version
|
||||
* that is being run
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
function getHumanEnvironment(env) {
|
||||
var binding = env.replace(/_binding\.node$/, ''),
|
||||
parts = binding.split('-'),
|
||||
platform = getHumanPlatform(parts[0]),
|
||||
arch = getHumanArchitecture(parts[1]),
|
||||
runtime = getHumanNodeVersion(parts[2]);
|
||||
|
||||
if (parts.length !== 3) {
|
||||
return 'Unknown environment (' + binding + ')';
|
||||
}
|
||||
|
||||
if (!platform) {
|
||||
platform = 'Unsupported platform (' + parts[0] + ')';
|
||||
}
|
||||
|
||||
if (!arch) {
|
||||
arch = 'Unsupported architecture (' + parts[1] + ')';
|
||||
}
|
||||
|
||||
if (!runtime) {
|
||||
runtime = 'Unsupported runtime (' + parts[2] + ')';
|
||||
}
|
||||
|
||||
return [
|
||||
platform, arch, 'with', runtime,
|
||||
].join(' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the binaries under the default path
|
||||
*
|
||||
* @return {Array} The currently installed node-sass bindings
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
function getInstalledBinaries() {
|
||||
return fs.readdirSync(defaultBinaryPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that an environment matches the whitelisted values or the current
|
||||
* environment if no parameters are passed
|
||||
*
|
||||
* @param {string} platform - The name of the OS platform(darwin, win32, etc...)
|
||||
* @param {string} arch - The instruction set architecture of the Node environment
|
||||
* @param {string} abi - The Node Application Binary Interface
|
||||
* @return {Boolean} True, if node-sass supports the current platform, false otherwise
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
function isSupportedEnvironment(platform, arch, abi) {
|
||||
return (
|
||||
false !== getHumanPlatform(platform) &&
|
||||
false !== getHumanArchitecture(arch) &&
|
||||
false !== getHumanNodeVersion(abi)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a CLI argument
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Array} args
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getArgument(name, args) {
|
||||
var flags = args || process.argv.slice(2),
|
||||
index = flags.lastIndexOf(name);
|
||||
|
||||
if (index === -1 || index + 1 >= flags.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return flags[index + 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get binary name.
|
||||
* If environment variable SASS_BINARY_NAME,
|
||||
* .npmrc variable sass_binary_name or
|
||||
* process argument --binary-name is provided,
|
||||
* return it as is, otherwise make default binary
|
||||
* name: {platform}-{arch}-{v8 version}.node
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function getBinaryName() {
|
||||
var binaryName,
|
||||
variant,
|
||||
platform = process.platform;
|
||||
|
||||
if (getArgument('--sass-binary-name')) {
|
||||
binaryName = getArgument('--sass-binary-name');
|
||||
} else if (process.env.SASS_BINARY_NAME) {
|
||||
binaryName = process.env.SASS_BINARY_NAME;
|
||||
} else if (process.env.npm_config_sass_binary_name) {
|
||||
binaryName = process.env.npm_config_sass_binary_name;
|
||||
} else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryName) {
|
||||
binaryName = pkg.nodeSassConfig.binaryName;
|
||||
} else {
|
||||
variant = getPlatformVariant();
|
||||
if (variant) {
|
||||
platform += '_' + variant;
|
||||
}
|
||||
|
||||
binaryName = [
|
||||
platform, '-',
|
||||
process.arch, '-',
|
||||
process.versions.modules
|
||||
].join('');
|
||||
}
|
||||
|
||||
return [binaryName, 'binding.node'].join('_');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the URL to fetch binary file from.
|
||||
* By default fetch from the node-sass distribution
|
||||
* site on GitHub.
|
||||
*
|
||||
* The default URL can be overriden using
|
||||
* the environment variable SASS_BINARY_SITE,
|
||||
* .npmrc variable sass_binary_site or
|
||||
* or a command line option --sass-binary-site:
|
||||
*
|
||||
* node scripts/install.js --sass-binary-site http://example.com/
|
||||
*
|
||||
* The URL should to the mirror of the repository
|
||||
* laid out as follows:
|
||||
*
|
||||
* SASS_BINARY_SITE/
|
||||
*
|
||||
* v3.0.0
|
||||
* v3.0.0/freebsd-x64-14_binding.node
|
||||
* ....
|
||||
* v3.0.0
|
||||
* v3.0.0/freebsd-ia32-11_binding.node
|
||||
* v3.0.0/freebsd-x64-42_binding.node
|
||||
* ... etc. for all supported versions and platforms
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function getBinaryUrl() {
|
||||
var site = getArgument('--sass-binary-site') ||
|
||||
process.env.SASS_BINARY_SITE ||
|
||||
process.env.npm_config_sass_binary_site ||
|
||||
(pkg.nodeSassConfig && pkg.nodeSassConfig.binarySite) ||
|
||||
'https://github.com/sass/node-sass/releases/download';
|
||||
|
||||
return [site, 'v' + pkg.version, getBinaryName()].join('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get binary path.
|
||||
* If environment variable SASS_BINARY_PATH,
|
||||
* .npmrc variable sass_binary_path or
|
||||
* process argument --sass-binary-path is provided,
|
||||
* select it by appending binary name, otherwise
|
||||
* make default binary path using binary name.
|
||||
* Once the primary selection is made, check if
|
||||
* callers wants to throw if file not exists before
|
||||
* returning.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function getBinaryPath() {
|
||||
var binaryPath;
|
||||
|
||||
if (getArgument('--sass-binary-path')) {
|
||||
binaryPath = getArgument('--sass-binary-path');
|
||||
} else if (process.env.SASS_BINARY_PATH) {
|
||||
binaryPath = process.env.SASS_BINARY_PATH;
|
||||
} else if (process.env.npm_config_sass_binary_path) {
|
||||
binaryPath = process.env.npm_config_sass_binary_path;
|
||||
} else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryPath) {
|
||||
binaryPath = pkg.nodeSassConfig.binaryPath;
|
||||
} else {
|
||||
binaryPath = path.join(defaultBinaryPath, getBinaryName().replace(/_(?=binding\.node)/, '/'));
|
||||
}
|
||||
|
||||
if (process.versions.modules < 46) {
|
||||
return binaryPath;
|
||||
}
|
||||
|
||||
try {
|
||||
return trueCasePathSync(binaryPath) || binaryPath;
|
||||
} catch (e) {
|
||||
return binaryPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An array of paths suitable for use as a local disk cache of the binding.
|
||||
*
|
||||
* @return {[]String} an array of paths
|
||||
* @api public
|
||||
*/
|
||||
function getCachePathCandidates() {
|
||||
return [
|
||||
process.env.npm_config_sass_binary_cache,
|
||||
process.env.npm_config_cache,
|
||||
].filter(function(_) { return _; });
|
||||
}
|
||||
|
||||
/**
|
||||
* The most suitable location for caching the binding on disk.
|
||||
*
|
||||
* Given the candidates directories provided by `getCachePathCandidates()` this
|
||||
* returns the first writable directory. By treating the candidate directories
|
||||
* as a prioritised list this method is deterministic, assuming no change to the
|
||||
* local environment.
|
||||
*
|
||||
* @return {String} directory to cache binding
|
||||
* @api public
|
||||
*/
|
||||
function getBinaryCachePath() {
|
||||
var i,
|
||||
cachePath,
|
||||
cachePathCandidates = getCachePathCandidates();
|
||||
|
||||
for (i = 0; i < cachePathCandidates.length; i++) {
|
||||
cachePath = path.join(cachePathCandidates[i], pkg.name, pkg.version);
|
||||
|
||||
try {
|
||||
mkdir.sync(cachePath);
|
||||
return cachePath;
|
||||
} catch (e) {
|
||||
// Directory is not writable, try another
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* The cached binding
|
||||
*
|
||||
* Check the candidates directories provided by `getCachePathCandidates()` for
|
||||
* the binding file, if it exists. By treating the candidate directories
|
||||
* as a prioritised list this method is deterministic, assuming no change to the
|
||||
* local environment.
|
||||
*
|
||||
* @return {String} path to cached binary
|
||||
* @api public
|
||||
*/
|
||||
function getCachedBinary() {
|
||||
var i,
|
||||
cachePath,
|
||||
cacheBinary,
|
||||
cachePathCandidates = getCachePathCandidates(),
|
||||
binaryName = getBinaryName();
|
||||
|
||||
for (i = 0; i < cachePathCandidates.length; i++) {
|
||||
cachePath = path.join(cachePathCandidates[i], pkg.name, pkg.version);
|
||||
cacheBinary = path.join(cachePath, binaryName);
|
||||
|
||||
if (fs.existsSync(cacheBinary)) {
|
||||
return cacheBinary;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the supplied binary path exist
|
||||
*
|
||||
* @param {String} binaryPath
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function hasBinary(binaryPath) {
|
||||
return fs.existsSync(binaryPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Sass version information
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function getVersionInfo(binding) {
|
||||
return [
|
||||
['node-sass', pkg.version, '(Wrapper)', '[JavaScript]'].join('\t'),
|
||||
['libsass ', binding.libsassVersion(), '(Sass Compiler)', '[C/C++]'].join('\t'),
|
||||
].join(eol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the platform variant, currently either an empty string or 'musl' for Linux/musl platforms.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function getPlatformVariant() {
|
||||
var contents = '';
|
||||
|
||||
if (process.platform !== 'linux') {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
contents = fs.readFileSync(process.execPath);
|
||||
|
||||
// Buffer.indexOf was added in v1.5.0 so cast to string for old node
|
||||
// Delay contents.toStrings because it's expensive
|
||||
if (!contents.indexOf) {
|
||||
contents = contents.toString();
|
||||
}
|
||||
|
||||
if (contents.indexOf('libc.musl-x86_64.so.1') !== -1) {
|
||||
return 'musl';
|
||||
}
|
||||
} catch (err) { } // eslint-disable-line no-empty
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
module.exports.hasBinary = hasBinary;
|
||||
module.exports.getBinaryUrl = getBinaryUrl;
|
||||
module.exports.getBinaryName = getBinaryName;
|
||||
module.exports.getBinaryPath = getBinaryPath;
|
||||
module.exports.getBinaryCachePath = getBinaryCachePath;
|
||||
module.exports.getCachedBinary = getCachedBinary;
|
||||
module.exports.getCachePathCandidates = getCachePathCandidates;
|
||||
module.exports.getVersionInfo = getVersionInfo;
|
||||
module.exports.getHumanEnvironment = getHumanEnvironment;
|
||||
module.exports.getInstalledBinaries = getInstalledBinaries;
|
||||
module.exports.isSupportedEnvironment = isSupportedEnvironment;
|
||||
+475
@@ -0,0 +1,475 @@
|
||||
/*!
|
||||
* node-sass: lib/index.js
|
||||
*/
|
||||
|
||||
var path = require('path'),
|
||||
clonedeep = require('lodash.clonedeep'),
|
||||
assign = require('lodash.assign'),
|
||||
sass = require('./extensions');
|
||||
|
||||
/**
|
||||
* Require binding
|
||||
*/
|
||||
|
||||
var binding = require('./binding')(sass);
|
||||
|
||||
/**
|
||||
* Get input file
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getInputFile(options) {
|
||||
return options.file ? path.resolve(options.file) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output file
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getOutputFile(options) {
|
||||
var outFile = options.outFile;
|
||||
|
||||
if (!outFile || typeof outFile !== 'string' || (!options.data && !options.file)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return path.resolve(outFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get source map
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getSourceMap(options) {
|
||||
var sourceMap = options.sourceMap;
|
||||
|
||||
if (sourceMap && typeof sourceMap !== 'string' && options.outFile) {
|
||||
sourceMap = options.outFile + '.map';
|
||||
}
|
||||
|
||||
return sourceMap && typeof sourceMap === 'string' ? path.resolve(sourceMap) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stats
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getStats(options) {
|
||||
var stats = {};
|
||||
|
||||
stats.entry = options.file || 'data';
|
||||
stats.start = Date.now();
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* End stats
|
||||
*
|
||||
* @param {Object} stats
|
||||
* @param {Object} sourceMap
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function endStats(stats) {
|
||||
stats.end = Date.now();
|
||||
stats.duration = stats.end - stats.start;
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getStyle(options) {
|
||||
var styles = {
|
||||
nested: 0,
|
||||
expanded: 1,
|
||||
compact: 2,
|
||||
compressed: 3
|
||||
};
|
||||
|
||||
return styles[options.outputStyle] || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get indent width
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getIndentWidth(options) {
|
||||
var width = parseInt(options.indentWidth) || 2;
|
||||
|
||||
return width > 10 ? 2 : width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get indent type
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getIndentType(options) {
|
||||
var types = {
|
||||
space: 0,
|
||||
tab: 1
|
||||
};
|
||||
|
||||
return types[options.indentType] || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get linefeed
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getLinefeed(options) {
|
||||
var feeds = {
|
||||
cr: '\r',
|
||||
crlf: '\r\n',
|
||||
lf: '\n',
|
||||
lfcr: '\n\r'
|
||||
};
|
||||
|
||||
return feeds[options.linefeed] || '\n';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an includePaths string
|
||||
* from the options.includePaths array and the SASS_PATH environment variable
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function buildIncludePaths(options) {
|
||||
options.includePaths = options.includePaths || [];
|
||||
|
||||
if (process.env.hasOwnProperty('SASS_PATH')) {
|
||||
options.includePaths = options.includePaths.concat(
|
||||
process.env.SASS_PATH.split(path.delimiter)
|
||||
);
|
||||
}
|
||||
|
||||
// Preserve the behaviour people have come to expect.
|
||||
// This behaviour was removed from Sass in 3.4 and
|
||||
// LibSass in 3.5.
|
||||
options.includePaths.unshift(process.cwd());
|
||||
|
||||
return options.includePaths.join(path.delimiter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getOptions(opts, cb) {
|
||||
if (typeof opts !== 'object') {
|
||||
throw new Error('Invalid: options is not an object.');
|
||||
}
|
||||
var options = clonedeep(opts || {});
|
||||
|
||||
options.sourceComments = options.sourceComments || false;
|
||||
if (options.hasOwnProperty('file')) {
|
||||
options.file = getInputFile(options);
|
||||
}
|
||||
options.outFile = getOutputFile(options);
|
||||
options.includePaths = buildIncludePaths(options);
|
||||
options.precision = parseInt(options.precision) || 5;
|
||||
options.sourceMap = getSourceMap(options);
|
||||
options.style = getStyle(options);
|
||||
options.indentWidth = getIndentWidth(options);
|
||||
options.indentType = getIndentType(options);
|
||||
options.linefeed = getLinefeed(options);
|
||||
|
||||
// context object represents node-sass environment
|
||||
options.context = { options: options, callback: cb };
|
||||
|
||||
options.result = {
|
||||
stats: getStats(options)
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a callback and transforms any exception raised into a sass error
|
||||
*
|
||||
* @param {Function} callback
|
||||
* @param {Array} arguments
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function tryCallback(callback, args) {
|
||||
try {
|
||||
return callback.apply(this, args);
|
||||
} catch (e) {
|
||||
if (typeof e === 'string') {
|
||||
return new binding.types.Error(e);
|
||||
} else if (e instanceof Error) {
|
||||
return new binding.types.Error(e.message);
|
||||
} else {
|
||||
return new binding.types.Error('An unexpected error occurred');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the signature of custom functions to make it possible to just supply the
|
||||
* function name and have the signature default to `fn(...)`. The callback is adjusted
|
||||
* to transform the input sass list into discrete arguments.
|
||||
*
|
||||
* @param {String} signature
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function normalizeFunctionSignature(signature, callback) {
|
||||
if (!/^\*|@warn|@error|@debug|\w+\(.*\)$/.test(signature)) {
|
||||
if (!/\w+/.test(signature)) {
|
||||
throw new Error('Invalid function signature format "' + signature + '"');
|
||||
}
|
||||
|
||||
return {
|
||||
signature: signature + '(...)',
|
||||
callback: function() {
|
||||
var args = Array.prototype.slice.call(arguments),
|
||||
list = args.shift(),
|
||||
i;
|
||||
|
||||
for (i = list.getLength() - 1; i >= 0; i--) {
|
||||
args.unshift(list.getValue(i));
|
||||
}
|
||||
|
||||
return callback.apply(this, args);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
signature: signature,
|
||||
callback: callback
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Render
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports.render = function(opts, cb) {
|
||||
var options = getOptions(opts, cb);
|
||||
|
||||
// options.error and options.success are for libsass binding
|
||||
options.error = function(err) {
|
||||
var payload = assign(new Error(), JSON.parse(err));
|
||||
|
||||
if (cb) {
|
||||
options.context.callback.call(options.context, payload, null);
|
||||
}
|
||||
};
|
||||
|
||||
options.success = function() {
|
||||
var result = options.result;
|
||||
var stats = endStats(result.stats);
|
||||
var payload = {
|
||||
css: result.css,
|
||||
map: result.map,
|
||||
stats: stats
|
||||
};
|
||||
|
||||
if (cb) {
|
||||
options.context.callback.call(options.context, null, payload);
|
||||
}
|
||||
};
|
||||
|
||||
var importer = options.importer;
|
||||
|
||||
if (importer) {
|
||||
if (Array.isArray(importer)) {
|
||||
options.importer = [];
|
||||
importer.forEach(function(subject, index) {
|
||||
options.importer[index] = function(file, prev, bridge) {
|
||||
function done(result) {
|
||||
bridge.success(result === module.exports.NULL ? null : result);
|
||||
}
|
||||
|
||||
var result = subject.call(options.context, file, prev, done);
|
||||
|
||||
if (result !== undefined) {
|
||||
done(result);
|
||||
}
|
||||
};
|
||||
});
|
||||
} else {
|
||||
options.importer = function(file, prev, bridge) {
|
||||
function done(result) {
|
||||
bridge.success(result === module.exports.NULL ? null : result);
|
||||
}
|
||||
|
||||
var result = importer.call(options.context, file, prev, done);
|
||||
|
||||
if (result !== undefined) {
|
||||
done(result);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var functions = clonedeep(options.functions);
|
||||
|
||||
if (functions) {
|
||||
options.functions = {};
|
||||
|
||||
Object.keys(functions).forEach(function(subject) {
|
||||
var cb = normalizeFunctionSignature(subject, functions[subject]);
|
||||
|
||||
options.functions[cb.signature] = function() {
|
||||
var args = Array.prototype.slice.call(arguments),
|
||||
bridge = args.pop();
|
||||
|
||||
function done(data) {
|
||||
bridge.success(data);
|
||||
}
|
||||
|
||||
var result = tryCallback(cb.callback.bind(options.context), args.concat(done));
|
||||
|
||||
if (result) {
|
||||
done(result);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (options.data) {
|
||||
binding.render(options);
|
||||
} else if (options.file) {
|
||||
binding.renderFile(options);
|
||||
} else {
|
||||
cb({status: 3, message: 'No input specified: provide a file name or a source string to process' });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Render sync
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports.renderSync = function(opts) {
|
||||
var options = getOptions(opts);
|
||||
var importer = options.importer;
|
||||
|
||||
if (importer) {
|
||||
if (Array.isArray(importer)) {
|
||||
options.importer = [];
|
||||
importer.forEach(function(subject, index) {
|
||||
options.importer[index] = function(file, prev) {
|
||||
var result = subject.call(options.context, file, prev);
|
||||
|
||||
return result === module.exports.NULL ? null : result;
|
||||
};
|
||||
});
|
||||
} else {
|
||||
options.importer = function(file, prev) {
|
||||
var result = importer.call(options.context, file, prev);
|
||||
|
||||
return result === module.exports.NULL ? null : result;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var functions = clonedeep(options.functions);
|
||||
|
||||
if (options.functions) {
|
||||
options.functions = {};
|
||||
|
||||
Object.keys(functions).forEach(function(signature) {
|
||||
var cb = normalizeFunctionSignature(signature, functions[signature]);
|
||||
|
||||
options.functions[cb.signature] = function() {
|
||||
return tryCallback(cb.callback.bind(options.context), arguments);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
var status;
|
||||
if (options.data) {
|
||||
status = binding.renderSync(options);
|
||||
} else if (options.file) {
|
||||
status = binding.renderFileSync(options);
|
||||
} else {
|
||||
throw new Error('No input specified: provide a file name or a source string to process');
|
||||
}
|
||||
|
||||
var result = options.result;
|
||||
|
||||
if (status) {
|
||||
result.stats = endStats(result.stats);
|
||||
return result;
|
||||
}
|
||||
|
||||
throw assign(new Error(), JSON.parse(result.error));
|
||||
};
|
||||
|
||||
/**
|
||||
* API Info
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports.info = sass.getVersionInfo(binding);
|
||||
|
||||
/**
|
||||
* Expose sass types
|
||||
*/
|
||||
|
||||
module.exports.types = binding.types;
|
||||
module.exports.TRUE = binding.types.Boolean.TRUE;
|
||||
module.exports.FALSE = binding.types.Boolean.FALSE;
|
||||
module.exports.NULL = binding.types.Null.NULL;
|
||||
|
||||
/**
|
||||
* Polyfill the old API
|
||||
*
|
||||
* TODO: remove for 4.0
|
||||
*/
|
||||
|
||||
function processSassDeprecationMessage() {
|
||||
console.log('Deprecation warning: `process.sass` is an undocumented internal that will be removed in future versions of Node Sass.');
|
||||
}
|
||||
|
||||
process.sass = process.sass || {
|
||||
get versionInfo() { processSassDeprecationMessage(); return module.exports.info; },
|
||||
get binaryName() { processSassDeprecationMessage(); return sass.getBinaryName(); },
|
||||
get binaryUrl() { processSassDeprecationMessage(); return sass.getBinaryUrl(); },
|
||||
get binaryPath() { processSassDeprecationMessage(); return sass.getBinaryPath(); },
|
||||
get getBinaryPath() { processSassDeprecationMessage(); return sass.getBinaryPath; },
|
||||
};
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*!
|
||||
* node-sass: lib/render.js
|
||||
*/
|
||||
|
||||
var chalk = require('chalk'),
|
||||
fs = require('fs'),
|
||||
mkdirp = require('mkdirp'),
|
||||
path = require('path'),
|
||||
sass = require('./');
|
||||
|
||||
/**
|
||||
* Render
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Object} emitter
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function(options, emitter) {
|
||||
var renderOptions = {
|
||||
includePaths: options.includePath,
|
||||
omitSourceMapUrl: options.omitSourceMapUrl,
|
||||
indentedSyntax: options.indentedSyntax,
|
||||
outFile: options.dest,
|
||||
outputStyle: options.outputStyle,
|
||||
precision: options.precision,
|
||||
sourceComments: options.sourceComments,
|
||||
sourceMapEmbed: options.sourceMapEmbed,
|
||||
sourceMapContents: options.sourceMapContents,
|
||||
sourceMap: options.sourceMap,
|
||||
sourceMapRoot: options.sourceMapRoot,
|
||||
importer: options.importer,
|
||||
functions: options.functions,
|
||||
indentWidth: options.indentWidth,
|
||||
indentType: options.indentType,
|
||||
linefeed: options.linefeed
|
||||
};
|
||||
|
||||
if (options.data) {
|
||||
renderOptions.data = options.data;
|
||||
} else if (options.src) {
|
||||
renderOptions.file = options.src;
|
||||
}
|
||||
|
||||
var sourceMap = options.sourceMap;
|
||||
var destination = options.dest;
|
||||
var stdin = options.stdin;
|
||||
|
||||
var success = function(result) {
|
||||
var todo = 1;
|
||||
var done = function() {
|
||||
if (--todo <= 0) {
|
||||
emitter.emit('done');
|
||||
}
|
||||
};
|
||||
|
||||
if (!destination || stdin) {
|
||||
emitter.emit('log', result.css.toString());
|
||||
|
||||
if (sourceMap && !options.sourceMapEmbed) {
|
||||
emitter.emit('log', result.map.toString());
|
||||
}
|
||||
|
||||
return done();
|
||||
}
|
||||
|
||||
emitter.emit('warn', chalk.green('Rendering Complete, saving .css file...'));
|
||||
|
||||
mkdirp(path.dirname(destination), function(err) {
|
||||
if (err) {
|
||||
return emitter.emit('error', chalk.red(err));
|
||||
}
|
||||
|
||||
fs.writeFile(destination, result.css.toString(), function(err) {
|
||||
if (err) {
|
||||
return emitter.emit('error', chalk.red(err));
|
||||
}
|
||||
|
||||
emitter.emit('warn', chalk.green('Wrote CSS to ' + destination));
|
||||
emitter.emit('write', err, destination, result.css.toString());
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
if (sourceMap) {
|
||||
todo++;
|
||||
|
||||
mkdirp(path.dirname(sourceMap), function(err) {
|
||||
if (err) {
|
||||
return emitter.emit('error', chalk.red(err));
|
||||
}
|
||||
fs.writeFile(sourceMap, result.map, function(err) {
|
||||
if (err) {
|
||||
return emitter.emit('error', chalk.red('Error' + err));
|
||||
}
|
||||
|
||||
emitter.emit('warn', chalk.green('Wrote Source Map to ' + sourceMap));
|
||||
emitter.emit('write-source-map', err, sourceMap, result.map);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
emitter.emit('render', result.css.toString());
|
||||
};
|
||||
|
||||
var error = function(error) {
|
||||
emitter.emit('error', chalk.red(JSON.stringify(error, null, 2)));
|
||||
};
|
||||
|
||||
var renderCallback = function(err, result) {
|
||||
if (err) {
|
||||
error(err);
|
||||
}
|
||||
else {
|
||||
success(result);
|
||||
}
|
||||
};
|
||||
|
||||
sass.render(renderOptions, renderCallback);
|
||||
};
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
var grapher = require('sass-graph'),
|
||||
clonedeep = require('lodash.clonedeep'),
|
||||
path = require('path'),
|
||||
config = {},
|
||||
watcher = {},
|
||||
graph = null;
|
||||
|
||||
watcher.reset = function(opts) {
|
||||
config = clonedeep(opts || config || {});
|
||||
var options = {
|
||||
loadPaths: config.includePath,
|
||||
extensions: ['scss', 'sass', 'css'],
|
||||
follow: config.follow,
|
||||
};
|
||||
|
||||
if (config.directory) {
|
||||
graph = grapher.parseDir(config.directory, options);
|
||||
} else {
|
||||
graph = grapher.parseFile(config.src, options);
|
||||
}
|
||||
|
||||
return Object.keys(graph.index);
|
||||
};
|
||||
|
||||
watcher.changed = function(absolutePath) {
|
||||
var files = {
|
||||
added: [],
|
||||
changed: [],
|
||||
removed: [],
|
||||
};
|
||||
|
||||
this.reset();
|
||||
|
||||
if (absolutePath && path.basename(absolutePath)[0] !== '_') {
|
||||
files.changed.push(absolutePath);
|
||||
}
|
||||
|
||||
graph.visitAncestors(absolutePath, function(parent) {
|
||||
if (path.basename(parent)[0] !== '_') {
|
||||
files.changed.push(parent);
|
||||
}
|
||||
});
|
||||
|
||||
graph.visitDescendents(absolutePath, function(child) {
|
||||
files.added.push(child);
|
||||
});
|
||||
|
||||
return files;
|
||||
};
|
||||
|
||||
watcher.added = function(absolutePath) {
|
||||
var files = {
|
||||
added: [],
|
||||
changed: [],
|
||||
removed: [],
|
||||
};
|
||||
|
||||
this.reset();
|
||||
|
||||
if (Object.keys(graph.index).indexOf(absolutePath) === -1) {
|
||||
files.added.push(absolutePath);
|
||||
}
|
||||
|
||||
graph.visitDescendents(absolutePath, function(child) {
|
||||
files.added.push(child);
|
||||
});
|
||||
|
||||
return files;
|
||||
};
|
||||
|
||||
watcher.removed = function(absolutePath) {
|
||||
var files = {
|
||||
added: [],
|
||||
changed: [],
|
||||
removed: [],
|
||||
};
|
||||
|
||||
graph.visitAncestors(absolutePath, function(parent) {
|
||||
if (path.basename(parent)[0] !== '_') {
|
||||
files.changed.push(parent);
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(graph.index).indexOf(absolutePath) !== -1) {
|
||||
files.removed.push(absolutePath);
|
||||
}
|
||||
|
||||
this.reset();
|
||||
|
||||
return files;
|
||||
};
|
||||
|
||||
module.exports = watcher;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
test
|
||||
.gitignore
|
||||
.travis.yml
|
||||
Makefile
|
||||
example.js
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
(MIT)
|
||||
|
||||
Copyright (c) 2013 Julian Gruber <julian@juliangruber.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.
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
# balanced-match
|
||||
|
||||
Match balanced string pairs, like `{` and `}` or `<b>` and `</b>`. Supports regular expressions as well!
|
||||
|
||||
[](http://travis-ci.org/juliangruber/balanced-match)
|
||||
[](https://www.npmjs.org/package/balanced-match)
|
||||
|
||||
[](https://ci.testling.com/juliangruber/balanced-match)
|
||||
|
||||
## Example
|
||||
|
||||
Get the first matching pair of braces:
|
||||
|
||||
```js
|
||||
var balanced = require('balanced-match');
|
||||
|
||||
console.log(balanced('{', '}', 'pre{in{nested}}post'));
|
||||
console.log(balanced('{', '}', 'pre{first}between{second}post'));
|
||||
console.log(balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'));
|
||||
```
|
||||
|
||||
The matches are:
|
||||
|
||||
```bash
|
||||
$ node example.js
|
||||
{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }
|
||||
{ start: 3,
|
||||
end: 9,
|
||||
pre: 'pre',
|
||||
body: 'first',
|
||||
post: 'between{second}post' }
|
||||
{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### var m = balanced(a, b, str)
|
||||
|
||||
For the first non-nested matching pair of `a` and `b` in `str`, return an
|
||||
object with those keys:
|
||||
|
||||
* **start** the index of the first match of `a`
|
||||
* **end** the index of the matching `b`
|
||||
* **pre** the preamble, `a` and `b` not included
|
||||
* **body** the match, `a` and `b` not included
|
||||
* **post** the postscript, `a` and `b` not included
|
||||
|
||||
If there's no match, `undefined` will be returned.
|
||||
|
||||
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.
|
||||
|
||||
### var r = balanced.range(a, b, str)
|
||||
|
||||
For the first non-nested matching pair of `a` and `b` in `str`, return an
|
||||
array with indexes: `[ <a index>, <b index> ]`.
|
||||
|
||||
If there's no match, `undefined` will be returned.
|
||||
|
||||
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `[ 1, 3 ]` and `{a}}` will match `[0, 2]`.
|
||||
|
||||
## Installation
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```bash
|
||||
npm install balanced-match
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
(MIT)
|
||||
|
||||
Copyright (c) 2013 Julian Gruber <julian@juliangruber.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.
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
module.exports = balanced;
|
||||
function balanced(a, b, str) {
|
||||
if (a instanceof RegExp) a = maybeMatch(a, str);
|
||||
if (b instanceof RegExp) b = maybeMatch(b, str);
|
||||
|
||||
var r = range(a, b, str);
|
||||
|
||||
return r && {
|
||||
start: r[0],
|
||||
end: r[1],
|
||||
pre: str.slice(0, r[0]),
|
||||
body: str.slice(r[0] + a.length, r[1]),
|
||||
post: str.slice(r[1] + b.length)
|
||||
};
|
||||
}
|
||||
|
||||
function maybeMatch(reg, str) {
|
||||
var m = str.match(reg);
|
||||
return m ? m[0] : null;
|
||||
}
|
||||
|
||||
balanced.range = range;
|
||||
function range(a, b, str) {
|
||||
var begs, beg, left, right, result;
|
||||
var ai = str.indexOf(a);
|
||||
var bi = str.indexOf(b, ai + 1);
|
||||
var i = ai;
|
||||
|
||||
if (ai >= 0 && bi > 0) {
|
||||
begs = [];
|
||||
left = str.length;
|
||||
|
||||
while (i >= 0 && !result) {
|
||||
if (i == ai) {
|
||||
begs.push(i);
|
||||
ai = str.indexOf(a, i + 1);
|
||||
} else if (begs.length == 1) {
|
||||
result = [ begs.pop(), bi ];
|
||||
} else {
|
||||
beg = begs.pop();
|
||||
if (beg < left) {
|
||||
left = beg;
|
||||
right = bi;
|
||||
}
|
||||
|
||||
bi = str.indexOf(b, i + 1);
|
||||
}
|
||||
|
||||
i = ai < bi && ai >= 0 ? ai : bi;
|
||||
}
|
||||
|
||||
if (begs.length) {
|
||||
result = [ left, right ];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "balanced-match@^1.0.0",
|
||||
"scope": null,
|
||||
"escapedName": "balanced-match",
|
||||
"name": "balanced-match",
|
||||
"rawSpec": "^1.0.0",
|
||||
"spec": ">=1.0.0 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/mnt/Data/bach/Documents/ola/OLA#4/OLA#4DOC/sys/node_modules/node-sass/node_modules/brace-expansion"
|
||||
]
|
||||
],
|
||||
"_from": "balanced-match@>=1.0.0 <2.0.0",
|
||||
"_id": "balanced-match@1.0.0",
|
||||
"_inCache": true,
|
||||
"_location": "/node-sass/balanced-match",
|
||||
"_nodeVersion": "7.8.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "s3://npm-registry-packages",
|
||||
"tmp": "tmp/balanced-match-1.0.0.tgz_1497251909645_0.8755026108119637"
|
||||
},
|
||||
"_npmUser": {
|
||||
"name": "juliangruber",
|
||||
"email": "julian@juliangruber.com"
|
||||
},
|
||||
"_npmVersion": "4.2.0",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "balanced-match@^1.0.0",
|
||||
"scope": null,
|
||||
"escapedName": "balanced-match",
|
||||
"name": "balanced-match",
|
||||
"rawSpec": "^1.0.0",
|
||||
"spec": ">=1.0.0 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/node-sass/brace-expansion"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
"_shasum": "89b4d199ab2bee49de164ea02b89ce462d71b767",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "balanced-match@^1.0.0",
|
||||
"_where": "/mnt/Data/bach/Documents/ola/OLA#4/OLA#4DOC/sys/node_modules/node-sass/node_modules/brace-expansion",
|
||||
"author": {
|
||||
"name": "Julian Gruber",
|
||||
"email": "mail@juliangruber.com",
|
||||
"url": "http://juliangruber.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/juliangruber/balanced-match/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Match balanced character pairs, like \"{\" and \"}\"",
|
||||
"devDependencies": {
|
||||
"matcha": "^0.7.0",
|
||||
"tape": "^4.6.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "89b4d199ab2bee49de164ea02b89ce462d71b767",
|
||||
"tarball": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz"
|
||||
},
|
||||
"gitHead": "d701a549a7653a874eebce7eca25d3577dc868ac",
|
||||
"homepage": "https://github.com/juliangruber/balanced-match",
|
||||
"keywords": [
|
||||
"match",
|
||||
"regexp",
|
||||
"test",
|
||||
"balanced",
|
||||
"parse"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "juliangruber",
|
||||
"email": "julian@juliangruber.com"
|
||||
}
|
||||
],
|
||||
"name": "balanced-match",
|
||||
"optionalDependencies": {},
|
||||
"readme": "# balanced-match\n\nMatch balanced string pairs, like `{` and `}` or `<b>` and `</b>`. Supports regular expressions as well!\n\n[](http://travis-ci.org/juliangruber/balanced-match)\n[](https://www.npmjs.org/package/balanced-match)\n\n[](https://ci.testling.com/juliangruber/balanced-match)\n\n## Example\n\nGet the first matching pair of braces:\n\n```js\nvar balanced = require('balanced-match');\n\nconsole.log(balanced('{', '}', 'pre{in{nested}}post'));\nconsole.log(balanced('{', '}', 'pre{first}between{second}post'));\nconsole.log(balanced(/\\s+\\{\\s+/, /\\s+\\}\\s+/, 'pre { in{nest} } post'));\n```\n\nThe matches are:\n\n```bash\n$ node example.js\n{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }\n{ start: 3,\n end: 9,\n pre: 'pre',\n body: 'first',\n post: 'between{second}post' }\n{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }\n```\n\n## API\n\n### var m = balanced(a, b, str)\n\nFor the first non-nested matching pair of `a` and `b` in `str`, return an\nobject with those keys:\n\n* **start** the index of the first match of `a`\n* **end** the index of the matching `b`\n* **pre** the preamble, `a` and `b` not included\n* **body** the match, `a` and `b` not included\n* **post** the postscript, `a` and `b` not included\n\nIf there's no match, `undefined` will be returned.\n\nIf the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.\n\n### var r = balanced.range(a, b, str)\n\nFor the first non-nested matching pair of `a` and `b` in `str`, return an\narray with indexes: `[ <a index>, <b index> ]`.\n\nIf there's no match, `undefined` will be returned.\n\nIf the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `[ 1, 3 ]` and `{a}}` will match `[0, 2]`.\n\n## Installation\n\nWith [npm](https://npmjs.org) do:\n\n```bash\nnpm install balanced-match\n```\n\n## License\n\n(MIT)\n\nCopyright (c) 2013 Julian Gruber <julian@juliangruber.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
|
||||
"readmeFilename": "README.md",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/juliangruber/balanced-match.git"
|
||||
},
|
||||
"scripts": {
|
||||
"bench": "make bench",
|
||||
"test": "make test"
|
||||
},
|
||||
"testling": {
|
||||
"files": "test/*.js",
|
||||
"browsers": [
|
||||
"ie/8..latest",
|
||||
"firefox/20..latest",
|
||||
"firefox/nightly",
|
||||
"chrome/25..latest",
|
||||
"chrome/canary",
|
||||
"opera/12..latest",
|
||||
"opera/next",
|
||||
"safari/5.1..latest",
|
||||
"ipad/6.0..latest",
|
||||
"iphone/6.0..latest",
|
||||
"android-browser/4.2..latest"
|
||||
]
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
# brace-expansion
|
||||
|
||||
[Brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html),
|
||||
as known from sh/bash, in JavaScript.
|
||||
|
||||
[](http://travis-ci.org/juliangruber/brace-expansion)
|
||||
[](https://www.npmjs.org/package/brace-expansion)
|
||||
[](https://greenkeeper.io/)
|
||||
|
||||
[](https://ci.testling.com/juliangruber/brace-expansion)
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var expand = require('brace-expansion');
|
||||
|
||||
expand('file-{a,b,c}.jpg')
|
||||
// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
|
||||
|
||||
expand('-v{,,}')
|
||||
// => ['-v', '-v', '-v']
|
||||
|
||||
expand('file{0..2}.jpg')
|
||||
// => ['file0.jpg', 'file1.jpg', 'file2.jpg']
|
||||
|
||||
expand('file-{a..c}.jpg')
|
||||
// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
|
||||
|
||||
expand('file{2..0}.jpg')
|
||||
// => ['file2.jpg', 'file1.jpg', 'file0.jpg']
|
||||
|
||||
expand('file{0..4..2}.jpg')
|
||||
// => ['file0.jpg', 'file2.jpg', 'file4.jpg']
|
||||
|
||||
expand('file-{a..e..2}.jpg')
|
||||
// => ['file-a.jpg', 'file-c.jpg', 'file-e.jpg']
|
||||
|
||||
expand('file{00..10..5}.jpg')
|
||||
// => ['file00.jpg', 'file05.jpg', 'file10.jpg']
|
||||
|
||||
expand('{{A..C},{a..c}}')
|
||||
// => ['A', 'B', 'C', 'a', 'b', 'c']
|
||||
|
||||
expand('ppp{,config,oe{,conf}}')
|
||||
// => ['ppp', 'pppconfig', 'pppoe', 'pppoeconf']
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
var expand = require('brace-expansion');
|
||||
```
|
||||
|
||||
### var expanded = expand(str)
|
||||
|
||||
Return an array of all possible and valid expansions of `str`. If none are
|
||||
found, `[str]` is returned.
|
||||
|
||||
Valid expansions are:
|
||||
|
||||
```js
|
||||
/^(.*,)+(.+)?$/
|
||||
// {a,b,...}
|
||||
```
|
||||
|
||||
A comma seperated list of options, like `{a,b}` or `{a,{b,c}}` or `{,a,}`.
|
||||
|
||||
```js
|
||||
/^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
|
||||
// {x..y[..incr]}
|
||||
```
|
||||
|
||||
A numeric sequence from `x` to `y` inclusive, with optional increment.
|
||||
If `x` or `y` start with a leading `0`, all the numbers will be padded
|
||||
to have equal length. Negative numbers and backwards iteration work too.
|
||||
|
||||
```js
|
||||
/^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
|
||||
// {x..y[..incr]}
|
||||
```
|
||||
|
||||
An alphabetic sequence from `x` to `y` inclusive, with optional increment.
|
||||
`x` and `y` must be exactly one character, and if given, `incr` must be a
|
||||
number.
|
||||
|
||||
For compatibility reasons, the string `${` is not eligible for brace expansion.
|
||||
|
||||
## Installation
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```bash
|
||||
npm install brace-expansion
|
||||
```
|
||||
|
||||
## Contributors
|
||||
|
||||
- [Julian Gruber](https://github.com/juliangruber)
|
||||
- [Isaac Z. Schlueter](https://github.com/isaacs)
|
||||
|
||||
## License
|
||||
|
||||
(MIT)
|
||||
|
||||
Copyright (c) 2013 Julian Gruber <julian@juliangruber.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.
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
var concatMap = require('concat-map');
|
||||
var balanced = require('balanced-match');
|
||||
|
||||
module.exports = expandTop;
|
||||
|
||||
var escSlash = '\0SLASH'+Math.random()+'\0';
|
||||
var escOpen = '\0OPEN'+Math.random()+'\0';
|
||||
var escClose = '\0CLOSE'+Math.random()+'\0';
|
||||
var escComma = '\0COMMA'+Math.random()+'\0';
|
||||
var escPeriod = '\0PERIOD'+Math.random()+'\0';
|
||||
|
||||
function numeric(str) {
|
||||
return parseInt(str, 10) == str
|
||||
? parseInt(str, 10)
|
||||
: str.charCodeAt(0);
|
||||
}
|
||||
|
||||
function escapeBraces(str) {
|
||||
return str.split('\\\\').join(escSlash)
|
||||
.split('\\{').join(escOpen)
|
||||
.split('\\}').join(escClose)
|
||||
.split('\\,').join(escComma)
|
||||
.split('\\.').join(escPeriod);
|
||||
}
|
||||
|
||||
function unescapeBraces(str) {
|
||||
return str.split(escSlash).join('\\')
|
||||
.split(escOpen).join('{')
|
||||
.split(escClose).join('}')
|
||||
.split(escComma).join(',')
|
||||
.split(escPeriod).join('.');
|
||||
}
|
||||
|
||||
|
||||
// Basically just str.split(","), but handling cases
|
||||
// where we have nested braced sections, which should be
|
||||
// treated as individual members, like {a,{b,c},d}
|
||||
function parseCommaParts(str) {
|
||||
if (!str)
|
||||
return [''];
|
||||
|
||||
var parts = [];
|
||||
var m = balanced('{', '}', str);
|
||||
|
||||
if (!m)
|
||||
return str.split(',');
|
||||
|
||||
var pre = m.pre;
|
||||
var body = m.body;
|
||||
var post = m.post;
|
||||
var p = pre.split(',');
|
||||
|
||||
p[p.length-1] += '{' + body + '}';
|
||||
var postParts = parseCommaParts(post);
|
||||
if (post.length) {
|
||||
p[p.length-1] += postParts.shift();
|
||||
p.push.apply(p, postParts);
|
||||
}
|
||||
|
||||
parts.push.apply(parts, p);
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
function expandTop(str) {
|
||||
if (!str)
|
||||
return [];
|
||||
|
||||
// I don't know why Bash 4.3 does this, but it does.
|
||||
// Anything starting with {} will have the first two bytes preserved
|
||||
// but *only* at the top level, so {},a}b will not expand to anything,
|
||||
// but a{},b}c will be expanded to [a}c,abc].
|
||||
// One could argue that this is a bug in Bash, but since the goal of
|
||||
// this module is to match Bash's rules, we escape a leading {}
|
||||
if (str.substr(0, 2) === '{}') {
|
||||
str = '\\{\\}' + str.substr(2);
|
||||
}
|
||||
|
||||
return expand(escapeBraces(str), true).map(unescapeBraces);
|
||||
}
|
||||
|
||||
function identity(e) {
|
||||
return e;
|
||||
}
|
||||
|
||||
function embrace(str) {
|
||||
return '{' + str + '}';
|
||||
}
|
||||
function isPadded(el) {
|
||||
return /^-?0\d/.test(el);
|
||||
}
|
||||
|
||||
function lte(i, y) {
|
||||
return i <= y;
|
||||
}
|
||||
function gte(i, y) {
|
||||
return i >= y;
|
||||
}
|
||||
|
||||
function expand(str, isTop) {
|
||||
var expansions = [];
|
||||
|
||||
var m = balanced('{', '}', str);
|
||||
if (!m || /\$$/.test(m.pre)) return [str];
|
||||
|
||||
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
||||
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
||||
var isSequence = isNumericSequence || isAlphaSequence;
|
||||
var isOptions = m.body.indexOf(',') >= 0;
|
||||
if (!isSequence && !isOptions) {
|
||||
// {a},b}
|
||||
if (m.post.match(/,.*\}/)) {
|
||||
str = m.pre + '{' + m.body + escClose + m.post;
|
||||
return expand(str);
|
||||
}
|
||||
return [str];
|
||||
}
|
||||
|
||||
var n;
|
||||
if (isSequence) {
|
||||
n = m.body.split(/\.\./);
|
||||
} else {
|
||||
n = parseCommaParts(m.body);
|
||||
if (n.length === 1) {
|
||||
// x{{a,b}}y ==> x{a}y x{b}y
|
||||
n = expand(n[0], false).map(embrace);
|
||||
if (n.length === 1) {
|
||||
var post = m.post.length
|
||||
? expand(m.post, false)
|
||||
: [''];
|
||||
return post.map(function(p) {
|
||||
return m.pre + n[0] + p;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// at this point, n is the parts, and we know it's not a comma set
|
||||
// with a single entry.
|
||||
|
||||
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
||||
var pre = m.pre;
|
||||
var post = m.post.length
|
||||
? expand(m.post, false)
|
||||
: [''];
|
||||
|
||||
var N;
|
||||
|
||||
if (isSequence) {
|
||||
var x = numeric(n[0]);
|
||||
var y = numeric(n[1]);
|
||||
var width = Math.max(n[0].length, n[1].length)
|
||||
var incr = n.length == 3
|
||||
? Math.abs(numeric(n[2]))
|
||||
: 1;
|
||||
var test = lte;
|
||||
var reverse = y < x;
|
||||
if (reverse) {
|
||||
incr *= -1;
|
||||
test = gte;
|
||||
}
|
||||
var pad = n.some(isPadded);
|
||||
|
||||
N = [];
|
||||
|
||||
for (var i = x; test(i, y); i += incr) {
|
||||
var c;
|
||||
if (isAlphaSequence) {
|
||||
c = String.fromCharCode(i);
|
||||
if (c === '\\')
|
||||
c = '';
|
||||
} else {
|
||||
c = String(i);
|
||||
if (pad) {
|
||||
var need = width - c.length;
|
||||
if (need > 0) {
|
||||
var z = new Array(need + 1).join('0');
|
||||
if (i < 0)
|
||||
c = '-' + z + c.slice(1);
|
||||
else
|
||||
c = z + c;
|
||||
}
|
||||
}
|
||||
}
|
||||
N.push(c);
|
||||
}
|
||||
} else {
|
||||
N = concatMap(n, function(el) { return expand(el, false) });
|
||||
}
|
||||
|
||||
for (var j = 0; j < N.length; j++) {
|
||||
for (var k = 0; k < post.length; k++) {
|
||||
var expansion = pre + N[j] + post[k];
|
||||
if (!isTop || isSequence || expansion)
|
||||
expansions.push(expansion);
|
||||
}
|
||||
}
|
||||
|
||||
return expansions;
|
||||
}
|
||||
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "brace-expansion@^1.1.7",
|
||||
"scope": null,
|
||||
"escapedName": "brace-expansion",
|
||||
"name": "brace-expansion",
|
||||
"rawSpec": "^1.1.7",
|
||||
"spec": ">=1.1.7 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/mnt/Data/bach/Documents/ola/OLA#4/OLA#4DOC/sys/node_modules/node-sass/node_modules/minimatch"
|
||||
]
|
||||
],
|
||||
"_from": "brace-expansion@>=1.1.7 <2.0.0",
|
||||
"_id": "brace-expansion@1.1.8",
|
||||
"_inCache": true,
|
||||
"_location": "/node-sass/brace-expansion",
|
||||
"_nodeVersion": "7.8.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "s3://npm-registry-packages",
|
||||
"tmp": "tmp/brace-expansion-1.1.8.tgz_1497251980593_0.6575565172825009"
|
||||
},
|
||||
"_npmUser": {
|
||||
"name": "juliangruber",
|
||||
"email": "julian@juliangruber.com"
|
||||
},
|
||||
"_npmVersion": "4.2.0",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "brace-expansion@^1.1.7",
|
||||
"scope": null,
|
||||
"escapedName": "brace-expansion",
|
||||
"name": "brace-expansion",
|
||||
"rawSpec": "^1.1.7",
|
||||
"spec": ">=1.1.7 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/node-sass/minimatch"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
|
||||
"_shasum": "c07b211c7c952ec1f8efd51a77ef0d1d3990a292",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "brace-expansion@^1.1.7",
|
||||
"_where": "/mnt/Data/bach/Documents/ola/OLA#4/OLA#4DOC/sys/node_modules/node-sass/node_modules/minimatch",
|
||||
"author": {
|
||||
"name": "Julian Gruber",
|
||||
"email": "mail@juliangruber.com",
|
||||
"url": "http://juliangruber.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/juliangruber/brace-expansion/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
},
|
||||
"description": "Brace expansion as known from sh/bash",
|
||||
"devDependencies": {
|
||||
"matcha": "^0.7.0",
|
||||
"tape": "^4.6.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "c07b211c7c952ec1f8efd51a77ef0d1d3990a292",
|
||||
"tarball": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz"
|
||||
},
|
||||
"gitHead": "8f59e68bd5c915a0d624e8e39354e1ccf672edf6",
|
||||
"homepage": "https://github.com/juliangruber/brace-expansion",
|
||||
"keywords": [],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "juliangruber",
|
||||
"email": "julian@juliangruber.com"
|
||||
},
|
||||
{
|
||||
"name": "isaacs",
|
||||
"email": "isaacs@npmjs.com"
|
||||
}
|
||||
],
|
||||
"name": "brace-expansion",
|
||||
"optionalDependencies": {},
|
||||
"readme": "# brace-expansion\n\n[Brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html), \nas known from sh/bash, in JavaScript.\n\n[](http://travis-ci.org/juliangruber/brace-expansion)\n[](https://www.npmjs.org/package/brace-expansion)\n[](https://greenkeeper.io/)\n\n[](https://ci.testling.com/juliangruber/brace-expansion)\n\n## Example\n\n```js\nvar expand = require('brace-expansion');\n\nexpand('file-{a,b,c}.jpg')\n// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']\n\nexpand('-v{,,}')\n// => ['-v', '-v', '-v']\n\nexpand('file{0..2}.jpg')\n// => ['file0.jpg', 'file1.jpg', 'file2.jpg']\n\nexpand('file-{a..c}.jpg')\n// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']\n\nexpand('file{2..0}.jpg')\n// => ['file2.jpg', 'file1.jpg', 'file0.jpg']\n\nexpand('file{0..4..2}.jpg')\n// => ['file0.jpg', 'file2.jpg', 'file4.jpg']\n\nexpand('file-{a..e..2}.jpg')\n// => ['file-a.jpg', 'file-c.jpg', 'file-e.jpg']\n\nexpand('file{00..10..5}.jpg')\n// => ['file00.jpg', 'file05.jpg', 'file10.jpg']\n\nexpand('{{A..C},{a..c}}')\n// => ['A', 'B', 'C', 'a', 'b', 'c']\n\nexpand('ppp{,config,oe{,conf}}')\n// => ['ppp', 'pppconfig', 'pppoe', 'pppoeconf']\n```\n\n## API\n\n```js\nvar expand = require('brace-expansion');\n```\n\n### var expanded = expand(str)\n\nReturn an array of all possible and valid expansions of `str`. If none are\nfound, `[str]` is returned.\n\nValid expansions are:\n\n```js\n/^(.*,)+(.+)?$/\n// {a,b,...}\n```\n\nA comma seperated list of options, like `{a,b}` or `{a,{b,c}}` or `{,a,}`.\n\n```js\n/^-?\\d+\\.\\.-?\\d+(\\.\\.-?\\d+)?$/\n// {x..y[..incr]}\n```\n\nA numeric sequence from `x` to `y` inclusive, with optional increment.\nIf `x` or `y` start with a leading `0`, all the numbers will be padded\nto have equal length. Negative numbers and backwards iteration work too.\n\n```js\n/^-?\\d+\\.\\.-?\\d+(\\.\\.-?\\d+)?$/\n// {x..y[..incr]}\n```\n\nAn alphabetic sequence from `x` to `y` inclusive, with optional increment.\n`x` and `y` must be exactly one character, and if given, `incr` must be a\nnumber.\n\nFor compatibility reasons, the string `${` is not eligible for brace expansion.\n\n## Installation\n\nWith [npm](https://npmjs.org) do:\n\n```bash\nnpm install brace-expansion\n```\n\n## Contributors\n\n- [Julian Gruber](https://github.com/juliangruber)\n- [Isaac Z. Schlueter](https://github.com/isaacs)\n\n## License\n\n(MIT)\n\nCopyright (c) 2013 Julian Gruber <julian@juliangruber.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
|
||||
"readmeFilename": "README.md",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/juliangruber/brace-expansion.git"
|
||||
},
|
||||
"scripts": {
|
||||
"bench": "matcha test/perf/bench.js",
|
||||
"gentest": "bash test/generate.sh",
|
||||
"test": "tape test/*.js"
|
||||
},
|
||||
"testling": {
|
||||
"files": "test/*.js",
|
||||
"browsers": [
|
||||
"ie/8..latest",
|
||||
"firefox/20..latest",
|
||||
"firefox/nightly",
|
||||
"chrome/25..latest",
|
||||
"chrome/canary",
|
||||
"opera/12..latest",
|
||||
"opera/next",
|
||||
"safari/5.1..latest",
|
||||
"ipad/6.0..latest",
|
||||
"iphone/6.0..latest",
|
||||
"android-browser/4.2..latest"
|
||||
]
|
||||
},
|
||||
"version": "1.1.8"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2016 Kyle Robinson Young
|
||||
|
||||
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.
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
# gaze [](https://travis-ci.org/shama/gaze) [](https://ci.appveyor.com/project/shama/gaze)
|
||||
|
||||
A globbing fs.watch wrapper built from the best parts of other fine watch libs.
|
||||
Compatible with Node.js 4.x/0.12/0.10, Windows, OSX and Linux.
|
||||
|
||||

|
||||
|
||||
[](https://nodei.co/npm/gaze/)
|
||||
|
||||
## Usage
|
||||
Install the module with: `npm install gaze` or place into your `package.json`
|
||||
and run `npm install`.
|
||||
|
||||
```javascript
|
||||
var gaze = require('gaze');
|
||||
|
||||
// Watch all .js files/dirs in process.cwd()
|
||||
gaze('**/*.js', function(err, watcher) {
|
||||
// Files have all started watching
|
||||
// watcher === this
|
||||
|
||||
// Get all watched files
|
||||
var watched = this.watched();
|
||||
|
||||
// On file changed
|
||||
this.on('changed', function(filepath) {
|
||||
console.log(filepath + ' was changed');
|
||||
});
|
||||
|
||||
// On file added
|
||||
this.on('added', function(filepath) {
|
||||
console.log(filepath + ' was added');
|
||||
});
|
||||
|
||||
// On file deleted
|
||||
this.on('deleted', function(filepath) {
|
||||
console.log(filepath + ' was deleted');
|
||||
});
|
||||
|
||||
// On changed/added/deleted
|
||||
this.on('all', function(event, filepath) {
|
||||
console.log(filepath + ' was ' + event);
|
||||
});
|
||||
|
||||
// Get watched files with relative paths
|
||||
var files = this.relative();
|
||||
});
|
||||
|
||||
// Also accepts an array of patterns
|
||||
gaze(['stylesheets/*.css', 'images/**/*.png'], function() {
|
||||
// Add more patterns later to be watched
|
||||
this.add(['js/*.js']);
|
||||
});
|
||||
```
|
||||
|
||||
### Alternate Interface
|
||||
|
||||
```javascript
|
||||
var Gaze = require('gaze').Gaze;
|
||||
|
||||
var gaze = new Gaze('**/*');
|
||||
|
||||
// Files have all started watching
|
||||
gaze.on('ready', function(watcher) { });
|
||||
|
||||
// A file has been added/changed/deleted has occurred
|
||||
gaze.on('all', function(event, filepath) { });
|
||||
```
|
||||
|
||||
### Errors
|
||||
|
||||
```javascript
|
||||
gaze('**/*', function(error, watcher) {
|
||||
if (error) {
|
||||
// Handle error if it occurred while starting up
|
||||
}
|
||||
});
|
||||
|
||||
// Or with the alternative interface
|
||||
var gaze = new Gaze();
|
||||
gaze.on('error', function(error) {
|
||||
// Handle error here
|
||||
});
|
||||
gaze.add('**/*');
|
||||
```
|
||||
|
||||
### Minimatch / Glob
|
||||
|
||||
See [isaacs's minimatch](https://github.com/isaacs/minimatch) for more
|
||||
information on glob patterns.
|
||||
|
||||
## Documentation
|
||||
|
||||
### gaze([patterns, options, callback])
|
||||
|
||||
* `patterns` {String|Array} File patterns to be matched
|
||||
* `options` {Object}
|
||||
* `callback` {Function}
|
||||
* `err` {Error | null}
|
||||
* `watcher` {Object} Instance of the Gaze watcher
|
||||
|
||||
### Class: gaze.Gaze
|
||||
|
||||
Create a Gaze object by instancing the `gaze.Gaze` class.
|
||||
|
||||
```javascript
|
||||
var Gaze = require('gaze').Gaze;
|
||||
var gaze = new Gaze(pattern, options, callback);
|
||||
```
|
||||
|
||||
#### Properties
|
||||
|
||||
* `options` The options object passed in.
|
||||
* `interval` {integer} Interval to pass to fs.watchFile
|
||||
* `debounceDelay` {integer} Delay for events called in succession for the same
|
||||
file/event in milliseconds
|
||||
* `mode` {string} Force the watch mode. Either `'auto'` (default), `'watch'` (force native events), or `'poll'` (force stat polling).
|
||||
* `cwd` {string} The current working directory to base file patterns from. Default is `process.cwd()`.
|
||||
|
||||
#### Events
|
||||
|
||||
* `ready(watcher)` When files have been globbed and watching has begun.
|
||||
* `all(event, filepath)` When an `added`, `changed` or `deleted` event occurs.
|
||||
* `added(filepath)` When a file has been added to a watch directory.
|
||||
* `changed(filepath)` When a file has been changed.
|
||||
* `deleted(filepath)` When a file has been deleted.
|
||||
* `renamed(newPath, oldPath)` When a file has been renamed.
|
||||
* `end()` When the watcher is closed and watches have been removed.
|
||||
* `error(err)` When an error occurs.
|
||||
* `nomatch` When no files have been matched.
|
||||
|
||||
#### Methods
|
||||
|
||||
* `emit(event, [...])` Wrapper for the EventEmitter.emit.
|
||||
`added`|`changed`|`deleted` events will also trigger the `all` event.
|
||||
* `close()` Unwatch all files and reset the watch instance.
|
||||
* `add(patterns, callback)` Adds file(s) patterns to be watched.
|
||||
* `remove(filepath)` removes a file or directory from being watched. Does not
|
||||
recurse directories.
|
||||
* `watched()` Returns the currently watched files.
|
||||
* `relative([dir, unixify])` Returns the currently watched files with relative paths.
|
||||
* `dir` {string} Only return relative files for this directory.
|
||||
* `unixify` {boolean} Return paths with `/` instead of `\\` if on Windows.
|
||||
|
||||
## Similar Projects
|
||||
|
||||
Other great watch libraries to try are:
|
||||
|
||||
* [paulmillr's chokidar](https://github.com/paulmillr/chokidar)
|
||||
* [amasad's sane](https://github.com/amasad/sane)
|
||||
* [mikeal's watch](https://github.com/mikeal/watch)
|
||||
* [github's pathwatcher](https://github.com/atom/node-pathwatcher)
|
||||
* [bevry's watchr](https://github.com/bevry/watchr)
|
||||
|
||||
## 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
|
||||
* 1.1.2 - Prevent more ENOENT errors from escaping (@alexgorbatchev).
|
||||
* 1.1.1 - Prevent fs.watch errors from escaping error handler (@rosen-vladimirov). Fix _addToWatched without path.sep (@wyicwx).
|
||||
* 1.1.0 - Update to `globule@1.0.0` with `minimatch >= 3.0.0`.
|
||||
* 1.0.0 - Revert back to 0.5.2. Drop support for Node.js v0.8. Fix for `maxListeners`. Update globule to `0.2.0`.
|
||||
* 0.6.4 - Catch and emit error from readdir (@oconnore). Fix for 0 maxListeners. Use graceful-fs to avoid EMFILE errors in other places fs is used. Better method to determine if pathwatcher was built. Fix keeping process alive too much, only init pathwatcher if a file is being watched. Set min required to Windows Vista when building on Windows (@pvolok).
|
||||
* 0.6.3 - Add support for node v0.11
|
||||
* 0.6.2 - Fix argument error with watched(). Fix for erroneous added events on folders. Ignore msvs build error 4244.
|
||||
* 0.6.1 - Fix for absolute paths.
|
||||
* 0.6.0 - Uses native OS events (fork of pathwatcher) but can fall back to stat polling. Everything is async to avoid blocking, including `relative()` and `watched()`. Better error handling. Update to globule@0.2.0. No longer watches `cwd` by default. Added `mode` option. Better `EMFILE` message. Avoids `ENOENT` errors with symlinks. All constructor arguments are optional.
|
||||
* 0.5.2 - Fix for ENOENT error with non-existent symlinks [BACKPORTED].
|
||||
* 0.5.1 - Use setImmediate (process.nextTick for node v0.8) to defer ready/nomatch events (@amasad).
|
||||
* 0.5.0 - Process is now kept alive while watching files. Emits a nomatch event when no files are matching.
|
||||
* 0.4.3 - Track file additions in newly created folders (@brett-shwom).
|
||||
* 0.4.2 - Fix .remove() method to remove a single file in a directory (@kaelzhang). Fixing Cannot call method 'call' of undefined (@krasimir). Track new file additions within folders (@brett-shwom).
|
||||
* 0.4.1 - Fix watchDir not respecting close in race condition (@chrisirhc).
|
||||
* 0.4.0 - Drop support for node v0.6. Use globule for file matching. Avoid node v0.10 path.resolve/join errors. Register new files when added to non-existent folder. Multiple instances can now poll the same files (@jpommerening).
|
||||
* 0.3.4 - Code clean up. Fix path must be strings errors (@groner). Fix incorrect added events (@groner).
|
||||
* 0.3.3 - Fix for multiple patterns with negate.
|
||||
* 0.3.2 - Emit `end` before removeAllListeners.
|
||||
* 0.3.1 - Fix added events within subfolder patterns.
|
||||
* 0.3.0 - Handle safewrite events, `forceWatchMethod` option removed, bug fixes and watch optimizations (@rgaskill).
|
||||
* 0.2.2 - Fix issue where subsequent add calls dont get watched (@samcday). removeAllListeners on close.
|
||||
* 0.2.1 - Fix issue with invalid `added` events in current working dir.
|
||||
* 0.2.0 - Support and mark folders with `path.sep`. Add `forceWatchMethod` option. Support `renamed` events.
|
||||
* 0.1.6 - Recognize the `cwd` option properly
|
||||
* 0.1.5 - Catch too many open file errors
|
||||
* 0.1.4 - Really fix the race condition with 2 watches
|
||||
* 0.1.3 - Fix race condition with 2 watches
|
||||
* 0.1.2 - Read triggering changed event fix
|
||||
* 0.1.1 - Minor fixes
|
||||
* 0.1.0 - Initial release
|
||||
|
||||
## License
|
||||
Copyright (c) 2015 Kyle Robinson Young
|
||||
Licensed under the MIT license.
|
||||
+459
@@ -0,0 +1,459 @@
|
||||
/*
|
||||
* gaze
|
||||
* https://github.com/shama/gaze
|
||||
*
|
||||
* Copyright (c) 2016 Kyle Robinson Young
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// libs
|
||||
var util = require('util');
|
||||
var EE = require('events').EventEmitter;
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var globule = require('globule');
|
||||
var helper = require('./helper');
|
||||
|
||||
// shim setImmediate for node v0.8
|
||||
var setImmediate = require('timers').setImmediate;
|
||||
if (typeof setImmediate !== 'function') {
|
||||
setImmediate = process.nextTick;
|
||||
}
|
||||
|
||||
// globals
|
||||
var delay = 10;
|
||||
|
||||
// `Gaze` EventEmitter object to return in the callback
|
||||
function Gaze (patterns, opts, done) {
|
||||
var self = this;
|
||||
EE.call(self);
|
||||
|
||||
// If second arg is the callback
|
||||
if (typeof opts === 'function') {
|
||||
done = opts;
|
||||
opts = {};
|
||||
}
|
||||
|
||||
// Default options
|
||||
opts = opts || {};
|
||||
opts.mark = true;
|
||||
opts.interval = opts.interval || 100;
|
||||
opts.debounceDelay = opts.debounceDelay || 500;
|
||||
opts.cwd = opts.cwd || process.cwd();
|
||||
this.options = opts;
|
||||
|
||||
// Default done callback
|
||||
done = done || function () {};
|
||||
|
||||
// Remember our watched dir:files
|
||||
this._watched = Object.create(null);
|
||||
|
||||
// Store watchers
|
||||
this._watchers = Object.create(null);
|
||||
|
||||
// Store watchFile listeners
|
||||
this._pollers = Object.create(null);
|
||||
|
||||
// Store patterns
|
||||
this._patterns = [];
|
||||
|
||||
// Cached events for debouncing
|
||||
this._cached = Object.create(null);
|
||||
|
||||
// Set maxListeners
|
||||
if (this.options.maxListeners != null) {
|
||||
this.setMaxListeners(this.options.maxListeners);
|
||||
Gaze.super_.prototype.setMaxListeners(this.options.maxListeners);
|
||||
delete this.options.maxListeners;
|
||||
}
|
||||
|
||||
// Initialize the watch on files
|
||||
if (patterns) {
|
||||
this.add(patterns, done);
|
||||
}
|
||||
|
||||
// keep the process alive
|
||||
this._keepalive = setInterval(function () {}, 200);
|
||||
|
||||
return this;
|
||||
}
|
||||
util.inherits(Gaze, EE);
|
||||
|
||||
// Main entry point. Start watching and call done when setup
|
||||
module.exports = function gaze (patterns, opts, done) {
|
||||
return new Gaze(patterns, opts, done);
|
||||
};
|
||||
module.exports.Gaze = Gaze;
|
||||
|
||||
// Override the emit function to emit `all` events
|
||||
// and debounce on duplicate events per file
|
||||
Gaze.prototype.emit = function () {
|
||||
var self = this;
|
||||
var args = arguments;
|
||||
|
||||
var e = args[0];
|
||||
var filepath = args[1];
|
||||
var timeoutId;
|
||||
|
||||
// If not added/deleted/changed/renamed then just emit the event
|
||||
if (e.slice(-2) !== 'ed') {
|
||||
Gaze.super_.prototype.emit.apply(self, args);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Detect rename event, if added and previous deleted is in the cache
|
||||
if (e === 'added') {
|
||||
Object.keys(this._cached).forEach(function (oldFile) {
|
||||
if (self._cached[oldFile].indexOf('deleted') !== -1) {
|
||||
args[0] = e = 'renamed';
|
||||
[].push.call(args, oldFile);
|
||||
delete self._cached[oldFile];
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If cached doesnt exist, create a delay before running the next
|
||||
// then emit the event
|
||||
var cache = this._cached[filepath] || [];
|
||||
if (cache.indexOf(e) === -1) {
|
||||
helper.objectPush(self._cached, filepath, e);
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(function () {
|
||||
delete self._cached[filepath];
|
||||
}, this.options.debounceDelay);
|
||||
// Emit the event and `all` event
|
||||
Gaze.super_.prototype.emit.apply(self, args);
|
||||
Gaze.super_.prototype.emit.apply(self, ['all', e].concat([].slice.call(args, 1)));
|
||||
}
|
||||
|
||||
// Detect if new folder added to trigger for matching files within folder
|
||||
if (e === 'added') {
|
||||
if (helper.isDir(filepath)) {
|
||||
// It's possible that between `isDir` and `readdirSync()` calls the `filepath`
|
||||
// gets removed, which will result in `ENOENT` exception
|
||||
|
||||
var files;
|
||||
|
||||
try {
|
||||
files = fs.readdirSync(filepath);
|
||||
} catch (e) {
|
||||
// Rethrow the error if it's anything other than `ENOENT`
|
||||
if (e.code !== 'ENOENT') {
|
||||
throw e;
|
||||
}
|
||||
|
||||
files = [];
|
||||
}
|
||||
|
||||
files.map(function (file) {
|
||||
return path.join(filepath, file);
|
||||
}).filter(function (file) {
|
||||
return globule.isMatch(self._patterns, file, self.options);
|
||||
}).forEach(function (file) {
|
||||
self.emit('added', file);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// Close watchers
|
||||
Gaze.prototype.close = function (_reset) {
|
||||
var self = this;
|
||||
Object.keys(self._watchers).forEach(function (file) {
|
||||
self._watchers[file].close();
|
||||
});
|
||||
self._watchers = Object.create(null);
|
||||
Object.keys(this._watched).forEach(function (dir) {
|
||||
self._unpollDir(dir);
|
||||
});
|
||||
if (_reset !== false) {
|
||||
self._watched = Object.create(null);
|
||||
setTimeout(function () {
|
||||
self.emit('end');
|
||||
self.removeAllListeners();
|
||||
clearInterval(self._keepalive);
|
||||
}, delay + 100);
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
// Add file patterns to be watched
|
||||
Gaze.prototype.add = function (files, done) {
|
||||
if (typeof files === 'string') { files = [files]; }
|
||||
this._patterns = helper.unique.apply(null, [this._patterns, files]);
|
||||
files = globule.find(this._patterns, this.options);
|
||||
this._addToWatched(files);
|
||||
this.close(false);
|
||||
this._initWatched(done);
|
||||
};
|
||||
|
||||
// Dont increment patterns and dont call done if nothing added
|
||||
Gaze.prototype._internalAdd = function (file, done) {
|
||||
var files = [];
|
||||
if (helper.isDir(file)) {
|
||||
files = [helper.markDir(file)].concat(globule.find(this._patterns, this.options));
|
||||
} else {
|
||||
if (globule.isMatch(this._patterns, file, this.options)) {
|
||||
files = [file];
|
||||
}
|
||||
}
|
||||
if (files.length > 0) {
|
||||
this._addToWatched(files);
|
||||
this.close(false);
|
||||
this._initWatched(done);
|
||||
}
|
||||
};
|
||||
|
||||
// Remove file/dir from `watched`
|
||||
Gaze.prototype.remove = function (file) {
|
||||
var self = this;
|
||||
if (this._watched[file]) {
|
||||
// is dir, remove all files
|
||||
this._unpollDir(file);
|
||||
delete this._watched[file];
|
||||
} else {
|
||||
// is a file, find and remove
|
||||
Object.keys(this._watched).forEach(function (dir) {
|
||||
var index = self._watched[dir].indexOf(file);
|
||||
if (index !== -1) {
|
||||
self._unpollFile(file);
|
||||
self._watched[dir].splice(index, 1);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (this._watchers[file]) {
|
||||
this._watchers[file].close();
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
// Return watched files
|
||||
Gaze.prototype.watched = function () {
|
||||
return this._watched;
|
||||
};
|
||||
|
||||
// Returns `watched` files with relative paths to process.cwd()
|
||||
Gaze.prototype.relative = function (dir, unixify) {
|
||||
var self = this;
|
||||
var relative = Object.create(null);
|
||||
var relDir, relFile, unixRelDir;
|
||||
var cwd = this.options.cwd || process.cwd();
|
||||
if (dir === '') { dir = '.'; }
|
||||
dir = helper.markDir(dir);
|
||||
unixify = unixify || false;
|
||||
Object.keys(this._watched).forEach(function (dir) {
|
||||
relDir = path.relative(cwd, dir) + path.sep;
|
||||
if (relDir === path.sep) { relDir = '.'; }
|
||||
unixRelDir = unixify ? helper.unixifyPathSep(relDir) : relDir;
|
||||
relative[unixRelDir] = self._watched[dir].map(function (file) {
|
||||
relFile = path.relative(path.join(cwd, relDir) || '', file || '');
|
||||
if (helper.isDir(file)) {
|
||||
relFile = helper.markDir(relFile);
|
||||
}
|
||||
if (unixify) {
|
||||
relFile = helper.unixifyPathSep(relFile);
|
||||
}
|
||||
return relFile;
|
||||
});
|
||||
});
|
||||
if (dir && unixify) {
|
||||
dir = helper.unixifyPathSep(dir);
|
||||
}
|
||||
return dir ? relative[dir] || [] : relative;
|
||||
};
|
||||
|
||||
// Adds files and dirs to watched
|
||||
Gaze.prototype._addToWatched = function (files) {
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var file = files[i];
|
||||
var filepath = path.resolve(this.options.cwd, file);
|
||||
|
||||
var dirname = (helper.isDir(file)) ? filepath : path.dirname(filepath);
|
||||
dirname = helper.markDir(dirname);
|
||||
|
||||
// If a new dir is added
|
||||
if (helper.isDir(file) && !(dirname in this._watched)) {
|
||||
helper.objectPush(this._watched, dirname, []);
|
||||
}
|
||||
|
||||
if (file.slice(-1) === '/') { filepath += path.sep; }
|
||||
helper.objectPush(this._watched, path.dirname(filepath) + path.sep, filepath);
|
||||
|
||||
// add folders into the mix
|
||||
var readdir = fs.readdirSync(dirname);
|
||||
for (var j = 0; j < readdir.length; j++) {
|
||||
var dirfile = path.join(dirname, readdir[j]);
|
||||
if (fs.lstatSync(dirfile).isDirectory()) {
|
||||
helper.objectPush(this._watched, dirname, dirfile + path.sep);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Gaze.prototype._watchDir = function (dir, done) {
|
||||
var self = this;
|
||||
var timeoutId;
|
||||
try {
|
||||
this._watchers[dir] = fs.watch(dir, function (event) {
|
||||
// race condition. Let's give the fs a little time to settle down. so we
|
||||
// don't fire events on non existent files.
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(function () {
|
||||
// race condition. Ensure that this directory is still being watched
|
||||
// before continuing.
|
||||
if ((dir in self._watchers) && fs.existsSync(dir)) {
|
||||
done(null, dir);
|
||||
}
|
||||
}, delay + 100);
|
||||
});
|
||||
|
||||
this._watchers[dir].on('error', function (err) {
|
||||
self._handleError(err);
|
||||
});
|
||||
} catch (err) {
|
||||
return this._handleError(err);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Gaze.prototype._unpollFile = function (file) {
|
||||
if (this._pollers[file]) {
|
||||
fs.unwatchFile(file, this._pollers[file]);
|
||||
delete this._pollers[file];
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Gaze.prototype._unpollDir = function (dir) {
|
||||
this._unpollFile(dir);
|
||||
for (var i = 0; i < this._watched[dir].length; i++) {
|
||||
this._unpollFile(this._watched[dir][i]);
|
||||
}
|
||||
};
|
||||
|
||||
Gaze.prototype._pollFile = function (file, done) {
|
||||
var opts = { persistent: true, interval: this.options.interval };
|
||||
if (!this._pollers[file]) {
|
||||
this._pollers[file] = function (curr, prev) {
|
||||
done(null, file);
|
||||
};
|
||||
try {
|
||||
fs.watchFile(file, opts, this._pollers[file]);
|
||||
} catch (err) {
|
||||
return this._handleError(err);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
// Initialize the actual watch on `watched` files
|
||||
Gaze.prototype._initWatched = function (done) {
|
||||
var self = this;
|
||||
var cwd = this.options.cwd || process.cwd();
|
||||
var curWatched = Object.keys(self._watched);
|
||||
|
||||
// if no matching files
|
||||
if (curWatched.length < 1) {
|
||||
// Defer to emitting to give a chance to attach event handlers.
|
||||
setImmediate(function () {
|
||||
self.emit('ready', self);
|
||||
if (done) { done.call(self, null, self); }
|
||||
self.emit('nomatch');
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
helper.forEachSeries(curWatched, function (dir, next) {
|
||||
dir = dir || '';
|
||||
var files = self._watched[dir];
|
||||
// Triggered when a watched dir has an event
|
||||
self._watchDir(dir, function (event, dirpath) {
|
||||
var relDir = cwd === dir ? '.' : path.relative(cwd, dir);
|
||||
relDir = relDir || '';
|
||||
|
||||
fs.readdir(dirpath, function (err, current) {
|
||||
if (err) { return self.emit('error', err); }
|
||||
if (!current) { return; }
|
||||
|
||||
try {
|
||||
// append path.sep to directories so they match previous.
|
||||
current = current.map(function (curPath) {
|
||||
if (fs.existsSync(path.join(dir, curPath)) && fs.lstatSync(path.join(dir, curPath)).isDirectory()) {
|
||||
return curPath + path.sep;
|
||||
} else {
|
||||
return curPath;
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
// race condition-- sometimes the file no longer exists
|
||||
}
|
||||
|
||||
// Get watched files for this dir
|
||||
var previous = self.relative(relDir);
|
||||
|
||||
// If file was deleted
|
||||
previous.filter(function (file) {
|
||||
return current.indexOf(file) < 0;
|
||||
}).forEach(function (file) {
|
||||
if (!helper.isDir(file)) {
|
||||
var filepath = path.join(dir, file);
|
||||
self.remove(filepath);
|
||||
self.emit('deleted', filepath);
|
||||
}
|
||||
});
|
||||
|
||||
// If file was added
|
||||
current.filter(function (file) {
|
||||
return previous.indexOf(file) < 0;
|
||||
}).forEach(function (file) {
|
||||
// Is it a matching pattern?
|
||||
var relFile = path.join(relDir, file);
|
||||
// Add to watch then emit event
|
||||
self._internalAdd(relFile, function () {
|
||||
self.emit('added', path.join(dir, file));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Watch for change/rename events on files
|
||||
files.forEach(function (file) {
|
||||
if (helper.isDir(file)) { return; }
|
||||
self._pollFile(file, function (err, filepath) {
|
||||
if (err) {
|
||||
self.emit('error', err);
|
||||
return;
|
||||
}
|
||||
// Only emit changed if the file still exists
|
||||
// Prevents changed/deleted duplicate events
|
||||
if (fs.existsSync(filepath)) {
|
||||
self.emit('changed', filepath);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
next();
|
||||
}, function () {
|
||||
// Return this instance of Gaze
|
||||
// delay before ready solves a lot of issues
|
||||
setTimeout(function () {
|
||||
self.emit('ready', self);
|
||||
if (done) { done.call(self, null, self); }
|
||||
}, delay + 100);
|
||||
});
|
||||
};
|
||||
|
||||
// If an error, handle it here
|
||||
Gaze.prototype._handleError = function (err) {
|
||||
if (err.code === 'EMFILE') {
|
||||
return this.emit('error', new Error('EMFILE: Too many opened files.'));
|
||||
}
|
||||
return this.emit('error', err);
|
||||
};
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var helper = module.exports = {};
|
||||
|
||||
// Returns boolean whether filepath is dir terminated
|
||||
helper.isDir = function isDir (dir) {
|
||||
if (typeof dir !== 'string') {
|
||||
return false;
|
||||
}
|
||||
return (dir.slice(-(path.sep.length)) === path.sep);
|
||||
};
|
||||
|
||||
// Create a `key:[]` if doesnt exist on `obj` then push or concat the `val`
|
||||
helper.objectPush = function objectPush (obj, key, val) {
|
||||
if (obj[key] == null) {
|
||||
obj[key] = [];
|
||||
}
|
||||
if (Array.isArray(val)) {
|
||||
obj[key] = obj[key].concat(val);
|
||||
} else if (val) {
|
||||
obj[key].push(val);
|
||||
}
|
||||
obj[key] = helper.unique(obj[key]);
|
||||
return obj[key];
|
||||
};
|
||||
|
||||
// Ensures the dir is marked with path.sep
|
||||
helper.markDir = function markDir (dir) {
|
||||
if (typeof dir === 'string' &&
|
||||
dir.slice(-(path.sep.length)) !== path.sep &&
|
||||
dir !== '.') {
|
||||
dir += path.sep;
|
||||
}
|
||||
return dir;
|
||||
};
|
||||
|
||||
// Changes path.sep to unix ones for testing
|
||||
helper.unixifyPathSep = function unixifyPathSep (filepath) {
|
||||
return (process.platform === 'win32') ? String(filepath).replace(/\\/g, '/') : filepath;
|
||||
};
|
||||
|
||||
/**
|
||||
* Lo-Dash 1.0.1 <http://lodash.com/>
|
||||
* Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
|
||||
* Based on Underscore.js 1.4.4 <http://underscorejs.org/>
|
||||
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
|
||||
* Available under MIT license <http://lodash.com/license>
|
||||
*/
|
||||
helper.unique = function unique () {
|
||||
var array = Array.prototype.concat.apply(Array.prototype, arguments);
|
||||
var result = [];
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (result.indexOf(array[i]) === -1) {
|
||||
result.push(array[i]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Copyright (c) 2010 Caolan McMahon
|
||||
* Available under MIT license <https://raw.github.com/caolan/async/master/LICENSE>
|
||||
*/
|
||||
helper.forEachSeries = function forEachSeries (arr, iterator, callback) {
|
||||
if (!arr.length) { return callback(); }
|
||||
var completed = 0;
|
||||
var iterate = function () {
|
||||
iterator(arr[completed], function (err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
callback = function () {};
|
||||
} else {
|
||||
completed += 1;
|
||||
if (completed === arr.length) {
|
||||
callback(null);
|
||||
} else {
|
||||
iterate();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
iterate();
|
||||
};
|
||||
+164
File diff suppressed because one or more lines are too long
+15
@@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
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.
|
||||
+368
@@ -0,0 +1,368 @@
|
||||
# Glob
|
||||
|
||||
Match files using the patterns the shell uses, like stars and stuff.
|
||||
|
||||
[](https://travis-ci.org/isaacs/node-glob/) [](https://ci.appveyor.com/project/isaacs/node-glob) [](https://coveralls.io/github/isaacs/node-glob?branch=master)
|
||||
|
||||
This is a glob implementation in JavaScript. It uses the `minimatch`
|
||||
library to do its matching.
|
||||
|
||||

|
||||
|
||||
## Usage
|
||||
|
||||
Install with npm
|
||||
|
||||
```
|
||||
npm i glob
|
||||
```
|
||||
|
||||
```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.
|
||||
})
|
||||
```
|
||||
|
||||
## Glob Primer
|
||||
|
||||
"Globs" are the patterns you type when you do stuff like `ls *.js` on
|
||||
the command line, or put `build/*` in a `.gitignore` file.
|
||||
|
||||
Before parsing the path part patterns, braced sections are expanded
|
||||
into a set. Braced sections start with `{` and end with `}`, with any
|
||||
number of comma-delimited sections within. Braced sections may contain
|
||||
slash characters, so `a{/b/c,bcd}` would expand into `a/b/c` and `abcd`.
|
||||
|
||||
The following characters have special magic meaning when used in a
|
||||
path portion:
|
||||
|
||||
* `*` Matches 0 or more characters in a single path portion
|
||||
* `?` Matches 1 character
|
||||
* `[...]` Matches a range of characters, similar to a RegExp range.
|
||||
If the first character of the range is `!` or `^` then it matches
|
||||
any character not in the range.
|
||||
* `!(pattern|pattern|pattern)` Matches anything that does not match
|
||||
any of the patterns provided.
|
||||
* `?(pattern|pattern|pattern)` Matches zero or one occurrence of the
|
||||
patterns provided.
|
||||
* `+(pattern|pattern|pattern)` Matches one or more occurrences of the
|
||||
patterns provided.
|
||||
* `*(a|b|c)` Matches zero or more occurrences of the patterns provided
|
||||
* `@(pattern|pat*|pat?erN)` Matches exactly one of the patterns
|
||||
provided
|
||||
* `**` If a "globstar" is alone in a path portion, then it matches
|
||||
zero or more directories and subdirectories searching for matches.
|
||||
It does not crawl symlinked directories.
|
||||
|
||||
### Dots
|
||||
|
||||
If a file or directory path portion has a `.` as the first character,
|
||||
then it will not match any glob pattern unless that pattern's
|
||||
corresponding path part also has a `.` as its first character.
|
||||
|
||||
For example, the pattern `a/.*/c` would match the file at `a/.b/c`.
|
||||
However the pattern `a/*/c` would not, because `*` does not start with
|
||||
a dot character.
|
||||
|
||||
You can make glob treat dots as normal characters by setting
|
||||
`dot:true` in the options.
|
||||
|
||||
### Basename Matching
|
||||
|
||||
If you set `matchBase:true` in the options, and the pattern has no
|
||||
slashes in it, then it will seek for any file anywhere in the tree
|
||||
with a matching basename. For example, `*.js` would match
|
||||
`test/simple/basic.js`.
|
||||
|
||||
### Empty Sets
|
||||
|
||||
If no matching files are found, then an empty array is returned. This
|
||||
differs from the shell, where the pattern itself is returned. For
|
||||
example:
|
||||
|
||||
$ echo a*s*d*f
|
||||
a*s*d*f
|
||||
|
||||
To get the bash-style behavior, set the `nonull:true` in the options.
|
||||
|
||||
### See Also:
|
||||
|
||||
* `man sh`
|
||||
* `man bash` (Search for "Pattern Matching")
|
||||
* `man 3 fnmatch`
|
||||
* `man 5 gitignore`
|
||||
* [minimatch documentation](https://github.com/isaacs/minimatch)
|
||||
|
||||
## glob.hasMagic(pattern, [options])
|
||||
|
||||
Returns `true` if there are any special characters in the pattern, and
|
||||
`false` otherwise.
|
||||
|
||||
Note that the options affect the results. If `noext:true` is set in
|
||||
the options object, then `+(a|b)` will not be considered a magic
|
||||
pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`
|
||||
then that is considered magical, unless `nobrace:true` is set in the
|
||||
options.
|
||||
|
||||
## 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 instantiating 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.
|
||||
* `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.
|
||||
* `cache` Convenience object. Each field has the following possible
|
||||
values:
|
||||
* `false` - Path does not exist
|
||||
* `true` - Path exists
|
||||
* `'FILE'` - Path exists, and is not a directory
|
||||
* `'DIR'` - Path exists, and is a directory
|
||||
* `[file, entries, ...]` - Path exists, is a directory, and the
|
||||
array value is the results of `fs.readdir`
|
||||
* `statCache` Cache of `fs.stat` results, to prevent statting the same
|
||||
path multiple times.
|
||||
* `symlinks` A record of which paths are symbolic links, which is
|
||||
relevant in resolving `**` patterns.
|
||||
* `realpathCache` An optional object which is passed to `fs.realpath`
|
||||
to minimize unnecessary syscalls. It is stored on the instantiated
|
||||
Glob object, and may be re-used.
|
||||
|
||||
### 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 specific
|
||||
thing that matched. It is not deduplicated or resolved to a realpath.
|
||||
* `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
|
||||
|
||||
* `pause` Temporarily stop the search
|
||||
* `resume` Resume the search
|
||||
* `abort` Stop the search forever
|
||||
|
||||
### 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.
|
||||
|
||||
If you are running many `glob` operations, you can pass a Glob object
|
||||
as the `options` argument to a subsequent operation to shortcut some
|
||||
`stat` and `readdir` calls. At the very least, you may pass in shared
|
||||
`symlinks`, `statCache`, `realpathCache`, and `cache` options, so that
|
||||
parallel glob operations will be sped up by sharing information about
|
||||
the filesystem.
|
||||
|
||||
* `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.
|
||||
* `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.)
|
||||
* `symlinks` A cache of known symbolic links. You may pass in a
|
||||
previously generated `symlinks` object to save `lstat` calls when
|
||||
resolving `**` matches.
|
||||
* `sync` DEPRECATED: use `glob.sync(pattern, opts)` instead.
|
||||
* `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).
|
||||
* `debug` Set to enable debug logging in minimatch and glob.
|
||||
* `nobrace` Do not expand `{a,b}` and `{1..3}` brace sets.
|
||||
* `noglobstar` Do not match `**` against multiple filenames. (Ie,
|
||||
treat it as a normal `*` instead.)
|
||||
* `noext` Do not match `+(a|b)` "extglob" patterns.
|
||||
* `nocase` Perform a case-insensitive match. Note: on
|
||||
case-insensitive filesystems, non-magic patterns will match by
|
||||
default, since `stat` and `readdir` will not raise errors.
|
||||
* `matchBase` Perform a basename-only match if the pattern does not
|
||||
contain any slash characters. That is, `*.js` would be treated as
|
||||
equivalent to `**/*.js`, matching all js files in all directories.
|
||||
* `nodir` Do not match directories, only files. (Note: to match
|
||||
*only* directories, simply put a `/` at the end of the pattern.)
|
||||
* `ignore` Add a pattern or an array of glob patterns to exclude matches.
|
||||
Note: `ignore` patterns are *always* in `dot:true` mode, regardless
|
||||
of any other settings.
|
||||
* `follow` Follow symlinked directories when expanding `**` patterns.
|
||||
Note that this can result in a lot of duplicate references in the
|
||||
presence of cyclic links.
|
||||
* `realpath` Set to true to call `fs.realpath` on all of the results.
|
||||
In the case of a symlink that cannot be resolved, the full absolute
|
||||
path to the matched entry is returned (though it will usually be a
|
||||
broken symlink)
|
||||
* `absolute` Set to true to always receive absolute paths for matched
|
||||
files. Unlike `realpath`, this also affects the values returned in
|
||||
the `match` event.
|
||||
|
||||
## 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.
|
||||
|
||||
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.3, 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.
|
||||
|
||||
Note that symlinked directories are not crawled as part of a `**`,
|
||||
though their contents may match against subsequent portions of the
|
||||
pattern. This prevents infinite loops and duplicates and the like.
|
||||
|
||||
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.
|
||||
|
||||
### Comments and Negation
|
||||
|
||||
Previously, this module let you mark a pattern as a "comment" if it
|
||||
started with a `#` character, or a "negated" pattern if it started
|
||||
with a `!` character.
|
||||
|
||||
These options were deprecated in version 5, and removed in version 6.
|
||||
|
||||
To specify things that should not match, use the `ignore` option.
|
||||
|
||||
## 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.
|
||||
|
||||
## Contributing
|
||||
|
||||
Any change to behavior (including bugfixes) must come with a test.
|
||||
|
||||
Patches that fail tests or reduce performance will be rejected.
|
||||
|
||||
```
|
||||
# to run tests
|
||||
npm test
|
||||
|
||||
# to re-generate test fixtures
|
||||
npm run test-regen
|
||||
|
||||
# to benchmark against bash/zsh
|
||||
npm run bench
|
||||
|
||||
# to profile javascript
|
||||
npm run prof
|
||||
```
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
## 7.0
|
||||
|
||||
- Raise error if `options.cwd` is specified, and not a directory
|
||||
|
||||
## 6.0
|
||||
|
||||
- Remove comment and negation pattern support
|
||||
- Ignore patterns are always in `dot:true` mode
|
||||
|
||||
## 5.0
|
||||
|
||||
- Deprecate comment and negation patterns
|
||||
- Fix regression in `mark` and `nodir` options from making all cache
|
||||
keys absolute path.
|
||||
- Abort if `fs.readdir` returns an error that's unexpected
|
||||
- Don't emit `match` events for ignored items
|
||||
- Treat ENOTSUP like ENOTDIR in readdir
|
||||
|
||||
## 4.5
|
||||
|
||||
- Add `options.follow` to always follow directory symlinks in globstar
|
||||
- Add `options.realpath` to call `fs.realpath` on all results
|
||||
- Always cache based on absolute path
|
||||
|
||||
## 4.4
|
||||
|
||||
- Add `options.ignore`
|
||||
- Fix handling of broken symlinks
|
||||
|
||||
## 4.3
|
||||
|
||||
- Bump minimatch to 2.x
|
||||
- Pass all tests on Windows
|
||||
|
||||
## 4.2
|
||||
|
||||
- Add `glob.hasMagic` function
|
||||
- Add `options.nodir` flag
|
||||
|
||||
## 4.1
|
||||
|
||||
- Refactor sync and async implementations for performance
|
||||
- Throw if callback provided to sync glob function
|
||||
- Treat symbolic links in globstar results the same as Bash 4.3
|
||||
|
||||
## 4.0
|
||||
|
||||
- Use `^` for dependency versions (bumped major because this breaks
|
||||
older npm versions)
|
||||
- Ensure callbacks are only ever called once
|
||||
- switch to ISC license
|
||||
|
||||
## 3.x
|
||||
|
||||
- Rewrite in JavaScript
|
||||
- Add support for setting root, cwd, and windows support
|
||||
- Cache many fs calls
|
||||
- Add globstar support
|
||||
- emit match events
|
||||
|
||||
## 2.x
|
||||
|
||||
- Use `glob.h` and `fnmatch.h` from NetBSD
|
||||
|
||||
## 1.x
|
||||
|
||||
- `glob.h` static binding.
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
exports.alphasort = alphasort
|
||||
exports.alphasorti = alphasorti
|
||||
exports.setopts = setopts
|
||||
exports.ownProp = ownProp
|
||||
exports.makeAbs = makeAbs
|
||||
exports.finish = finish
|
||||
exports.mark = mark
|
||||
exports.isIgnored = isIgnored
|
||||
exports.childrenIgnored = childrenIgnored
|
||||
|
||||
function ownProp (obj, field) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, field)
|
||||
}
|
||||
|
||||
var path = require("path")
|
||||
var minimatch = require("minimatch")
|
||||
var isAbsolute = require("path-is-absolute")
|
||||
var Minimatch = minimatch.Minimatch
|
||||
|
||||
function alphasorti (a, b) {
|
||||
return a.toLowerCase().localeCompare(b.toLowerCase())
|
||||
}
|
||||
|
||||
function alphasort (a, b) {
|
||||
return a.localeCompare(b)
|
||||
}
|
||||
|
||||
function setupIgnores (self, options) {
|
||||
self.ignore = options.ignore || []
|
||||
|
||||
if (!Array.isArray(self.ignore))
|
||||
self.ignore = [self.ignore]
|
||||
|
||||
if (self.ignore.length) {
|
||||
self.ignore = self.ignore.map(ignoreMap)
|
||||
}
|
||||
}
|
||||
|
||||
// ignore patterns are always in dot:true mode.
|
||||
function ignoreMap (pattern) {
|
||||
var gmatcher = null
|
||||
if (pattern.slice(-3) === '/**') {
|
||||
var gpattern = pattern.replace(/(\/\*\*)+$/, '')
|
||||
gmatcher = new Minimatch(gpattern, { dot: true })
|
||||
}
|
||||
|
||||
return {
|
||||
matcher: new Minimatch(pattern, { dot: true }),
|
||||
gmatcher: gmatcher
|
||||
}
|
||||
}
|
||||
|
||||
function setopts (self, pattern, options) {
|
||||
if (!options)
|
||||
options = {}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
self.silent = !!options.silent
|
||||
self.pattern = pattern
|
||||
self.strict = options.strict !== false
|
||||
self.realpath = !!options.realpath
|
||||
self.realpathCache = options.realpathCache || Object.create(null)
|
||||
self.follow = !!options.follow
|
||||
self.dot = !!options.dot
|
||||
self.mark = !!options.mark
|
||||
self.nodir = !!options.nodir
|
||||
if (self.nodir)
|
||||
self.mark = true
|
||||
self.sync = !!options.sync
|
||||
self.nounique = !!options.nounique
|
||||
self.nonull = !!options.nonull
|
||||
self.nosort = !!options.nosort
|
||||
self.nocase = !!options.nocase
|
||||
self.stat = !!options.stat
|
||||
self.noprocess = !!options.noprocess
|
||||
self.absolute = !!options.absolute
|
||||
|
||||
self.maxLength = options.maxLength || Infinity
|
||||
self.cache = options.cache || Object.create(null)
|
||||
self.statCache = options.statCache || Object.create(null)
|
||||
self.symlinks = options.symlinks || Object.create(null)
|
||||
|
||||
setupIgnores(self, options)
|
||||
|
||||
self.changedCwd = false
|
||||
var cwd = process.cwd()
|
||||
if (!ownProp(options, "cwd"))
|
||||
self.cwd = cwd
|
||||
else {
|
||||
self.cwd = path.resolve(options.cwd)
|
||||
self.changedCwd = self.cwd !== cwd
|
||||
}
|
||||
|
||||
self.root = options.root || path.resolve(self.cwd, "/")
|
||||
self.root = path.resolve(self.root)
|
||||
if (process.platform === "win32")
|
||||
self.root = self.root.replace(/\\/g, "/")
|
||||
|
||||
// TODO: is an absolute `cwd` supposed to be resolved against `root`?
|
||||
// e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
|
||||
self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd)
|
||||
if (process.platform === "win32")
|
||||
self.cwdAbs = self.cwdAbs.replace(/\\/g, "/")
|
||||
self.nomount = !!options.nomount
|
||||
|
||||
// disable comments and negation in Minimatch.
|
||||
// Note that they are not supported in Glob itself anyway.
|
||||
options.nonegate = true
|
||||
options.nocomment = true
|
||||
|
||||
self.minimatch = new Minimatch(pattern, options)
|
||||
self.options = self.minimatch.options
|
||||
}
|
||||
|
||||
function finish (self) {
|
||||
var nou = self.nounique
|
||||
var all = nou ? [] : Object.create(null)
|
||||
|
||||
for (var i = 0, l = self.matches.length; i < l; i ++) {
|
||||
var matches = self.matches[i]
|
||||
if (!matches || Object.keys(matches).length === 0) {
|
||||
if (self.nonull) {
|
||||
// do like the shell, and spit out the literal glob
|
||||
var literal = self.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 (!self.nosort)
|
||||
all = all.sort(self.nocase ? alphasorti : alphasort)
|
||||
|
||||
// at *some* point we statted all of these
|
||||
if (self.mark) {
|
||||
for (var i = 0; i < all.length; i++) {
|
||||
all[i] = self._mark(all[i])
|
||||
}
|
||||
if (self.nodir) {
|
||||
all = all.filter(function (e) {
|
||||
var notDir = !(/\/$/.test(e))
|
||||
var c = self.cache[e] || self.cache[makeAbs(self, e)]
|
||||
if (notDir && c)
|
||||
notDir = c !== 'DIR' && !Array.isArray(c)
|
||||
return notDir
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (self.ignore.length)
|
||||
all = all.filter(function(m) {
|
||||
return !isIgnored(self, m)
|
||||
})
|
||||
|
||||
self.found = all
|
||||
}
|
||||
|
||||
function mark (self, p) {
|
||||
var abs = makeAbs(self, p)
|
||||
var c = self.cache[abs]
|
||||
var m = p
|
||||
if (c) {
|
||||
var isDir = c === 'DIR' || Array.isArray(c)
|
||||
var slash = p.slice(-1) === '/'
|
||||
|
||||
if (isDir && !slash)
|
||||
m += '/'
|
||||
else if (!isDir && slash)
|
||||
m = m.slice(0, -1)
|
||||
|
||||
if (m !== p) {
|
||||
var mabs = makeAbs(self, m)
|
||||
self.statCache[mabs] = self.statCache[abs]
|
||||
self.cache[mabs] = self.cache[abs]
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// lotta situps...
|
||||
function makeAbs (self, f) {
|
||||
var abs = f
|
||||
if (f.charAt(0) === '/') {
|
||||
abs = path.join(self.root, f)
|
||||
} else if (isAbsolute(f) || f === '') {
|
||||
abs = f
|
||||
} else if (self.changedCwd) {
|
||||
abs = path.resolve(self.cwd, f)
|
||||
} else {
|
||||
abs = path.resolve(f)
|
||||
}
|
||||
|
||||
if (process.platform === 'win32')
|
||||
abs = abs.replace(/\\/g, '/')
|
||||
|
||||
return abs
|
||||
}
|
||||
|
||||
|
||||
// Return true, if pattern ends with globstar '**', for the accompanying parent directory.
|
||||
// Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
|
||||
function isIgnored (self, path) {
|
||||
if (!self.ignore.length)
|
||||
return false
|
||||
|
||||
return self.ignore.some(function(item) {
|
||||
return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path))
|
||||
})
|
||||
}
|
||||
|
||||
function childrenIgnored (self, path) {
|
||||
if (!self.ignore.length)
|
||||
return false
|
||||
|
||||
return self.ignore.some(function(item) {
|
||||
return !!(item.gmatcher && item.gmatcher.match(path))
|
||||
})
|
||||
}
|
||||
+790
@@ -0,0 +1,790 @@
|
||||
// Approach:
|
||||
//
|
||||
// 1. Get the minimatch set
|
||||
// 2. For each pattern in the set, PROCESS(pattern, false)
|
||||
// 3. Store matches per-set, then uniq them
|
||||
//
|
||||
// PROCESS(pattern, inGlobStar)
|
||||
// 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.
|
||||
//
|
||||
// If inGlobStar and PREFIX is symlink and points to dir
|
||||
// set ENTRIES = []
|
||||
// else readdir(PREFIX) as ENTRIES
|
||||
// If fail, END
|
||||
//
|
||||
// with ENTRIES
|
||||
// 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 .. $], false)
|
||||
// // handle other cases.
|
||||
// for ENTRY in ENTRIES (not dotfiles)
|
||||
// // attach globstar + tail onto the entry
|
||||
// // Mark that this entry is a globstar match
|
||||
// PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
|
||||
//
|
||||
// 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')
|
||||
var rp = require('fs.realpath')
|
||||
var minimatch = require('minimatch')
|
||||
var Minimatch = minimatch.Minimatch
|
||||
var inherits = require('inherits')
|
||||
var EE = require('events').EventEmitter
|
||||
var path = require('path')
|
||||
var assert = require('assert')
|
||||
var isAbsolute = require('path-is-absolute')
|
||||
var globSync = require('./sync.js')
|
||||
var common = require('./common.js')
|
||||
var alphasort = common.alphasort
|
||||
var alphasorti = common.alphasorti
|
||||
var setopts = common.setopts
|
||||
var ownProp = common.ownProp
|
||||
var inflight = require('inflight')
|
||||
var util = require('util')
|
||||
var childrenIgnored = common.childrenIgnored
|
||||
var isIgnored = common.isIgnored
|
||||
|
||||
var once = require('once')
|
||||
|
||||
function glob (pattern, options, cb) {
|
||||
if (typeof options === 'function') cb = options, options = {}
|
||||
if (!options) options = {}
|
||||
|
||||
if (options.sync) {
|
||||
if (cb)
|
||||
throw new TypeError('callback provided to sync glob')
|
||||
return globSync(pattern, options)
|
||||
}
|
||||
|
||||
return new Glob(pattern, options, cb)
|
||||
}
|
||||
|
||||
glob.sync = globSync
|
||||
var GlobSync = glob.GlobSync = globSync.GlobSync
|
||||
|
||||
// old api surface
|
||||
glob.glob = glob
|
||||
|
||||
function extend (origin, add) {
|
||||
if (add === null || typeof add !== 'object') {
|
||||
return origin
|
||||
}
|
||||
|
||||
var keys = Object.keys(add)
|
||||
var i = keys.length
|
||||
while (i--) {
|
||||
origin[keys[i]] = add[keys[i]]
|
||||
}
|
||||
return origin
|
||||
}
|
||||
|
||||
glob.hasMagic = function (pattern, options_) {
|
||||
var options = extend({}, options_)
|
||||
options.noprocess = true
|
||||
|
||||
var g = new Glob(pattern, options)
|
||||
var set = g.minimatch.set
|
||||
|
||||
if (!pattern)
|
||||
return false
|
||||
|
||||
if (set.length > 1)
|
||||
return true
|
||||
|
||||
for (var j = 0; j < set[0].length; j++) {
|
||||
if (typeof set[0][j] !== 'string')
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
glob.Glob = Glob
|
||||
inherits(Glob, EE)
|
||||
function Glob (pattern, options, cb) {
|
||||
if (typeof options === 'function') {
|
||||
cb = options
|
||||
options = null
|
||||
}
|
||||
|
||||
if (options && options.sync) {
|
||||
if (cb)
|
||||
throw new TypeError('callback provided to sync glob')
|
||||
return new GlobSync(pattern, options)
|
||||
}
|
||||
|
||||
if (!(this instanceof Glob))
|
||||
return new Glob(pattern, options, cb)
|
||||
|
||||
setopts(this, pattern, options)
|
||||
this._didRealPath = false
|
||||
|
||||
// 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)
|
||||
|
||||
if (typeof cb === 'function') {
|
||||
cb = once(cb)
|
||||
this.on('error', cb)
|
||||
this.on('end', function (matches) {
|
||||
cb(null, matches)
|
||||
})
|
||||
}
|
||||
|
||||
var self = this
|
||||
this._processing = 0
|
||||
|
||||
this._emitQueue = []
|
||||
this._processQueue = []
|
||||
this.paused = false
|
||||
|
||||
if (this.noprocess)
|
||||
return this
|
||||
|
||||
if (n === 0)
|
||||
return done()
|
||||
|
||||
var sync = true
|
||||
for (var i = 0; i < n; i ++) {
|
||||
this._process(this.minimatch.set[i], i, false, done)
|
||||
}
|
||||
sync = false
|
||||
|
||||
function done () {
|
||||
--self._processing
|
||||
if (self._processing <= 0) {
|
||||
if (sync) {
|
||||
process.nextTick(function () {
|
||||
self._finish()
|
||||
})
|
||||
} else {
|
||||
self._finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Glob.prototype._finish = function () {
|
||||
assert(this instanceof Glob)
|
||||
if (this.aborted)
|
||||
return
|
||||
|
||||
if (this.realpath && !this._didRealpath)
|
||||
return this._realpath()
|
||||
|
||||
common.finish(this)
|
||||
this.emit('end', this.found)
|
||||
}
|
||||
|
||||
Glob.prototype._realpath = function () {
|
||||
if (this._didRealpath)
|
||||
return
|
||||
|
||||
this._didRealpath = true
|
||||
|
||||
var n = this.matches.length
|
||||
if (n === 0)
|
||||
return this._finish()
|
||||
|
||||
var self = this
|
||||
for (var i = 0; i < this.matches.length; i++)
|
||||
this._realpathSet(i, next)
|
||||
|
||||
function next () {
|
||||
if (--n === 0)
|
||||
self._finish()
|
||||
}
|
||||
}
|
||||
|
||||
Glob.prototype._realpathSet = function (index, cb) {
|
||||
var matchset = this.matches[index]
|
||||
if (!matchset)
|
||||
return cb()
|
||||
|
||||
var found = Object.keys(matchset)
|
||||
var self = this
|
||||
var n = found.length
|
||||
|
||||
if (n === 0)
|
||||
return cb()
|
||||
|
||||
var set = this.matches[index] = Object.create(null)
|
||||
found.forEach(function (p, i) {
|
||||
// If there's a problem with the stat, then it means that
|
||||
// one or more of the links in the realpath couldn't be
|
||||
// resolved. just return the abs value in that case.
|
||||
p = self._makeAbs(p)
|
||||
rp.realpath(p, self.realpathCache, function (er, real) {
|
||||
if (!er)
|
||||
set[real] = true
|
||||
else if (er.syscall === 'stat')
|
||||
set[p] = true
|
||||
else
|
||||
self.emit('error', er) // srsly wtf right here
|
||||
|
||||
if (--n === 0) {
|
||||
self.matches[index] = set
|
||||
cb()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Glob.prototype._mark = function (p) {
|
||||
return common.mark(this, p)
|
||||
}
|
||||
|
||||
Glob.prototype._makeAbs = function (f) {
|
||||
return common.makeAbs(this, f)
|
||||
}
|
||||
|
||||
Glob.prototype.abort = function () {
|
||||
this.aborted = true
|
||||
this.emit('abort')
|
||||
}
|
||||
|
||||
Glob.prototype.pause = function () {
|
||||
if (!this.paused) {
|
||||
this.paused = true
|
||||
this.emit('pause')
|
||||
}
|
||||
}
|
||||
|
||||
Glob.prototype.resume = function () {
|
||||
if (this.paused) {
|
||||
this.emit('resume')
|
||||
this.paused = false
|
||||
if (this._emitQueue.length) {
|
||||
var eq = this._emitQueue.slice(0)
|
||||
this._emitQueue.length = 0
|
||||
for (var i = 0; i < eq.length; i ++) {
|
||||
var e = eq[i]
|
||||
this._emitMatch(e[0], e[1])
|
||||
}
|
||||
}
|
||||
if (this._processQueue.length) {
|
||||
var pq = this._processQueue.slice(0)
|
||||
this._processQueue.length = 0
|
||||
for (var i = 0; i < pq.length; i ++) {
|
||||
var p = pq[i]
|
||||
this._processing--
|
||||
this._process(p[0], p[1], p[2], p[3])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
|
||||
assert(this instanceof Glob)
|
||||
assert(typeof cb === 'function')
|
||||
|
||||
if (this.aborted)
|
||||
return
|
||||
|
||||
this._processing++
|
||||
if (this.paused) {
|
||||
this._processQueue.push([pattern, index, inGlobStar, cb])
|
||||
return
|
||||
}
|
||||
|
||||
//console.error('PROCESS %d', this._processing, pattern)
|
||||
|
||||
// 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:
|
||||
this._processSimple(pattern.join('/'), index, 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).join('/')
|
||||
break
|
||||
}
|
||||
|
||||
var remain = pattern.slice(n)
|
||||
|
||||
// get the list of entries.
|
||||
var read
|
||||
if (prefix === null)
|
||||
read = '.'
|
||||
else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
|
||||
if (!prefix || !isAbsolute(prefix))
|
||||
prefix = '/' + prefix
|
||||
read = prefix
|
||||
} else
|
||||
read = prefix
|
||||
|
||||
var abs = this._makeAbs(read)
|
||||
|
||||
//if ignored, skip _processing
|
||||
if (childrenIgnored(this, read))
|
||||
return cb()
|
||||
|
||||
var isGlobStar = remain[0] === minimatch.GLOBSTAR
|
||||
if (isGlobStar)
|
||||
this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb)
|
||||
else
|
||||
this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb)
|
||||
}
|
||||
|
||||
Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
|
||||
var self = this
|
||||
this._readdir(abs, inGlobStar, function (er, entries) {
|
||||
return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
|
||||
})
|
||||
}
|
||||
|
||||
Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
|
||||
|
||||
// if the abs isn't a dir, then nothing can match!
|
||||
if (!entries)
|
||||
return cb()
|
||||
|
||||
// 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 = remain[0]
|
||||
var negate = !!this.minimatch.negate
|
||||
var rawGlob = pn._glob
|
||||
var dotOk = this.dot || rawGlob.charAt(0) === '.'
|
||||
|
||||
var matchedEntries = []
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var e = entries[i]
|
||||
if (e.charAt(0) !== '.' || dotOk) {
|
||||
var m
|
||||
if (negate && !prefix) {
|
||||
m = !e.match(pn)
|
||||
} else {
|
||||
m = e.match(pn)
|
||||
}
|
||||
if (m)
|
||||
matchedEntries.push(e)
|
||||
}
|
||||
}
|
||||
|
||||
//console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
|
||||
|
||||
var len = matchedEntries.length
|
||||
// If there are no matched entries, then nothing matches.
|
||||
if (len === 0)
|
||||
return cb()
|
||||
|
||||
// if this is the last remaining pattern bit, then no need for
|
||||
// an additional stat *unless* the user has specified mark or
|
||||
// stat explicitly. We know they exist, since readdir returned
|
||||
// them.
|
||||
|
||||
if (remain.length === 1 && !this.mark && !this.stat) {
|
||||
if (!this.matches[index])
|
||||
this.matches[index] = Object.create(null)
|
||||
|
||||
for (var i = 0; i < len; i ++) {
|
||||
var e = matchedEntries[i]
|
||||
if (prefix) {
|
||||
if (prefix !== '/')
|
||||
e = prefix + '/' + e
|
||||
else
|
||||
e = prefix + e
|
||||
}
|
||||
|
||||
if (e.charAt(0) === '/' && !this.nomount) {
|
||||
e = path.join(this.root, e)
|
||||
}
|
||||
this._emitMatch(index, e)
|
||||
}
|
||||
// This was the last one, and no stats were needed
|
||||
return cb()
|
||||
}
|
||||
|
||||
// now test all matched entries as stand-ins for that part
|
||||
// of the pattern.
|
||||
remain.shift()
|
||||
for (var i = 0; i < len; i ++) {
|
||||
var e = matchedEntries[i]
|
||||
var newPattern
|
||||
if (prefix) {
|
||||
if (prefix !== '/')
|
||||
e = prefix + '/' + e
|
||||
else
|
||||
e = prefix + e
|
||||
}
|
||||
this._process([e].concat(remain), index, inGlobStar, cb)
|
||||
}
|
||||
cb()
|
||||
}
|
||||
|
||||
Glob.prototype._emitMatch = function (index, e) {
|
||||
if (this.aborted)
|
||||
return
|
||||
|
||||
if (isIgnored(this, e))
|
||||
return
|
||||
|
||||
if (this.paused) {
|
||||
this._emitQueue.push([index, e])
|
||||
return
|
||||
}
|
||||
|
||||
var abs = isAbsolute(e) ? e : this._makeAbs(e)
|
||||
|
||||
if (this.mark)
|
||||
e = this._mark(e)
|
||||
|
||||
if (this.absolute)
|
||||
e = abs
|
||||
|
||||
if (this.matches[index][e])
|
||||
return
|
||||
|
||||
if (this.nodir) {
|
||||
var c = this.cache[abs]
|
||||
if (c === 'DIR' || Array.isArray(c))
|
||||
return
|
||||
}
|
||||
|
||||
this.matches[index][e] = true
|
||||
|
||||
var st = this.statCache[abs]
|
||||
if (st)
|
||||
this.emit('stat', e, st)
|
||||
|
||||
this.emit('match', e)
|
||||
}
|
||||
|
||||
Glob.prototype._readdirInGlobStar = function (abs, cb) {
|
||||
if (this.aborted)
|
||||
return
|
||||
|
||||
// follow all symlinked directories forever
|
||||
// just proceed as if this is a non-globstar situation
|
||||
if (this.follow)
|
||||
return this._readdir(abs, false, cb)
|
||||
|
||||
var lstatkey = 'lstat\0' + abs
|
||||
var self = this
|
||||
var lstatcb = inflight(lstatkey, lstatcb_)
|
||||
|
||||
if (lstatcb)
|
||||
fs.lstat(abs, lstatcb)
|
||||
|
||||
function lstatcb_ (er, lstat) {
|
||||
if (er && er.code === 'ENOENT')
|
||||
return cb()
|
||||
|
||||
var isSym = lstat && lstat.isSymbolicLink()
|
||||
self.symlinks[abs] = isSym
|
||||
|
||||
// If it's not a symlink or a dir, then it's definitely a regular file.
|
||||
// don't bother doing a readdir in that case.
|
||||
if (!isSym && lstat && !lstat.isDirectory()) {
|
||||
self.cache[abs] = 'FILE'
|
||||
cb()
|
||||
} else
|
||||
self._readdir(abs, false, cb)
|
||||
}
|
||||
}
|
||||
|
||||
Glob.prototype._readdir = function (abs, inGlobStar, cb) {
|
||||
if (this.aborted)
|
||||
return
|
||||
|
||||
cb = inflight('readdir\0'+abs+'\0'+inGlobStar, cb)
|
||||
if (!cb)
|
||||
return
|
||||
|
||||
//console.error('RD %j %j', +inGlobStar, abs)
|
||||
if (inGlobStar && !ownProp(this.symlinks, abs))
|
||||
return this._readdirInGlobStar(abs, cb)
|
||||
|
||||
if (ownProp(this.cache, abs)) {
|
||||
var c = this.cache[abs]
|
||||
if (!c || c === 'FILE')
|
||||
return cb()
|
||||
|
||||
if (Array.isArray(c))
|
||||
return cb(null, c)
|
||||
}
|
||||
|
||||
var self = this
|
||||
fs.readdir(abs, readdirCb(this, abs, cb))
|
||||
}
|
||||
|
||||
function readdirCb (self, abs, cb) {
|
||||
return function (er, entries) {
|
||||
if (er)
|
||||
self._readdirError(abs, er, cb)
|
||||
else
|
||||
self._readdirEntries(abs, entries, cb)
|
||||
}
|
||||
}
|
||||
|
||||
Glob.prototype._readdirEntries = function (abs, entries, cb) {
|
||||
if (this.aborted)
|
||||
return
|
||||
|
||||
// if we haven't asked to stat everything, then just
|
||||
// assume that everything in there exists, so we can avoid
|
||||
// having to stat it a second time.
|
||||
if (!this.mark && !this.stat) {
|
||||
for (var i = 0; i < entries.length; i ++) {
|
||||
var e = entries[i]
|
||||
if (abs === '/')
|
||||
e = abs + e
|
||||
else
|
||||
e = abs + '/' + e
|
||||
this.cache[e] = true
|
||||
}
|
||||
}
|
||||
|
||||
this.cache[abs] = entries
|
||||
return cb(null, entries)
|
||||
}
|
||||
|
||||
Glob.prototype._readdirError = function (f, er, cb) {
|
||||
if (this.aborted)
|
||||
return
|
||||
|
||||
// handle errors, and cache the information
|
||||
switch (er.code) {
|
||||
case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
|
||||
case 'ENOTDIR': // totally normal. means it *does* exist.
|
||||
var abs = this._makeAbs(f)
|
||||
this.cache[abs] = 'FILE'
|
||||
if (abs === this.cwdAbs) {
|
||||
var error = new Error(er.code + ' invalid cwd ' + this.cwd)
|
||||
error.path = this.cwd
|
||||
error.code = er.code
|
||||
this.emit('error', error)
|
||||
this.abort()
|
||||
}
|
||||
break
|
||||
|
||||
case 'ENOENT': // not terribly unusual
|
||||
case 'ELOOP':
|
||||
case 'ENAMETOOLONG':
|
||||
case 'UNKNOWN':
|
||||
this.cache[this._makeAbs(f)] = false
|
||||
break
|
||||
|
||||
default: // some unusual error. Treat as failure.
|
||||
this.cache[this._makeAbs(f)] = false
|
||||
if (this.strict) {
|
||||
this.emit('error', er)
|
||||
// If the error is handled, then we abort
|
||||
// if not, we threw out of here
|
||||
this.abort()
|
||||
}
|
||||
if (!this.silent)
|
||||
console.error('glob error', er)
|
||||
break
|
||||
}
|
||||
|
||||
return cb()
|
||||
}
|
||||
|
||||
Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
|
||||
var self = this
|
||||
this._readdir(abs, inGlobStar, function (er, entries) {
|
||||
self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
|
||||
//console.error('pgs2', prefix, remain[0], entries)
|
||||
|
||||
// no entries means not a dir, so it can never have matches
|
||||
// foo.txt/** doesn't match foo.txt
|
||||
if (!entries)
|
||||
return cb()
|
||||
|
||||
// test without the globstar, and with every child both below
|
||||
// and replacing the globstar.
|
||||
var remainWithoutGlobStar = remain.slice(1)
|
||||
var gspref = prefix ? [ prefix ] : []
|
||||
var noGlobStar = gspref.concat(remainWithoutGlobStar)
|
||||
|
||||
// the noGlobStar pattern exits the inGlobStar state
|
||||
this._process(noGlobStar, index, false, cb)
|
||||
|
||||
var isSym = this.symlinks[abs]
|
||||
var len = entries.length
|
||||
|
||||
// If it's a symlink, and we're in a globstar, then stop
|
||||
if (isSym && inGlobStar)
|
||||
return cb()
|
||||
|
||||
for (var i = 0; i < len; i++) {
|
||||
var e = entries[i]
|
||||
if (e.charAt(0) === '.' && !this.dot)
|
||||
continue
|
||||
|
||||
// these two cases enter the inGlobStar state
|
||||
var instead = gspref.concat(entries[i], remainWithoutGlobStar)
|
||||
this._process(instead, index, true, cb)
|
||||
|
||||
var below = gspref.concat(entries[i], remain)
|
||||
this._process(below, index, true, cb)
|
||||
}
|
||||
|
||||
cb()
|
||||
}
|
||||
|
||||
Glob.prototype._processSimple = function (prefix, index, cb) {
|
||||
// XXX review this. Shouldn't it be doing the mounting etc
|
||||
// before doing stat? kinda weird?
|
||||
var self = this
|
||||
this._stat(prefix, function (er, exists) {
|
||||
self._processSimple2(prefix, index, er, exists, cb)
|
||||
})
|
||||
}
|
||||
Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
|
||||
|
||||
//console.error('ps2', prefix, exists)
|
||||
|
||||
if (!this.matches[index])
|
||||
this.matches[index] = Object.create(null)
|
||||
|
||||
// If it doesn't exist, then just mark the lack of results
|
||||
if (!exists)
|
||||
return cb()
|
||||
|
||||
if (prefix && isAbsolute(prefix) && !this.nomount) {
|
||||
var trail = /[\/\\]$/.test(prefix)
|
||||
if (prefix.charAt(0) === '/') {
|
||||
prefix = path.join(this.root, prefix)
|
||||
} else {
|
||||
prefix = path.resolve(this.root, prefix)
|
||||
if (trail)
|
||||
prefix += '/'
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === 'win32')
|
||||
prefix = prefix.replace(/\\/g, '/')
|
||||
|
||||
// Mark this as a match
|
||||
this._emitMatch(index, prefix)
|
||||
cb()
|
||||
}
|
||||
|
||||
// Returns either 'DIR', 'FILE', or false
|
||||
Glob.prototype._stat = function (f, cb) {
|
||||
var abs = this._makeAbs(f)
|
||||
var needDir = f.slice(-1) === '/'
|
||||
|
||||
if (f.length > this.maxLength)
|
||||
return cb()
|
||||
|
||||
if (!this.stat && ownProp(this.cache, abs)) {
|
||||
var c = this.cache[abs]
|
||||
|
||||
if (Array.isArray(c))
|
||||
c = 'DIR'
|
||||
|
||||
// It exists, but maybe not how we need it
|
||||
if (!needDir || c === 'DIR')
|
||||
return cb(null, c)
|
||||
|
||||
if (needDir && c === 'FILE')
|
||||
return cb()
|
||||
|
||||
// otherwise we have to stat, because maybe c=true
|
||||
// if we know it exists, but not what it is.
|
||||
}
|
||||
|
||||
var exists
|
||||
var stat = this.statCache[abs]
|
||||
if (stat !== undefined) {
|
||||
if (stat === false)
|
||||
return cb(null, stat)
|
||||
else {
|
||||
var type = stat.isDirectory() ? 'DIR' : 'FILE'
|
||||
if (needDir && type === 'FILE')
|
||||
return cb()
|
||||
else
|
||||
return cb(null, type, stat)
|
||||
}
|
||||
}
|
||||
|
||||
var self = this
|
||||
var statcb = inflight('stat\0' + abs, lstatcb_)
|
||||
if (statcb)
|
||||
fs.lstat(abs, statcb)
|
||||
|
||||
function lstatcb_ (er, lstat) {
|
||||
if (lstat && lstat.isSymbolicLink()) {
|
||||
// If it's a symlink, then treat it as the target, unless
|
||||
// the target does not exist, then treat it as a file.
|
||||
return fs.stat(abs, function (er, stat) {
|
||||
if (er)
|
||||
self._stat2(f, abs, null, lstat, cb)
|
||||
else
|
||||
self._stat2(f, abs, er, stat, cb)
|
||||
})
|
||||
} else {
|
||||
self._stat2(f, abs, er, lstat, cb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
|
||||
if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
|
||||
this.statCache[abs] = false
|
||||
return cb()
|
||||
}
|
||||
|
||||
var needDir = f.slice(-1) === '/'
|
||||
this.statCache[abs] = stat
|
||||
|
||||
if (abs.slice(-1) === '/' && stat && !stat.isDirectory())
|
||||
return cb(null, false, stat)
|
||||
|
||||
var c = true
|
||||
if (stat)
|
||||
c = stat.isDirectory() ? 'DIR' : 'FILE'
|
||||
this.cache[abs] = this.cache[abs] || c
|
||||
|
||||
if (needDir && c === 'FILE')
|
||||
return cb()
|
||||
|
||||
return cb(null, c, stat)
|
||||
}
|
||||
+114
File diff suppressed because one or more lines are too long
+486
@@ -0,0 +1,486 @@
|
||||
module.exports = globSync
|
||||
globSync.GlobSync = GlobSync
|
||||
|
||||
var fs = require('fs')
|
||||
var rp = require('fs.realpath')
|
||||
var minimatch = require('minimatch')
|
||||
var Minimatch = minimatch.Minimatch
|
||||
var Glob = require('./glob.js').Glob
|
||||
var util = require('util')
|
||||
var path = require('path')
|
||||
var assert = require('assert')
|
||||
var isAbsolute = require('path-is-absolute')
|
||||
var common = require('./common.js')
|
||||
var alphasort = common.alphasort
|
||||
var alphasorti = common.alphasorti
|
||||
var setopts = common.setopts
|
||||
var ownProp = common.ownProp
|
||||
var childrenIgnored = common.childrenIgnored
|
||||
var isIgnored = common.isIgnored
|
||||
|
||||
function globSync (pattern, options) {
|
||||
if (typeof options === 'function' || arguments.length === 3)
|
||||
throw new TypeError('callback provided to sync glob\n'+
|
||||
'See: https://github.com/isaacs/node-glob/issues/167')
|
||||
|
||||
return new GlobSync(pattern, options).found
|
||||
}
|
||||
|
||||
function GlobSync (pattern, options) {
|
||||
if (!pattern)
|
||||
throw new Error('must provide pattern')
|
||||
|
||||
if (typeof options === 'function' || arguments.length === 3)
|
||||
throw new TypeError('callback provided to sync glob\n'+
|
||||
'See: https://github.com/isaacs/node-glob/issues/167')
|
||||
|
||||
if (!(this instanceof GlobSync))
|
||||
return new GlobSync(pattern, options)
|
||||
|
||||
setopts(this, pattern, options)
|
||||
|
||||
if (this.noprocess)
|
||||
return this
|
||||
|
||||
var n = this.minimatch.set.length
|
||||
this.matches = new Array(n)
|
||||
for (var i = 0; i < n; i ++) {
|
||||
this._process(this.minimatch.set[i], i, false)
|
||||
}
|
||||
this._finish()
|
||||
}
|
||||
|
||||
GlobSync.prototype._finish = function () {
|
||||
assert(this instanceof GlobSync)
|
||||
if (this.realpath) {
|
||||
var self = this
|
||||
this.matches.forEach(function (matchset, index) {
|
||||
var set = self.matches[index] = Object.create(null)
|
||||
for (var p in matchset) {
|
||||
try {
|
||||
p = self._makeAbs(p)
|
||||
var real = rp.realpathSync(p, self.realpathCache)
|
||||
set[real] = true
|
||||
} catch (er) {
|
||||
if (er.syscall === 'stat')
|
||||
set[self._makeAbs(p)] = true
|
||||
else
|
||||
throw er
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
common.finish(this)
|
||||
}
|
||||
|
||||
|
||||
GlobSync.prototype._process = function (pattern, index, inGlobStar) {
|
||||
assert(this instanceof GlobSync)
|
||||
|
||||
// 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:
|
||||
this._processSimple(pattern.join('/'), index)
|
||||
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).join('/')
|
||||
break
|
||||
}
|
||||
|
||||
var remain = pattern.slice(n)
|
||||
|
||||
// get the list of entries.
|
||||
var read
|
||||
if (prefix === null)
|
||||
read = '.'
|
||||
else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
|
||||
if (!prefix || !isAbsolute(prefix))
|
||||
prefix = '/' + prefix
|
||||
read = prefix
|
||||
} else
|
||||
read = prefix
|
||||
|
||||
var abs = this._makeAbs(read)
|
||||
|
||||
//if ignored, skip processing
|
||||
if (childrenIgnored(this, read))
|
||||
return
|
||||
|
||||
var isGlobStar = remain[0] === minimatch.GLOBSTAR
|
||||
if (isGlobStar)
|
||||
this._processGlobStar(prefix, read, abs, remain, index, inGlobStar)
|
||||
else
|
||||
this._processReaddir(prefix, read, abs, remain, index, inGlobStar)
|
||||
}
|
||||
|
||||
|
||||
GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
|
||||
var entries = this._readdir(abs, inGlobStar)
|
||||
|
||||
// if the abs isn't a dir, then nothing can match!
|
||||
if (!entries)
|
||||
return
|
||||
|
||||
// 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 = remain[0]
|
||||
var negate = !!this.minimatch.negate
|
||||
var rawGlob = pn._glob
|
||||
var dotOk = this.dot || rawGlob.charAt(0) === '.'
|
||||
|
||||
var matchedEntries = []
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var e = entries[i]
|
||||
if (e.charAt(0) !== '.' || dotOk) {
|
||||
var m
|
||||
if (negate && !prefix) {
|
||||
m = !e.match(pn)
|
||||
} else {
|
||||
m = e.match(pn)
|
||||
}
|
||||
if (m)
|
||||
matchedEntries.push(e)
|
||||
}
|
||||
}
|
||||
|
||||
var len = matchedEntries.length
|
||||
// If there are no matched entries, then nothing matches.
|
||||
if (len === 0)
|
||||
return
|
||||
|
||||
// if this is the last remaining pattern bit, then no need for
|
||||
// an additional stat *unless* the user has specified mark or
|
||||
// stat explicitly. We know they exist, since readdir returned
|
||||
// them.
|
||||
|
||||
if (remain.length === 1 && !this.mark && !this.stat) {
|
||||
if (!this.matches[index])
|
||||
this.matches[index] = Object.create(null)
|
||||
|
||||
for (var i = 0; i < len; i ++) {
|
||||
var e = matchedEntries[i]
|
||||
if (prefix) {
|
||||
if (prefix.slice(-1) !== '/')
|
||||
e = prefix + '/' + e
|
||||
else
|
||||
e = prefix + e
|
||||
}
|
||||
|
||||
if (e.charAt(0) === '/' && !this.nomount) {
|
||||
e = path.join(this.root, e)
|
||||
}
|
||||
this._emitMatch(index, e)
|
||||
}
|
||||
// This was the last one, and no stats were needed
|
||||
return
|
||||
}
|
||||
|
||||
// now test all matched entries as stand-ins for that part
|
||||
// of the pattern.
|
||||
remain.shift()
|
||||
for (var i = 0; i < len; i ++) {
|
||||
var e = matchedEntries[i]
|
||||
var newPattern
|
||||
if (prefix)
|
||||
newPattern = [prefix, e]
|
||||
else
|
||||
newPattern = [e]
|
||||
this._process(newPattern.concat(remain), index, inGlobStar)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GlobSync.prototype._emitMatch = function (index, e) {
|
||||
if (isIgnored(this, e))
|
||||
return
|
||||
|
||||
var abs = this._makeAbs(e)
|
||||
|
||||
if (this.mark)
|
||||
e = this._mark(e)
|
||||
|
||||
if (this.absolute) {
|
||||
e = abs
|
||||
}
|
||||
|
||||
if (this.matches[index][e])
|
||||
return
|
||||
|
||||
if (this.nodir) {
|
||||
var c = this.cache[abs]
|
||||
if (c === 'DIR' || Array.isArray(c))
|
||||
return
|
||||
}
|
||||
|
||||
this.matches[index][e] = true
|
||||
|
||||
if (this.stat)
|
||||
this._stat(e)
|
||||
}
|
||||
|
||||
|
||||
GlobSync.prototype._readdirInGlobStar = function (abs) {
|
||||
// follow all symlinked directories forever
|
||||
// just proceed as if this is a non-globstar situation
|
||||
if (this.follow)
|
||||
return this._readdir(abs, false)
|
||||
|
||||
var entries
|
||||
var lstat
|
||||
var stat
|
||||
try {
|
||||
lstat = fs.lstatSync(abs)
|
||||
} catch (er) {
|
||||
if (er.code === 'ENOENT') {
|
||||
// lstat failed, doesn't exist
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
var isSym = lstat && lstat.isSymbolicLink()
|
||||
this.symlinks[abs] = isSym
|
||||
|
||||
// If it's not a symlink or a dir, then it's definitely a regular file.
|
||||
// don't bother doing a readdir in that case.
|
||||
if (!isSym && lstat && !lstat.isDirectory())
|
||||
this.cache[abs] = 'FILE'
|
||||
else
|
||||
entries = this._readdir(abs, false)
|
||||
|
||||
return entries
|
||||
}
|
||||
|
||||
GlobSync.prototype._readdir = function (abs, inGlobStar) {
|
||||
var entries
|
||||
|
||||
if (inGlobStar && !ownProp(this.symlinks, abs))
|
||||
return this._readdirInGlobStar(abs)
|
||||
|
||||
if (ownProp(this.cache, abs)) {
|
||||
var c = this.cache[abs]
|
||||
if (!c || c === 'FILE')
|
||||
return null
|
||||
|
||||
if (Array.isArray(c))
|
||||
return c
|
||||
}
|
||||
|
||||
try {
|
||||
return this._readdirEntries(abs, fs.readdirSync(abs))
|
||||
} catch (er) {
|
||||
this._readdirError(abs, er)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
GlobSync.prototype._readdirEntries = function (abs, entries) {
|
||||
// if we haven't asked to stat everything, then just
|
||||
// assume that everything in there exists, so we can avoid
|
||||
// having to stat it a second time.
|
||||
if (!this.mark && !this.stat) {
|
||||
for (var i = 0; i < entries.length; i ++) {
|
||||
var e = entries[i]
|
||||
if (abs === '/')
|
||||
e = abs + e
|
||||
else
|
||||
e = abs + '/' + e
|
||||
this.cache[e] = true
|
||||
}
|
||||
}
|
||||
|
||||
this.cache[abs] = entries
|
||||
|
||||
// mark and cache dir-ness
|
||||
return entries
|
||||
}
|
||||
|
||||
GlobSync.prototype._readdirError = function (f, er) {
|
||||
// handle errors, and cache the information
|
||||
switch (er.code) {
|
||||
case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
|
||||
case 'ENOTDIR': // totally normal. means it *does* exist.
|
||||
var abs = this._makeAbs(f)
|
||||
this.cache[abs] = 'FILE'
|
||||
if (abs === this.cwdAbs) {
|
||||
var error = new Error(er.code + ' invalid cwd ' + this.cwd)
|
||||
error.path = this.cwd
|
||||
error.code = er.code
|
||||
throw error
|
||||
}
|
||||
break
|
||||
|
||||
case 'ENOENT': // not terribly unusual
|
||||
case 'ELOOP':
|
||||
case 'ENAMETOOLONG':
|
||||
case 'UNKNOWN':
|
||||
this.cache[this._makeAbs(f)] = false
|
||||
break
|
||||
|
||||
default: // some unusual error. Treat as failure.
|
||||
this.cache[this._makeAbs(f)] = false
|
||||
if (this.strict)
|
||||
throw er
|
||||
if (!this.silent)
|
||||
console.error('glob error', er)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
GlobSync.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
|
||||
|
||||
var entries = this._readdir(abs, inGlobStar)
|
||||
|
||||
// no entries means not a dir, so it can never have matches
|
||||
// foo.txt/** doesn't match foo.txt
|
||||
if (!entries)
|
||||
return
|
||||
|
||||
// test without the globstar, and with every child both below
|
||||
// and replacing the globstar.
|
||||
var remainWithoutGlobStar = remain.slice(1)
|
||||
var gspref = prefix ? [ prefix ] : []
|
||||
var noGlobStar = gspref.concat(remainWithoutGlobStar)
|
||||
|
||||
// the noGlobStar pattern exits the inGlobStar state
|
||||
this._process(noGlobStar, index, false)
|
||||
|
||||
var len = entries.length
|
||||
var isSym = this.symlinks[abs]
|
||||
|
||||
// If it's a symlink, and we're in a globstar, then stop
|
||||
if (isSym && inGlobStar)
|
||||
return
|
||||
|
||||
for (var i = 0; i < len; i++) {
|
||||
var e = entries[i]
|
||||
if (e.charAt(0) === '.' && !this.dot)
|
||||
continue
|
||||
|
||||
// these two cases enter the inGlobStar state
|
||||
var instead = gspref.concat(entries[i], remainWithoutGlobStar)
|
||||
this._process(instead, index, true)
|
||||
|
||||
var below = gspref.concat(entries[i], remain)
|
||||
this._process(below, index, true)
|
||||
}
|
||||
}
|
||||
|
||||
GlobSync.prototype._processSimple = function (prefix, index) {
|
||||
// XXX review this. Shouldn't it be doing the mounting etc
|
||||
// before doing stat? kinda weird?
|
||||
var exists = this._stat(prefix)
|
||||
|
||||
if (!this.matches[index])
|
||||
this.matches[index] = Object.create(null)
|
||||
|
||||
// If it doesn't exist, then just mark the lack of results
|
||||
if (!exists)
|
||||
return
|
||||
|
||||
if (prefix && isAbsolute(prefix) && !this.nomount) {
|
||||
var trail = /[\/\\]$/.test(prefix)
|
||||
if (prefix.charAt(0) === '/') {
|
||||
prefix = path.join(this.root, prefix)
|
||||
} else {
|
||||
prefix = path.resolve(this.root, prefix)
|
||||
if (trail)
|
||||
prefix += '/'
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === 'win32')
|
||||
prefix = prefix.replace(/\\/g, '/')
|
||||
|
||||
// Mark this as a match
|
||||
this._emitMatch(index, prefix)
|
||||
}
|
||||
|
||||
// Returns either 'DIR', 'FILE', or false
|
||||
GlobSync.prototype._stat = function (f) {
|
||||
var abs = this._makeAbs(f)
|
||||
var needDir = f.slice(-1) === '/'
|
||||
|
||||
if (f.length > this.maxLength)
|
||||
return false
|
||||
|
||||
if (!this.stat && ownProp(this.cache, abs)) {
|
||||
var c = this.cache[abs]
|
||||
|
||||
if (Array.isArray(c))
|
||||
c = 'DIR'
|
||||
|
||||
// It exists, but maybe not how we need it
|
||||
if (!needDir || c === 'DIR')
|
||||
return c
|
||||
|
||||
if (needDir && c === 'FILE')
|
||||
return false
|
||||
|
||||
// otherwise we have to stat, because maybe c=true
|
||||
// if we know it exists, but not what it is.
|
||||
}
|
||||
|
||||
var exists
|
||||
var stat = this.statCache[abs]
|
||||
if (!stat) {
|
||||
var lstat
|
||||
try {
|
||||
lstat = fs.lstatSync(abs)
|
||||
} catch (er) {
|
||||
if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
|
||||
this.statCache[abs] = false
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (lstat && lstat.isSymbolicLink()) {
|
||||
try {
|
||||
stat = fs.statSync(abs)
|
||||
} catch (er) {
|
||||
stat = lstat
|
||||
}
|
||||
} else {
|
||||
stat = lstat
|
||||
}
|
||||
}
|
||||
|
||||
this.statCache[abs] = stat
|
||||
|
||||
var c = true
|
||||
if (stat)
|
||||
c = stat.isDirectory() ? 'DIR' : 'FILE'
|
||||
|
||||
this.cache[abs] = this.cache[abs] || c
|
||||
|
||||
if (needDir && c === 'FILE')
|
||||
return false
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
GlobSync.prototype._mark = function (p) {
|
||||
return common.mark(this, p)
|
||||
}
|
||||
|
||||
GlobSync.prototype._makeAbs = function (f) {
|
||||
return common.makeAbs(this, f)
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2017 "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.
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
# globule [](https://travis-ci.org/cowboy/node-globule) [](https://ci.appveyor.com/project/gruntjs/node-globule/branch/master)
|
||||
|
||||
An easy-to-use wildcard globbing library.
|
||||
|
||||
## Getting Started
|
||||
Install the module with: `npm install globule`
|
||||
|
||||
```javascript
|
||||
var globule = require('globule');
|
||||
var filepaths = globule.find('**/*.js');
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
### globule.find
|
||||
Returns a unique array of all file or directory paths that match the given globbing pattern(s). This method accepts either comma separated globbing patterns or an array of globbing patterns. Paths matching patterns that begin with `!` will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant. Patterns may be specified as function arguments or as a `src` property of the options object.
|
||||
|
||||
```js
|
||||
globule.find(patterns [, patterns [, ...]] [, options])
|
||||
globule.find({src: patterns, /* other options */})
|
||||
```
|
||||
|
||||
The `options` object supports all [glob][] library options, along with a few extras. These are the most commonly used:
|
||||
|
||||
* `src` This property may be used instead of specifying patterns as function arguments.
|
||||
* `filter` Either a valid [fs.Stats method name](http://nodejs.org/docs/latest/api/fs.html#fs_class_fs_stats) or a function that will be passed the matched `src` filepath and `options` object as arguments. This function should return a `Boolean` value.
|
||||
* `nonull` Retain globbing patterns in result set even if they fail to match files.
|
||||
* `matchBase` Patterns without slashes will match just the basename part. Eg. this makes `*.js` work like `**/*.js`.
|
||||
* `srcBase` Patterns will be matched relative to the specified path instead of the current working directory. This is a synonym for `cwd`.
|
||||
* `prefixBase` Any specified `srcBase` will be prefixed to all returned filepaths.
|
||||
|
||||
[glob]: https://github.com/isaacs/node-glob
|
||||
|
||||
### globule.match
|
||||
Match one or more globbing patterns against one or more file paths. Returns a uniqued array of all file paths that match any of the specified globbing patterns. Both the `patterns` and `filepaths` arguments can be a single string or array of strings. Paths matching patterns that begin with `!` will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant.
|
||||
|
||||
```js
|
||||
globule.match(patterns, filepaths [, options])
|
||||
```
|
||||
|
||||
### globule.isMatch
|
||||
This method contains the same signature and logic as the `globule.match` method, but returns `true` if any files were matched, otherwise `false`.
|
||||
|
||||
```js
|
||||
globule.isMatch(patterns, filepaths [, options])
|
||||
```
|
||||
|
||||
### globule.mapping
|
||||
Given a set of source file paths, returns an array of src-dest file mapping objects. Both src and dest paths may be renamed, depending on the options specified. Patterns may be specified as function arguments or as a `src` property of the options object.
|
||||
|
||||
```js
|
||||
globule.mapping(filepaths [, filepaths [, ...]] [, options])
|
||||
globule.mapping({src: filepaths, /* other options */})
|
||||
```
|
||||
|
||||
In addition to the options the `globule.find` method supports, the options object also supports these properties:
|
||||
|
||||
* `srcBase` The directory from which patterns are matched. Any string specified as `srcBase` is effectively stripped from the beginning of all matched paths.
|
||||
* `destBase` The specified path is prefixed to all `dest` filepaths.
|
||||
* `ext` Remove anything after (and including) the first `.` in the destination path, then append this value.
|
||||
* `extDot` Change the behavior of `ext`, `"first"` and `"last"` will remove anything after the first or last `.` in the destination filename, respectively. Defaults to `"first"`.
|
||||
* `flatten` Remove the path component from all matched src files. The src file path is still joined to the specified destBase.
|
||||
* `rename` If specified, this function will be responsible for returning the final `dest` filepath. By default, it flattens paths (if specified), changes extensions (if specified) and joins the matched path to the `destBase`.
|
||||
|
||||
### globule.findMapping
|
||||
This method is a convenience wrapper around the `globule.find` and `globule.mapping` methods.
|
||||
|
||||
```js
|
||||
globule.findMapping(patterns [, options])
|
||||
```
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
Given the files `foo/a.js` and `foo/b.js`:
|
||||
|
||||
### srcBase and destBase
|
||||
|
||||
```js
|
||||
globule.find("foo/*.js")
|
||||
// ["foo/a.js", "foo/b.js"]
|
||||
|
||||
globule.find("*.js", {srcBase: "foo"})
|
||||
// ["a.js", "b.js"]
|
||||
|
||||
globule.find({src: "*.js", srcBase: "foo", prefixBase: true})
|
||||
// ["foo/a.js", "foo/b.js"]
|
||||
```
|
||||
|
||||
```js
|
||||
globule.findMapping("foo/*.js")
|
||||
// [{src: ["foo/a.js"], dest: "foo/a.js"}, {src: ["foo/b.js"], dest: "foo/b.js"}]
|
||||
|
||||
globule.findMapping("foo/*.js", {destBase: "bar"})
|
||||
// [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]
|
||||
|
||||
globule.findMapping({src: "*.js", srcBase: "foo", destBase: "bar"})
|
||||
// [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]
|
||||
```
|
||||
|
||||
```js
|
||||
globule.mapping(["foo/a.js", "foo/b.js"])
|
||||
// [{src: ["foo/a.js"], dest: "foo/a.js"}, {src: ["foo/b.js"], dest: "foo/b.js"}]
|
||||
|
||||
globule.mapping(["foo/a.js", "foo/b.js"], {destBase: "bar"})
|
||||
// [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]
|
||||
|
||||
globule.mapping("foo/a.js", "foo/b.js", {destBase: "bar"})
|
||||
// [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]
|
||||
|
||||
globule.mapping(["a.js", "b.js"], {srcBase: "foo", destBase: "bar"})
|
||||
// [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]
|
||||
|
||||
globule.mapping({src: ["a.js", "b.js"], srcBase: "foo", destBase: "bar"})
|
||||
// [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]
|
||||
```
|
||||
|
||||
## 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
|
||||
2017-06-10 - v1.2.0 - Update dependencies, lodash@4.17.
|
||||
2016-10-23 - v1.1.0 - Update dependencies, lodash@4.16, glob@7.1.
|
||||
2016-04-14 - v1.0.0 - Update dependencies, lodash@4.9, glob@7.0, minimatch@3.0. Paths are unix-style with prefixBase enabled.
|
||||
2014-01-07 - v0.2.0 - Updated dependencies. Added `src` option. Improved exclusion speed significantly.
|
||||
2013-04-11 - v0.1.0 - Initial release.
|
||||
|
||||
## License
|
||||
Copyright (c) 2017 "Cowboy" Ben Alman
|
||||
Licensed under the MIT license.
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* globule
|
||||
* https://github.com/cowboy/node-globule
|
||||
*
|
||||
* Copyright (c) 2017 "Cowboy" Ben Alman
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var _ = require('lodash');
|
||||
var glob = require('glob');
|
||||
var minimatch = require('minimatch');
|
||||
|
||||
// The module.
|
||||
var globule = exports;
|
||||
|
||||
// Process specified wildcard glob patterns or filenames against a
|
||||
// callback, excluding and uniquing files in the result set.
|
||||
function processPatterns(patterns, options, fn) {
|
||||
var result = [];
|
||||
_.each(patterns, function(pattern) {
|
||||
// The first character is not ! (inclusion). Add all matching filepaths
|
||||
// to the result set.
|
||||
if (pattern.indexOf('!') !== 0) {
|
||||
result = _.union(result, fn(pattern));
|
||||
return;
|
||||
}
|
||||
// The first character is ! (exclusion). Remove any filepaths from the
|
||||
// result set that match this pattern, sans leading !.
|
||||
var filterFn = minimatch.filter(pattern.slice(1), options);
|
||||
result = _.filter(result, function(filepath) {
|
||||
return !filterFn(filepath);
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// Normalize paths to be unix-style.
|
||||
var pathSeparatorRe = /[\/\\]/g;
|
||||
function normalizePath(path) {
|
||||
return path.replace(pathSeparatorRe, '/');
|
||||
}
|
||||
|
||||
// Match a filepath or filepaths against one or more wildcard patterns. Returns
|
||||
// all matching filepaths. This behaves just like minimatch.match, but supports
|
||||
// any number of patterns.
|
||||
globule.match = function(patterns, filepaths, options) {
|
||||
// Return empty set if either patterns or filepaths was omitted.
|
||||
if (patterns == null || filepaths == null) { return []; }
|
||||
// Normalize patterns and filepaths to flattened arrays.
|
||||
patterns = _.isArray(patterns) ? _.flattenDeep(patterns) : [patterns];
|
||||
filepaths = _.isArray(filepaths) ? _.flattenDeep(filepaths) : [filepaths];
|
||||
// Return empty set if there are no patterns or filepaths.
|
||||
if (patterns.length === 0 || filepaths.length === 0) { return []; }
|
||||
// Return all matching filepaths.
|
||||
return processPatterns(patterns, options, function(pattern) {
|
||||
return minimatch.match(filepaths, pattern, options || {});
|
||||
});
|
||||
};
|
||||
|
||||
// Match a filepath or filepaths against one or more wildcard patterns. Returns
|
||||
// true if any of the patterns match.
|
||||
globule.isMatch = function() {
|
||||
return globule.match.apply(null, arguments).length > 0;
|
||||
};
|
||||
|
||||
// Return an array of all file paths that match the given wildcard patterns.
|
||||
globule.find = function() {
|
||||
var args = _.toArray(arguments);
|
||||
// If the last argument is an options object, remove it from args.
|
||||
var options = _.isPlainObject(args[args.length - 1]) ? args.pop() : {};
|
||||
// If options.src was specified, use it. Otherwise, use all non-options
|
||||
// arguments. Flatten nested arrays.
|
||||
var patterns;
|
||||
if (options.src) {
|
||||
patterns = _.isArray(options.src) ? _.flattenDeep(options.src) : [options.src];
|
||||
} else {
|
||||
patterns = _.flattenDeep(args);
|
||||
}
|
||||
// Return empty set if there are no patterns.
|
||||
if (patterns.length === 0) { return []; }
|
||||
var srcBase = options.srcBase || options.cwd;
|
||||
// Create glob-specific options object.
|
||||
var globOptions = _.extend({}, options);
|
||||
if (srcBase) {
|
||||
globOptions.cwd = srcBase;
|
||||
}
|
||||
// Get all matching filepaths.
|
||||
var matches = processPatterns(patterns, options, function(pattern) {
|
||||
return glob.sync(pattern, globOptions);
|
||||
});
|
||||
// If srcBase and prefixBase were specified, prefix srcBase to matched paths.
|
||||
if (srcBase && options.prefixBase) {
|
||||
matches = matches.map(function(filepath) {
|
||||
return normalizePath(path.join(srcBase, filepath));
|
||||
});
|
||||
}
|
||||
// Filter result set?
|
||||
if (options.filter) {
|
||||
matches = matches.filter(function(filepath) {
|
||||
// If srcBase was specified but prefixBase was NOT, prefix srcBase
|
||||
// temporarily, for filtering.
|
||||
if (srcBase && !options.prefixBase) {
|
||||
filepath = normalizePath(path.join(srcBase, filepath));
|
||||
}
|
||||
try {
|
||||
if (_.isFunction(options.filter)) {
|
||||
return options.filter(filepath, options);
|
||||
} else {
|
||||
// If the file is of the right type and exists, this should work.
|
||||
return fs.statSync(filepath)[options.filter]();
|
||||
}
|
||||
} catch(err) {
|
||||
// Otherwise, it's probably not the right type.
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
return matches;
|
||||
};
|
||||
|
||||
var extDotRe = {
|
||||
first: /(\.[^\/]*)?$/,
|
||||
last: /(\.[^\/\.]*)?$/,
|
||||
};
|
||||
function rename(dest, options) {
|
||||
// Flatten path?
|
||||
if (options.flatten) {
|
||||
dest = path.basename(dest);
|
||||
}
|
||||
// Change the extension?
|
||||
if (options.ext) {
|
||||
dest = dest.replace(extDotRe[options.extDot], options.ext);
|
||||
}
|
||||
// Join dest and destBase?
|
||||
if (options.destBase) {
|
||||
dest = path.join(options.destBase, dest);
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
// Build a mapping of src-dest filepaths from the given set of filepaths.
|
||||
globule.mapping = function(filepaths, options) {
|
||||
// Return empty set if filepaths was omitted.
|
||||
if (filepaths == null) { return []; }
|
||||
options = _.defaults({}, options, {
|
||||
extDot: 'first',
|
||||
rename: rename,
|
||||
});
|
||||
var files = [];
|
||||
var fileByDest = {};
|
||||
// Find all files matching pattern, using passed-in options.
|
||||
filepaths.forEach(function(src) {
|
||||
// Generate destination filename.
|
||||
var dest = options.rename(src, options);
|
||||
// Prepend srcBase to all src paths.
|
||||
if (options.srcBase) {
|
||||
src = path.join(options.srcBase, src);
|
||||
}
|
||||
// Normalize filepaths to be unix-style.
|
||||
dest = normalizePath(dest);
|
||||
src = normalizePath(src);
|
||||
// Map correct src path to dest path.
|
||||
if (fileByDest[dest]) {
|
||||
// If dest already exists, push this src onto that dest's src array.
|
||||
fileByDest[dest].src.push(src);
|
||||
} else {
|
||||
// Otherwise create a new src-dest file mapping object.
|
||||
files.push({
|
||||
src: [src],
|
||||
dest: dest,
|
||||
});
|
||||
// And store a reference for later use.
|
||||
fileByDest[dest] = files[files.length - 1];
|
||||
}
|
||||
});
|
||||
return files;
|
||||
};
|
||||
|
||||
// Return a mapping of src-dest filepaths from files matching the given
|
||||
// wildcard patterns.
|
||||
globule.findMapping = function() {
|
||||
var args = _.toArray(arguments);
|
||||
// If the last argument is an options object, remove it from args.
|
||||
var options = _.isPlainObject(args[args.length - 1]) ? args.pop() : {};
|
||||
// Generate mapping from found filepaths.
|
||||
return globule.mapping(globule.find(args, options), options);
|
||||
};
|
||||
+115
File diff suppressed because one or more lines are too long
+47
@@ -0,0 +1,47 @@
|
||||
Copyright JS Foundation and other contributors <https://js.foundation/>
|
||||
|
||||
Based on Underscore.js, copyright Jeremy Ashkenas,
|
||||
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
||||
|
||||
This software consists of voluntary contributions made by many
|
||||
individuals. For exact contribution history, see the revision history
|
||||
available at https://github.com/lodash/lodash
|
||||
|
||||
The following license applies to all parts of this software except as
|
||||
documented below:
|
||||
|
||||
====
|
||||
|
||||
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.
|
||||
|
||||
====
|
||||
|
||||
Copyright and related rights for sample code are waived via CC0. Sample
|
||||
code is defined as all source code displayed within the prose of the
|
||||
documentation.
|
||||
|
||||
CC0: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
====
|
||||
|
||||
Files located in the node_modules and vendor directories are externally
|
||||
maintained libraries used by this software which have their own
|
||||
licenses; we recommend you read them, as their terms may differ from the
|
||||
terms above.
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
# lodash v4.17.4
|
||||
|
||||
The [Lodash](https://lodash.com/) library exported as [Node.js](https://nodejs.org/) modules.
|
||||
|
||||
## Installation
|
||||
|
||||
Using npm:
|
||||
```shell
|
||||
$ npm i -g npm
|
||||
$ npm i --save lodash
|
||||
```
|
||||
|
||||
In Node.js:
|
||||
```js
|
||||
// Load the full build.
|
||||
var _ = require('lodash');
|
||||
// Load the core build.
|
||||
var _ = require('lodash/core');
|
||||
// Load the FP build for immutable auto-curried iteratee-first data-last methods.
|
||||
var fp = require('lodash/fp');
|
||||
|
||||
// Load method categories.
|
||||
var array = require('lodash/array');
|
||||
var object = require('lodash/fp/object');
|
||||
|
||||
// Cherry-pick methods for smaller browserify/rollup/webpack bundles.
|
||||
var at = require('lodash/at');
|
||||
var curryN = require('lodash/fp/curryN');
|
||||
```
|
||||
|
||||
See the [package source](https://github.com/lodash/lodash/tree/4.17.4-npm) for more details.
|
||||
|
||||
**Note:**<br>
|
||||
Install [n_](https://www.npmjs.com/package/n_) for Lodash use in the Node.js < 6 REPL.
|
||||
|
||||
## Support
|
||||
|
||||
Tested in Chrome 54-55, Firefox 49-50, IE 11, Edge 14, Safari 9-10, Node.js 6-7, & PhantomJS 2.1.1.<br>
|
||||
Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available.
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
var getNative = require('./_getNative'),
|
||||
root = require('./_root');
|
||||
|
||||
/* Built-in method references that are verified to be native. */
|
||||
var DataView = getNative(root, 'DataView');
|
||||
|
||||
module.exports = DataView;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
var hashClear = require('./_hashClear'),
|
||||
hashDelete = require('./_hashDelete'),
|
||||
hashGet = require('./_hashGet'),
|
||||
hashHas = require('./_hashHas'),
|
||||
hashSet = require('./_hashSet');
|
||||
|
||||
/**
|
||||
* Creates a hash object.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @param {Array} [entries] The key-value pairs to cache.
|
||||
*/
|
||||
function Hash(entries) {
|
||||
var index = -1,
|
||||
length = entries == null ? 0 : entries.length;
|
||||
|
||||
this.clear();
|
||||
while (++index < length) {
|
||||
var entry = entries[index];
|
||||
this.set(entry[0], entry[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add methods to `Hash`.
|
||||
Hash.prototype.clear = hashClear;
|
||||
Hash.prototype['delete'] = hashDelete;
|
||||
Hash.prototype.get = hashGet;
|
||||
Hash.prototype.has = hashHas;
|
||||
Hash.prototype.set = hashSet;
|
||||
|
||||
module.exports = Hash;
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
var baseCreate = require('./_baseCreate'),
|
||||
baseLodash = require('./_baseLodash');
|
||||
|
||||
/** Used as references for the maximum length and index of an array. */
|
||||
var MAX_ARRAY_LENGTH = 4294967295;
|
||||
|
||||
/**
|
||||
* Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @param {*} value The value to wrap.
|
||||
*/
|
||||
function LazyWrapper(value) {
|
||||
this.__wrapped__ = value;
|
||||
this.__actions__ = [];
|
||||
this.__dir__ = 1;
|
||||
this.__filtered__ = false;
|
||||
this.__iteratees__ = [];
|
||||
this.__takeCount__ = MAX_ARRAY_LENGTH;
|
||||
this.__views__ = [];
|
||||
}
|
||||
|
||||
// Ensure `LazyWrapper` is an instance of `baseLodash`.
|
||||
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
||||
LazyWrapper.prototype.constructor = LazyWrapper;
|
||||
|
||||
module.exports = LazyWrapper;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
var listCacheClear = require('./_listCacheClear'),
|
||||
listCacheDelete = require('./_listCacheDelete'),
|
||||
listCacheGet = require('./_listCacheGet'),
|
||||
listCacheHas = require('./_listCacheHas'),
|
||||
listCacheSet = require('./_listCacheSet');
|
||||
|
||||
/**
|
||||
* Creates an list cache object.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @param {Array} [entries] The key-value pairs to cache.
|
||||
*/
|
||||
function ListCache(entries) {
|
||||
var index = -1,
|
||||
length = entries == null ? 0 : entries.length;
|
||||
|
||||
this.clear();
|
||||
while (++index < length) {
|
||||
var entry = entries[index];
|
||||
this.set(entry[0], entry[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add methods to `ListCache`.
|
||||
ListCache.prototype.clear = listCacheClear;
|
||||
ListCache.prototype['delete'] = listCacheDelete;
|
||||
ListCache.prototype.get = listCacheGet;
|
||||
ListCache.prototype.has = listCacheHas;
|
||||
ListCache.prototype.set = listCacheSet;
|
||||
|
||||
module.exports = ListCache;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
var baseCreate = require('./_baseCreate'),
|
||||
baseLodash = require('./_baseLodash');
|
||||
|
||||
/**
|
||||
* The base constructor for creating `lodash` wrapper objects.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to wrap.
|
||||
* @param {boolean} [chainAll] Enable explicit method chain sequences.
|
||||
*/
|
||||
function LodashWrapper(value, chainAll) {
|
||||
this.__wrapped__ = value;
|
||||
this.__actions__ = [];
|
||||
this.__chain__ = !!chainAll;
|
||||
this.__index__ = 0;
|
||||
this.__values__ = undefined;
|
||||
}
|
||||
|
||||
LodashWrapper.prototype = baseCreate(baseLodash.prototype);
|
||||
LodashWrapper.prototype.constructor = LodashWrapper;
|
||||
|
||||
module.exports = LodashWrapper;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
var getNative = require('./_getNative'),
|
||||
root = require('./_root');
|
||||
|
||||
/* Built-in method references that are verified to be native. */
|
||||
var Map = getNative(root, 'Map');
|
||||
|
||||
module.exports = Map;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
var mapCacheClear = require('./_mapCacheClear'),
|
||||
mapCacheDelete = require('./_mapCacheDelete'),
|
||||
mapCacheGet = require('./_mapCacheGet'),
|
||||
mapCacheHas = require('./_mapCacheHas'),
|
||||
mapCacheSet = require('./_mapCacheSet');
|
||||
|
||||
/**
|
||||
* Creates a map cache object to store key-value pairs.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @param {Array} [entries] The key-value pairs to cache.
|
||||
*/
|
||||
function MapCache(entries) {
|
||||
var index = -1,
|
||||
length = entries == null ? 0 : entries.length;
|
||||
|
||||
this.clear();
|
||||
while (++index < length) {
|
||||
var entry = entries[index];
|
||||
this.set(entry[0], entry[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add methods to `MapCache`.
|
||||
MapCache.prototype.clear = mapCacheClear;
|
||||
MapCache.prototype['delete'] = mapCacheDelete;
|
||||
MapCache.prototype.get = mapCacheGet;
|
||||
MapCache.prototype.has = mapCacheHas;
|
||||
MapCache.prototype.set = mapCacheSet;
|
||||
|
||||
module.exports = MapCache;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
var getNative = require('./_getNative'),
|
||||
root = require('./_root');
|
||||
|
||||
/* Built-in method references that are verified to be native. */
|
||||
var Promise = getNative(root, 'Promise');
|
||||
|
||||
module.exports = Promise;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
var getNative = require('./_getNative'),
|
||||
root = require('./_root');
|
||||
|
||||
/* Built-in method references that are verified to be native. */
|
||||
var Set = getNative(root, 'Set');
|
||||
|
||||
module.exports = Set;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
var MapCache = require('./_MapCache'),
|
||||
setCacheAdd = require('./_setCacheAdd'),
|
||||
setCacheHas = require('./_setCacheHas');
|
||||
|
||||
/**
|
||||
*
|
||||
* Creates an array cache object to store unique values.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @param {Array} [values] The values to cache.
|
||||
*/
|
||||
function SetCache(values) {
|
||||
var index = -1,
|
||||
length = values == null ? 0 : values.length;
|
||||
|
||||
this.__data__ = new MapCache;
|
||||
while (++index < length) {
|
||||
this.add(values[index]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add methods to `SetCache`.
|
||||
SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
|
||||
SetCache.prototype.has = setCacheHas;
|
||||
|
||||
module.exports = SetCache;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
var ListCache = require('./_ListCache'),
|
||||
stackClear = require('./_stackClear'),
|
||||
stackDelete = require('./_stackDelete'),
|
||||
stackGet = require('./_stackGet'),
|
||||
stackHas = require('./_stackHas'),
|
||||
stackSet = require('./_stackSet');
|
||||
|
||||
/**
|
||||
* Creates a stack cache object to store key-value pairs.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @param {Array} [entries] The key-value pairs to cache.
|
||||
*/
|
||||
function Stack(entries) {
|
||||
var data = this.__data__ = new ListCache(entries);
|
||||
this.size = data.size;
|
||||
}
|
||||
|
||||
// Add methods to `Stack`.
|
||||
Stack.prototype.clear = stackClear;
|
||||
Stack.prototype['delete'] = stackDelete;
|
||||
Stack.prototype.get = stackGet;
|
||||
Stack.prototype.has = stackHas;
|
||||
Stack.prototype.set = stackSet;
|
||||
|
||||
module.exports = Stack;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
var root = require('./_root');
|
||||
|
||||
/** Built-in value references. */
|
||||
var Symbol = root.Symbol;
|
||||
|
||||
module.exports = Symbol;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
var root = require('./_root');
|
||||
|
||||
/** Built-in value references. */
|
||||
var Uint8Array = root.Uint8Array;
|
||||
|
||||
module.exports = Uint8Array;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
var getNative = require('./_getNative'),
|
||||
root = require('./_root');
|
||||
|
||||
/* Built-in method references that are verified to be native. */
|
||||
var WeakMap = getNative(root, 'WeakMap');
|
||||
|
||||
module.exports = WeakMap;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Adds the key-value `pair` to `map`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} map The map to modify.
|
||||
* @param {Array} pair The key-value pair to add.
|
||||
* @returns {Object} Returns `map`.
|
||||
*/
|
||||
function addMapEntry(map, pair) {
|
||||
// Don't return `map.set` because it's not chainable in IE 11.
|
||||
map.set(pair[0], pair[1]);
|
||||
return map;
|
||||
}
|
||||
|
||||
module.exports = addMapEntry;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Adds `value` to `set`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} set The set to modify.
|
||||
* @param {*} value The value to add.
|
||||
* @returns {Object} Returns `set`.
|
||||
*/
|
||||
function addSetEntry(set, value) {
|
||||
// Don't return `set.add` because it's not chainable in IE 11.
|
||||
set.add(value);
|
||||
return set;
|
||||
}
|
||||
|
||||
module.exports = addSetEntry;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* A faster alternative to `Function#apply`, this function invokes `func`
|
||||
* with the `this` binding of `thisArg` and the arguments of `args`.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} func The function to invoke.
|
||||
* @param {*} thisArg The `this` binding of `func`.
|
||||
* @param {Array} args The arguments to invoke `func` with.
|
||||
* @returns {*} Returns the result of `func`.
|
||||
*/
|
||||
function apply(func, thisArg, args) {
|
||||
switch (args.length) {
|
||||
case 0: return func.call(thisArg);
|
||||
case 1: return func.call(thisArg, args[0]);
|
||||
case 2: return func.call(thisArg, args[0], args[1]);
|
||||
case 3: return func.call(thisArg, args[0], args[1], args[2]);
|
||||
}
|
||||
return func.apply(thisArg, args);
|
||||
}
|
||||
|
||||
module.exports = apply;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* A specialized version of `baseAggregator` for arrays.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to iterate over.
|
||||
* @param {Function} setter The function to set `accumulator` values.
|
||||
* @param {Function} iteratee The iteratee to transform keys.
|
||||
* @param {Object} accumulator The initial aggregated object.
|
||||
* @returns {Function} Returns `accumulator`.
|
||||
*/
|
||||
function arrayAggregator(array, setter, iteratee, accumulator) {
|
||||
var index = -1,
|
||||
length = array == null ? 0 : array.length;
|
||||
|
||||
while (++index < length) {
|
||||
var value = array[index];
|
||||
setter(accumulator, value, iteratee(value), array);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
module.exports = arrayAggregator;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* A specialized version of `_.forEach` for arrays without support for
|
||||
* iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {Array} Returns `array`.
|
||||
*/
|
||||
function arrayEach(array, iteratee) {
|
||||
var index = -1,
|
||||
length = array == null ? 0 : array.length;
|
||||
|
||||
while (++index < length) {
|
||||
if (iteratee(array[index], index, array) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
module.exports = arrayEach;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* A specialized version of `_.forEachRight` for arrays without support for
|
||||
* iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {Array} Returns `array`.
|
||||
*/
|
||||
function arrayEachRight(array, iteratee) {
|
||||
var length = array == null ? 0 : array.length;
|
||||
|
||||
while (length--) {
|
||||
if (iteratee(array[length], length, array) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
module.exports = arrayEachRight;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* A specialized version of `_.every` for arrays without support for
|
||||
* iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to iterate over.
|
||||
* @param {Function} predicate The function invoked per iteration.
|
||||
* @returns {boolean} Returns `true` if all elements pass the predicate check,
|
||||
* else `false`.
|
||||
*/
|
||||
function arrayEvery(array, predicate) {
|
||||
var index = -1,
|
||||
length = array == null ? 0 : array.length;
|
||||
|
||||
while (++index < length) {
|
||||
if (!predicate(array[index], index, array)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = arrayEvery;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* A specialized version of `_.filter` for arrays without support for
|
||||
* iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to iterate over.
|
||||
* @param {Function} predicate The function invoked per iteration.
|
||||
* @returns {Array} Returns the new filtered array.
|
||||
*/
|
||||
function arrayFilter(array, predicate) {
|
||||
var index = -1,
|
||||
length = array == null ? 0 : array.length,
|
||||
resIndex = 0,
|
||||
result = [];
|
||||
|
||||
while (++index < length) {
|
||||
var value = array[index];
|
||||
if (predicate(value, index, array)) {
|
||||
result[resIndex++] = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = arrayFilter;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
var baseIndexOf = require('./_baseIndexOf');
|
||||
|
||||
/**
|
||||
* A specialized version of `_.includes` for arrays without support for
|
||||
* specifying an index to search from.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to inspect.
|
||||
* @param {*} target The value to search for.
|
||||
* @returns {boolean} Returns `true` if `target` is found, else `false`.
|
||||
*/
|
||||
function arrayIncludes(array, value) {
|
||||
var length = array == null ? 0 : array.length;
|
||||
return !!length && baseIndexOf(array, value, 0) > -1;
|
||||
}
|
||||
|
||||
module.exports = arrayIncludes;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* This function is like `arrayIncludes` except that it accepts a comparator.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to inspect.
|
||||
* @param {*} target The value to search for.
|
||||
* @param {Function} comparator The comparator invoked per element.
|
||||
* @returns {boolean} Returns `true` if `target` is found, else `false`.
|
||||
*/
|
||||
function arrayIncludesWith(array, value, comparator) {
|
||||
var index = -1,
|
||||
length = array == null ? 0 : array.length;
|
||||
|
||||
while (++index < length) {
|
||||
if (comparator(value, array[index])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = arrayIncludesWith;
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
var baseTimes = require('./_baseTimes'),
|
||||
isArguments = require('./isArguments'),
|
||||
isArray = require('./isArray'),
|
||||
isBuffer = require('./isBuffer'),
|
||||
isIndex = require('./_isIndex'),
|
||||
isTypedArray = require('./isTypedArray');
|
||||
|
||||
/** Used for built-in method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Creates an array of the enumerable property names of the array-like `value`.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to query.
|
||||
* @param {boolean} inherited Specify returning inherited property names.
|
||||
* @returns {Array} Returns the array of property names.
|
||||
*/
|
||||
function arrayLikeKeys(value, inherited) {
|
||||
var isArr = isArray(value),
|
||||
isArg = !isArr && isArguments(value),
|
||||
isBuff = !isArr && !isArg && isBuffer(value),
|
||||
isType = !isArr && !isArg && !isBuff && isTypedArray(value),
|
||||
skipIndexes = isArr || isArg || isBuff || isType,
|
||||
result = skipIndexes ? baseTimes(value.length, String) : [],
|
||||
length = result.length;
|
||||
|
||||
for (var key in value) {
|
||||
if ((inherited || hasOwnProperty.call(value, key)) &&
|
||||
!(skipIndexes && (
|
||||
// Safari 9 has enumerable `arguments.length` in strict mode.
|
||||
key == 'length' ||
|
||||
// Node.js 0.10 has enumerable non-index properties on buffers.
|
||||
(isBuff && (key == 'offset' || key == 'parent')) ||
|
||||
// PhantomJS 2 has enumerable non-index properties on typed arrays.
|
||||
(isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
|
||||
// Skip index properties.
|
||||
isIndex(key, length)
|
||||
))) {
|
||||
result.push(key);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = arrayLikeKeys;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* A specialized version of `_.map` for arrays without support for iteratee
|
||||
* shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {Array} Returns the new mapped array.
|
||||
*/
|
||||
function arrayMap(array, iteratee) {
|
||||
var index = -1,
|
||||
length = array == null ? 0 : array.length,
|
||||
result = Array(length);
|
||||
|
||||
while (++index < length) {
|
||||
result[index] = iteratee(array[index], index, array);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = arrayMap;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Appends the elements of `values` to `array`.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to modify.
|
||||
* @param {Array} values The values to append.
|
||||
* @returns {Array} Returns `array`.
|
||||
*/
|
||||
function arrayPush(array, values) {
|
||||
var index = -1,
|
||||
length = values.length,
|
||||
offset = array.length;
|
||||
|
||||
while (++index < length) {
|
||||
array[offset + index] = values[index];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
module.exports = arrayPush;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* A specialized version of `_.reduce` for arrays without support for
|
||||
* iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @param {*} [accumulator] The initial value.
|
||||
* @param {boolean} [initAccum] Specify using the first element of `array` as
|
||||
* the initial value.
|
||||
* @returns {*} Returns the accumulated value.
|
||||
*/
|
||||
function arrayReduce(array, iteratee, accumulator, initAccum) {
|
||||
var index = -1,
|
||||
length = array == null ? 0 : array.length;
|
||||
|
||||
if (initAccum && length) {
|
||||
accumulator = array[++index];
|
||||
}
|
||||
while (++index < length) {
|
||||
accumulator = iteratee(accumulator, array[index], index, array);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
module.exports = arrayReduce;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* A specialized version of `_.reduceRight` for arrays without support for
|
||||
* iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @param {*} [accumulator] The initial value.
|
||||
* @param {boolean} [initAccum] Specify using the last element of `array` as
|
||||
* the initial value.
|
||||
* @returns {*} Returns the accumulated value.
|
||||
*/
|
||||
function arrayReduceRight(array, iteratee, accumulator, initAccum) {
|
||||
var length = array == null ? 0 : array.length;
|
||||
if (initAccum && length) {
|
||||
accumulator = array[--length];
|
||||
}
|
||||
while (length--) {
|
||||
accumulator = iteratee(accumulator, array[length], length, array);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
module.exports = arrayReduceRight;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
var baseRandom = require('./_baseRandom');
|
||||
|
||||
/**
|
||||
* A specialized version of `_.sample` for arrays.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to sample.
|
||||
* @returns {*} Returns the random element.
|
||||
*/
|
||||
function arraySample(array) {
|
||||
var length = array.length;
|
||||
return length ? array[baseRandom(0, length - 1)] : undefined;
|
||||
}
|
||||
|
||||
module.exports = arraySample;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
var baseClamp = require('./_baseClamp'),
|
||||
copyArray = require('./_copyArray'),
|
||||
shuffleSelf = require('./_shuffleSelf');
|
||||
|
||||
/**
|
||||
* A specialized version of `_.sampleSize` for arrays.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to sample.
|
||||
* @param {number} n The number of elements to sample.
|
||||
* @returns {Array} Returns the random elements.
|
||||
*/
|
||||
function arraySampleSize(array, n) {
|
||||
return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
|
||||
}
|
||||
|
||||
module.exports = arraySampleSize;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
var copyArray = require('./_copyArray'),
|
||||
shuffleSelf = require('./_shuffleSelf');
|
||||
|
||||
/**
|
||||
* A specialized version of `_.shuffle` for arrays.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to shuffle.
|
||||
* @returns {Array} Returns the new shuffled array.
|
||||
*/
|
||||
function arrayShuffle(array) {
|
||||
return shuffleSelf(copyArray(array));
|
||||
}
|
||||
|
||||
module.exports = arrayShuffle;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* A specialized version of `_.some` for arrays without support for iteratee
|
||||
* shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} [array] The array to iterate over.
|
||||
* @param {Function} predicate The function invoked per iteration.
|
||||
* @returns {boolean} Returns `true` if any element passes the predicate check,
|
||||
* else `false`.
|
||||
*/
|
||||
function arraySome(array, predicate) {
|
||||
var index = -1,
|
||||
length = array == null ? 0 : array.length;
|
||||
|
||||
while (++index < length) {
|
||||
if (predicate(array[index], index, array)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = arraySome;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
var baseProperty = require('./_baseProperty');
|
||||
|
||||
/**
|
||||
* Gets the size of an ASCII `string`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} string The string inspect.
|
||||
* @returns {number} Returns the string size.
|
||||
*/
|
||||
var asciiSize = baseProperty('length');
|
||||
|
||||
module.exports = asciiSize;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Converts an ASCII `string` to an array.
|
||||
*
|
||||
* @private
|
||||
* @param {string} string The string to convert.
|
||||
* @returns {Array} Returns the converted array.
|
||||
*/
|
||||
function asciiToArray(string) {
|
||||
return string.split('');
|
||||
}
|
||||
|
||||
module.exports = asciiToArray;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/** Used to match words composed of alphanumeric characters. */
|
||||
var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
||||
|
||||
/**
|
||||
* Splits an ASCII `string` into an array of its words.
|
||||
*
|
||||
* @private
|
||||
* @param {string} The string to inspect.
|
||||
* @returns {Array} Returns the words of `string`.
|
||||
*/
|
||||
function asciiWords(string) {
|
||||
return string.match(reAsciiWord) || [];
|
||||
}
|
||||
|
||||
module.exports = asciiWords;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
var baseAssignValue = require('./_baseAssignValue'),
|
||||
eq = require('./eq');
|
||||
|
||||
/**
|
||||
* This function is like `assignValue` except that it doesn't assign
|
||||
* `undefined` values.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to modify.
|
||||
* @param {string} key The key of the property to assign.
|
||||
* @param {*} value The value to assign.
|
||||
*/
|
||||
function assignMergeValue(object, key, value) {
|
||||
if ((value !== undefined && !eq(object[key], value)) ||
|
||||
(value === undefined && !(key in object))) {
|
||||
baseAssignValue(object, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = assignMergeValue;
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
var baseAssignValue = require('./_baseAssignValue'),
|
||||
eq = require('./eq');
|
||||
|
||||
/** Used for built-in method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Assigns `value` to `key` of `object` if the existing value is not equivalent
|
||||
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||||
* for equality comparisons.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to modify.
|
||||
* @param {string} key The key of the property to assign.
|
||||
* @param {*} value The value to assign.
|
||||
*/
|
||||
function assignValue(object, key, value) {
|
||||
var objValue = object[key];
|
||||
if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
|
||||
(value === undefined && !(key in object))) {
|
||||
baseAssignValue(object, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = assignValue;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
var eq = require('./eq');
|
||||
|
||||
/**
|
||||
* Gets the index at which the `key` is found in `array` of key-value pairs.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to inspect.
|
||||
* @param {*} key The key to search for.
|
||||
* @returns {number} Returns the index of the matched value, else `-1`.
|
||||
*/
|
||||
function assocIndexOf(array, key) {
|
||||
var length = array.length;
|
||||
while (length--) {
|
||||
if (eq(array[length][0], key)) {
|
||||
return length;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
module.exports = assocIndexOf;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
var baseEach = require('./_baseEach');
|
||||
|
||||
/**
|
||||
* Aggregates elements of `collection` on `accumulator` with keys transformed
|
||||
* by `iteratee` and values set by `setter`.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {Function} setter The function to set `accumulator` values.
|
||||
* @param {Function} iteratee The iteratee to transform keys.
|
||||
* @param {Object} accumulator The initial aggregated object.
|
||||
* @returns {Function} Returns `accumulator`.
|
||||
*/
|
||||
function baseAggregator(collection, setter, iteratee, accumulator) {
|
||||
baseEach(collection, function(value, key, collection) {
|
||||
setter(accumulator, value, iteratee(value), collection);
|
||||
});
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
module.exports = baseAggregator;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
var copyObject = require('./_copyObject'),
|
||||
keys = require('./keys');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.assign` without support for multiple sources
|
||||
* or `customizer` functions.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The destination object.
|
||||
* @param {Object} source The source object.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
function baseAssign(object, source) {
|
||||
return object && copyObject(source, keys(source), object);
|
||||
}
|
||||
|
||||
module.exports = baseAssign;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
var copyObject = require('./_copyObject'),
|
||||
keysIn = require('./keysIn');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.assignIn` without support for multiple sources
|
||||
* or `customizer` functions.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The destination object.
|
||||
* @param {Object} source The source object.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
function baseAssignIn(object, source) {
|
||||
return object && copyObject(source, keysIn(source), object);
|
||||
}
|
||||
|
||||
module.exports = baseAssignIn;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
var defineProperty = require('./_defineProperty');
|
||||
|
||||
/**
|
||||
* The base implementation of `assignValue` and `assignMergeValue` without
|
||||
* value checks.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to modify.
|
||||
* @param {string} key The key of the property to assign.
|
||||
* @param {*} value The value to assign.
|
||||
*/
|
||||
function baseAssignValue(object, key, value) {
|
||||
if (key == '__proto__' && defineProperty) {
|
||||
defineProperty(object, key, {
|
||||
'configurable': true,
|
||||
'enumerable': true,
|
||||
'value': value,
|
||||
'writable': true
|
||||
});
|
||||
} else {
|
||||
object[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = baseAssignValue;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
var get = require('./get');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.at` without support for individual paths.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to iterate over.
|
||||
* @param {string[]} paths The property paths to pick.
|
||||
* @returns {Array} Returns the picked elements.
|
||||
*/
|
||||
function baseAt(object, paths) {
|
||||
var index = -1,
|
||||
length = paths.length,
|
||||
result = Array(length),
|
||||
skip = object == null;
|
||||
|
||||
while (++index < length) {
|
||||
result[index] = skip ? undefined : get(object, paths[index]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = baseAt;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* The base implementation of `_.clamp` which doesn't coerce arguments.
|
||||
*
|
||||
* @private
|
||||
* @param {number} number The number to clamp.
|
||||
* @param {number} [lower] The lower bound.
|
||||
* @param {number} upper The upper bound.
|
||||
* @returns {number} Returns the clamped number.
|
||||
*/
|
||||
function baseClamp(number, lower, upper) {
|
||||
if (number === number) {
|
||||
if (upper !== undefined) {
|
||||
number = number <= upper ? number : upper;
|
||||
}
|
||||
if (lower !== undefined) {
|
||||
number = number >= lower ? number : lower;
|
||||
}
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
module.exports = baseClamp;
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
var Stack = require('./_Stack'),
|
||||
arrayEach = require('./_arrayEach'),
|
||||
assignValue = require('./_assignValue'),
|
||||
baseAssign = require('./_baseAssign'),
|
||||
baseAssignIn = require('./_baseAssignIn'),
|
||||
cloneBuffer = require('./_cloneBuffer'),
|
||||
copyArray = require('./_copyArray'),
|
||||
copySymbols = require('./_copySymbols'),
|
||||
copySymbolsIn = require('./_copySymbolsIn'),
|
||||
getAllKeys = require('./_getAllKeys'),
|
||||
getAllKeysIn = require('./_getAllKeysIn'),
|
||||
getTag = require('./_getTag'),
|
||||
initCloneArray = require('./_initCloneArray'),
|
||||
initCloneByTag = require('./_initCloneByTag'),
|
||||
initCloneObject = require('./_initCloneObject'),
|
||||
isArray = require('./isArray'),
|
||||
isBuffer = require('./isBuffer'),
|
||||
isObject = require('./isObject'),
|
||||
keys = require('./keys');
|
||||
|
||||
/** Used to compose bitmasks for cloning. */
|
||||
var CLONE_DEEP_FLAG = 1,
|
||||
CLONE_FLAT_FLAG = 2,
|
||||
CLONE_SYMBOLS_FLAG = 4;
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var argsTag = '[object Arguments]',
|
||||
arrayTag = '[object Array]',
|
||||
boolTag = '[object Boolean]',
|
||||
dateTag = '[object Date]',
|
||||
errorTag = '[object Error]',
|
||||
funcTag = '[object Function]',
|
||||
genTag = '[object GeneratorFunction]',
|
||||
mapTag = '[object Map]',
|
||||
numberTag = '[object Number]',
|
||||
objectTag = '[object Object]',
|
||||
regexpTag = '[object RegExp]',
|
||||
setTag = '[object Set]',
|
||||
stringTag = '[object String]',
|
||||
symbolTag = '[object Symbol]',
|
||||
weakMapTag = '[object WeakMap]';
|
||||
|
||||
var arrayBufferTag = '[object ArrayBuffer]',
|
||||
dataViewTag = '[object DataView]',
|
||||
float32Tag = '[object Float32Array]',
|
||||
float64Tag = '[object Float64Array]',
|
||||
int8Tag = '[object Int8Array]',
|
||||
int16Tag = '[object Int16Array]',
|
||||
int32Tag = '[object Int32Array]',
|
||||
uint8Tag = '[object Uint8Array]',
|
||||
uint8ClampedTag = '[object Uint8ClampedArray]',
|
||||
uint16Tag = '[object Uint16Array]',
|
||||
uint32Tag = '[object Uint32Array]';
|
||||
|
||||
/** Used to identify `toStringTag` values supported by `_.clone`. */
|
||||
var cloneableTags = {};
|
||||
cloneableTags[argsTag] = cloneableTags[arrayTag] =
|
||||
cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
|
||||
cloneableTags[boolTag] = cloneableTags[dateTag] =
|
||||
cloneableTags[float32Tag] = cloneableTags[float64Tag] =
|
||||
cloneableTags[int8Tag] = cloneableTags[int16Tag] =
|
||||
cloneableTags[int32Tag] = cloneableTags[mapTag] =
|
||||
cloneableTags[numberTag] = cloneableTags[objectTag] =
|
||||
cloneableTags[regexpTag] = cloneableTags[setTag] =
|
||||
cloneableTags[stringTag] = cloneableTags[symbolTag] =
|
||||
cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
|
||||
cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
|
||||
cloneableTags[errorTag] = cloneableTags[funcTag] =
|
||||
cloneableTags[weakMapTag] = false;
|
||||
|
||||
/**
|
||||
* The base implementation of `_.clone` and `_.cloneDeep` which tracks
|
||||
* traversed objects.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to clone.
|
||||
* @param {boolean} bitmask The bitmask flags.
|
||||
* 1 - Deep clone
|
||||
* 2 - Flatten inherited properties
|
||||
* 4 - Clone symbols
|
||||
* @param {Function} [customizer] The function to customize cloning.
|
||||
* @param {string} [key] The key of `value`.
|
||||
* @param {Object} [object] The parent object of `value`.
|
||||
* @param {Object} [stack] Tracks traversed objects and their clone counterparts.
|
||||
* @returns {*} Returns the cloned value.
|
||||
*/
|
||||
function baseClone(value, bitmask, customizer, key, object, stack) {
|
||||
var result,
|
||||
isDeep = bitmask & CLONE_DEEP_FLAG,
|
||||
isFlat = bitmask & CLONE_FLAT_FLAG,
|
||||
isFull = bitmask & CLONE_SYMBOLS_FLAG;
|
||||
|
||||
if (customizer) {
|
||||
result = object ? customizer(value, key, object, stack) : customizer(value);
|
||||
}
|
||||
if (result !== undefined) {
|
||||
return result;
|
||||
}
|
||||
if (!isObject(value)) {
|
||||
return value;
|
||||
}
|
||||
var isArr = isArray(value);
|
||||
if (isArr) {
|
||||
result = initCloneArray(value);
|
||||
if (!isDeep) {
|
||||
return copyArray(value, result);
|
||||
}
|
||||
} else {
|
||||
var tag = getTag(value),
|
||||
isFunc = tag == funcTag || tag == genTag;
|
||||
|
||||
if (isBuffer(value)) {
|
||||
return cloneBuffer(value, isDeep);
|
||||
}
|
||||
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
||||
result = (isFlat || isFunc) ? {} : initCloneObject(value);
|
||||
if (!isDeep) {
|
||||
return isFlat
|
||||
? copySymbolsIn(value, baseAssignIn(result, value))
|
||||
: copySymbols(value, baseAssign(result, value));
|
||||
}
|
||||
} else {
|
||||
if (!cloneableTags[tag]) {
|
||||
return object ? value : {};
|
||||
}
|
||||
result = initCloneByTag(value, tag, baseClone, isDeep);
|
||||
}
|
||||
}
|
||||
// Check for circular references and return its corresponding clone.
|
||||
stack || (stack = new Stack);
|
||||
var stacked = stack.get(value);
|
||||
if (stacked) {
|
||||
return stacked;
|
||||
}
|
||||
stack.set(value, result);
|
||||
|
||||
var keysFunc = isFull
|
||||
? (isFlat ? getAllKeysIn : getAllKeys)
|
||||
: (isFlat ? keysIn : keys);
|
||||
|
||||
var props = isArr ? undefined : keysFunc(value);
|
||||
arrayEach(props || value, function(subValue, key) {
|
||||
if (props) {
|
||||
key = subValue;
|
||||
subValue = value[key];
|
||||
}
|
||||
// Recursively populate clone (susceptible to call stack limits).
|
||||
assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = baseClone;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
var baseConformsTo = require('./_baseConformsTo'),
|
||||
keys = require('./keys');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.conforms` which doesn't clone `source`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} source The object of property predicates to conform to.
|
||||
* @returns {Function} Returns the new spec function.
|
||||
*/
|
||||
function baseConforms(source) {
|
||||
var props = keys(source);
|
||||
return function(object) {
|
||||
return baseConformsTo(object, source, props);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = baseConforms;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* The base implementation of `_.conformsTo` which accepts `props` to check.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to inspect.
|
||||
* @param {Object} source The object of property predicates to conform to.
|
||||
* @returns {boolean} Returns `true` if `object` conforms, else `false`.
|
||||
*/
|
||||
function baseConformsTo(object, source, props) {
|
||||
var length = props.length;
|
||||
if (object == null) {
|
||||
return !length;
|
||||
}
|
||||
object = Object(object);
|
||||
while (length--) {
|
||||
var key = props[length],
|
||||
predicate = source[key],
|
||||
value = object[key];
|
||||
|
||||
if ((value === undefined && !(key in object)) || !predicate(value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = baseConformsTo;
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
var isObject = require('./isObject');
|
||||
|
||||
/** Built-in value references. */
|
||||
var objectCreate = Object.create;
|
||||
|
||||
/**
|
||||
* The base implementation of `_.create` without support for assigning
|
||||
* properties to the created object.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} proto The object to inherit from.
|
||||
* @returns {Object} Returns the new object.
|
||||
*/
|
||||
var baseCreate = (function() {
|
||||
function object() {}
|
||||
return function(proto) {
|
||||
if (!isObject(proto)) {
|
||||
return {};
|
||||
}
|
||||
if (objectCreate) {
|
||||
return objectCreate(proto);
|
||||
}
|
||||
object.prototype = proto;
|
||||
var result = new object;
|
||||
object.prototype = undefined;
|
||||
return result;
|
||||
};
|
||||
}());
|
||||
|
||||
module.exports = baseCreate;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/** Error message constants. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
|
||||
/**
|
||||
* The base implementation of `_.delay` and `_.defer` which accepts `args`
|
||||
* to provide to `func`.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} func The function to delay.
|
||||
* @param {number} wait The number of milliseconds to delay invocation.
|
||||
* @param {Array} args The arguments to provide to `func`.
|
||||
* @returns {number|Object} Returns the timer id or timeout object.
|
||||
*/
|
||||
function baseDelay(func, wait, args) {
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return setTimeout(function() { func.apply(undefined, args); }, wait);
|
||||
}
|
||||
|
||||
module.exports = baseDelay;
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
var SetCache = require('./_SetCache'),
|
||||
arrayIncludes = require('./_arrayIncludes'),
|
||||
arrayIncludesWith = require('./_arrayIncludesWith'),
|
||||
arrayMap = require('./_arrayMap'),
|
||||
baseUnary = require('./_baseUnary'),
|
||||
cacheHas = require('./_cacheHas');
|
||||
|
||||
/** Used as the size to enable large array optimizations. */
|
||||
var LARGE_ARRAY_SIZE = 200;
|
||||
|
||||
/**
|
||||
* The base implementation of methods like `_.difference` without support
|
||||
* for excluding multiple arrays or iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to inspect.
|
||||
* @param {Array} values The values to exclude.
|
||||
* @param {Function} [iteratee] The iteratee invoked per element.
|
||||
* @param {Function} [comparator] The comparator invoked per element.
|
||||
* @returns {Array} Returns the new array of filtered values.
|
||||
*/
|
||||
function baseDifference(array, values, iteratee, comparator) {
|
||||
var index = -1,
|
||||
includes = arrayIncludes,
|
||||
isCommon = true,
|
||||
length = array.length,
|
||||
result = [],
|
||||
valuesLength = values.length;
|
||||
|
||||
if (!length) {
|
||||
return result;
|
||||
}
|
||||
if (iteratee) {
|
||||
values = arrayMap(values, baseUnary(iteratee));
|
||||
}
|
||||
if (comparator) {
|
||||
includes = arrayIncludesWith;
|
||||
isCommon = false;
|
||||
}
|
||||
else if (values.length >= LARGE_ARRAY_SIZE) {
|
||||
includes = cacheHas;
|
||||
isCommon = false;
|
||||
values = new SetCache(values);
|
||||
}
|
||||
outer:
|
||||
while (++index < length) {
|
||||
var value = array[index],
|
||||
computed = iteratee == null ? value : iteratee(value);
|
||||
|
||||
value = (comparator || value !== 0) ? value : 0;
|
||||
if (isCommon && computed === computed) {
|
||||
var valuesIndex = valuesLength;
|
||||
while (valuesIndex--) {
|
||||
if (values[valuesIndex] === computed) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
result.push(value);
|
||||
}
|
||||
else if (!includes(values, computed, comparator)) {
|
||||
result.push(value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = baseDifference;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
var baseForOwn = require('./_baseForOwn'),
|
||||
createBaseEach = require('./_createBaseEach');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.forEach` without support for iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {Array|Object} Returns `collection`.
|
||||
*/
|
||||
var baseEach = createBaseEach(baseForOwn);
|
||||
|
||||
module.exports = baseEach;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
var baseForOwnRight = require('./_baseForOwnRight'),
|
||||
createBaseEach = require('./_createBaseEach');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.forEachRight` without support for iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {Array|Object} Returns `collection`.
|
||||
*/
|
||||
var baseEachRight = createBaseEach(baseForOwnRight, true);
|
||||
|
||||
module.exports = baseEachRight;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
var baseEach = require('./_baseEach');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.every` without support for iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {Function} predicate The function invoked per iteration.
|
||||
* @returns {boolean} Returns `true` if all elements pass the predicate check,
|
||||
* else `false`
|
||||
*/
|
||||
function baseEvery(collection, predicate) {
|
||||
var result = true;
|
||||
baseEach(collection, function(value, index, collection) {
|
||||
result = !!predicate(value, index, collection);
|
||||
return result;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = baseEvery;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
var isSymbol = require('./isSymbol');
|
||||
|
||||
/**
|
||||
* The base implementation of methods like `_.max` and `_.min` which accepts a
|
||||
* `comparator` to determine the extremum value.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
* @param {Function} iteratee The iteratee invoked per iteration.
|
||||
* @param {Function} comparator The comparator used to compare values.
|
||||
* @returns {*} Returns the extremum value.
|
||||
*/
|
||||
function baseExtremum(array, iteratee, comparator) {
|
||||
var index = -1,
|
||||
length = array.length;
|
||||
|
||||
while (++index < length) {
|
||||
var value = array[index],
|
||||
current = iteratee(value);
|
||||
|
||||
if (current != null && (computed === undefined
|
||||
? (current === current && !isSymbol(current))
|
||||
: comparator(current, computed)
|
||||
)) {
|
||||
var computed = current,
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = baseExtremum;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
var toInteger = require('./toInteger'),
|
||||
toLength = require('./toLength');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.fill` without an iteratee call guard.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to fill.
|
||||
* @param {*} value The value to fill `array` with.
|
||||
* @param {number} [start=0] The start position.
|
||||
* @param {number} [end=array.length] The end position.
|
||||
* @returns {Array} Returns `array`.
|
||||
*/
|
||||
function baseFill(array, value, start, end) {
|
||||
var length = array.length;
|
||||
|
||||
start = toInteger(start);
|
||||
if (start < 0) {
|
||||
start = -start > length ? 0 : (length + start);
|
||||
}
|
||||
end = (end === undefined || end > length) ? length : toInteger(end);
|
||||
if (end < 0) {
|
||||
end += length;
|
||||
}
|
||||
end = start > end ? 0 : toLength(end);
|
||||
while (start < end) {
|
||||
array[start++] = value;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
module.exports = baseFill;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
var baseEach = require('./_baseEach');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.filter` without support for iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {Function} predicate The function invoked per iteration.
|
||||
* @returns {Array} Returns the new filtered array.
|
||||
*/
|
||||
function baseFilter(collection, predicate) {
|
||||
var result = [];
|
||||
baseEach(collection, function(value, index, collection) {
|
||||
if (predicate(value, index, collection)) {
|
||||
result.push(value);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = baseFilter;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* The base implementation of `_.findIndex` and `_.findLastIndex` without
|
||||
* support for iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to inspect.
|
||||
* @param {Function} predicate The function invoked per iteration.
|
||||
* @param {number} fromIndex The index to search from.
|
||||
* @param {boolean} [fromRight] Specify iterating from right to left.
|
||||
* @returns {number} Returns the index of the matched value, else `-1`.
|
||||
*/
|
||||
function baseFindIndex(array, predicate, fromIndex, fromRight) {
|
||||
var length = array.length,
|
||||
index = fromIndex + (fromRight ? 1 : -1);
|
||||
|
||||
while ((fromRight ? index-- : ++index < length)) {
|
||||
if (predicate(array[index], index, array)) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
module.exports = baseFindIndex;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* The base implementation of methods like `_.findKey` and `_.findLastKey`,
|
||||
* without support for iteratee shorthands, which iterates over `collection`
|
||||
* using `eachFunc`.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object} collection The collection to inspect.
|
||||
* @param {Function} predicate The function invoked per iteration.
|
||||
* @param {Function} eachFunc The function to iterate over `collection`.
|
||||
* @returns {*} Returns the found element or its key, else `undefined`.
|
||||
*/
|
||||
function baseFindKey(collection, predicate, eachFunc) {
|
||||
var result;
|
||||
eachFunc(collection, function(value, key, collection) {
|
||||
if (predicate(value, key, collection)) {
|
||||
result = key;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = baseFindKey;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
var arrayPush = require('./_arrayPush'),
|
||||
isFlattenable = require('./_isFlattenable');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.flatten` with support for restricting flattening.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to flatten.
|
||||
* @param {number} depth The maximum recursion depth.
|
||||
* @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
|
||||
* @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
|
||||
* @param {Array} [result=[]] The initial result value.
|
||||
* @returns {Array} Returns the new flattened array.
|
||||
*/
|
||||
function baseFlatten(array, depth, predicate, isStrict, result) {
|
||||
var index = -1,
|
||||
length = array.length;
|
||||
|
||||
predicate || (predicate = isFlattenable);
|
||||
result || (result = []);
|
||||
|
||||
while (++index < length) {
|
||||
var value = array[index];
|
||||
if (depth > 0 && predicate(value)) {
|
||||
if (depth > 1) {
|
||||
// Recursively flatten arrays (susceptible to call stack limits).
|
||||
baseFlatten(value, depth - 1, predicate, isStrict, result);
|
||||
} else {
|
||||
arrayPush(result, value);
|
||||
}
|
||||
} else if (!isStrict) {
|
||||
result[result.length] = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = baseFlatten;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
var createBaseFor = require('./_createBaseFor');
|
||||
|
||||
/**
|
||||
* The base implementation of `baseForOwn` which iterates over `object`
|
||||
* properties returned by `keysFunc` and invokes `iteratee` for each property.
|
||||
* Iteratee functions may exit iteration early by explicitly returning `false`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @param {Function} keysFunc The function to get the keys of `object`.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
var baseFor = createBaseFor();
|
||||
|
||||
module.exports = baseFor;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
var baseFor = require('./_baseFor'),
|
||||
keys = require('./keys');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.forOwn` without support for iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
function baseForOwn(object, iteratee) {
|
||||
return object && baseFor(object, iteratee, keys);
|
||||
}
|
||||
|
||||
module.exports = baseForOwn;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
var baseForRight = require('./_baseForRight'),
|
||||
keys = require('./keys');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.forOwnRight` without support for iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
function baseForOwnRight(object, iteratee) {
|
||||
return object && baseForRight(object, iteratee, keys);
|
||||
}
|
||||
|
||||
module.exports = baseForOwnRight;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user