Template Upload
This commit is contained in:
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
|
7
node_modules/hoek/.travis.yml
generated
vendored
Normal file
7
node_modules/hoek/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- 0.10
|
||||
- 4.0
|
||||
|
||||
sudo: false
|
1
node_modules/hoek/CONTRIBUTING.md
generated
vendored
Normal file
1
node_modules/hoek/CONTRIBUTING.md
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
Please view our [hapijs contributing guide](https://github.com/hapijs/hapi/blob/master/CONTRIBUTING.md).
|
31
node_modules/hoek/LICENSE
generated
vendored
Normal file
31
node_modules/hoek/LICENSE
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
Copyright (c) 2011-2014, Walmart and other contributors.
|
||||
Copyright (c) 2011, Yahoo Inc.
|
||||
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.
|
||||
* The names of any contributors may not 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
* * *
|
||||
|
||||
The complete list of contributors can be found at: https://github.com/hapijs/hapi/graphs/contributors
|
||||
Portions of this project were initially based on the Yahoo! Inc. Postmile project,
|
||||
published at https://github.com/yahoo/postmile.
|
584
node_modules/hoek/README.md
generated
vendored
Normal file
584
node_modules/hoek/README.md
generated
vendored
Normal file
@ -0,0 +1,584 @@
|
||||

|
||||
|
||||
Utility methods for the hapi ecosystem. This module is not intended to solve every problem for everyone, but rather as a central place to store hapi-specific methods. If you're looking for a general purpose utility module, check out [lodash](https://github.com/lodash/lodash) or [underscore](https://github.com/jashkenas/underscore).
|
||||
|
||||
[](http://travis-ci.org/hapijs/hoek)
|
||||
|
||||
Lead Maintainer: [Nathan LaFreniere](https://github.com/nlf)
|
||||
|
||||
# Table of Contents
|
||||
|
||||
* [Introduction](#introduction "Introduction")
|
||||
* [Object](#object "Object")
|
||||
* [clone](#cloneobj "clone")
|
||||
* [cloneWithShallow](#clonewithshallowobj-keys "cloneWithShallow")
|
||||
* [merge](#mergetarget-source-isnulloverride-ismergearrays "merge")
|
||||
* [applyToDefaults](#applytodefaultsdefaults-options-isnulloverride "applyToDefaults")
|
||||
* [applyToDefaultsWithShallow](#applytodefaultswithshallowdefaults-options-keys "applyToDefaultsWithShallow")
|
||||
* [deepEqual](#deepequala-b "deepEqual")
|
||||
* [unique](#uniquearray-key "unique")
|
||||
* [mapToObject](#maptoobjectarray-key "mapToObject")
|
||||
* [intersect](#intersectarray1-array2 "intersect")
|
||||
* [contain](#containref-values-options "contain")
|
||||
* [flatten](#flattenarray-target "flatten")
|
||||
* [reach](#reachobj-chain-options "reach")
|
||||
* [reachTemplate](#reachtemplateobj-template-options "reachTemplate")
|
||||
* [transform](#transformobj-transform-options "transform")
|
||||
* [shallow](#shallowobj "shallow")
|
||||
* [stringify](#stringifyobj "stringify")
|
||||
* [Timer](#timer "Timer")
|
||||
* [Bench](#bench "Bench")
|
||||
* [Binary Encoding/Decoding](#binary-encodingdecoding "Binary Encoding/Decoding")
|
||||
* [base64urlEncode](#base64urlencodevalue "binary64urlEncode")
|
||||
* [base64urlDecode](#base64urldecodevalue "binary64urlDecode")
|
||||
* [Escaping Characters](#escaping-characters "Escaping Characters")
|
||||
* [escapeHtml](#escapehtmlstring "escapeHtml")
|
||||
* [escapeHeaderAttribute](#escapeheaderattributeattribute "escapeHeaderAttribute")
|
||||
* [escapeRegex](#escaperegexstring "escapeRegex")
|
||||
* [Errors](#errors "Errors")
|
||||
* [assert](#assertcondition-message "assert")
|
||||
* [abort](#abortmessage "abort")
|
||||
* [displayStack](#displaystackslice "displayStack")
|
||||
* [callStack](#callstackslice "callStack")
|
||||
* [Function](#function "Function")
|
||||
* [nextTick](#nexttickfn "nextTick")
|
||||
* [once](#oncefn "once")
|
||||
* [ignore](#ignore "ignore")
|
||||
* [Miscellaneous](#miscellaneous "Miscellaneous")
|
||||
* [uniqueFilename](#uniquefilenamepath-extension "uniqueFilename")
|
||||
* [isAbsolutePath](#isabsolutepathpath-platform "isAbsolutePath")
|
||||
* [isInteger](#isintegervalue "isInteger")
|
||||
|
||||
|
||||
|
||||
# Introduction
|
||||
|
||||
The *Hoek* library contains some common functions used within the hapi ecosystem. 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, as well as non-enumerable properties).
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
### cloneWithShallow(obj, keys)
|
||||
keys is an array of key names to shallow copy
|
||||
|
||||
This method is also used to clone an object or array, however any keys listed in the `keys` array are shallow copied while those not listed are deep copied.
|
||||
|
||||
```javascript
|
||||
|
||||
var nestedObj = {
|
||||
w: /^something$/ig,
|
||||
x: {
|
||||
a: [1, 2, 3],
|
||||
b: 123456,
|
||||
c: new Date()
|
||||
},
|
||||
y: 'y',
|
||||
z: new Date()
|
||||
};
|
||||
|
||||
var copy = Hoek.cloneWithShallow(nestedObj, ['x']);
|
||||
|
||||
copy.x.b = 100;
|
||||
|
||||
console.log(copy.y); // results in 'y'
|
||||
console.log(nestedObj.x.b); // results in 100
|
||||
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 conflict, and by default null and undefined from source are applied.
|
||||
Merge is destructive where the target is modified. For non destructive merge, use `applyToDefaults`.
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
var target = {a: 1, b : 2};
|
||||
var source = {a: 0, c: 5};
|
||||
var source2 = {a: null, c: 5};
|
||||
|
||||
Hoek.merge(target, source); // results in {a: 0, b: 2, c: 5}
|
||||
Hoek.merge(target, source2); // results in {a: null, b: 2, c: 5}
|
||||
Hoek.merge(target, source2, false); // results in {a: 1, b: 2, c: 5}
|
||||
|
||||
var targetArray = [1, 2, 3];
|
||||
var sourceArray = [4, 5];
|
||||
|
||||
Hoek.merge(targetArray, sourceArray); // results in [1, 2, 3, 4, 5]
|
||||
Hoek.merge(targetArray, sourceArray, true, false); // results in [4, 5]
|
||||
```
|
||||
|
||||
### applyToDefaults(defaults, options, isNullOverride)
|
||||
isNullOverride defaults to false
|
||||
|
||||
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 }
|
||||
```
|
||||
|
||||
Apply options with a null value to a copy of the defaults
|
||||
|
||||
```javascript
|
||||
|
||||
var defaults = { host: "localhost", port: 8000 };
|
||||
var options = { host: null, port: 8080 };
|
||||
|
||||
var config = Hoek.applyToDefaults(defaults, options, true); // results in { host: null, port: 8080 }
|
||||
```
|
||||
|
||||
### applyToDefaultsWithShallow(defaults, options, keys)
|
||||
keys is an array of key names to shallow copy
|
||||
|
||||
Apply options to a copy of the defaults. Keys specified in the last parameter are shallow copied from options instead of merged.
|
||||
|
||||
```javascript
|
||||
|
||||
var defaults = {
|
||||
server: {
|
||||
host: "localhost",
|
||||
port: 8000
|
||||
},
|
||||
name: 'example'
|
||||
};
|
||||
|
||||
var options = { server: { port: 8080 } };
|
||||
|
||||
var config = Hoek.applyToDefaultsWithShallow(defaults, options, ['server']); // results in { server: { port: 8080 }, name: 'example' }
|
||||
```
|
||||
|
||||
### deepEqual(b, a, [options])
|
||||
|
||||
Performs a deep comparison of the two values including support for circular dependencies, prototype, and properties. To skip prototype comparisons, use `options.prototype = false`
|
||||
|
||||
```javascript
|
||||
Hoek.deepEqual({ a: [1, 2], b: 'string', c: { d: true } }, { a: [1, 2], b: 'string', c: { d: true } }); //results in true
|
||||
Hoek.deepEqual(Object.create(null), {}, { prototype: false }); //results in true
|
||||
Hoek.deepEqual(Object.create(null), {}); //results in false
|
||||
```
|
||||
|
||||
### 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]
|
||||
```
|
||||
|
||||
### contain(ref, values, [options])
|
||||
|
||||
Tests if the reference value contains the provided values where:
|
||||
- `ref` - the reference string, array, or object.
|
||||
- `values` - a single or array of values to find within the `ref` value. If `ref` is an object, `values` can be a key name,
|
||||
an array of key names, or an object with key-value pairs to compare.
|
||||
- `options` - an optional object with the following optional settings:
|
||||
- `deep` - if `true`, performed a deep comparison of the values.
|
||||
- `once` - if `true`, allows only one occurrence of each value.
|
||||
- `only` - if `true`, does not allow values not explicitly listed.
|
||||
- `part` - if `true`, allows partial match of the values (at least one must always match).
|
||||
|
||||
Note: comparing a string to overlapping values will result in failed comparison (e.g. `contain('abc', ['ab', 'bc'])`).
|
||||
Also, if an object key's value does not match the provided value, `false` is returned even when `part` is specified.
|
||||
|
||||
```javascript
|
||||
Hoek.contain('aaa', 'a', { only: true }); // true
|
||||
Hoek.contain([{ a: 1 }], [{ a: 1 }], { deep: true }); // true
|
||||
Hoek.contain([1, 2, 2], [1, 2], { once: true }); // false
|
||||
Hoek.contain({ a: 1, b: 2, c: 3 }, { a: 1, d: 4 }, { part: true }); // true
|
||||
```
|
||||
|
||||
### flatten(array, [target])
|
||||
|
||||
Flatten an array
|
||||
|
||||
```javascript
|
||||
|
||||
var array = [1, [2, 3]];
|
||||
|
||||
var flattenedArray = Hoek.flatten(array); // results in [1, 2, 3]
|
||||
|
||||
array = [1, [2, 3]];
|
||||
target = [4, [5]];
|
||||
|
||||
flattenedArray = Hoek.flatten(array, target); // results in [4, [5], 1, 2, 3]
|
||||
```
|
||||
|
||||
### reach(obj, chain, [options])
|
||||
|
||||
Converts an object key chain string to reference
|
||||
|
||||
- `options` - optional settings
|
||||
- `separator` - string to split chain path on, defaults to '.'
|
||||
- `default` - value to return if the path or value is not present, default is `undefined`
|
||||
- `strict` - if `true`, will throw an error on missing member, default is `false`
|
||||
- `functions` - if `true` allow traversing functions for properties. `false` will throw an error if a function is part of the chain.
|
||||
|
||||
A chain including negative numbers will work like negative indices on an
|
||||
array.
|
||||
|
||||
If chain is `null`, `undefined` or `false`, the object itself will be returned.
|
||||
|
||||
```javascript
|
||||
|
||||
var chain = 'a.b.c';
|
||||
var obj = {a : {b : { c : 1}}};
|
||||
|
||||
Hoek.reach(obj, chain); // returns 1
|
||||
|
||||
var chain = 'a.b.-1';
|
||||
var obj = {a : {b : [2,3,6]}};
|
||||
|
||||
Hoek.reach(obj, chain); // returns 6
|
||||
```
|
||||
|
||||
### reachTemplate(obj, template, [options])
|
||||
|
||||
Replaces string parameters (`{name}`) with their corresponding object key values by applying the
|
||||
(`reach()`)[#reachobj-chain-options] method where:
|
||||
|
||||
- `obj` - the context object used for key lookup.
|
||||
- `template` - a string containing `{}` parameters.
|
||||
- `options` - optional (`reach()`)[#reachobj-chain-options] options.
|
||||
|
||||
```javascript
|
||||
|
||||
var chain = 'a.b.c';
|
||||
var obj = {a : {b : { c : 1}}};
|
||||
|
||||
Hoek.reachTemplate(obj, '1+{a.b.c}=2'); // returns '1+1=2'
|
||||
```
|
||||
|
||||
### transform(obj, transform, [options])
|
||||
|
||||
Transforms an existing object into a new one based on the supplied `obj` and `transform` map. `options` are the same as the `reach` options. The first argument can also be an array of objects. In that case the method will return an array of transformed objects.
|
||||
|
||||
```javascript
|
||||
var source = {
|
||||
address: {
|
||||
one: '123 main street',
|
||||
two: 'PO Box 1234'
|
||||
},
|
||||
title: 'Warehouse',
|
||||
state: 'CA'
|
||||
};
|
||||
|
||||
var result = Hoek.transform(source, {
|
||||
'person.address.lineOne': 'address.one',
|
||||
'person.address.lineTwo': 'address.two',
|
||||
'title': 'title',
|
||||
'person.address.region': 'state'
|
||||
});
|
||||
// Results in
|
||||
// {
|
||||
// person: {
|
||||
// address: {
|
||||
// lineOne: '123 main street',
|
||||
// lineTwo: 'PO Box 1234',
|
||||
// region: 'CA'
|
||||
// }
|
||||
// },
|
||||
// title: 'Warehouse'
|
||||
// }
|
||||
```
|
||||
|
||||
### shallow(obj)
|
||||
|
||||
Performs a shallow copy by copying the references of all the top level children where:
|
||||
- `obj` - the object to be copied.
|
||||
|
||||
```javascript
|
||||
var shallow = Hoek.shallow({ a: { b: 1 } });
|
||||
```
|
||||
|
||||
### stringify(obj)
|
||||
|
||||
Converts an object to string using the built-in `JSON.stringify()` method with the difference that any errors are caught
|
||||
and reported back in the form of the returned string. Used as a shortcut for displaying information to the console (e.g. in
|
||||
error message) without the need to worry about invalid conversion.
|
||||
|
||||
```javascript
|
||||
var a = {};
|
||||
a.b = a;
|
||||
Hoek.stringify(a); // Returns '[Cannot display object: Converting circular structure to JSON]'
|
||||
```
|
||||
|
||||
# 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
|
||||
|
||||
var timerObj = new Hoek.Timer();
|
||||
console.log("Time is now: " + timerObj.ts);
|
||||
console.log("Elapsed time from initialization: " + timerObj.elapsed() + 'milliseconds');
|
||||
```
|
||||
|
||||
|
||||
# Bench
|
||||
|
||||
Same as Timer with the exception that `ts` stores the internal node clock which is not related to `Date.now()` and cannot be used to display
|
||||
human-readable timestamps. More accurate for benchmarking or internal timers.
|
||||
|
||||
# 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(condition, message)
|
||||
|
||||
```javascript
|
||||
|
||||
var a = 1, b = 2;
|
||||
|
||||
Hoek.assert(a === b, 'a should equal b'); // Throws 'a should equal b'
|
||||
```
|
||||
|
||||
Note that you may also pass an already created Error object as the second parameter, and `assert` will throw that object.
|
||||
|
||||
```javascript
|
||||
|
||||
var a = 1, b = 2;
|
||||
|
||||
Hoek.assert(a === b, new Error('a should equal b')); // Throws the given error object
|
||||
```
|
||||
|
||||
### 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 ] ]
|
||||
```
|
||||
|
||||
## Function
|
||||
|
||||
### nextTick(fn)
|
||||
|
||||
Returns a new function that wraps `fn` in `process.nextTick`.
|
||||
|
||||
```javascript
|
||||
|
||||
var myFn = function () {
|
||||
console.log('Do this later');
|
||||
};
|
||||
|
||||
var nextFn = Hoek.nextTick(myFn);
|
||||
|
||||
nextFn();
|
||||
console.log('Do this first');
|
||||
|
||||
// Results in:
|
||||
//
|
||||
// Do this first
|
||||
// Do this later
|
||||
```
|
||||
|
||||
### once(fn)
|
||||
|
||||
Returns a new function that can be run multiple times, but makes sure `fn` is only run once.
|
||||
|
||||
```javascript
|
||||
|
||||
var myFn = function () {
|
||||
console.log('Ran myFn');
|
||||
};
|
||||
|
||||
var onceFn = Hoek.once(myFn);
|
||||
onceFn(); // results in "Ran myFn"
|
||||
onceFn(); // results in undefined
|
||||
```
|
||||
|
||||
### ignore
|
||||
|
||||
A simple no-op function. It does nothing at all.
|
||||
|
||||
## Miscellaneous
|
||||
|
||||
### uniqueFilename(path, extension)
|
||||
`path` to prepend with the randomly generated file name. `extension` is the optional file extension, defaults to `''`.
|
||||
|
||||
Returns a randomly generated file name at the specified `path`. The result is a fully resolved path to a file.
|
||||
|
||||
```javascript
|
||||
var result = Hoek.uniqueFilename('./test/modules', 'txt'); // results in "full/path/test/modules/{random}.txt"
|
||||
```
|
||||
|
||||
### isAbsolutePath(path, [platform])
|
||||
|
||||
Determines whether `path` is an absolute path. Returns `true` or `false`.
|
||||
|
||||
- `path` - A file path to test for whether it is absolute or not.
|
||||
- `platform` - An optional parameter used for specifying the platform. Defaults to `process.platform`.
|
||||
|
||||
### isInteger(value)
|
||||
|
||||
Check `value` to see if it is an integer. Returns true/false.
|
||||
|
||||
```javascript
|
||||
var result = Hoek.isInteger('23')
|
||||
```
|
BIN
node_modules/hoek/images/hoek.png
generated
vendored
Normal file
BIN
node_modules/hoek/images/hoek.png
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
132
node_modules/hoek/lib/escape.js
generated
vendored
Normal file
132
node_modules/hoek/lib/escape.js
generated
vendored
Normal 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) || // 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;
|
||||
}());
|
993
node_modules/hoek/lib/index.js
generated
vendored
Normal file
993
node_modules/hoek/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,993 @@
|
||||
// Load modules
|
||||
|
||||
var Crypto = require('crypto');
|
||||
var Path = require('path');
|
||||
var Util = require('util');
|
||||
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;
|
||||
var cloneDeep = false;
|
||||
|
||||
if (!Array.isArray(obj)) {
|
||||
if (Buffer.isBuffer(obj)) {
|
||||
newObj = new Buffer(obj);
|
||||
}
|
||||
else if (obj instanceof Date) {
|
||||
newObj = new Date(obj.getTime());
|
||||
}
|
||||
else if (obj instanceof RegExp) {
|
||||
newObj = new RegExp(obj);
|
||||
}
|
||||
else {
|
||||
var proto = Object.getPrototypeOf(obj);
|
||||
if (proto &&
|
||||
proto.isImmutable) {
|
||||
|
||||
newObj = obj;
|
||||
}
|
||||
else {
|
||||
newObj = Object.create(proto);
|
||||
cloneDeep = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
newObj = [];
|
||||
cloneDeep = true;
|
||||
}
|
||||
|
||||
seen.orig.push(obj);
|
||||
seen.copy.push(newObj);
|
||||
|
||||
if (cloneDeep) {
|
||||
var keys = Object.getOwnPropertyNames(obj);
|
||||
for (var i = 0, il = keys.length; i < il; ++i) {
|
||||
var key = keys[i];
|
||||
var descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
||||
if (descriptor &&
|
||||
(descriptor.get ||
|
||||
descriptor.set)) {
|
||||
|
||||
Object.defineProperty(newObj, key, descriptor);
|
||||
}
|
||||
else {
|
||||
newObj[key] = exports.clone(obj[key], seen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newObj;
|
||||
};
|
||||
|
||||
|
||||
// Merge all the properties of source into target, source wins in conflict, and by default null and undefined from source are applied
|
||||
/*eslint-disable */
|
||||
exports.merge = function (target, source, isNullOverride /* = true */, isMergeArrays /* = true */) {
|
||||
/*eslint-enable */
|
||||
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 (Array.isArray(source)) {
|
||||
exports.assert(Array.isArray(target), '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(exports.clone(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' ||
|
||||
(Array.isArray(target[key]) ^ Array.isArray(value)) ||
|
||||
value instanceof Date ||
|
||||
Buffer.isBuffer(value) ||
|
||||
value instanceof RegExp) {
|
||||
|
||||
target[key] = exports.clone(value);
|
||||
}
|
||||
else {
|
||||
exports.merge(target[key], value, 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, isNullOverride) {
|
||||
|
||||
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, isNullOverride === true, false);
|
||||
};
|
||||
|
||||
|
||||
// Clone an object except for the listed keys which are shallow copied
|
||||
|
||||
exports.cloneWithShallow = function (source, keys) {
|
||||
|
||||
if (!source ||
|
||||
typeof source !== 'object') {
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
var storage = internals.store(source, keys); // Move shallow copy items to storage
|
||||
var copy = exports.clone(source); // Deep copy the rest
|
||||
internals.restore(copy, source, storage); // Shallow copy the stored items and restore
|
||||
return copy;
|
||||
};
|
||||
|
||||
|
||||
internals.store = function (source, keys) {
|
||||
|
||||
var storage = {};
|
||||
for (var i = 0, il = keys.length; i < il; ++i) {
|
||||
var key = keys[i];
|
||||
var value = exports.reach(source, key);
|
||||
if (value !== undefined) {
|
||||
storage[key] = value;
|
||||
internals.reachSet(source, key, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
return storage;
|
||||
};
|
||||
|
||||
|
||||
internals.restore = function (copy, source, storage) {
|
||||
|
||||
var keys = Object.keys(storage);
|
||||
for (var i = 0, il = keys.length; i < il; ++i) {
|
||||
var key = keys[i];
|
||||
internals.reachSet(copy, key, storage[key]);
|
||||
internals.reachSet(source, key, storage[key]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
internals.reachSet = function (obj, key, value) {
|
||||
|
||||
var path = key.split('.');
|
||||
var ref = obj;
|
||||
for (var i = 0, il = path.length; i < il; ++i) {
|
||||
var segment = path[i];
|
||||
if (i + 1 === il) {
|
||||
ref[segment] = value;
|
||||
}
|
||||
|
||||
ref = ref[segment];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Apply options to defaults except for the listed keys which are shallow copied from option without merging
|
||||
|
||||
exports.applyToDefaultsWithShallow = function (defaults, options, keys) {
|
||||
|
||||
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');
|
||||
exports.assert(keys && Array.isArray(keys), 'Invalid keys');
|
||||
|
||||
if (!options) { // If no options, return null
|
||||
return null;
|
||||
}
|
||||
|
||||
var copy = exports.cloneWithShallow(defaults, keys);
|
||||
|
||||
if (options === true) { // If options is set to true, use defaults
|
||||
return copy;
|
||||
}
|
||||
|
||||
var storage = internals.store(options, keys); // Move shallow copy items to storage
|
||||
exports.merge(copy, options, false, false); // Deep copy the rest
|
||||
internals.restore(copy, options, storage); // Shallow copy the stored items and restore
|
||||
return copy;
|
||||
};
|
||||
|
||||
|
||||
// Deep object or array comparison
|
||||
|
||||
exports.deepEqual = function (obj, ref, options, seen) {
|
||||
|
||||
options = options || { prototype: true };
|
||||
|
||||
var type = typeof obj;
|
||||
|
||||
if (type !== typeof ref) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type !== 'object' ||
|
||||
obj === null ||
|
||||
ref === null) {
|
||||
|
||||
if (obj === ref) { // Copied from Deep-eql, copyright(c) 2013 Jake Luer, jake@alogicalparadox.com, MIT Licensed, https://github.com/chaijs/deep-eql
|
||||
return obj !== 0 || 1 / obj === 1 / ref; // -0 / +0
|
||||
}
|
||||
|
||||
return obj !== obj && ref !== ref; // NaN
|
||||
}
|
||||
|
||||
seen = seen || [];
|
||||
if (seen.indexOf(obj) !== -1) {
|
||||
return true; // If previous comparison failed, it would have stopped execution
|
||||
}
|
||||
|
||||
seen.push(obj);
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
if (!Array.isArray(ref)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!options.part && obj.length !== ref.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0, il = obj.length; i < il; ++i) {
|
||||
if (options.part) {
|
||||
var found = false;
|
||||
for (var r = 0, rl = ref.length; r < rl; ++r) {
|
||||
if (exports.deepEqual(obj[i], ref[r], options, seen)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
if (!exports.deepEqual(obj[i], ref[i], options, seen)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Buffer.isBuffer(obj)) {
|
||||
if (!Buffer.isBuffer(ref)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj.length !== ref.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var j = 0, jl = obj.length; j < jl; ++j) {
|
||||
if (obj[j] !== ref[j]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obj instanceof Date) {
|
||||
return (ref instanceof Date && obj.getTime() === ref.getTime());
|
||||
}
|
||||
|
||||
if (obj instanceof RegExp) {
|
||||
return (ref instanceof RegExp && obj.toString() === ref.toString());
|
||||
}
|
||||
|
||||
if (options.prototype) {
|
||||
if (Object.getPrototypeOf(obj) !== Object.getPrototypeOf(ref)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var keys = Object.getOwnPropertyNames(obj);
|
||||
|
||||
if (!options.part && keys.length !== Object.getOwnPropertyNames(ref).length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var k = 0, kl = keys.length; k < kl; ++k) {
|
||||
var key = keys[k];
|
||||
var descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
||||
if (descriptor.get) {
|
||||
if (!exports.deepEqual(descriptor, Object.getOwnPropertyDescriptor(ref, key), options, seen)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!exports.deepEqual(obj[key], ref[key], options, seen)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
// 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 = (Array.isArray(array1) ? 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);
|
||||
};
|
||||
|
||||
|
||||
// Test if the reference contains the values
|
||||
|
||||
exports.contain = function (ref, values, options) {
|
||||
|
||||
/*
|
||||
string -> string(s)
|
||||
array -> item(s)
|
||||
object -> key(s)
|
||||
object -> object (key:value)
|
||||
*/
|
||||
|
||||
var valuePairs = null;
|
||||
if (typeof ref === 'object' &&
|
||||
typeof values === 'object' &&
|
||||
!Array.isArray(ref) &&
|
||||
!Array.isArray(values)) {
|
||||
|
||||
valuePairs = values;
|
||||
values = Object.keys(values);
|
||||
}
|
||||
else {
|
||||
values = [].concat(values);
|
||||
}
|
||||
|
||||
options = options || {}; // deep, once, only, part
|
||||
|
||||
exports.assert(arguments.length >= 2, 'Insufficient arguments');
|
||||
exports.assert(typeof ref === 'string' || typeof ref === 'object', 'Reference must be string or an object');
|
||||
exports.assert(values.length, 'Values array cannot be empty');
|
||||
|
||||
var compare, compareFlags;
|
||||
if (options.deep) {
|
||||
compare = exports.deepEqual;
|
||||
|
||||
var hasOnly = options.hasOwnProperty('only'), hasPart = options.hasOwnProperty('part');
|
||||
|
||||
compareFlags = {
|
||||
prototype: hasOnly ? options.only : hasPart ? !options.part : false,
|
||||
part: hasOnly ? !options.only : hasPart ? options.part : true
|
||||
};
|
||||
}
|
||||
else {
|
||||
compare = function (a, b) {
|
||||
|
||||
return a === b;
|
||||
};
|
||||
}
|
||||
|
||||
var misses = false;
|
||||
var matches = new Array(values.length);
|
||||
for (var i = 0, il = matches.length; i < il; ++i) {
|
||||
matches[i] = 0;
|
||||
}
|
||||
|
||||
if (typeof ref === 'string') {
|
||||
var pattern = '(';
|
||||
for (i = 0, il = values.length; i < il; ++i) {
|
||||
var value = values[i];
|
||||
exports.assert(typeof value === 'string', 'Cannot compare string reference to non-string value');
|
||||
pattern += (i ? '|' : '') + exports.escapeRegex(value);
|
||||
}
|
||||
|
||||
var regex = new RegExp(pattern + ')', 'g');
|
||||
var leftovers = ref.replace(regex, function ($0, $1) {
|
||||
|
||||
var index = values.indexOf($1);
|
||||
++matches[index];
|
||||
return ''; // Remove from string
|
||||
});
|
||||
|
||||
misses = !!leftovers;
|
||||
}
|
||||
else if (Array.isArray(ref)) {
|
||||
for (i = 0, il = ref.length; i < il; ++i) {
|
||||
for (var j = 0, jl = values.length, matched = false; j < jl && matched === false; ++j) {
|
||||
matched = compare(values[j], ref[i], compareFlags) && j;
|
||||
}
|
||||
|
||||
if (matched !== false) {
|
||||
++matches[matched];
|
||||
}
|
||||
else {
|
||||
misses = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var keys = Object.keys(ref);
|
||||
for (i = 0, il = keys.length; i < il; ++i) {
|
||||
var key = keys[i];
|
||||
var pos = values.indexOf(key);
|
||||
if (pos !== -1) {
|
||||
if (valuePairs &&
|
||||
!compare(valuePairs[key], ref[key], compareFlags)) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
++matches[pos];
|
||||
}
|
||||
else {
|
||||
misses = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var result = false;
|
||||
for (i = 0, il = matches.length; i < il; ++i) {
|
||||
result = result || !!matches[i];
|
||||
if ((options.once && matches[i] > 1) ||
|
||||
(!options.part && !matches[i])) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.only &&
|
||||
misses) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
|
||||
// Convert an object key chain string ('a.b.c') to reference (object[a][b][c])
|
||||
|
||||
exports.reach = function (obj, chain, options) {
|
||||
|
||||
if (chain === false ||
|
||||
chain === null ||
|
||||
typeof chain === 'undefined') {
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
if (typeof options === 'string') {
|
||||
options = { separator: options };
|
||||
}
|
||||
|
||||
var path = chain.split(options.separator || '.');
|
||||
var ref = obj;
|
||||
for (var i = 0, il = path.length; i < il; ++i) {
|
||||
var key = path[i];
|
||||
if (key[0] === '-' && Array.isArray(ref)) {
|
||||
key = key.slice(1, key.length);
|
||||
key = ref.length - key;
|
||||
}
|
||||
|
||||
if (!ref ||
|
||||
!ref.hasOwnProperty(key) ||
|
||||
(typeof ref !== 'object' && options.functions === false)) { // Only object and function can have properties
|
||||
|
||||
exports.assert(!options.strict || i + 1 === il, 'Missing segment', key, 'in reach path ', chain);
|
||||
exports.assert(typeof ref === 'object' || options.functions === true || typeof ref !== 'function', 'Invalid segment', key, 'in reach path ', chain);
|
||||
ref = options.default;
|
||||
break;
|
||||
}
|
||||
|
||||
ref = ref[key];
|
||||
}
|
||||
|
||||
return ref;
|
||||
};
|
||||
|
||||
|
||||
exports.reachTemplate = function (obj, template, options) {
|
||||
|
||||
return template.replace(/{([^}]+)}/g, function ($0, chain) {
|
||||
|
||||
var value = exports.reach(obj, chain, options);
|
||||
return (value === undefined || value === null ? '' : value);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
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); /*eslint no-caller:0 */
|
||||
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;
|
||||
}
|
||||
|
||||
if (arguments.length === 2 && arguments[1] instanceof Error) {
|
||||
throw arguments[1];
|
||||
}
|
||||
|
||||
var msgs = [];
|
||||
for (var i = 1, il = arguments.length; i < il; ++i) {
|
||||
if (arguments[i] !== '') {
|
||||
msgs.push(arguments[i]); // Avoids Array.slice arguments leak, allowing for V8 optimizations
|
||||
}
|
||||
}
|
||||
|
||||
msgs = msgs.map(function (msg) {
|
||||
|
||||
return typeof msg === 'string' ? msg : msg instanceof Error ? msg.message : exports.stringify(msg);
|
||||
});
|
||||
throw new Error(msgs.join(' ') || 'Unknown error');
|
||||
};
|
||||
|
||||
|
||||
exports.Timer = function () {
|
||||
|
||||
this.ts = 0;
|
||||
this.reset();
|
||||
};
|
||||
|
||||
|
||||
exports.Timer.prototype.reset = function () {
|
||||
|
||||
this.ts = Date.now();
|
||||
};
|
||||
|
||||
|
||||
exports.Timer.prototype.elapsed = function () {
|
||||
|
||||
return Date.now() - this.ts;
|
||||
};
|
||||
|
||||
|
||||
exports.Bench = function () {
|
||||
|
||||
this.ts = 0;
|
||||
this.reset();
|
||||
};
|
||||
|
||||
|
||||
exports.Bench.prototype.reset = function () {
|
||||
|
||||
this.ts = exports.Bench.now();
|
||||
};
|
||||
|
||||
|
||||
exports.Bench.prototype.elapsed = function () {
|
||||
|
||||
return exports.Bench.now() - this.ts;
|
||||
};
|
||||
|
||||
|
||||
exports.Bench.now = function () {
|
||||
|
||||
var ts = process.hrtime();
|
||||
return (ts[0] * 1e3) + (ts[1] / 1e6);
|
||||
};
|
||||
|
||||
|
||||
// Escape string for Regex construction
|
||||
|
||||
exports.escapeRegex = function (string) {
|
||||
|
||||
// Escape ^$.*+-?=!:|\/()[]{},
|
||||
return string.replace(/[\^\$\.\*\+\-\?\=\!\:\|\\\/\(\)\[\]\{\}\,]/g, '\\$&');
|
||||
};
|
||||
|
||||
|
||||
// Base64url (RFC 4648) encode
|
||||
|
||||
exports.base64urlEncode = function (value, encoding) {
|
||||
|
||||
var buf = (Buffer.isBuffer(value) ? value : new Buffer(value, encoding || 'binary'));
|
||||
return buf.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
|
||||
};
|
||||
|
||||
|
||||
// Base64url (RFC 4648) decode
|
||||
|
||||
exports.base64urlDecode = function (value, encoding) {
|
||||
|
||||
if (value &&
|
||||
!/^[\w\-]*$/.test(value)) {
|
||||
|
||||
return new Error('Invalid character');
|
||||
}
|
||||
|
||||
try {
|
||||
var buf = new Buffer(value, 'base64');
|
||||
return (encoding === 'buffer' ? buf : buf.toString(encoding || '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(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~\"\\]*$/.test(attribute), '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);
|
||||
};
|
||||
|
||||
|
||||
exports.nextTick = function (callback) {
|
||||
|
||||
return function () {
|
||||
|
||||
var args = arguments;
|
||||
process.nextTick(function () {
|
||||
|
||||
callback.apply(null, args);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
exports.once = function (method) {
|
||||
|
||||
if (method._hoekOnce) {
|
||||
return method;
|
||||
}
|
||||
|
||||
var once = false;
|
||||
var wrapped = function () {
|
||||
|
||||
if (!once) {
|
||||
once = true;
|
||||
method.apply(null, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
wrapped._hoekOnce = true;
|
||||
|
||||
return wrapped;
|
||||
};
|
||||
|
||||
|
||||
exports.isAbsolutePath = function (path, platform) {
|
||||
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Path.isAbsolute) { // node >= 0.11
|
||||
return Path.isAbsolute(path);
|
||||
}
|
||||
|
||||
platform = platform || process.platform;
|
||||
|
||||
// Unix
|
||||
|
||||
if (platform !== 'win32') {
|
||||
return path[0] === '/';
|
||||
}
|
||||
|
||||
// Windows
|
||||
|
||||
return !!/^(?:[a-zA-Z]:[\\\/])|(?:[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/])/.test(path); // C:\ or \\something\something
|
||||
};
|
||||
|
||||
|
||||
exports.isInteger = function (value) {
|
||||
|
||||
return (typeof value === 'number' &&
|
||||
parseFloat(value) === parseInt(value, 10) &&
|
||||
!isNaN(value));
|
||||
};
|
||||
|
||||
|
||||
exports.ignore = function () { };
|
||||
|
||||
|
||||
exports.inherits = Util.inherits;
|
||||
|
||||
|
||||
exports.format = Util.format;
|
||||
|
||||
|
||||
exports.transform = function (source, transform, options) {
|
||||
|
||||
exports.assert(source === null || source === undefined || typeof source === 'object' || Array.isArray(source), 'Invalid source object: must be null, undefined, an object, or an array');
|
||||
|
||||
if (Array.isArray(source)) {
|
||||
var results = [];
|
||||
for (var i = 0, il = source.length; i < il; ++i) {
|
||||
results.push(exports.transform(source[i], transform, options));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
var result = {};
|
||||
var keys = Object.keys(transform);
|
||||
|
||||
for (var k = 0, kl = keys.length; k < kl; ++k) {
|
||||
var key = keys[k];
|
||||
var path = key.split('.');
|
||||
var sourcePath = transform[key];
|
||||
|
||||
exports.assert(typeof sourcePath === 'string', 'All mappings must be "." delineated strings');
|
||||
|
||||
var segment;
|
||||
var res = result;
|
||||
|
||||
while (path.length > 1) {
|
||||
segment = path.shift();
|
||||
if (!res[segment]) {
|
||||
res[segment] = {};
|
||||
}
|
||||
res = res[segment];
|
||||
}
|
||||
segment = path.shift();
|
||||
res[segment] = exports.reach(source, sourcePath, options);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
exports.uniqueFilename = function (path, extension) {
|
||||
|
||||
if (extension) {
|
||||
extension = extension[0] !== '.' ? '.' + extension : extension;
|
||||
}
|
||||
else {
|
||||
extension = '';
|
||||
}
|
||||
|
||||
path = Path.resolve(path);
|
||||
var name = [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-') + extension;
|
||||
return Path.join(path, name);
|
||||
};
|
||||
|
||||
|
||||
exports.stringify = function () {
|
||||
|
||||
try {
|
||||
return JSON.stringify.apply(null, arguments);
|
||||
}
|
||||
catch (err) {
|
||||
return '[Cannot display object: ' + err.message + ']';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.shallow = function (source) {
|
||||
|
||||
var target = {};
|
||||
var keys = Object.keys(source);
|
||||
for (var i = 0, il = keys.length; i < il; ++i) {
|
||||
var key = keys[i];
|
||||
target[key] = source[key];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
87
node_modules/hoek/package.json
generated
vendored
Normal file
87
node_modules/hoek/package.json
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"hoek@2.x.x",
|
||||
"C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\hawk"
|
||||
]
|
||||
],
|
||||
"_from": "hoek@>=2.0.0-0 <3.0.0-0",
|
||||
"_id": "hoek@2.16.3",
|
||||
"_inCache": true,
|
||||
"_location": "/hoek",
|
||||
"_nodeVersion": "4.1.0",
|
||||
"_npmUser": {
|
||||
"email": "quitlahok@gmail.com",
|
||||
"name": "nlf"
|
||||
},
|
||||
"_npmVersion": "3.3.3",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "hoek",
|
||||
"raw": "hoek@2.x.x",
|
||||
"rawSpec": "2.x.x",
|
||||
"scope": null,
|
||||
"spec": ">=2.0.0-0 <3.0.0-0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/boom",
|
||||
"/hawk",
|
||||
"/sntp"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz",
|
||||
"_shasum": "20bb7403d3cea398e91dc4710a8ff1b8274a25ed",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "hoek@2.x.x",
|
||||
"_where": "C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\hawk",
|
||||
"bugs": {
|
||||
"url": "https://github.com/hapijs/hoek/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "General purpose node utilities",
|
||||
"devDependencies": {
|
||||
"code": "1.x.x",
|
||||
"lab": "5.x.x"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "20bb7403d3cea398e91dc4710a8ff1b8274a25ed",
|
||||
"tarball": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.40"
|
||||
},
|
||||
"gitHead": "20f36e85616264d4b73a64a374803175213a9121",
|
||||
"homepage": "https://github.com/hapijs/hoek#readme",
|
||||
"installable": true,
|
||||
"keywords": [
|
||||
"utilities"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "lib/index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "hueniverse",
|
||||
"email": "eran@hueniverse.com"
|
||||
},
|
||||
{
|
||||
"name": "wyatt",
|
||||
"email": "wpreul@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "nlf",
|
||||
"email": "quitlahok@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "hoek",
|
||||
"optionalDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/hapijs/hoek.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "lab -a code -t 100 -L",
|
||||
"test-cov-html": "lab -a code -t 100 -L -r html -o coverage.html"
|
||||
},
|
||||
"version": "2.16.3"
|
||||
}
|
88
node_modules/hoek/test/escaper.js
generated
vendored
Normal file
88
node_modules/hoek/test/escaper.js
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
// Load modules
|
||||
|
||||
var Code = require('code');
|
||||
var Hoek = require('../lib');
|
||||
var Lab = require('lab');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
// Test shortcuts
|
||||
|
||||
var lab = exports.lab = Lab.script();
|
||||
var describe = lab.experiment;
|
||||
var it = lab.test;
|
||||
var expect = Code.expect;
|
||||
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
it('encodes {} characters', function (done) {
|
||||
|
||||
var encoded = Hoek.escapeHtml('{}');
|
||||
expect(encoded).to.equal('{}');
|
||||
done();
|
||||
});
|
||||
});
|
2513
node_modules/hoek/test/index.js
generated
vendored
Normal file
2513
node_modules/hoek/test/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
0
node_modules/hoek/test/modules/ignore.txt
generated
vendored
Normal file
0
node_modules/hoek/test/modules/ignore.txt
generated
vendored
Normal file
1
node_modules/hoek/test/modules/test1.js
generated
vendored
Normal file
1
node_modules/hoek/test/modules/test1.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.x = 1;
|
1
node_modules/hoek/test/modules/test2.js
generated
vendored
Normal file
1
node_modules/hoek/test/modules/test2.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.y = 2;
|
1
node_modules/hoek/test/modules/test3.js
generated
vendored
Normal file
1
node_modules/hoek/test/modules/test3.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.z = 3;
|
Reference in New Issue
Block a user