install gulp
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
Copyright (c) 2013 Fractal <contact@wearefractal.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.
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
# vinyl [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [](https://david-dm.org/wearefractal/vinyl)
|
||||
|
||||
|
||||
## Information
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>Package</td><td>vinyl</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Description</td>
|
||||
<td>A virtual file format</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Node Version</td>
|
||||
<td>>= 0.9</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## What is this?
|
||||
|
||||
Read this for more info about how this plays into the grand scheme of things https://medium.com/@eschoff/3828e8126466
|
||||
|
||||
## File
|
||||
|
||||
```javascript
|
||||
var File = require('vinyl');
|
||||
|
||||
var coffeeFile = new File({
|
||||
cwd: "/",
|
||||
base: "/test/",
|
||||
path: "/test/file.coffee",
|
||||
contents: new Buffer("test = 123")
|
||||
});
|
||||
```
|
||||
|
||||
### constructor(options)
|
||||
|
||||
#### options.cwd
|
||||
|
||||
Type: `String`
|
||||
Default: `process.cwd()`
|
||||
|
||||
#### options.base
|
||||
|
||||
Used for relative pathing. Typically where a glob starts.
|
||||
|
||||
Type: `String`
|
||||
Default: `options.cwd`
|
||||
|
||||
#### options.path
|
||||
|
||||
Full path to the file.
|
||||
|
||||
Type: `String`
|
||||
Default: `null`
|
||||
|
||||
#### options.stat
|
||||
|
||||
The result of an fs.stat call. See [fs.Stats](http://nodejs.org/api/fs.html#fs_class_fs_stats) for more information.
|
||||
|
||||
Type: `fs.Stats`
|
||||
Default: `null`
|
||||
|
||||
#### options.contents
|
||||
|
||||
File contents.
|
||||
|
||||
Type: `Buffer, Stream, or null`
|
||||
Default: `null`
|
||||
|
||||
### isBuffer()
|
||||
|
||||
Returns true if file.contents is a Buffer.
|
||||
|
||||
### isStream()
|
||||
|
||||
Returns true if file.contents is a Stream.
|
||||
|
||||
### isNull()
|
||||
|
||||
Returns true if file.contents is null.
|
||||
|
||||
### clone()
|
||||
|
||||
Returns a new File object with all attributes cloned. Custom attributes are deep-cloned.
|
||||
|
||||
### pipe(stream[, opt])
|
||||
|
||||
If file.contents is a Buffer, it will write it to the stream.
|
||||
|
||||
If file.contents is a Stream, it will pipe it to the stream.
|
||||
|
||||
If file.contents is null, it will do nothing.
|
||||
|
||||
If opt.end is false, the destination stream will not be ended (same as node core).
|
||||
|
||||
Returns the stream.
|
||||
|
||||
### inspect()
|
||||
|
||||
Returns a pretty String interpretation of the File. Useful for console.log.
|
||||
|
||||
### relative
|
||||
|
||||
Returns path.relative for the file base and file path.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var file = new File({
|
||||
cwd: "/",
|
||||
base: "/test/",
|
||||
path: "/test/file.coffee"
|
||||
});
|
||||
|
||||
console.log(file.relative); // file.coffee
|
||||
```
|
||||
|
||||
[npm-url]: https://npmjs.org/package/vinyl
|
||||
[npm-image]: https://badge.fury.io/js/vinyl.png
|
||||
[travis-url]: https://travis-ci.org/wearefractal/vinyl
|
||||
[travis-image]: https://travis-ci.org/wearefractal/vinyl.png?branch=master
|
||||
[coveralls-url]: https://coveralls.io/r/wearefractal/vinyl
|
||||
[coveralls-image]: https://coveralls.io/repos/wearefractal/vinyl/badge.png
|
||||
[depstat-url]: https://david-dm.org/wearefractal/vinyl
|
||||
[depstat-image]: https://david-dm.org/wearefractal/vinyl.png
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
var path = require('path');
|
||||
var clone = require('clone');
|
||||
var cloneStats = require('clone-stats');
|
||||
var cloneBuffer = require('./lib/cloneBuffer');
|
||||
var isBuffer = require('./lib/isBuffer');
|
||||
var isStream = require('./lib/isStream');
|
||||
var isNull = require('./lib/isNull');
|
||||
var inspectStream = require('./lib/inspectStream');
|
||||
var Stream = require('stream');
|
||||
|
||||
function File(file) {
|
||||
if (!file) file = {};
|
||||
|
||||
// record path change
|
||||
var history = file.path ? [file.path] : file.history;
|
||||
this.history = history || [];
|
||||
|
||||
// TODO: should this be moved to vinyl-fs?
|
||||
this.cwd = file.cwd || process.cwd();
|
||||
this.base = file.base || this.cwd;
|
||||
|
||||
// stat = fs stats object
|
||||
// TODO: should this be moved to vinyl-fs?
|
||||
this.stat = file.stat || null;
|
||||
|
||||
// contents = stream, buffer, or null if not read
|
||||
this.contents = file.contents || null;
|
||||
}
|
||||
|
||||
File.prototype.isBuffer = function() {
|
||||
return isBuffer(this.contents);
|
||||
};
|
||||
|
||||
File.prototype.isStream = function() {
|
||||
return isStream(this.contents);
|
||||
};
|
||||
|
||||
File.prototype.isNull = function() {
|
||||
return isNull(this.contents);
|
||||
};
|
||||
|
||||
// TODO: should this be moved to vinyl-fs?
|
||||
File.prototype.isDirectory = function() {
|
||||
return this.isNull() && this.stat && this.stat.isDirectory();
|
||||
};
|
||||
|
||||
File.prototype.clone = function(opt) {
|
||||
if (typeof opt === 'boolean') {
|
||||
opt = {
|
||||
deep: opt,
|
||||
contents: true
|
||||
};
|
||||
} else if (!opt) {
|
||||
opt = {
|
||||
deep: false,
|
||||
contents: true
|
||||
};
|
||||
} else {
|
||||
opt.deep = opt.deep === true;
|
||||
opt.contents = opt.contents !== false;
|
||||
}
|
||||
|
||||
// clone our file contents
|
||||
var contents;
|
||||
if (this.isStream()) {
|
||||
contents = this.contents.pipe(new Stream.PassThrough());
|
||||
this.contents = this.contents.pipe(new Stream.PassThrough());
|
||||
} else if (this.isBuffer()) {
|
||||
contents = opt.contents ? cloneBuffer(this.contents) : this.contents;
|
||||
}
|
||||
|
||||
var file = new File({
|
||||
cwd: this.cwd,
|
||||
base: this.base,
|
||||
stat: (this.stat ? cloneStats(this.stat) : null),
|
||||
history: this.history.slice(),
|
||||
contents: contents
|
||||
});
|
||||
|
||||
// clone our custom properties
|
||||
Object.keys(this).forEach(function(key) {
|
||||
// ignore built-in fields
|
||||
if (key === '_contents' || key === 'stat' ||
|
||||
key === 'history' || key === 'path' ||
|
||||
key === 'base' || key === 'cwd') {
|
||||
return;
|
||||
}
|
||||
file[key] = opt.deep ? clone(this[key], true) : this[key];
|
||||
}, this);
|
||||
return file;
|
||||
};
|
||||
|
||||
File.prototype.pipe = function(stream, opt) {
|
||||
if (!opt) opt = {};
|
||||
if (typeof opt.end === 'undefined') opt.end = true;
|
||||
|
||||
if (this.isStream()) {
|
||||
return this.contents.pipe(stream, opt);
|
||||
}
|
||||
if (this.isBuffer()) {
|
||||
if (opt.end) {
|
||||
stream.end(this.contents);
|
||||
} else {
|
||||
stream.write(this.contents);
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
// isNull
|
||||
if (opt.end) stream.end();
|
||||
return stream;
|
||||
};
|
||||
|
||||
File.prototype.inspect = function() {
|
||||
var inspect = [];
|
||||
|
||||
// use relative path if possible
|
||||
var filePath = (this.base && this.path) ? this.relative : this.path;
|
||||
|
||||
if (filePath) {
|
||||
inspect.push('"'+filePath+'"');
|
||||
}
|
||||
|
||||
if (this.isBuffer()) {
|
||||
inspect.push(this.contents.inspect());
|
||||
}
|
||||
|
||||
if (this.isStream()) {
|
||||
inspect.push(inspectStream(this.contents));
|
||||
}
|
||||
|
||||
return '<File '+inspect.join(' ')+'>';
|
||||
};
|
||||
|
||||
// virtual attributes
|
||||
// or stuff with extra logic
|
||||
Object.defineProperty(File.prototype, 'contents', {
|
||||
get: function() {
|
||||
return this._contents;
|
||||
},
|
||||
set: function(val) {
|
||||
if (!isBuffer(val) && !isStream(val) && !isNull(val)) {
|
||||
throw new Error('File.contents can only be a Buffer, a Stream, or null.');
|
||||
}
|
||||
this._contents = val;
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: should this be moved to vinyl-fs?
|
||||
Object.defineProperty(File.prototype, 'relative', {
|
||||
get: function() {
|
||||
if (!this.base) throw new Error('No base specified! Can not get relative.');
|
||||
if (!this.path) throw new Error('No path specified! Can not get relative.');
|
||||
return path.relative(this.base, this.path);
|
||||
},
|
||||
set: function() {
|
||||
throw new Error('File.relative is generated from the base and path attributes. Do not modify it.');
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(File.prototype, 'path', {
|
||||
get: function() {
|
||||
return this.history[this.history.length - 1];
|
||||
},
|
||||
set: function(path) {
|
||||
if (typeof path !== 'string') throw new Error('path should be string');
|
||||
|
||||
// record history only when path changed
|
||||
if (path && path !== this.path) {
|
||||
this.history.push(path);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = File;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
var Buffer = require('buffer').Buffer;
|
||||
|
||||
module.exports = function(buf) {
|
||||
var out = new Buffer(buf.length);
|
||||
buf.copy(out);
|
||||
return out;
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
var isStream = require('./isStream');
|
||||
|
||||
module.exports = function(stream) {
|
||||
if (!isStream(stream)) return;
|
||||
|
||||
var streamType = stream.constructor.name;
|
||||
// avoid StreamStream
|
||||
if (streamType === 'Stream') streamType = '';
|
||||
|
||||
return '<'+streamType+'Stream>';
|
||||
};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
var buf = require('buffer');
|
||||
var Buffer = buf.Buffer;
|
||||
|
||||
// could use Buffer.isBuffer but this is the same exact thing...
|
||||
module.exports = function(o) {
|
||||
return typeof o === 'object' && o instanceof Buffer;
|
||||
};
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
module.exports = function(v) {
|
||||
return v === null;
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
var Stream = require('stream').Stream;
|
||||
|
||||
module.exports = function(o) {
|
||||
return !!o && o instanceof Stream;
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
node_modules/
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.6
|
||||
- 0.8
|
||||
- 0.10
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
Copyright © 2011-2014 Paul Vorbach <paul@vorba.ch>
|
||||
|
||||
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, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
# clone
|
||||
|
||||
[](http://travis-ci.org/pvorb/node-clone)
|
||||
|
||||
offers foolproof _deep cloning_ of variables in JavaScript.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
npm install clone
|
||||
|
||||
or
|
||||
|
||||
ender build clone
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
~~~ javascript
|
||||
var clone = require('clone');
|
||||
|
||||
var a, b;
|
||||
|
||||
a = { foo: { bar: 'baz' } }; // initial value of a
|
||||
|
||||
b = clone(a); // clone a -> b
|
||||
a.foo.bar = 'foo'; // change a
|
||||
|
||||
console.log(a); // show a
|
||||
console.log(b); // show b
|
||||
~~~
|
||||
|
||||
This will print:
|
||||
|
||||
~~~ javascript
|
||||
{ foo: { bar: 'foo' } }
|
||||
{ foo: { bar: 'baz' } }
|
||||
~~~
|
||||
|
||||
**clone** masters cloning simple objects (even with custom prototype), arrays,
|
||||
Date objects, and RegExp objects. Everything is cloned recursively, so that you
|
||||
can clone dates in arrays in objects, for example.
|
||||
|
||||
|
||||
## API
|
||||
|
||||
`clone(val, circular, depth)`
|
||||
|
||||
* `val` -- the value that you want to clone, any type allowed
|
||||
* `circular` -- boolean
|
||||
|
||||
Call `clone` with `circular` set to `false` if you are certain that `obj`
|
||||
contains no circular references. This will give better performance if needed.
|
||||
There is no error if `undefined` or `null` is passed as `obj`.
|
||||
* `depth` -- depth to which the object is to be cloned (optional,
|
||||
defaults to infinity)
|
||||
|
||||
`clone.clonePrototype(obj)`
|
||||
|
||||
* `obj` -- the object that you want to clone
|
||||
|
||||
Does a prototype clone as
|
||||
[described by Oran Looney](http://oranlooney.com/functional-javascript/).
|
||||
|
||||
|
||||
## Circular References
|
||||
|
||||
~~~ javascript
|
||||
var a, b;
|
||||
|
||||
a = { hello: 'world' };
|
||||
|
||||
a.myself = a;
|
||||
b = clone(a);
|
||||
|
||||
console.log(b);
|
||||
~~~
|
||||
|
||||
This will print:
|
||||
|
||||
~~~ javascript
|
||||
{ hello: "world", myself: [Circular] }
|
||||
~~~
|
||||
|
||||
So, `b.myself` points to `b`, not `a`. Neat!
|
||||
|
||||
|
||||
## Test
|
||||
|
||||
npm test
|
||||
|
||||
|
||||
## Caveat
|
||||
|
||||
Some special objects like a socket or `process.stdout`/`stderr` are known to not
|
||||
be cloneable. If you find other objects that cannot be cloned, please [open an
|
||||
issue](https://github.com/pvorb/node-clone/issues/new).
|
||||
|
||||
|
||||
## Bugs and Issues
|
||||
|
||||
If you encounter any bugs or issues, feel free to [open an issue at
|
||||
github](https://github.com/pvorb/node-clone/issues) or send me an email to
|
||||
<paul@vorba.ch>. I also always like to hear from you, if you’re using my code.
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2011-2014 [Paul Vorbach](http://paul.vorba.ch/) and
|
||||
[contributors](https://github.com/pvorb/node-clone/graphs/contributors).
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the “Software”), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
'use strict';
|
||||
|
||||
function objectToString(o) {
|
||||
return Object.prototype.toString.call(o);
|
||||
}
|
||||
|
||||
// shim for Node's 'util' package
|
||||
// DO NOT REMOVE THIS! It is required for compatibility with EnderJS (http://enderjs.com/).
|
||||
var util = {
|
||||
isArray: function (ar) {
|
||||
return Array.isArray(ar) || (typeof ar === 'object' && objectToString(ar) === '[object Array]');
|
||||
},
|
||||
isDate: function (d) {
|
||||
return typeof d === 'object' && objectToString(d) === '[object Date]';
|
||||
},
|
||||
isRegExp: function (re) {
|
||||
return typeof re === 'object' && objectToString(re) === '[object RegExp]';
|
||||
},
|
||||
getRegExpFlags: function (re) {
|
||||
var flags = '';
|
||||
re.global && (flags += 'g');
|
||||
re.ignoreCase && (flags += 'i');
|
||||
re.multiline && (flags += 'm');
|
||||
return flags;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (typeof module === 'object')
|
||||
module.exports = clone;
|
||||
|
||||
/**
|
||||
* Clones (copies) an Object using deep copying.
|
||||
*
|
||||
* This function supports circular references by default, but if you are certain
|
||||
* there are no circular references in your object, you can save some CPU time
|
||||
* by calling clone(obj, false).
|
||||
*
|
||||
* Caution: if `circular` is false and `parent` contains circular references,
|
||||
* your program may enter an infinite loop and crash.
|
||||
*
|
||||
* @param `parent` - the object to be cloned
|
||||
* @param `circular` - set to true if the object to be cloned may contain
|
||||
* circular references. (optional - true by default)
|
||||
* @param `depth` - set to a number if the object is only to be cloned to
|
||||
* a particular depth. (optional - defaults to Infinity)
|
||||
* @param `prototype` - sets the prototype to be used when cloning an object.
|
||||
* (optional - defaults to parent prototype).
|
||||
*/
|
||||
|
||||
function clone(parent, circular, depth, prototype) {
|
||||
// maintain two arrays for circular references, where corresponding parents
|
||||
// and children have the same index
|
||||
var allParents = [];
|
||||
var allChildren = [];
|
||||
|
||||
var useBuffer = typeof Buffer != 'undefined';
|
||||
|
||||
if (typeof circular == 'undefined')
|
||||
circular = true;
|
||||
|
||||
if (typeof depth == 'undefined')
|
||||
depth = Infinity;
|
||||
|
||||
// recurse this function so we don't reset allParents and allChildren
|
||||
function _clone(parent, depth) {
|
||||
// cloning null always returns null
|
||||
if (parent === null)
|
||||
return null;
|
||||
|
||||
if (depth == 0)
|
||||
return parent;
|
||||
|
||||
var child;
|
||||
var proto;
|
||||
if (typeof parent != 'object') {
|
||||
return parent;
|
||||
}
|
||||
|
||||
if (util.isArray(parent)) {
|
||||
child = [];
|
||||
} else if (util.isRegExp(parent)) {
|
||||
child = new RegExp(parent.source, util.getRegExpFlags(parent));
|
||||
if (parent.lastIndex) child.lastIndex = parent.lastIndex;
|
||||
} else if (util.isDate(parent)) {
|
||||
child = new Date(parent.getTime());
|
||||
} else if (useBuffer && Buffer.isBuffer(parent)) {
|
||||
child = new Buffer(parent.length);
|
||||
parent.copy(child);
|
||||
return child;
|
||||
} else {
|
||||
if (typeof prototype == 'undefined') {
|
||||
proto = Object.getPrototypeOf(parent);
|
||||
child = Object.create(proto);
|
||||
}
|
||||
else {
|
||||
child = Object.create(prototype);
|
||||
proto = prototype;
|
||||
}
|
||||
}
|
||||
|
||||
if (circular) {
|
||||
var index = allParents.indexOf(parent);
|
||||
|
||||
if (index != -1) {
|
||||
return allChildren[index];
|
||||
}
|
||||
allParents.push(parent);
|
||||
allChildren.push(child);
|
||||
}
|
||||
|
||||
for (var i in parent) {
|
||||
var attrs;
|
||||
if (proto) {
|
||||
attrs = Object.getOwnPropertyDescriptor(proto, i);
|
||||
}
|
||||
|
||||
if (attrs && attrs.set == null) {
|
||||
continue;
|
||||
}
|
||||
child[i] = _clone(parent[i], depth - 1);
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
return _clone(parent, depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple flat clone using prototype, accepts only objects, usefull for property
|
||||
* override on FLAT configuration object (no nested props).
|
||||
*
|
||||
* USE WITH CAUTION! This may not behave as you wish if you do not know how this
|
||||
* works.
|
||||
*/
|
||||
clone.clonePrototype = function(parent) {
|
||||
if (parent === null)
|
||||
return null;
|
||||
|
||||
var c = function () {};
|
||||
c.prototype = parent;
|
||||
return new c();
|
||||
};
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
{
|
||||
"_from": "clone@^0.2.0",
|
||||
"_id": "clone@0.2.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-xhJqkK1Pctv1rNskPMN3JP6T/B8=",
|
||||
"_location": "/vinyl/clone",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "clone@^0.2.0",
|
||||
"name": "clone",
|
||||
"escapedName": "clone",
|
||||
"rawSpec": "^0.2.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.2.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/vinyl"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/clone/-/clone-0.2.0.tgz",
|
||||
"_shasum": "c6126a90ad4f72dbf5acdb243cc37724fe93fc1f",
|
||||
"_spec": "clone@^0.2.0",
|
||||
"_where": "/mnt/data/Sites/anissabensalah.net/user/themes/anissabensalah/node_modules/vinyl",
|
||||
"author": {
|
||||
"name": "Paul Vorbach",
|
||||
"email": "paul@vorba.ch",
|
||||
"url": "http://paul.vorba.ch/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/pvorb/node-clone/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Blake Miner",
|
||||
"email": "miner.blake@gmail.com",
|
||||
"url": "http://www.blakeminer.com/"
|
||||
},
|
||||
{
|
||||
"name": "Tian You",
|
||||
"email": "axqd001@gmail.com",
|
||||
"url": "http://blog.axqd.net/"
|
||||
},
|
||||
{
|
||||
"name": "George Stagas",
|
||||
"email": "gstagas@gmail.com",
|
||||
"url": "http://stagas.com/"
|
||||
},
|
||||
{
|
||||
"name": "Tobiasz Cudnik",
|
||||
"email": "tobiasz.cudnik@gmail.com",
|
||||
"url": "https://github.com/TobiaszCudnik"
|
||||
},
|
||||
{
|
||||
"name": "Pavel Lang",
|
||||
"email": "langpavel@phpskelet.org",
|
||||
"url": "https://github.com/langpavel"
|
||||
},
|
||||
{
|
||||
"name": "Dan MacTough",
|
||||
"url": "http://yabfog.com/"
|
||||
},
|
||||
{
|
||||
"name": "w1nk",
|
||||
"url": "https://github.com/w1nk"
|
||||
},
|
||||
{
|
||||
"name": "Hugh Kennedy",
|
||||
"url": "http://twitter.com/hughskennedy"
|
||||
},
|
||||
{
|
||||
"name": "Dustin Diaz",
|
||||
"url": "http://dustindiaz.com"
|
||||
},
|
||||
{
|
||||
"name": "Ilya Shaisultanov",
|
||||
"url": "https://github.com/diversario"
|
||||
},
|
||||
{
|
||||
"name": "Nathan MacInnes",
|
||||
"email": "nathan@macinn.es",
|
||||
"url": "http://macinn.es/"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin E. Coe",
|
||||
"email": "ben@npmjs.com",
|
||||
"url": "https://twitter.com/benjamincoe"
|
||||
},
|
||||
{
|
||||
"name": "Nathan Zadoks",
|
||||
"url": "https://github.com/nathan7"
|
||||
},
|
||||
{
|
||||
"name": "Róbert Oroszi",
|
||||
"email": "robert+gh@oroszi.net",
|
||||
"url": "https://github.com/oroce"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "deep cloning of objects and arrays",
|
||||
"devDependencies": {
|
||||
"nodeunit": "*",
|
||||
"underscore": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"homepage": "https://github.com/pvorb/node-clone#readme",
|
||||
"license": "MIT",
|
||||
"main": "clone.js",
|
||||
"name": "clone",
|
||||
"optionalDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/pvorb/node-clone.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "nodeunit test.js"
|
||||
},
|
||||
"tags": [
|
||||
"clone",
|
||||
"object",
|
||||
"array",
|
||||
"function",
|
||||
"date"
|
||||
],
|
||||
"version": "0.2.0"
|
||||
}
|
||||
+289
@@ -0,0 +1,289 @@
|
||||
if(module.parent === null) {
|
||||
console.log('Run this test file with nodeunit:');
|
||||
console.log('$ nodeunit test.js');
|
||||
}
|
||||
|
||||
|
||||
var clone = require('./');
|
||||
var util = require('util');
|
||||
var _ = require('underscore');
|
||||
|
||||
|
||||
|
||||
exports["clone string"] = function(test) {
|
||||
test.expect(2); // how many tests?
|
||||
|
||||
var a = "foo";
|
||||
test.strictEqual(clone(a), a);
|
||||
a = "";
|
||||
test.strictEqual(clone(a), a);
|
||||
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
|
||||
exports["clone number"] = function(test) {
|
||||
test.expect(5); // how many tests?
|
||||
|
||||
var a = 0;
|
||||
test.strictEqual(clone(a), a);
|
||||
a = 1;
|
||||
test.strictEqual(clone(a), a);
|
||||
a = -1000;
|
||||
test.strictEqual(clone(a), a);
|
||||
a = 3.1415927;
|
||||
test.strictEqual(clone(a), a);
|
||||
a = -3.1415927;
|
||||
test.strictEqual(clone(a), a);
|
||||
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
|
||||
exports["clone date"] = function(test) {
|
||||
test.expect(3); // how many tests?
|
||||
|
||||
var a = new Date;
|
||||
var c = clone(a);
|
||||
test.ok(a instanceof Date);
|
||||
test.ok(c instanceof Date);
|
||||
test.equal(c.getTime(), a.getTime());
|
||||
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
|
||||
exports["clone object"] = function(test) {
|
||||
test.expect(2); // how many tests?
|
||||
|
||||
var a = { foo: { bar: "baz" } };
|
||||
var b = clone(a);
|
||||
|
||||
test.ok(_(a).isEqual(b), "underscore equal");
|
||||
test.deepEqual(b, a);
|
||||
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
|
||||
exports["clone array"] = function(test) {
|
||||
test.expect(2); // how many tests?
|
||||
|
||||
var a = [
|
||||
{ foo: "bar" },
|
||||
"baz"
|
||||
];
|
||||
var b = clone(a);
|
||||
|
||||
test.ok(_(a).isEqual(b), "underscore equal");
|
||||
test.deepEqual(b, a);
|
||||
|
||||
test.done();
|
||||
};
|
||||
|
||||
exports["clone buffer"] = function(test) {
|
||||
test.expect(1);
|
||||
|
||||
var a = new Buffer("this is a test buffer");
|
||||
var b = clone(a);
|
||||
|
||||
// no underscore equal since it has no concept of Buffers
|
||||
test.deepEqual(b, a);
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
|
||||
exports["clone regexp"] = function(test) {
|
||||
test.expect(5);
|
||||
|
||||
var a = /abc123/gi;
|
||||
var b = clone(a);
|
||||
|
||||
test.deepEqual(b, a);
|
||||
|
||||
var c = /a/g;
|
||||
test.ok(c.lastIndex === 0);
|
||||
|
||||
c.exec('123a456a');
|
||||
test.ok(c.lastIndex === 4);
|
||||
|
||||
var d = clone(c);
|
||||
test.ok(d.global);
|
||||
test.ok(d.lastIndex === 4);
|
||||
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
exports["clone object containing array"] = function(test) {
|
||||
test.expect(2); // how many tests?
|
||||
|
||||
var a = {
|
||||
arr1: [ { a: '1234', b: '2345' } ],
|
||||
arr2: [ { c: '345', d: '456' } ]
|
||||
};
|
||||
var b = clone(a);
|
||||
|
||||
test.ok(_(a).isEqual(b), "underscore equal");
|
||||
test.deepEqual(b, a);
|
||||
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
|
||||
exports["clone object with circular reference"] = function(test) {
|
||||
test.expect(8); // how many tests?
|
||||
|
||||
var _ = test.ok;
|
||||
var c = [1, "foo", {'hello': 'bar'}, function() {}, false, [2]];
|
||||
var b = [c, 2, 3, 4];
|
||||
var a = {'b': b, 'c': c};
|
||||
a.loop = a;
|
||||
a.loop2 = a;
|
||||
c.loop = c;
|
||||
c.aloop = a;
|
||||
var aCopy = clone(a);
|
||||
_(a != aCopy);
|
||||
_(a.c != aCopy.c);
|
||||
_(aCopy.c == aCopy.b[0]);
|
||||
_(aCopy.c.loop.loop.aloop == aCopy);
|
||||
_(aCopy.c[0] == a.c[0]);
|
||||
|
||||
//console.log(util.inspect(aCopy, true, null) );
|
||||
//console.log("------------------------------------------------------------");
|
||||
//console.log(util.inspect(a, true, null) );
|
||||
_(eq(a, aCopy));
|
||||
aCopy.c[0] = 2;
|
||||
_(!eq(a, aCopy));
|
||||
aCopy.c = "2";
|
||||
_(!eq(a, aCopy));
|
||||
//console.log("------------------------------------------------------------");
|
||||
//console.log(util.inspect(aCopy, true, null) );
|
||||
|
||||
function eq(x, y) {
|
||||
return util.inspect(x, true, null) === util.inspect(y, true, null);
|
||||
}
|
||||
|
||||
test.done();
|
||||
};
|
||||
|
||||
|
||||
|
||||
exports['clonePrototype'] = function(test) {
|
||||
test.expect(3); // how many tests?
|
||||
|
||||
var a = {
|
||||
a: "aaa",
|
||||
x: 123,
|
||||
y: 45.65
|
||||
};
|
||||
var b = clone.clonePrototype(a);
|
||||
|
||||
test.strictEqual(b.a, a.a);
|
||||
test.strictEqual(b.x, a.x);
|
||||
test.strictEqual(b.y, a.y);
|
||||
|
||||
test.done();
|
||||
}
|
||||
|
||||
exports['cloneWithinNewVMContext'] = function(test) {
|
||||
test.expect(3);
|
||||
var vm = require('vm');
|
||||
var ctx = vm.createContext({ clone: clone });
|
||||
var script = "clone( {array: [1, 2, 3], date: new Date(), regex: /^foo$/ig} );";
|
||||
var results = vm.runInContext(script, ctx);
|
||||
test.ok(results.array instanceof Array);
|
||||
test.ok(results.date instanceof Date);
|
||||
test.ok(results.regex instanceof RegExp);
|
||||
test.done();
|
||||
}
|
||||
|
||||
exports['cloneObjectWithNoConstructor'] = function(test) {
|
||||
test.expect(3);
|
||||
var n = null;
|
||||
var a = { foo: 'bar' };
|
||||
a.__proto__ = n;
|
||||
test.ok(typeof a === 'object');
|
||||
test.ok(typeof a !== null);
|
||||
var b = clone(a);
|
||||
test.ok(a.foo, b.foo);
|
||||
test.done();
|
||||
}
|
||||
|
||||
exports['clone object with depth argument'] = function (test) {
|
||||
test.expect(6);
|
||||
var a = {
|
||||
foo: {
|
||||
bar : {
|
||||
baz : 'qux'
|
||||
}
|
||||
}
|
||||
};
|
||||
var b = clone(a, false, 1);
|
||||
test.deepEqual(b, a);
|
||||
test.notEqual(b, a);
|
||||
test.strictEqual(b.foo, a.foo);
|
||||
|
||||
b = clone(a, true, 2);
|
||||
test.deepEqual(b, a);
|
||||
test.notEqual(b.foo, a.foo);
|
||||
test.strictEqual(b.foo.bar, a.foo.bar);
|
||||
test.done();
|
||||
}
|
||||
|
||||
exports['maintain prototype chain in clones'] = function (test) {
|
||||
test.expect(1);
|
||||
function Constructor() {}
|
||||
var a = new Constructor();
|
||||
var b = clone(a);
|
||||
test.strictEqual(Object.getPrototypeOf(a), Object.getPrototypeOf(b));
|
||||
test.done();
|
||||
}
|
||||
|
||||
exports['parent prototype is overriden with prototype provided'] = function (test) {
|
||||
test.expect(1);
|
||||
function Constructor() {}
|
||||
var a = new Constructor();
|
||||
var b = clone(a, true, Infinity, null);
|
||||
test.strictEqual(b.__defineSetter__, undefined);
|
||||
test.done();
|
||||
}
|
||||
|
||||
exports['clone object with null children'] = function(test) {
|
||||
test.expect(1);
|
||||
var a = {
|
||||
foo: {
|
||||
bar: null,
|
||||
baz: {
|
||||
qux: false
|
||||
}
|
||||
}
|
||||
};
|
||||
var b = clone(a);
|
||||
test.deepEqual(b, a);
|
||||
test.done();
|
||||
}
|
||||
|
||||
exports['clone instance with getter'] = function(test) {
|
||||
test.expect(1);
|
||||
function Ctor() {};
|
||||
Object.defineProperty(Ctor.prototype, 'prop', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return 'value';
|
||||
}
|
||||
});
|
||||
|
||||
var a = new Ctor();
|
||||
var b = clone(a);
|
||||
|
||||
test.strictEqual(b.prop, 'value');
|
||||
test.done();
|
||||
};
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"_from": "vinyl@^0.4.0",
|
||||
"_id": "vinyl@0.4.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-LzVsh6VQolVGHza76ypbqL94SEc=",
|
||||
"_location": "/vinyl",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "vinyl@^0.4.0",
|
||||
"name": "vinyl",
|
||||
"escapedName": "vinyl",
|
||||
"rawSpec": "^0.4.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.4.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/vinyl-fs"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/vinyl/-/vinyl-0.4.6.tgz",
|
||||
"_shasum": "2f356c87a550a255461f36bbeb2a5ba8bf784847",
|
||||
"_spec": "vinyl@^0.4.0",
|
||||
"_where": "/mnt/data/Sites/anissabensalah.net/user/themes/anissabensalah/node_modules/vinyl-fs",
|
||||
"author": {
|
||||
"name": "Fractal",
|
||||
"email": "contact@wearefractal.com",
|
||||
"url": "http://wearefractal.com/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/wearefractal/vinyl/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"clone": "^0.2.0",
|
||||
"clone-stats": "^0.0.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A virtual file format",
|
||||
"devDependencies": {
|
||||
"buffer-equal": "0.0.1",
|
||||
"coveralls": "^2.6.1",
|
||||
"event-stream": "^3.1.0",
|
||||
"istanbul": "^0.3.0",
|
||||
"jshint": "^2.4.1",
|
||||
"lodash.templatesettings": "^2.4.1",
|
||||
"mocha": "^2.0.0",
|
||||
"mocha-lcov-reporter": "^0.0.1",
|
||||
"rimraf": "^2.2.5",
|
||||
"should": "^4.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.9"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"lib"
|
||||
],
|
||||
"homepage": "http://github.com/wearefractal/vinyl",
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://github.com/wearefractal/vinyl/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "./index.js",
|
||||
"name": "vinyl",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/wearefractal/vinyl.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coveralls": "istanbul cover _mocha -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
|
||||
"test": "mocha --reporter spec && jshint lib"
|
||||
},
|
||||
"version": "0.4.6"
|
||||
}
|
||||
Reference in New Issue
Block a user