Deployed the page to Github Pages.
This commit is contained in:
parent
1d79754e93
commit
2c89899458
62797 changed files with 6551425 additions and 15279 deletions
18
node_modules/hoek/.npmignore
generated
vendored
Normal file
18
node_modules/hoek/.npmignore
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
.idea
|
||||
*.iml
|
||||
npm-debug.log
|
||||
dump.rdb
|
||||
node_modules
|
||||
results.tap
|
||||
results.xml
|
||||
npm-shrinkwrap.json
|
||||
config.json
|
||||
.DS_Store
|
||||
*/.DS_Store
|
||||
*/*/.DS_Store
|
||||
._*
|
||||
*/._*
|
||||
*/*/._*
|
||||
coverage.*
|
||||
lib-cov
|
||||
complexity.md
|
5
node_modules/hoek/.travis.yml
generated
vendored
Executable file
5
node_modules/hoek/.travis.yml
generated
vendored
Executable file
|
@ -0,0 +1,5 @@
|
|||
language: node_js
|
||||
|
||||
node_js:
|
||||
- 0.10
|
||||
|
33
node_modules/hoek/LICENSE
generated
vendored
Executable file
33
node_modules/hoek/LICENSE
generated
vendored
Executable file
|
@ -0,0 +1,33 @@
|
|||
Copyright (c) 2011-2013, Walmart.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of Walmart nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL WALMART BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
* * *
|
||||
|
||||
|
||||
Portions of this project were initially based on Postmile, Copyright (c) 2011, Yahoo Inc.
|
||||
Postmile is published at https://github.com/yahoo/postmile and its licensing terms are
|
||||
published at https://github.com/yahoo/postmile/blob/master/LICENSE.
|
||||
|
436
node_modules/hoek/README.md
generated
vendored
Executable file
436
node_modules/hoek/README.md
generated
vendored
Executable file
|
@ -0,0 +1,436 @@
|
|||
<a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a>
|
||||

|
||||
|
||||
General purpose node utilities
|
||||
|
||||
[](http://travis-ci.org/spumko/hoek)
|
||||
|
||||
# Table of Contents
|
||||
|
||||
* [Introduction](#introduction "Introduction")
|
||||
* [Object](#object "Object")
|
||||
* [clone](#cloneobj "clone")
|
||||
* [merge](#mergetarget-source-isnulloverride-ismergearrays "merge")
|
||||
* [applyToDefaults](#applytodefaultsdefaults-options "applyToDefaults")
|
||||
* [unique](#uniquearray-key "unique")
|
||||
* [mapToObject](#maptoobjectarray-key "mapToObject")
|
||||
* [intersect](#intersectarray1-array2 "intersect")
|
||||
* [matchKeys](#matchkeysobj-keys "matchKeys")
|
||||
* [flatten](#flattenarray-target "flatten")
|
||||
* [removeKeys](#removekeysobject-keys "removeKeys")
|
||||
* [reach](#reachobj-chain "reach")
|
||||
* [inheritAsync](#inheritasyncself-obj-keys "inheritAsync")
|
||||
* [rename](#renameobj-from-to "rename")
|
||||
* [Timer](#timer "Timer")
|
||||
* [Binary Encoding/Decoding](#binary "Binary Encoding/Decoding")
|
||||
* [base64urlEncode](#binary64urlEncodevalue "binary64urlEncode")
|
||||
* [base64urlDecode](#binary64urlDecodevalue "binary64urlDecode")
|
||||
* [Escaping Characters](#escaped "Escaping Characters")
|
||||
* [escapeHtml](#escapeHtmlstring "escapeHtml")
|
||||
* [escapeHeaderAttribute](#escapeHeaderAttributeattribute "escapeHeaderAttribute")
|
||||
* [escapeRegex](#escapeRegexstring "escapeRegex")
|
||||
* [Errors](#errors "Errors")
|
||||
* [assert](#assertmessage "assert")
|
||||
* [abort](#abortmessage "abort")
|
||||
* [displayStack](#displayStackslice "displayStack")
|
||||
* [callStack](#callStackslice "callStack")
|
||||
* [toss](#tosscondition "toss")
|
||||
* [Load files](#load-files "Load Files")
|
||||
* [loadPackage](#loadPackagedir "loadpackage")
|
||||
* [loadDirModules](#loadDirModulespath-excludefiles-target "loaddirmodules")
|
||||
|
||||
|
||||
|
||||
# Introduction
|
||||
|
||||
The *Hoek* general purpose node utilities library is used to aid in a variety of manners. It comes with useful methods for Arrays (clone, merge, applyToDefaults), Objects (removeKeys, copy), Asserting and more.
|
||||
|
||||
For example, to use Hoek to set configuration with default options:
|
||||
```javascript
|
||||
var Hoek = require('hoek');
|
||||
|
||||
var default = {url : "www.github.com", port : "8000", debug : true}
|
||||
|
||||
var config = Hoek.applyToDefaults(default, {port : "3000", admin : true});
|
||||
|
||||
// In this case, config would be { url: 'www.github.com', port: '3000', debug: true, admin: true }
|
||||
```
|
||||
|
||||
Under each of the sections (such as Array), there are subsections which correspond to Hoek methods. Each subsection will explain how to use the corresponding method. In each js excerpt below, the var Hoek = require('hoek') is omitted for brevity.
|
||||
|
||||
## Object
|
||||
|
||||
Hoek provides several helpful methods for objects and arrays.
|
||||
|
||||
### clone(obj)
|
||||
|
||||
This method is used to clone an object or an array. A *deep copy* is made (duplicates everything, including values that are objects).
|
||||
|
||||
```javascript
|
||||
|
||||
var nestedObj = {
|
||||
w: /^something$/ig,
|
||||
x: {
|
||||
a: [1, 2, 3],
|
||||
b: 123456,
|
||||
c: new Date()
|
||||
},
|
||||
y: 'y',
|
||||
z: new Date()
|
||||
};
|
||||
|
||||
var copy = Hoek.clone(nestedObj);
|
||||
|
||||
copy.x.b = 100;
|
||||
|
||||
console.log(copy.y) // results in 'y'
|
||||
console.log(nestedObj.x.b) // results in 123456
|
||||
console.log(copy.x.b) // results in 100
|
||||
```
|
||||
|
||||
### merge(target, source, isNullOverride, isMergeArrays)
|
||||
isNullOverride, isMergeArrays default to true
|
||||
|
||||
Merge all the properties of source into target, source wins in conflic, and by default null and undefined from source are applied
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
var target = {a: 1, b : 2}
|
||||
var source = {a: 0, c: 5}
|
||||
var source2 = {a: null, c: 5}
|
||||
|
||||
var targetArray = [1, 2, 3];
|
||||
var sourceArray = [4, 5];
|
||||
|
||||
var newTarget = Hoek.merge(target, source); // results in {a: 0, b: 2, c: 5}
|
||||
newTarget = Hoek.merge(target, source2); // results in {a: null, b: 2, c: 5}
|
||||
newTarget = Hoek.merge(target, source2, false); // results in {a: 1, b: 2, c: 5}
|
||||
|
||||
newTarget = Hoek.merge(targetArray, sourceArray) // results in [1, 2, 3, 4, 5]
|
||||
newTarget = Hoek.merge(targetArray, sourceArray, true, false) // results in [4, 5]
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
### applyToDefaults(defaults, options)
|
||||
|
||||
Apply options to a copy of the defaults
|
||||
|
||||
```javascript
|
||||
|
||||
var defaults = {host: "localhost", port: 8000};
|
||||
var options = {port: 8080};
|
||||
|
||||
var config = Hoek.applyToDefaults(defaults, options); // results in {host: "localhost", port: 8080};
|
||||
|
||||
|
||||
```
|
||||
|
||||
### unique(array, key)
|
||||
|
||||
Remove duplicate items from Array
|
||||
|
||||
```javascript
|
||||
|
||||
var array = [1, 2, 2, 3, 3, 4, 5, 6];
|
||||
|
||||
var newArray = Hoek.unique(array); // results in [1,2,3,4,5,6];
|
||||
|
||||
array = [{id: 1}, {id: 1}, {id: 2}];
|
||||
|
||||
newArray = Hoek.unique(array, "id") // results in [{id: 1}, {id: 2}]
|
||||
|
||||
```
|
||||
|
||||
### mapToObject(array, key)
|
||||
|
||||
Convert an Array into an Object
|
||||
|
||||
```javascript
|
||||
|
||||
var array = [1,2,3];
|
||||
var newObject = Hoek.mapToObject(array); // results in [{"1": true}, {"2": true}, {"3": true}]
|
||||
|
||||
array = [{id: 1}, {id: 2}];
|
||||
newObject = Hoek.mapToObject(array, "id") // results in [{"id": 1}, {"id": 2}]
|
||||
|
||||
```
|
||||
### intersect(array1, array2)
|
||||
|
||||
Find the common unique items in two arrays
|
||||
|
||||
```javascript
|
||||
|
||||
var array1 = [1, 2, 3];
|
||||
var array2 = [1, 4, 5];
|
||||
|
||||
var newArray = Hoek.intersect(array1, array2) // results in [1]
|
||||
|
||||
```
|
||||
|
||||
### matchKeys(obj, keys)
|
||||
|
||||
Find which keys are present
|
||||
|
||||
```javascript
|
||||
|
||||
var obj = {a: 1, b: 2, c: 3};
|
||||
var keys = ["a", "e"];
|
||||
|
||||
Hoek.matchKeys(obj, keys) // returns ["a"]
|
||||
|
||||
```
|
||||
|
||||
### flatten(array, target)
|
||||
|
||||
Flatten an array
|
||||
|
||||
```javascript
|
||||
|
||||
var array = [1, 2, 3];
|
||||
var target = [4, 5];
|
||||
|
||||
var flattenedArray = Hoek.flatten(array, target) // results in [4, 5, 1, 2, 3];
|
||||
|
||||
```
|
||||
|
||||
### removeKeys(object, keys)
|
||||
|
||||
Remove keys
|
||||
|
||||
```javascript
|
||||
|
||||
var object = {a: 1, b: 2, c: 3, d: 4};
|
||||
|
||||
var keys = ["a", "b"];
|
||||
|
||||
Hoek.removeKeys(object, keys) // object is now {c: 3, d: 4}
|
||||
|
||||
```
|
||||
|
||||
### reach(obj, chain)
|
||||
|
||||
Converts an object key chain string to reference
|
||||
|
||||
```javascript
|
||||
|
||||
var chain = 'a.b.c';
|
||||
var obj = {a : {b : { c : 1}}};
|
||||
|
||||
Hoek.reach(obj, chain) // returns 1
|
||||
|
||||
```
|
||||
|
||||
### inheritAsync(self, obj, keys)
|
||||
|
||||
Inherits a selected set of methods from an object, wrapping functions in asynchronous syntax and catching errors
|
||||
|
||||
```javascript
|
||||
|
||||
var targetFunc = function () { };
|
||||
|
||||
var proto = {
|
||||
a: function () {
|
||||
return 'a!';
|
||||
},
|
||||
b: function () {
|
||||
return 'b!';
|
||||
},
|
||||
c: function () {
|
||||
throw new Error('c!');
|
||||
}
|
||||
};
|
||||
|
||||
var keys = ['a', 'c'];
|
||||
|
||||
Hoek.inheritAsync(targetFunc, proto, ['a', 'c']);
|
||||
|
||||
var target = new targetFunc();
|
||||
|
||||
target.a(function(err, result){console.log(result)} // returns 'a!'
|
||||
|
||||
target.c(function(err, result){console.log(result)} // returns undefined
|
||||
|
||||
target.b(function(err, result){console.log(result)} // gives error: Object [object Object] has no method 'b'
|
||||
|
||||
```
|
||||
|
||||
### rename(obj, from, to)
|
||||
|
||||
Rename a key of an object
|
||||
|
||||
```javascript
|
||||
|
||||
var obj = {a : 1, b : 2};
|
||||
|
||||
Hoek.rename(obj, "a", "c"); // obj is now {c : 1, b : 2}
|
||||
|
||||
```
|
||||
|
||||
|
||||
# Timer
|
||||
|
||||
A Timer object. Initializing a new timer object sets the ts to the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.
|
||||
|
||||
```javascript
|
||||
|
||||
|
||||
example :
|
||||
|
||||
|
||||
var timerObj = new Hoek.Timer();
|
||||
console.log("Time is now: " + timerObj.ts)
|
||||
console.log("Elapsed time from initialization: " + timerObj.elapsed() + 'milliseconds')
|
||||
|
||||
```
|
||||
|
||||
# Binary Encoding/Decoding
|
||||
|
||||
### base64urlEncode(value)
|
||||
|
||||
Encodes value in Base64 or URL encoding
|
||||
|
||||
### base64urlDecode(value)
|
||||
|
||||
Decodes data in Base64 or URL encoding.
|
||||
# Escaping Characters
|
||||
|
||||
Hoek provides convenient methods for escaping html characters. The escaped characters are as followed:
|
||||
|
||||
```javascript
|
||||
|
||||
internals.htmlEscaped = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
'`': '`'
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### escapeHtml(string)
|
||||
|
||||
```javascript
|
||||
|
||||
var string = '<html> hey </html>';
|
||||
var escapedString = Hoek.escapeHtml(string); // returns <html> hey </html>
|
||||
|
||||
```
|
||||
|
||||
### escapeHeaderAttribute(attribute)
|
||||
|
||||
Escape attribute value for use in HTTP header
|
||||
|
||||
```javascript
|
||||
|
||||
var a = Hoek.escapeHeaderAttribute('I said "go w\\o me"'); //returns I said \"go w\\o me\"
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
### escapeRegex(string)
|
||||
|
||||
Escape string for Regex construction
|
||||
|
||||
```javascript
|
||||
|
||||
var a = Hoek.escapeRegex('4^f$s.4*5+-_?%=#!:@|~\\/`"(>)[<]d{}s,'); // returns 4\^f\$s\.4\*5\+\-_\?%\=#\!\:@\|~\\\/`"\(>\)\[<\]d\{\}s\,
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
# Errors
|
||||
|
||||
### assert(message)
|
||||
|
||||
```javascript
|
||||
|
||||
var a = 1, b =2;
|
||||
|
||||
Hoek.assert(a === b, 'a should equal b'); // ABORT: a should equal b
|
||||
|
||||
```
|
||||
|
||||
### abort(message)
|
||||
|
||||
First checks if process.env.NODE_ENV === 'test', and if so, throws error message. Otherwise,
|
||||
displays most recent stack and then exits process.
|
||||
|
||||
|
||||
|
||||
### displayStack(slice)
|
||||
|
||||
Displays the trace stack
|
||||
|
||||
```javascript
|
||||
|
||||
var stack = Hoek.displayStack();
|
||||
console.log(stack) // returns something like:
|
||||
|
||||
[ 'null (/Users/user/Desktop/hoek/test.js:4:18)',
|
||||
'Module._compile (module.js:449:26)',
|
||||
'Module._extensions..js (module.js:467:10)',
|
||||
'Module.load (module.js:356:32)',
|
||||
'Module._load (module.js:312:12)',
|
||||
'Module.runMain (module.js:492:10)',
|
||||
'startup.processNextTick.process._tickCallback (node.js:244:9)' ]
|
||||
|
||||
```
|
||||
|
||||
### callStack(slice)
|
||||
|
||||
Returns a trace stack array.
|
||||
|
||||
```javascript
|
||||
|
||||
var stack = Hoek.callStack();
|
||||
console.log(stack) // returns something like:
|
||||
|
||||
[ [ '/Users/user/Desktop/hoek/test.js', 4, 18, null, false ],
|
||||
[ 'module.js', 449, 26, 'Module._compile', false ],
|
||||
[ 'module.js', 467, 10, 'Module._extensions..js', false ],
|
||||
[ 'module.js', 356, 32, 'Module.load', false ],
|
||||
[ 'module.js', 312, 12, 'Module._load', false ],
|
||||
[ 'module.js', 492, 10, 'Module.runMain', false ],
|
||||
[ 'node.js',
|
||||
244,
|
||||
9,
|
||||
'startup.processNextTick.process._tickCallback',
|
||||
false ] ]
|
||||
|
||||
|
||||
```
|
||||
|
||||
### toss(condition)
|
||||
|
||||
toss(condition /*, [message], callback */)
|
||||
|
||||
Return an error as first argument of a callback
|
||||
|
||||
|
||||
# Load Files
|
||||
|
||||
### loadPackage(dir)
|
||||
|
||||
Load and parse package.json process root or given directory
|
||||
|
||||
```javascript
|
||||
|
||||
var pack = Hoek.loadPackage(); // pack.name === 'hoek'
|
||||
|
||||
```
|
||||
|
||||
### loadDirModules(path, excludeFiles, target)
|
||||
|
||||
Loads modules from a given path; option to exclude files (array).
|
||||
|
||||
|
||||
|
||||
|
BIN
node_modules/hoek/images/hoek.png
generated
vendored
Executable file
BIN
node_modules/hoek/images/hoek.png
generated
vendored
Executable file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
132
node_modules/hoek/lib/escape.js
generated
vendored
Executable file
132
node_modules/hoek/lib/escape.js
generated
vendored
Executable file
|
@ -0,0 +1,132 @@
|
|||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
exports.escapeJavaScript = function (input) {
|
||||
|
||||
if (!input) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var escaped = '';
|
||||
|
||||
for (var i = 0, il = input.length; i < il; ++i) {
|
||||
|
||||
var charCode = input.charCodeAt(i);
|
||||
|
||||
if (internals.isSafe(charCode)) {
|
||||
escaped += input[i];
|
||||
}
|
||||
else {
|
||||
escaped += internals.escapeJavaScriptChar(charCode);
|
||||
}
|
||||
}
|
||||
|
||||
return escaped;
|
||||
};
|
||||
|
||||
|
||||
exports.escapeHtml = function (input) {
|
||||
|
||||
if (!input) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var escaped = '';
|
||||
|
||||
for (var i = 0, il = input.length; i < il; ++i) {
|
||||
|
||||
var charCode = input.charCodeAt(i);
|
||||
|
||||
if (internals.isSafe(charCode)) {
|
||||
escaped += input[i];
|
||||
}
|
||||
else {
|
||||
escaped += internals.escapeHtmlChar(charCode);
|
||||
}
|
||||
}
|
||||
|
||||
return escaped;
|
||||
};
|
||||
|
||||
|
||||
internals.escapeJavaScriptChar = function (charCode) {
|
||||
|
||||
if (charCode >= 256) {
|
||||
return '\\u' + internals.padLeft('' + charCode, 4);
|
||||
}
|
||||
|
||||
var hexValue = new Buffer(String.fromCharCode(charCode), 'ascii').toString('hex');
|
||||
return '\\x' + internals.padLeft(hexValue, 2);
|
||||
};
|
||||
|
||||
|
||||
internals.escapeHtmlChar = function (charCode) {
|
||||
|
||||
var namedEscape = internals.namedHtml[charCode];
|
||||
if (typeof namedEscape !== 'undefined') {
|
||||
return namedEscape;
|
||||
}
|
||||
|
||||
if (charCode >= 256) {
|
||||
return '&#' + charCode + ';';
|
||||
}
|
||||
|
||||
var hexValue = new Buffer(String.fromCharCode(charCode), 'ascii').toString('hex');
|
||||
return '&#x' + internals.padLeft(hexValue, 2) + ';';
|
||||
};
|
||||
|
||||
|
||||
internals.padLeft = function (str, len) {
|
||||
|
||||
while (str.length < len) {
|
||||
str = '0' + str;
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
|
||||
internals.isSafe = function (charCode) {
|
||||
|
||||
return (typeof internals.safeCharCodes[charCode] !== 'undefined');
|
||||
};
|
||||
|
||||
|
||||
internals.namedHtml = {
|
||||
'38': '&',
|
||||
'60': '<',
|
||||
'62': '>',
|
||||
'34': '"',
|
||||
'160': ' ',
|
||||
'162': '¢',
|
||||
'163': '£',
|
||||
'164': '¤',
|
||||
'169': '©',
|
||||
'174': '®'
|
||||
};
|
||||
|
||||
|
||||
internals.safeCharCodes = (function () {
|
||||
|
||||
var safe = {};
|
||||
|
||||
for (var i = 32; i < 123; ++i) {
|
||||
|
||||
if ((i >= 97 && i <= 122) || // a-z
|
||||
(i >= 65 && i <= 90) || // A-Z
|
||||
(i >= 48 && i <= 57) || // 0-9
|
||||
i === 32 || // space
|
||||
i === 46 || // .
|
||||
i === 44 || // ,
|
||||
i === 45 || // -
|
||||
i === 58 || // :
|
||||
i === 95) { // _
|
||||
|
||||
safe[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return safe;
|
||||
}());
|
585
node_modules/hoek/lib/index.js
generated
vendored
Executable file
585
node_modules/hoek/lib/index.js
generated
vendored
Executable file
|
@ -0,0 +1,585 @@
|
|||
// Load modules
|
||||
|
||||
var Fs = require('fs');
|
||||
var Escape = require('./escape');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
// Clone object or array
|
||||
|
||||
exports.clone = function (obj, seen) {
|
||||
|
||||
if (typeof obj !== 'object' ||
|
||||
obj === null) {
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
seen = seen || { orig: [], copy: [] };
|
||||
|
||||
var lookup = seen.orig.indexOf(obj);
|
||||
if (lookup !== -1) {
|
||||
return seen.copy[lookup];
|
||||
}
|
||||
|
||||
var newObj = (obj instanceof Array) ? [] : {};
|
||||
|
||||
seen.orig.push(obj);
|
||||
seen.copy.push(newObj);
|
||||
|
||||
for (var i in obj) {
|
||||
if (obj.hasOwnProperty(i)) {
|
||||
if (obj[i] instanceof Buffer) {
|
||||
newObj[i] = new Buffer(obj[i]);
|
||||
}
|
||||
else if (obj[i] instanceof Date) {
|
||||
newObj[i] = new Date(obj[i].getTime());
|
||||
}
|
||||
else if (obj[i] instanceof RegExp) {
|
||||
var flags = '' + (obj[i].global ? 'g' : '') + (obj[i].ignoreCase ? 'i' : '') + (obj[i].multiline ? 'm' : '');
|
||||
newObj[i] = new RegExp(obj[i].source, flags);
|
||||
}
|
||||
else {
|
||||
newObj[i] = exports.clone(obj[i], seen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newObj;
|
||||
};
|
||||
|
||||
|
||||
// Merge all the properties of source into target, source wins in conflic, and by default null and undefined from source are applied
|
||||
|
||||
exports.merge = function (target, source, isNullOverride /* = true */, isMergeArrays /* = true */) {
|
||||
|
||||
exports.assert(target && typeof target == 'object', 'Invalid target value: must be an object');
|
||||
exports.assert(source === null || source === undefined || typeof source === 'object', 'Invalid source value: must be null, undefined, or an object');
|
||||
|
||||
if (!source) {
|
||||
return target;
|
||||
}
|
||||
|
||||
if (source instanceof Array) {
|
||||
exports.assert(target instanceof Array, 'Cannot merge array onto an object');
|
||||
if (isMergeArrays === false) { // isMergeArrays defaults to true
|
||||
target.length = 0; // Must not change target assignment
|
||||
}
|
||||
|
||||
for (var i = 0, il = source.length; i < il; ++i) {
|
||||
target.push(source[i]);
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
var keys = Object.keys(source);
|
||||
for (var k = 0, kl = keys.length; k < kl; ++k) {
|
||||
var key = keys[k];
|
||||
var value = source[key];
|
||||
if (value &&
|
||||
typeof value === 'object') {
|
||||
|
||||
if (!target[key] ||
|
||||
typeof target[key] !== 'object') {
|
||||
|
||||
target[key] = exports.clone(value);
|
||||
}
|
||||
else {
|
||||
exports.merge(target[key], source[key], isNullOverride, isMergeArrays);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (value !== null && value !== undefined) { // Explicit to preserve empty strings
|
||||
target[key] = value;
|
||||
}
|
||||
else if (isNullOverride !== false) { // Defaults to true
|
||||
target[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
|
||||
// Apply options to a copy of the defaults
|
||||
|
||||
exports.applyToDefaults = function (defaults, options) {
|
||||
|
||||
exports.assert(defaults && typeof defaults == 'object', 'Invalid defaults value: must be an object');
|
||||
exports.assert(!options || options === true || typeof options === 'object', 'Invalid options value: must be true, falsy or an object');
|
||||
|
||||
if (!options) { // If no options, return null
|
||||
return null;
|
||||
}
|
||||
|
||||
var copy = exports.clone(defaults);
|
||||
|
||||
if (options === true) { // If options is set to true, use defaults
|
||||
return copy;
|
||||
}
|
||||
|
||||
return exports.merge(copy, options, false, false);
|
||||
};
|
||||
|
||||
|
||||
// Remove duplicate items from array
|
||||
|
||||
exports.unique = function (array, key) {
|
||||
|
||||
var index = {};
|
||||
var result = [];
|
||||
|
||||
for (var i = 0, il = array.length; i < il; ++i) {
|
||||
var id = (key ? array[i][key] : array[i]);
|
||||
if (index[id] !== true) {
|
||||
|
||||
result.push(array[i]);
|
||||
index[id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
// Convert array into object
|
||||
|
||||
exports.mapToObject = function (array, key) {
|
||||
|
||||
if (!array) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var obj = {};
|
||||
for (var i = 0, il = array.length; i < il; ++i) {
|
||||
if (key) {
|
||||
if (array[i][key]) {
|
||||
obj[array[i][key]] = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
obj[array[i]] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
// Find the common unique items in two arrays
|
||||
|
||||
exports.intersect = function (array1, array2, justFirst) {
|
||||
|
||||
if (!array1 || !array2) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var common = [];
|
||||
var hash = (array1 instanceof Array ? exports.mapToObject(array1) : array1);
|
||||
var found = {};
|
||||
for (var i = 0, il = array2.length; i < il; ++i) {
|
||||
if (hash[array2[i]] && !found[array2[i]]) {
|
||||
if (justFirst) {
|
||||
return array2[i];
|
||||
}
|
||||
|
||||
common.push(array2[i]);
|
||||
found[array2[i]] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return (justFirst ? null : common);
|
||||
};
|
||||
|
||||
|
||||
// Find which keys are present
|
||||
|
||||
exports.matchKeys = function (obj, keys) {
|
||||
|
||||
var matched = [];
|
||||
for (var i = 0, il = keys.length; i < il; ++i) {
|
||||
if (obj.hasOwnProperty(keys[i])) {
|
||||
matched.push(keys[i]);
|
||||
}
|
||||
}
|
||||
return matched;
|
||||
};
|
||||
|
||||
|
||||
// Flatten array
|
||||
|
||||
exports.flatten = function (array, target) {
|
||||
|
||||
var result = target || [];
|
||||
|
||||
for (var i = 0, il = array.length; i < il; ++i) {
|
||||
if (Array.isArray(array[i])) {
|
||||
exports.flatten(array[i], result);
|
||||
}
|
||||
else {
|
||||
result.push(array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
// Remove keys
|
||||
|
||||
exports.removeKeys = function (object, keys) {
|
||||
|
||||
for (var i = 0, il = keys.length; i < il; i++) {
|
||||
delete object[keys[i]];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Convert an object key chain string ('a.b.c') to reference (object[a][b][c])
|
||||
|
||||
exports.reach = function (obj, chain) {
|
||||
|
||||
var path = chain.split('.');
|
||||
var ref = obj;
|
||||
for (var i = 0, il = path.length; i < il; ++i) {
|
||||
if (ref) {
|
||||
ref = ref[path[i]];
|
||||
}
|
||||
}
|
||||
|
||||
return ref;
|
||||
};
|
||||
|
||||
|
||||
// Inherits a selected set of methods from an object, wrapping functions in asynchronous syntax and catching errors
|
||||
|
||||
exports.inheritAsync = function (self, obj, keys) {
|
||||
|
||||
keys = keys || null;
|
||||
|
||||
for (var i in obj) {
|
||||
if (obj.hasOwnProperty(i)) {
|
||||
if (keys instanceof Array &&
|
||||
keys.indexOf(i) < 0) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
self.prototype[i] = (function (fn) {
|
||||
|
||||
return function (next) {
|
||||
|
||||
var result = null;
|
||||
try {
|
||||
result = fn();
|
||||
}
|
||||
catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
return next(null, result);
|
||||
};
|
||||
})(obj[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.formatStack = function (stack) {
|
||||
|
||||
var trace = [];
|
||||
for (var i = 0, il = stack.length; i < il; ++i) {
|
||||
var item = stack[i];
|
||||
trace.push([item.getFileName(), item.getLineNumber(), item.getColumnNumber(), item.getFunctionName(), item.isConstructor()]);
|
||||
}
|
||||
|
||||
return trace;
|
||||
};
|
||||
|
||||
|
||||
exports.formatTrace = function (trace) {
|
||||
|
||||
var display = [];
|
||||
|
||||
for (var i = 0, il = trace.length; i < il; ++i) {
|
||||
var row = trace[i];
|
||||
display.push((row[4] ? 'new ' : '') + row[3] + ' (' + row[0] + ':' + row[1] + ':' + row[2] + ')');
|
||||
}
|
||||
|
||||
return display;
|
||||
};
|
||||
|
||||
|
||||
exports.callStack = function (slice) {
|
||||
|
||||
// http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
|
||||
|
||||
var v8 = Error.prepareStackTrace;
|
||||
Error.prepareStackTrace = function (err, stack) {
|
||||
|
||||
return stack;
|
||||
};
|
||||
|
||||
var capture = {};
|
||||
Error.captureStackTrace(capture, arguments.callee);
|
||||
var stack = capture.stack;
|
||||
|
||||
Error.prepareStackTrace = v8;
|
||||
|
||||
var trace = exports.formatStack(stack);
|
||||
|
||||
if (slice) {
|
||||
return trace.slice(slice);
|
||||
}
|
||||
|
||||
return trace;
|
||||
};
|
||||
|
||||
|
||||
exports.displayStack = function (slice) {
|
||||
|
||||
var trace = exports.callStack(slice === undefined ? 1 : slice + 1);
|
||||
|
||||
return exports.formatTrace(trace);
|
||||
};
|
||||
|
||||
|
||||
exports.abortThrow = false;
|
||||
|
||||
|
||||
exports.abort = function (message, hideStack) {
|
||||
|
||||
if (process.env.NODE_ENV === 'test' || exports.abortThrow === true) {
|
||||
throw new Error(message || 'Unknown error');
|
||||
}
|
||||
|
||||
var stack = '';
|
||||
if (!hideStack) {
|
||||
stack = exports.displayStack(1).join('\n\t');
|
||||
}
|
||||
console.log('ABORT: ' + message + '\n\t' + stack);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
|
||||
exports.assert = function (condition /*, msg1, msg2, msg3 */) {
|
||||
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
|
||||
var msgs = Array.prototype.slice.call(arguments, 1);
|
||||
msgs = msgs.map(function (msg) {
|
||||
|
||||
return typeof msg === 'string' ? msg : msg instanceof Error ? msg.message : JSON.stringify(msg);
|
||||
});
|
||||
throw new Error(msgs.join(' ') || 'Unknown error');
|
||||
};
|
||||
|
||||
|
||||
exports.loadDirModules = function (path, excludeFiles, target) { // target(filename, name, capName)
|
||||
|
||||
var exclude = {};
|
||||
for (var i = 0, il = excludeFiles.length; i < il; ++i) {
|
||||
exclude[excludeFiles[i] + '.js'] = true;
|
||||
}
|
||||
|
||||
var files = Fs.readdirSync(path);
|
||||
for (i = 0, il = files.length; i < il; ++i) {
|
||||
var filename = files[i];
|
||||
if (/\.js$/.test(filename) &&
|
||||
!exclude[filename]) {
|
||||
|
||||
var name = filename.substr(0, filename.lastIndexOf('.'));
|
||||
var capName = name.charAt(0).toUpperCase() + name.substr(1).toLowerCase();
|
||||
|
||||
if (typeof target !== 'function') {
|
||||
target[capName] = require(path + '/' + name);
|
||||
}
|
||||
else {
|
||||
target(path + '/' + name, name, capName);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.rename = function (obj, from, to) {
|
||||
|
||||
obj[to] = obj[from];
|
||||
delete obj[from];
|
||||
};
|
||||
|
||||
|
||||
exports.Timer = function () {
|
||||
|
||||
this.reset();
|
||||
};
|
||||
|
||||
|
||||
exports.Timer.prototype.reset = function () {
|
||||
|
||||
this.ts = Date.now();
|
||||
};
|
||||
|
||||
|
||||
exports.Timer.prototype.elapsed = function () {
|
||||
|
||||
return Date.now() - this.ts;
|
||||
};
|
||||
|
||||
|
||||
// Load and parse package.json process root or given directory
|
||||
|
||||
exports.loadPackage = function (dir) {
|
||||
|
||||
var result = {};
|
||||
var filepath = (dir || process.env.PWD) + '/package.json';
|
||||
if (Fs.existsSync(filepath)) {
|
||||
try {
|
||||
result = JSON.parse(Fs.readFileSync(filepath));
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
// Escape string for Regex construction
|
||||
|
||||
exports.escapeRegex = function (string) {
|
||||
|
||||
// Escape ^$.*+-?=!:|\/()[]{},
|
||||
return string.replace(/[\^\$\.\*\+\-\?\=\!\:\|\\\/\(\)\[\]\{\}\,]/g, '\\$&');
|
||||
};
|
||||
|
||||
|
||||
// Return an error as first argument of a callback
|
||||
|
||||
exports.toss = function (condition /*, [message], next */) {
|
||||
|
||||
var message = (arguments.length === 3 ? arguments[1] : '');
|
||||
var next = (arguments.length === 3 ? arguments[2] : arguments[1]);
|
||||
|
||||
var err = (message instanceof Error ? message : (message ? new Error(message) : (condition instanceof Error ? condition : new Error())));
|
||||
|
||||
if (condition instanceof Error ||
|
||||
!condition) {
|
||||
|
||||
return next(err);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Base64url (RFC 4648) encode
|
||||
|
||||
exports.base64urlEncode = function (value) {
|
||||
|
||||
return (new Buffer(value, 'binary')).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
|
||||
};
|
||||
|
||||
|
||||
// Base64url (RFC 4648) decode
|
||||
|
||||
exports.base64urlDecode = function (encoded) {
|
||||
|
||||
if (encoded &&
|
||||
!encoded.match(/^[\w\-]*$/)) {
|
||||
|
||||
return new Error('Invalid character');
|
||||
}
|
||||
|
||||
try {
|
||||
return (new Buffer(encoded.replace(/-/g, '+').replace(/:/g, '/'), 'base64')).toString('binary');
|
||||
}
|
||||
catch (err) {
|
||||
return err;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Escape attribute value for use in HTTP header
|
||||
|
||||
exports.escapeHeaderAttribute = function (attribute) {
|
||||
|
||||
// Allowed value characters: !#$%&'()*+,-./:;<=>?@[]^_`{|}~ and space, a-z, A-Z, 0-9, \, "
|
||||
|
||||
exports.assert(attribute.match(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~\"\\]*$/), 'Bad attribute value (' + attribute + ')');
|
||||
|
||||
return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"'); // Escape quotes and slash
|
||||
};
|
||||
|
||||
|
||||
exports.escapeHtml = function (string) {
|
||||
|
||||
return Escape.escapeHtml(string);
|
||||
};
|
||||
|
||||
|
||||
exports.escapeJavaScript = function (string) {
|
||||
|
||||
return Escape.escapeJavaScript(string);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
var event = {
|
||||
timestamp: now.getTime(),
|
||||
tags: ['tag'],
|
||||
data: { some: 'data' }
|
||||
};
|
||||
*/
|
||||
|
||||
exports.consoleFunc = console.log;
|
||||
|
||||
exports.printEvent = function (event) {
|
||||
|
||||
var pad = function (value) {
|
||||
|
||||
return (value < 10 ? '0' : '') + value;
|
||||
};
|
||||
|
||||
var now = new Date(event.timestamp);
|
||||
var timestring = (now.getYear() - 100).toString() +
|
||||
pad(now.getMonth() + 1) +
|
||||
pad(now.getDate()) +
|
||||
'/' +
|
||||
pad(now.getHours()) +
|
||||
pad(now.getMinutes()) +
|
||||
pad(now.getSeconds()) +
|
||||
'.' +
|
||||
now.getMilliseconds();
|
||||
|
||||
var data = event.data;
|
||||
if (typeof event.data !== 'string') {
|
||||
try {
|
||||
data = JSON.stringify(event.data);
|
||||
}
|
||||
catch (e) {
|
||||
data = 'JSON Error: ' + e.message;
|
||||
}
|
||||
}
|
||||
|
||||
var output = timestring + ', ' + event.tags[0] + ', ' + data;
|
||||
exports.consoleFunc(output);
|
||||
};
|
||||
|
||||
|
||||
exports.nextTick = function (callback) {
|
||||
|
||||
return function () {
|
||||
|
||||
var args = arguments;
|
||||
process.nextTick(function () {
|
||||
|
||||
callback.apply(null, args);
|
||||
});
|
||||
};
|
||||
};
|
32
node_modules/hoek/package.json
generated
vendored
Executable file
32
node_modules/hoek/package.json
generated
vendored
Executable file
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name": "hoek",
|
||||
"description": "General purpose node utilities",
|
||||
"version": "0.9.1",
|
||||
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",
|
||||
"contributors":[
|
||||
"Van Nguyen <the.gol.effect@gmail.com>"
|
||||
],
|
||||
"repository": "git://github.com/spumko/hoek",
|
||||
"main": "index",
|
||||
"keywords": [
|
||||
"utilities"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"lab": "0.1.x",
|
||||
"complexity-report": "0.x.x"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test-cov"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "BSD",
|
||||
"url": "http://github.com/spumko/hoek/raw/master/LICENSE"
|
||||
}
|
||||
]
|
||||
}
|
86
node_modules/hoek/test/escaper.js
generated
vendored
Normal file
86
node_modules/hoek/test/escaper.js
generated
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
// Load modules
|
||||
|
||||
var Lab = require('lab');
|
||||
var Hoek = require('../lib');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
// Test shortcuts
|
||||
|
||||
var expect = Lab.expect;
|
||||
var before = Lab.before;
|
||||
var after = Lab.after;
|
||||
var describe = Lab.experiment;
|
||||
var it = Lab.test;
|
||||
|
||||
|
||||
describe('Hoek', function () {
|
||||
|
||||
describe('#escapeJavaScript', function () {
|
||||
|
||||
it('encodes / characters', function (done) {
|
||||
|
||||
var encoded = Hoek.escapeJavaScript('<script>alert(1)</script>');
|
||||
expect(encoded).to.equal('\\x3cscript\\x3ealert\\x281\\x29\\x3c\\x2fscript\\x3e');
|
||||
done();
|
||||
});
|
||||
|
||||
it('encodes \' characters', function (done) {
|
||||
|
||||
var encoded = Hoek.escapeJavaScript('something(\'param\')');
|
||||
expect(encoded).to.equal('something\\x28\\x27param\\x27\\x29');
|
||||
done();
|
||||
});
|
||||
|
||||
it('encodes large unicode characters with the correct padding', function (done) {
|
||||
|
||||
var encoded = Hoek.escapeJavaScript(String.fromCharCode(500) + String.fromCharCode(1000));
|
||||
expect(encoded).to.equal('\\u0500\\u1000');
|
||||
done();
|
||||
});
|
||||
|
||||
it('doesn\'t throw an exception when passed null', function (done) {
|
||||
|
||||
var encoded = Hoek.escapeJavaScript(null);
|
||||
expect(encoded).to.equal('');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#escapeHtml', function () {
|
||||
|
||||
it('encodes / characters', function (done) {
|
||||
|
||||
var encoded = Hoek.escapeHtml('<script>alert(1)</script>');
|
||||
expect(encoded).to.equal('<script>alert(1)</script>');
|
||||
done();
|
||||
});
|
||||
|
||||
it('encodes < and > as named characters', function (done) {
|
||||
|
||||
var encoded = Hoek.escapeHtml('<script><>');
|
||||
expect(encoded).to.equal('<script><>');
|
||||
done();
|
||||
});
|
||||
|
||||
it('encodes large unicode characters', function (done) {
|
||||
|
||||
var encoded = Hoek.escapeHtml(String.fromCharCode(500) + String.fromCharCode(1000));
|
||||
expect(encoded).to.equal('ǴϨ');
|
||||
done();
|
||||
});
|
||||
|
||||
it('doesn\'t throw an exception when passed null', function (done) {
|
||||
|
||||
var encoded = Hoek.escapeHtml(null);
|
||||
expect(encoded).to.equal('');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
1078
node_modules/hoek/test/index.js
generated
vendored
Executable file
1078
node_modules/hoek/test/index.js
generated
vendored
Executable file
File diff suppressed because it is too large
Load diff
1
node_modules/hoek/test/modules/test1.js
generated
vendored
Executable file
1
node_modules/hoek/test/modules/test1.js
generated
vendored
Executable file
|
@ -0,0 +1 @@
|
|||
exports.x = 1;
|
1
node_modules/hoek/test/modules/test2.js
generated
vendored
Executable file
1
node_modules/hoek/test/modules/test2.js
generated
vendored
Executable file
|
@ -0,0 +1 @@
|
|||
exports.y = 2;
|
1
node_modules/hoek/test/modules/test3.js
generated
vendored
Executable file
1
node_modules/hoek/test/modules/test3.js
generated
vendored
Executable file
|
@ -0,0 +1 @@
|
|||
exports.z = 3;
|
Loading…
Add table
Add a link
Reference in a new issue