Commit 22cba4b7 authored by Sachinda 's avatar Sachinda

node rm

parent c790068e
Pipeline #8700 canceled with stages
build: components index.js
@component build --dev
components:
@component install --dev
clean:
rm -fr build components template.js
test:
open test/index.html
.PHONY: clean test
# type
Type assertions aka less-broken `typeof`.
## Example
```js
var type = require('type');
var obj = new Date;
if (type(obj) == 'date') ...
```
## API
```js
type(new Date) == 'date'
type({}) == 'object'
type(null) == 'null'
type(undefined) == 'undefined'
type("hey") == 'string'
type(true) == 'boolean'
type(false) == 'boolean'
type(12) == 'number'
type(type) == 'function'
type(/asdf/) == 'regexp'
type((function(){ return arguments })()) == 'arguments'
type([]) == 'array'
type(document.createElement('div')) == 'element'
type(NaN) == 'nan'
type(new Error('Ups! Something wrong...')) == 'error'
type(new Buffer) == 'buffer'
```
## License
MIT
{
"name": "type",
"description": "Cross-browser type assertions (less broken typeof)",
"version": "1.1.0",
"keywords": ["typeof", "type", "utility"],
"dependencies": {},
"development": {
"component/assert": "*"
},
"scripts": [
"index.js"
]
}
/**
* toString ref.
*/
var toString = Object.prototype.toString;
/**
* Return the type of `val`.
*
* @param {Mixed} val
* @return {String}
* @api public
*/
module.exports = function(val){
switch (toString.call(val)) {
case '[object Date]': return 'date';
case '[object RegExp]': return 'regexp';
case '[object Arguments]': return 'arguments';
case '[object Array]': return 'array';
case '[object Error]': return 'error';
}
if (val === null) return 'null';
if (val === undefined) return 'undefined';
if (val !== val) return 'nan';
if (val && val.nodeType === 1) return 'element';
if (isBuffer(val)) return 'buffer';
val = val.valueOf
? val.valueOf()
: Object.prototype.valueOf.apply(val);
return typeof val;
};
// code borrowed from https://github.com/feross/is-buffer/blob/master/index.js
function isBuffer(obj) {
return !!(obj != null &&
(obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor)
(obj.constructor &&
typeof obj.constructor.isBuffer === 'function' &&
obj.constructor.isBuffer(obj))
))
}
{
"_args": [
[
"component-type@1.2.1",
"/private/var/www/db/coutch_db_create"
]
],
"_from": "component-type@1.2.1",
"_id": "component-type@1.2.1",
"_inBundle": false,
"_integrity": "sha1-ikeQFwAjjk/DIml3EjAibyS0Fak=",
"_location": "/component-type",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "component-type@1.2.1",
"name": "component-type",
"escapedName": "component-type",
"rawSpec": "1.2.1",
"saveSpec": null,
"fetchSpec": "1.2.1"
},
"_requiredBy": [
"/validate"
],
"_resolved": "https://registry.npmjs.org/component-type/-/component-type-1.2.1.tgz",
"_spec": "1.2.1",
"_where": "/private/var/www/db/coutch_db_create",
"bugs": {
"url": "https://github.com/component/type/issues"
},
"dependencies": {},
"description": "Cross-browser type assertions (less broken typeof)",
"homepage": "https://github.com/component/type#readme",
"keywords": [
"typeof",
"type",
"utility"
],
"license": "MIT",
"main": "index.js",
"name": "component-type",
"repository": {
"type": "git",
"url": "git+https://github.com/component/type.git"
},
"version": "1.2.1"
}
<html>
<head>
<title>Mocha</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="../build/build.js"></script>
<script src="tests.js"></script>
<script>
mocha.run();
</script>
</body>
</html>
\ No newline at end of file
@charset "utf-8";
body {
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 60px 50px;
}
#mocha ul, #mocha li {
margin: 0;
padding: 0;
}
#mocha ul {
list-style: none;
}
#mocha h1, #mocha h2 {
margin: 0;
}
#mocha h1 {
margin-top: 15px;
font-size: 1em;
font-weight: 200;
}
#mocha h1 a {
text-decoration: none;
color: inherit;
}
#mocha h1 a:hover {
text-decoration: underline;
}
#mocha .suite .suite h1 {
margin-top: 0;
font-size: .8em;
}
.hidden {
display: none;
}
#mocha h2 {
font-size: 12px;
font-weight: normal;
cursor: pointer;
}
#mocha .suite {
margin-left: 15px;
}
#mocha .test {
margin-left: 15px;
overflow: hidden;
}
#mocha .test.pending:hover h2::after {
content: '(pending)';
font-family: arial;
}
#mocha .test.pass.medium .duration {
background: #C09853;
}
#mocha .test.pass.slow .duration {
background: #B94A48;
}
#mocha .test.pass::before {
content: '✓';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #00d6b2;
}
#mocha .test.pass .duration {
font-size: 9px;
margin-left: 5px;
padding: 2px 5px;
color: white;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
#mocha .test.pass.fast .duration {
display: none;
}
#mocha .test.pending {
color: #0b97c4;
}
#mocha .test.pending::before {
content: '◦';
color: #0b97c4;
}
#mocha .test.fail {
color: #c00;
}
#mocha .test.fail pre {
color: black;
}
#mocha .test.fail::before {
content: '✖';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #c00;
}
#mocha .test pre.error {
color: #c00;
max-height: 300px;
overflow: auto;
}
#mocha .test pre {
display: block;
float: left;
clear: left;
font: 12px/1.5 monaco, monospace;
margin: 5px;
padding: 15px;
border: 1px solid #eee;
border-bottom-color: #ddd;
-webkit-border-radius: 3px;
-webkit-box-shadow: 0 1px 3px #eee;
-moz-border-radius: 3px;
-moz-box-shadow: 0 1px 3px #eee;
}
#mocha .test h2 {
position: relative;
}
#mocha .test a.replay {
position: absolute;
top: 3px;
right: 0;
text-decoration: none;
vertical-align: middle;
display: block;
width: 15px;
height: 15px;
line-height: 15px;
text-align: center;
background: #eee;
font-size: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
-webkit-transition: opacity 200ms;
-moz-transition: opacity 200ms;
transition: opacity 200ms;
opacity: 0.3;
color: #888;
}
#mocha .test:hover a.replay {
opacity: 1;
}
#mocha-report.pass .test.fail {
display: none;
}
#mocha-report.fail .test.pass {
display: none;
}
#mocha-error {
color: #c00;
font-size: 1.5 em;
font-weight: 100;
letter-spacing: 1px;
}
#mocha-stats {
position: fixed;
top: 15px;
right: 10px;
font-size: 12px;
margin: 0;
color: #888;
}
#mocha-stats .progress {
float: right;
padding-top: 0;
}
#mocha-stats em {
color: black;
}
#mocha-stats a {
text-decoration: none;
color: inherit;
}
#mocha-stats a:hover {
border-bottom: 1px solid #eee;
}
#mocha-stats li {
display: inline-block;
margin: 0 5px;
list-style: none;
padding-top: 11px;
}
code .comment { color: #ddd }
code .init { color: #2F6FAD }
code .string { color: #5890AD }
code .keyword { color: #8A6343 }
code .number { color: #2F6FAD }
This source diff could not be displayed because it is too large. You can view the blob instead.
var type = require('type')
, assert = require('component-assert');
describe('type', function(){
it('should match objects', function(){
function Foo(){}
assert('object' === type({}));
assert('object' === type(new Foo));
});
it('should match numbers', function(){
assert('number' === type(12));
assert('number' === type(1.0));
assert('number' === type(-5));
assert('number' === type(new Number(123)));
assert('number' === type(Infinity));
});
it('should match NaN', function () {
assert('nan' === type(NaN));
});
it('should match strings', function(){
assert('string' === type("test"));
assert('string' === type(new String('whoop')));
});
it('should match dates', function(){
assert('date' === type(new Date));
});
it('should match booleans', function(){
assert('boolean' === type(true));
assert('boolean' === type(false));
assert('boolean' === type(new Boolean(true)));
});
it('should match null', function(){
assert('null' === type(null));
});
it('should match undefined', function(){
assert('undefined' === type());
assert('undefined' === type(undefined));
});
it('should match arrays', function(){
assert('array' === type([]));
assert('array' === type(new Array()));
});
it('should match regexps', function(){
assert('regexp' === type(/asdf/));
assert('regexp' === type(new RegExp('weee')));
});
it('should match functions', function(){
assert('function' === type(function(){}));
});
it('should match arguments', function(){
assert('arguments' === type(arguments));
});
it('should match elements', function(){
assert('element' === type(document.createElement('div')));
});
it('should match errors', function(){
assert('error' === type(new Error('Ups!')));
});
it('should match buffers', function(){
var b = {};
assert('object' === type(b));
if (window.Buffer) {
var val = new Buffer(4);
assert('buffer' === type(val));
}
});
});
# dot
Get and set object properties with dot notation
## Installation
$ component install eivindfjeldstad/dot
## API
### dot.set(object, path, value)
```js
dot.set(obj, 'cool.aid', 'rocks');
assert(obj.cool.aid === 'rocks');
```
### dot.get(object, path)
```js
var value = dot.get(obj, 'cool.aid');
assert(value === 'rocks');
```
## License
MIT
{
"name": "dot",
"repo": "eivindfjeldstad/dot",
"description": "Get and set object properties with dot notation",
"version": "0.0.1",
"keywords": [],
"dependencies": {},
"development": {},
"license": "MIT",
"main": "index.js",
"scripts": [
"index.js"
]
}
\ No newline at end of file
/**
* Set given `path`
*
* @param {Object} obj
* @param {String} path
* @param {Mixed} val
* @api public
*/
exports.set = function (obj, path, val) {
var segs = path.split('.');
var attr = segs.pop();
for (var i = 0; i < segs.length; i++) {
var seg = segs[i];
obj[seg] = obj[seg] || {};
obj = obj[seg];
}
obj[attr] = val;
};
/**
* Get given `path`
*
* @param {Object} obj
* @param {String} path
* @return {Mixed}
* @api public
*/
exports.get = function (obj, path) {
var segs = path.split('.');
var attr = segs.pop();
for (var i = 0; i < segs.length; i++) {
var seg = segs[i];
if (!obj[seg]) return;
obj = obj[seg];
}
return obj[attr];
};
\ No newline at end of file
{
"_args": [
[
"eivindfjeldstad-dot@0.0.1",
"/private/var/www/db/coutch_db_create"
]
],
"_from": "eivindfjeldstad-dot@0.0.1",
"_id": "eivindfjeldstad-dot@0.0.1",
"_inBundle": false,
"_integrity": "sha1-IvyXa/rzBuCDmjHbjoITSA+vuJM=",
"_location": "/eivindfjeldstad-dot",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "eivindfjeldstad-dot@0.0.1",
"name": "eivindfjeldstad-dot",
"escapedName": "eivindfjeldstad-dot",
"rawSpec": "0.0.1",
"saveSpec": null,
"fetchSpec": "0.0.1"
},
"_requiredBy": [
"/validate"
],
"_resolved": "https://registry.npmjs.org/eivindfjeldstad-dot/-/eivindfjeldstad-dot-0.0.1.tgz",
"_spec": "0.0.1",
"_where": "/private/var/www/db/coutch_db_create",
"bugs": {
"url": "https://github.com/eivindfjeldstad/dot/issues"
},
"description": "Get and set object properties with dot notation",
"directories": {
"test": "test"
},
"homepage": "https://github.com/eivindfjeldstad/dot",
"keywords": [
"dot",
"notation",
"properties",
"object",
"path"
],
"license": "MIT",
"main": "index.js",
"name": "eivindfjeldstad-dot",
"repository": {
"type": "git",
"url": "git+https://github.com/eivindfjeldstad/dot.git"
},
"scripts": {
"test": "node test"
},
"version": "0.0.1"
}
var assert = require('assert');
var dot = require('..');
var tests = module.exports = {
'test set': function () {
var obj = {};
dot.set(obj, 'cool.aid', 'rocks');
assert(obj.cool.aid === 'rocks');
},
'test get': function () {
var obj = {};
obj.cool = {};
obj.cool.aid = 'rocks';
var value = dot.get(obj, 'cool.aid');
assert(value === 'rocks');
}
}
for (var t in tests) {
tests[t]();
}
console.log('All tests passed!');
\ No newline at end of file
The MIT License (MIT)
Copyright (c) 2014 object-hash contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.objectHash=e()}}(function(){return function o(i,u,a){function s(n,e){if(!u[n]){if(!i[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(f)return f(n,!0);throw new Error("Cannot find module '"+n+"'")}var r=u[n]={exports:{}};i[n][0].call(r.exports,function(e){var t=i[n][1][e];return s(t||e)},r,r.exports,o,i,u,a)}return u[n].exports}for(var f="function"==typeof require&&require,e=0;e<a.length;e++)s(a[e]);return s}({1:[function(w,b,m){(function(e,t,f,n,r,o,i,u,a){"use strict";var s=w("crypto");function c(e,t){return function(e,t){var n;n="passthrough"!==t.algorithm?s.createHash(t.algorithm):new y;void 0===n.write&&(n.write=n.update,n.end=n.update);g(t,n).dispatch(e),n.update||n.end("");if(n.digest)return n.digest("buffer"===t.encoding?void 0:t.encoding);var r=n.read();return"buffer"!==t.encoding?r.toString(t.encoding):r}(e,t=h(e,t))}(m=b.exports=c).sha1=function(e){return c(e)},m.keys=function(e){return c(e,{excludeValues:!0,algorithm:"sha1",encoding:"hex"})},m.MD5=function(e){return c(e,{algorithm:"md5",encoding:"hex"})},m.keysMD5=function(e){return c(e,{algorithm:"md5",encoding:"hex",excludeValues:!0})};var l=s.getHashes?s.getHashes().slice():["sha1","md5"];l.push("passthrough");var d=["buffer","hex","binary","base64"];function h(e,t){t=t||{};var n={};if(n.algorithm=t.algorithm||"sha1",n.encoding=t.encoding||"hex",n.excludeValues=!!t.excludeValues,n.algorithm=n.algorithm.toLowerCase(),n.encoding=n.encoding.toLowerCase(),n.ignoreUnknown=!0===t.ignoreUnknown,n.respectType=!1!==t.respectType,n.respectFunctionNames=!1!==t.respectFunctionNames,n.respectFunctionProperties=!1!==t.respectFunctionProperties,n.unorderedArrays=!0===t.unorderedArrays,n.unorderedSets=!1!==t.unorderedSets,n.unorderedObjects=!1!==t.unorderedObjects,n.replacer=t.replacer||void 0,n.excludeKeys=t.excludeKeys||void 0,void 0===e)throw new Error("Object argument required.");for(var r=0;r<l.length;++r)l[r].toLowerCase()===n.algorithm.toLowerCase()&&(n.algorithm=l[r]);if(-1===l.indexOf(n.algorithm))throw new Error('Algorithm "'+n.algorithm+'" not supported. supported values: '+l.join(", "));if(-1===d.indexOf(n.encoding)&&"passthrough"!==n.algorithm)throw new Error('Encoding "'+n.encoding+'" not supported. supported values: '+d.join(", "));return n}function p(e){if("function"==typeof e){return null!=/^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i.exec(Function.prototype.toString.call(e))}}function g(u,t,a){a=a||[];function s(e){return t.update?t.update(e,"utf8"):t.write(e,"utf8")}return{dispatch:function(e){u.replacer&&(e=u.replacer(e));var t=typeof e;return null===e&&(t="null"),this["_"+t](e)},_object:function(t){var e=Object.prototype.toString.call(t),n=/\[object (.*)\]/i.exec(e);n=(n=n?n[1]:"unknown:["+e+"]").toLowerCase();var r;if(0<=(r=a.indexOf(t)))return this.dispatch("[CIRCULAR:"+r+"]");if(a.push(t),void 0!==f&&f.isBuffer&&f.isBuffer(t))return s("buffer:"),s(t);if("object"===n||"function"===n||"asyncfunction"===n){var o=Object.keys(t);u.unorderedObjects&&(o=o.sort()),!1===u.respectType||p(t)||o.splice(0,0,"prototype","__proto__","constructor"),u.excludeKeys&&(o=o.filter(function(e){return!u.excludeKeys(e)})),s("object:"+o.length+":");var i=this;return o.forEach(function(e){i.dispatch(e),s(":"),u.excludeValues||i.dispatch(t[e]),s(",")})}if(!this["_"+n]){if(u.ignoreUnknown)return s("["+n+"]");throw new Error('Unknown object type "'+n+'"')}this["_"+n](t)},_array:function(e,t){t=void 0!==t?t:!1!==u.unorderedArrays;var n=this;if(s("array:"+e.length+":"),!t||e.length<=1)return e.forEach(function(e){return n.dispatch(e)});var r=[],o=e.map(function(e){var t=new y,n=a.slice();return g(u,t,n).dispatch(e),r=r.concat(n.slice(a.length)),t.read().toString()});return a=a.concat(r),o.sort(),this._array(o,!1)},_date:function(e){return s("date:"+e.toJSON())},_symbol:function(e){return s("symbol:"+e.toString())},_error:function(e){return s("error:"+e.toString())},_boolean:function(e){return s("bool:"+e.toString())},_string:function(e){s("string:"+e.length+":"),s(e.toString())},_function:function(e){s("fn:"),p(e)?this.dispatch("[native]"):this.dispatch(e.toString()),!1!==u.respectFunctionNames&&this.dispatch("function-name:"+String(e.name)),u.respectFunctionProperties&&this._object(e)},_number:function(e){return s("number:"+e.toString())},_xml:function(e){return s("xml:"+e.toString())},_null:function(){return s("Null")},_undefined:function(){return s("Undefined")},_regexp:function(e){return s("regex:"+e.toString())},_uint8array:function(e){return s("uint8array:"),this.dispatch(Array.prototype.slice.call(e))},_uint8clampedarray:function(e){return s("uint8clampedarray:"),this.dispatch(Array.prototype.slice.call(e))},_int8array:function(e){return s("uint8array:"),this.dispatch(Array.prototype.slice.call(e))},_uint16array:function(e){return s("uint16array:"),this.dispatch(Array.prototype.slice.call(e))},_int16array:function(e){return s("uint16array:"),this.dispatch(Array.prototype.slice.call(e))},_uint32array:function(e){return s("uint32array:"),this.dispatch(Array.prototype.slice.call(e))},_int32array:function(e){return s("uint32array:"),this.dispatch(Array.prototype.slice.call(e))},_float32array:function(e){return s("float32array:"),this.dispatch(Array.prototype.slice.call(e))},_float64array:function(e){return s("float64array:"),this.dispatch(Array.prototype.slice.call(e))},_arraybuffer:function(e){return s("arraybuffer:"),this.dispatch(new Uint8Array(e))},_url:function(e){return s("url:"+e.toString())},_map:function(e){s("map:");var t=Array.from(e);return this._array(t,!1!==u.unorderedSets)},_set:function(e){s("set:");var t=Array.from(e);return this._array(t,!1!==u.unorderedSets)},_blob:function(){if(u.ignoreUnknown)return s("[blob]");throw Error('Hashing Blob objects is currently not supported\n(see https://github.com/puleos/object-hash/issues/26)\nUse "options.replacer" or "options.ignoreUnknown"\n')},_domwindow:function(){return s("domwindow")},_process:function(){return s("process")},_timer:function(){return s("timer")},_pipe:function(){return s("pipe")},_tcp:function(){return s("tcp")},_udp:function(){return s("udp")},_tty:function(){return s("tty")},_statwatcher:function(){return s("statwatcher")},_securecontext:function(){return s("securecontext")},_connection:function(){return s("connection")},_zlib:function(){return s("zlib")},_context:function(){return s("context")},_nodescript:function(){return s("nodescript")},_httpparser:function(){return s("httpparser")},_dataview:function(){return s("dataview")},_signal:function(){return s("signal")},_fsevent:function(){return s("fsevent")},_tlswrap:function(){return s("tlswrap")}}}function y(){return{buf:"",write:function(e){this.buf+=e},end:function(e){this.buf+=e},read:function(){return this.buf}}}m.writeToStream=function(e,t,n){return void 0===n&&(n=t,t={}),g(t=h(e,t),n).dispatch(e)}}).call(this,w("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},w("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_794fcf4d.js","/")},{buffer:3,crypto:5,lYpoI2:10}],2:[function(e,t,f){(function(e,t,n,r,o,i,u,a,s){!function(e){"use strict";var f="undefined"!=typeof Uint8Array?Uint8Array:Array,n="+".charCodeAt(0),r="/".charCodeAt(0),o="0".charCodeAt(0),i="a".charCodeAt(0),u="A".charCodeAt(0),a="-".charCodeAt(0),s="_".charCodeAt(0);function c(e){var t=e.charCodeAt(0);return t===n||t===a?62:t===r||t===s?63:t<o?-1:t<o+10?t-o+26+26:t<u+26?t-u:t<i+26?t-i+26:void 0}e.toByteArray=function(e){var t,n,r,o,i;if(0<e.length%4)throw new Error("Invalid string. Length must be a multiple of 4");var u=e.length;o="="===e.charAt(u-2)?2:"="===e.charAt(u-1)?1:0,i=new f(3*e.length/4-o),n=0<o?e.length-4:e.length;var a=0;function s(e){i[a++]=e}for(t=0;t<n;t+=4,0)s((16711680&(r=c(e.charAt(t))<<18|c(e.charAt(t+1))<<12|c(e.charAt(t+2))<<6|c(e.charAt(t+3))))>>16),s((65280&r)>>8),s(255&r);return 2==o?s(255&(r=c(e.charAt(t))<<2|c(e.charAt(t+1))>>4)):1==o&&(s((r=c(e.charAt(t))<<10|c(e.charAt(t+1))<<4|c(e.charAt(t+2))>>2)>>8&255),s(255&r)),i},e.fromByteArray=function(e){var t,n,r,o,i=e.length%3,u="";function a(e){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)}for(t=0,r=e.length-i;t<r;t+=3)n=(e[t]<<16)+(e[t+1]<<8)+e[t+2],u+=a((o=n)>>18&63)+a(o>>12&63)+a(o>>6&63)+a(63&o);switch(i){case 1:u+=a((n=e[e.length-1])>>2),u+=a(n<<4&63),u+="==";break;case 2:u+=a((n=(e[e.length-2]<<8)+e[e.length-1])>>10),u+=a(n>>4&63),u+=a(n<<2&63),u+="="}return u}}(void 0===f?this.base64js={}:f)}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/base64-js/lib/b64.js","/node_modules/gulp-browserify/node_modules/base64-js/lib")},{buffer:3,lYpoI2:10}],3:[function(O,e,H){(function(e,t,h,n,r,o,i,u,a){var s=O("base64-js"),f=O("ieee754");function h(e,t,n){if(!(this instanceof h))return new h(e,t,n);var r,o,i,u,a,s=typeof e;if("base64"===t&&"string"==s)for(e=(r=e).trim?r.trim():r.replace(/^\s+|\s+$/g,"");e.length%4!=0;)e+="=";if("number"==s)o=x(e);else if("string"==s)o=h.byteLength(e,t);else{if("object"!=s)throw new Error("First argument needs to be a number, array or string.");o=x(e.length)}if(h._useTypedArrays?i=h._augment(new Uint8Array(o)):((i=this).length=o,i._isBuffer=!0),h._useTypedArrays&&"number"==typeof e.byteLength)i._set(e);else if(S(a=e)||h.isBuffer(a)||a&&"object"==typeof a&&"number"==typeof a.length)for(u=0;u<o;u++)h.isBuffer(e)?i[u]=e.readUInt8(u):i[u]=e[u];else if("string"==s)i.write(e,0,t);else if("number"==s&&!h._useTypedArrays&&!n)for(u=0;u<o;u++)i[u]=0;return i}function p(e,t,n,r){return h._charsWritten=T(function(e){for(var t=[],n=0;n<e.length;n++)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function g(e,t,n,r){return h._charsWritten=T(function(e){for(var t,n,r,o=[],i=0;i<e.length;i++)t=e.charCodeAt(i),n=t>>8,r=t%256,o.push(r),o.push(n);return o}(t),e,n,r)}function c(e,t,n){var r="";n=Math.min(e.length,n);for(var o=t;o<n;o++)r+=String.fromCharCode(e[o]);return r}function l(e,t,n,r){r||(D("boolean"==typeof n,"missing or invalid endian"),D(null!=t,"missing offset"),D(t+1<e.length,"Trying to read beyond buffer length"));var o,i=e.length;if(!(i<=t))return n?(o=e[t],t+1<i&&(o|=e[t+1]<<8)):(o=e[t]<<8,t+1<i&&(o|=e[t+1])),o}function d(e,t,n,r){r||(D("boolean"==typeof n,"missing or invalid endian"),D(null!=t,"missing offset"),D(t+3<e.length,"Trying to read beyond buffer length"));var o,i=e.length;if(!(i<=t))return n?(t+2<i&&(o=e[t+2]<<16),t+1<i&&(o|=e[t+1]<<8),o|=e[t],t+3<i&&(o+=e[t+3]<<24>>>0)):(t+1<i&&(o=e[t+1]<<16),t+2<i&&(o|=e[t+2]<<8),t+3<i&&(o|=e[t+3]),o+=e[t]<<24>>>0),o}function y(e,t,n,r){if(r||(D("boolean"==typeof n,"missing or invalid endian"),D(null!=t,"missing offset"),D(t+1<e.length,"Trying to read beyond buffer length")),!(e.length<=t)){var o=l(e,t,n,!0);return 32768&o?-1*(65535-o+1):o}}function w(e,t,n,r){if(r||(D("boolean"==typeof n,"missing or invalid endian"),D(null!=t,"missing offset"),D(t+3<e.length,"Trying to read beyond buffer length")),!(e.length<=t)){var o=d(e,t,n,!0);return 2147483648&o?-1*(4294967295-o+1):o}}function b(e,t,n,r){return r||(D("boolean"==typeof n,"missing or invalid endian"),D(t+3<e.length,"Trying to read beyond buffer length")),f.read(e,t,n,23,4)}function m(e,t,n,r){return r||(D("boolean"==typeof n,"missing or invalid endian"),D(t+7<e.length,"Trying to read beyond buffer length")),f.read(e,t,n,52,8)}function v(e,t,n,r,o){o||(D(null!=t,"missing value"),D("boolean"==typeof r,"missing or invalid endian"),D(null!=n,"missing offset"),D(n+1<e.length,"trying to write beyond buffer length"),N(t,65535));var i=e.length;if(!(i<=n))for(var u=0,a=Math.min(i-n,2);u<a;u++)e[n+u]=(t&255<<8*(r?u:1-u))>>>8*(r?u:1-u)}function _(e,t,n,r,o){o||(D(null!=t,"missing value"),D("boolean"==typeof r,"missing or invalid endian"),D(null!=n,"missing offset"),D(n+3<e.length,"trying to write beyond buffer length"),N(t,4294967295));var i=e.length;if(!(i<=n))for(var u=0,a=Math.min(i-n,4);u<a;u++)e[n+u]=t>>>8*(r?u:3-u)&255}function E(e,t,n,r,o){o||(D(null!=t,"missing value"),D("boolean"==typeof r,"missing or invalid endian"),D(null!=n,"missing offset"),D(n+1<e.length,"Trying to write beyond buffer length"),Y(t,32767,-32768)),e.length<=n||v(e,0<=t?t:65535+t+1,n,r,o)}function I(e,t,n,r,o){o||(D(null!=t,"missing value"),D("boolean"==typeof r,"missing or invalid endian"),D(null!=n,"missing offset"),D(n+3<e.length,"Trying to write beyond buffer length"),Y(t,2147483647,-2147483648)),e.length<=n||_(e,0<=t?t:4294967295+t+1,n,r,o)}function A(e,t,n,r,o){o||(D(null!=t,"missing value"),D("boolean"==typeof r,"missing or invalid endian"),D(null!=n,"missing offset"),D(n+3<e.length,"Trying to write beyond buffer length"),F(t,34028234663852886e22,-34028234663852886e22)),e.length<=n||f.write(e,t,n,r,23,4)}function B(e,t,n,r,o){o||(D(null!=t,"missing value"),D("boolean"==typeof r,"missing or invalid endian"),D(null!=n,"missing offset"),D(n+7<e.length,"Trying to write beyond buffer length"),F(t,17976931348623157e292,-17976931348623157e292)),e.length<=n||f.write(e,t,n,r,52,8)}H.Buffer=h,H.SlowBuffer=h,H.INSPECT_MAX_BYTES=50,h.poolSize=8192,h._useTypedArrays=function(){try{var e=new ArrayBuffer(0),t=new Uint8Array(e);return t.foo=function(){return 42},42===t.foo()&&"function"==typeof t.subarray}catch(e){return!1}}(),h.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},h.isBuffer=function(e){return!(null==e||!e._isBuffer)},h.byteLength=function(e,t){var n;switch(e+="",t||"utf8"){case"hex":n=e.length/2;break;case"utf8":case"utf-8":n=C(e).length;break;case"ascii":case"binary":case"raw":n=e.length;break;case"base64":n=k(e).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":n=2*e.length;break;default:throw new Error("Unknown encoding")}return n},h.concat=function(e,t){if(D(S(e),"Usage: Buffer.concat(list, [totalLength])\nlist should be an Array."),0===e.length)return new h(0);if(1===e.length)return e[0];var n;if("number"!=typeof t)for(n=t=0;n<e.length;n++)t+=e[n].length;var r=new h(t),o=0;for(n=0;n<e.length;n++){var i=e[n];i.copy(r,o),o+=i.length}return r},h.prototype.write=function(e,t,n,r){if(isFinite(t))isFinite(n)||(r=n,n=void 0);else{var o=r;r=t,t=n,n=o}t=Number(t)||0;var i,u,a,s,f,c,l,d=this.length-t;switch((!n||d<(n=Number(n)))&&(n=d),r=String(r||"utf8").toLowerCase()){case"hex":i=function(e,t,n,r){n=Number(n)||0;var o=e.length-n;(!r||o<(r=Number(r)))&&(r=o);var i=t.length;D(i%2==0,"Invalid hex string"),i/2<r&&(r=i/2);for(var u=0;u<r;u++){var a=parseInt(t.substr(2*u,2),16);D(!isNaN(a),"Invalid hex string"),e[n+u]=a}return h._charsWritten=2*u,u}(this,e,t,n);break;case"utf8":case"utf-8":f=this,c=t,l=n,i=h._charsWritten=T(C(e),f,c,l);break;case"ascii":i=p(this,e,t,n);break;case"binary":i=p(this,e,t,n);break;case"base64":u=this,a=t,s=n,i=h._charsWritten=T(k(e),u,a,s);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":i=g(this,e,t,n);break;default:throw new Error("Unknown encoding")}return i},h.prototype.toString=function(e,t,n){var r,o,i,u,a=this;if(e=String(e||"utf8").toLowerCase(),t=Number(t)||0,(n=void 0!==n?Number(n):n=a.length)===t)return"";switch(e){case"hex":r=function(e,t,n){var r=e.length;(!t||t<0)&&(t=0);(!n||n<0||r<n)&&(n=r);for(var o="",i=t;i<n;i++)o+=j(e[i]);return o}(a,t,n);break;case"utf8":case"utf-8":r=function(e,t,n){var r="",o="";n=Math.min(e.length,n);for(var i=t;i<n;i++)e[i]<=127?(r+=M(o)+String.fromCharCode(e[i]),o=""):o+="%"+e[i].toString(16);return r+M(o)}(a,t,n);break;case"ascii":r=c(a,t,n);break;case"binary":r=c(a,t,n);break;case"base64":o=a,u=n,r=0===(i=t)&&u===o.length?s.fromByteArray(o):s.fromByteArray(o.slice(i,u));break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":r=function(e,t,n){for(var r=e.slice(t,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}(a,t,n);break;default:throw new Error("Unknown encoding")}return r},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},h.prototype.copy=function(e,t,n,r){if(n=n||0,r||0===r||(r=this.length),t=t||0,r!==n&&0!==e.length&&0!==this.length){D(n<=r,"sourceEnd < sourceStart"),D(0<=t&&t<e.length,"targetStart out of bounds"),D(0<=n&&n<this.length,"sourceStart out of bounds"),D(0<=r&&r<=this.length,"sourceEnd out of bounds"),r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var o=r-n;if(o<100||!h._useTypedArrays)for(var i=0;i<o;i++)e[i+t]=this[i+n];else e._set(this.subarray(n,n+o),t)}},h.prototype.slice=function(e,t){var n=this.length;if(e=U(e,n,0),t=U(t,n,n),h._useTypedArrays)return h._augment(this.subarray(e,t));for(var r=t-e,o=new h(r,void 0,!0),i=0;i<r;i++)o[i]=this[i+e];return o},h.prototype.get=function(e){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(e)},h.prototype.set=function(e,t){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(e,t)},h.prototype.readUInt8=function(e,t){if(t||(D(null!=e,"missing offset"),D(e<this.length,"Trying to read beyond buffer length")),!(e>=this.length))return this[e]},h.prototype.readUInt16LE=function(e,t){return l(this,e,!0,t)},h.prototype.readUInt16BE=function(e,t){return l(this,e,!1,t)},h.prototype.readUInt32LE=function(e,t){return d(this,e,!0,t)},h.prototype.readUInt32BE=function(e,t){return d(this,e,!1,t)},h.prototype.readInt8=function(e,t){if(t||(D(null!=e,"missing offset"),D(e<this.length,"Trying to read beyond buffer length")),!(e>=this.length))return 128&this[e]?-1*(255-this[e]+1):this[e]},h.prototype.readInt16LE=function(e,t){return y(this,e,!0,t)},h.prototype.readInt16BE=function(e,t){return y(this,e,!1,t)},h.prototype.readInt32LE=function(e,t){return w(this,e,!0,t)},h.prototype.readInt32BE=function(e,t){return w(this,e,!1,t)},h.prototype.readFloatLE=function(e,t){return b(this,e,!0,t)},h.prototype.readFloatBE=function(e,t){return b(this,e,!1,t)},h.prototype.readDoubleLE=function(e,t){return m(this,e,!0,t)},h.prototype.readDoubleBE=function(e,t){return m(this,e,!1,t)},h.prototype.writeUInt8=function(e,t,n){n||(D(null!=e,"missing value"),D(null!=t,"missing offset"),D(t<this.length,"trying to write beyond buffer length"),N(e,255)),t>=this.length||(this[t]=e)},h.prototype.writeUInt16LE=function(e,t,n){v(this,e,t,!0,n)},h.prototype.writeUInt16BE=function(e,t,n){v(this,e,t,!1,n)},h.prototype.writeUInt32LE=function(e,t,n){_(this,e,t,!0,n)},h.prototype.writeUInt32BE=function(e,t,n){_(this,e,t,!1,n)},h.prototype.writeInt8=function(e,t,n){n||(D(null!=e,"missing value"),D(null!=t,"missing offset"),D(t<this.length,"Trying to write beyond buffer length"),Y(e,127,-128)),t>=this.length||(0<=e?this.writeUInt8(e,t,n):this.writeUInt8(255+e+1,t,n))},h.prototype.writeInt16LE=function(e,t,n){E(this,e,t,!0,n)},h.prototype.writeInt16BE=function(e,t,n){E(this,e,t,!1,n)},h.prototype.writeInt32LE=function(e,t,n){I(this,e,t,!0,n)},h.prototype.writeInt32BE=function(e,t,n){I(this,e,t,!1,n)},h.prototype.writeFloatLE=function(e,t,n){A(this,e,t,!0,n)},h.prototype.writeFloatBE=function(e,t,n){A(this,e,t,!1,n)},h.prototype.writeDoubleLE=function(e,t,n){B(this,e,t,!0,n)},h.prototype.writeDoubleBE=function(e,t,n){B(this,e,t,!1,n)},h.prototype.fill=function(e,t,n){if(e=e||0,t=t||0,n=n||this.length,"string"==typeof e&&(e=e.charCodeAt(0)),D("number"==typeof e&&!isNaN(e),"value is not a number"),D(t<=n,"end < start"),n!==t&&0!==this.length){D(0<=t&&t<this.length,"start out of bounds"),D(0<=n&&n<=this.length,"end out of bounds");for(var r=t;r<n;r++)this[r]=e}},h.prototype.inspect=function(){for(var e=[],t=this.length,n=0;n<t;n++)if(e[n]=j(this[n]),n===H.INSPECT_MAX_BYTES){e[n+1]="...";break}return"<Buffer "+e.join(" ")+">"},h.prototype.toArrayBuffer=function(){if("undefined"==typeof Uint8Array)throw new Error("Buffer.toArrayBuffer not supported in this browser");if(h._useTypedArrays)return new h(this).buffer;for(var e=new Uint8Array(this.length),t=0,n=e.length;t<n;t+=1)e[t]=this[t];return e.buffer};var L=h.prototype;function U(e,t,n){return"number"!=typeof e?n:t<=(e=~~e)?t:0<=e||0<=(e+=t)?e:0}function x(e){return(e=~~Math.ceil(+e))<0?0:e}function S(e){return(Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)})(e)}function j(e){return e<16?"0"+e.toString(16):e.toString(16)}function C(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<=127)t.push(e.charCodeAt(n));else{var o=n;55296<=r&&r<=57343&&n++;for(var i=encodeURIComponent(e.slice(o,n+1)).substr(1).split("%"),u=0;u<i.length;u++)t.push(parseInt(i[u],16))}}return t}function k(e){return s.toByteArray(e)}function T(e,t,n,r){for(var o=0;o<r&&!(o+n>=t.length||o>=e.length);o++)t[o+n]=e[o];return o}function M(e){try{return decodeURIComponent(e)}catch(e){return String.fromCharCode(65533)}}function N(e,t){D("number"==typeof e,"cannot write a non-number as a number"),D(0<=e,"specified a negative value for writing an unsigned value"),D(e<=t,"value is larger than maximum value for type"),D(Math.floor(e)===e,"value has a fractional component")}function Y(e,t,n){D("number"==typeof e,"cannot write a non-number as a number"),D(e<=t,"value larger than maximum allowed value"),D(n<=e,"value smaller than minimum allowed value"),D(Math.floor(e)===e,"value has a fractional component")}function F(e,t,n){D("number"==typeof e,"cannot write a non-number as a number"),D(e<=t,"value larger than maximum allowed value"),D(n<=e,"value smaller than minimum allowed value")}function D(e,t){if(!e)throw new Error(t||"Failed assertion")}h._augment=function(e){return e._isBuffer=!0,e._get=e.get,e._set=e.set,e.get=L.get,e.set=L.set,e.write=L.write,e.toString=L.toString,e.toLocaleString=L.toString,e.toJSON=L.toJSON,e.copy=L.copy,e.slice=L.slice,e.readUInt8=L.readUInt8,e.readUInt16LE=L.readUInt16LE,e.readUInt16BE=L.readUInt16BE,e.readUInt32LE=L.readUInt32LE,e.readUInt32BE=L.readUInt32BE,e.readInt8=L.readInt8,e.readInt16LE=L.readInt16LE,e.readInt16BE=L.readInt16BE,e.readInt32LE=L.readInt32LE,e.readInt32BE=L.readInt32BE,e.readFloatLE=L.readFloatLE,e.readFloatBE=L.readFloatBE,e.readDoubleLE=L.readDoubleLE,e.readDoubleBE=L.readDoubleBE,e.writeUInt8=L.writeUInt8,e.writeUInt16LE=L.writeUInt16LE,e.writeUInt16BE=L.writeUInt16BE,e.writeUInt32LE=L.writeUInt32LE,e.writeUInt32BE=L.writeUInt32BE,e.writeInt8=L.writeInt8,e.writeInt16LE=L.writeInt16LE,e.writeInt16BE=L.writeInt16BE,e.writeInt32LE=L.writeInt32LE,e.writeInt32BE=L.writeInt32BE,e.writeFloatLE=L.writeFloatLE,e.writeFloatBE=L.writeFloatBE,e.writeDoubleLE=L.writeDoubleLE,e.writeDoubleBE=L.writeDoubleBE,e.fill=L.fill,e.inspect=L.inspect,e.toArrayBuffer=L.toArrayBuffer,e}}).call(this,O("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},O("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/buffer/index.js","/node_modules/gulp-browserify/node_modules/buffer")},{"base64-js":2,buffer:3,ieee754:11,lYpoI2:10}],4:[function(l,d,e){(function(e,t,u,n,r,o,i,a,s){u=l("buffer").Buffer;var f=4,c=new u(f);c.fill(0);d.exports={hash:function(e,t,n,r){return u.isBuffer(e)||(e=new u(e)),function(e,t,n){for(var r=new u(t),o=n?r.writeInt32BE:r.writeInt32LE,i=0;i<e.length;i++)o.call(r,e[i],4*i,!0);return r}(t(function(e,t){if(e.length%f!=0){var n=e.length+(f-e.length%f);e=u.concat([e,c],n)}for(var r=[],o=t?e.readInt32BE:e.readInt32LE,i=0;i<e.length;i+=f)r.push(o.call(e,i));return r}(e,r),8*e.length),n,r)}}}).call(this,l("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},l("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/helpers.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{buffer:3,lYpoI2:10}],5:[function(w,e,b){(function(e,t,a,n,r,o,i,u,s){a=w("buffer").Buffer;var f=w("./sha"),c=w("./sha256"),l=w("./rng"),d={sha1:f,sha256:c,md5:w("./md5")},h=64,p=new a(h);function g(e,r){var o=d[e=e||"sha1"],i=[];return o||y("algorithm:",e,"is not yet supported"),{update:function(e){return a.isBuffer(e)||(e=new a(e)),i.push(e),e.length,this},digest:function(e){var t=a.concat(i),n=r?function(e,t,n){a.isBuffer(t)||(t=new a(t)),a.isBuffer(n)||(n=new a(n)),t.length>h?t=e(t):t.length<h&&(t=a.concat([t,p],h));for(var r=new a(h),o=new a(h),i=0;i<h;i++)r[i]=54^t[i],o[i]=92^t[i];var u=e(a.concat([r,n]));return e(a.concat([o,u]))}(o,r,t):o(t);return i=null,e?n.toString(e):n}}}function y(){var e=[].slice.call(arguments).join(" ");throw new Error([e,"we accept pull requests","http://github.com/dominictarr/crypto-browserify"].join("\n"))}p.fill(0),b.createHash=function(e){return g(e)},b.createHmac=function(e,t){return g(e,t)},b.randomBytes=function(e,t){if(!t||!t.call)return new a(l(e));try{t.call(this,void 0,new a(l(e)))}catch(e){t(e)}},function(e,t){for(var n in e)t(e[n],n)}(["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman","pbkdf2"],function(e){b[e]=function(){y("sorry,",e,"is not implemented yet")}})}).call(this,w("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},w("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/index.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./md5":6,"./rng":7,"./sha":8,"./sha256":9,buffer:3,lYpoI2:10}],6:[function(w,b,e){(function(e,t,n,r,o,i,u,a,s){var f=w("./helpers");function c(e,t){e[t>>5]|=128<<t%32,e[14+(t+64>>>9<<4)]=t;for(var n=1732584193,r=-271733879,o=-1732584194,i=271733878,u=0;u<e.length;u+=16){var a=n,s=r,f=o,c=i;n=d(n,r,o,i,e[u+0],7,-680876936),i=d(i,n,r,o,e[u+1],12,-389564586),o=d(o,i,n,r,e[u+2],17,606105819),r=d(r,o,i,n,e[u+3],22,-1044525330),n=d(n,r,o,i,e[u+4],7,-176418897),i=d(i,n,r,o,e[u+5],12,1200080426),o=d(o,i,n,r,e[u+6],17,-1473231341),r=d(r,o,i,n,e[u+7],22,-45705983),n=d(n,r,o,i,e[u+8],7,1770035416),i=d(i,n,r,o,e[u+9],12,-1958414417),o=d(o,i,n,r,e[u+10],17,-42063),r=d(r,o,i,n,e[u+11],22,-1990404162),n=d(n,r,o,i,e[u+12],7,1804603682),i=d(i,n,r,o,e[u+13],12,-40341101),o=d(o,i,n,r,e[u+14],17,-1502002290),n=h(n,r=d(r,o,i,n,e[u+15],22,1236535329),o,i,e[u+1],5,-165796510),i=h(i,n,r,o,e[u+6],9,-1069501632),o=h(o,i,n,r,e[u+11],14,643717713),r=h(r,o,i,n,e[u+0],20,-373897302),n=h(n,r,o,i,e[u+5],5,-701558691),i=h(i,n,r,o,e[u+10],9,38016083),o=h(o,i,n,r,e[u+15],14,-660478335),r=h(r,o,i,n,e[u+4],20,-405537848),n=h(n,r,o,i,e[u+9],5,568446438),i=h(i,n,r,o,e[u+14],9,-1019803690),o=h(o,i,n,r,e[u+3],14,-187363961),r=h(r,o,i,n,e[u+8],20,1163531501),n=h(n,r,o,i,e[u+13],5,-1444681467),i=h(i,n,r,o,e[u+2],9,-51403784),o=h(o,i,n,r,e[u+7],14,1735328473),n=p(n,r=h(r,o,i,n,e[u+12],20,-1926607734),o,i,e[u+5],4,-378558),i=p(i,n,r,o,e[u+8],11,-2022574463),o=p(o,i,n,r,e[u+11],16,1839030562),r=p(r,o,i,n,e[u+14],23,-35309556),n=p(n,r,o,i,e[u+1],4,-1530992060),i=p(i,n,r,o,e[u+4],11,1272893353),o=p(o,i,n,r,e[u+7],16,-155497632),r=p(r,o,i,n,e[u+10],23,-1094730640),n=p(n,r,o,i,e[u+13],4,681279174),i=p(i,n,r,o,e[u+0],11,-358537222),o=p(o,i,n,r,e[u+3],16,-722521979),r=p(r,o,i,n,e[u+6],23,76029189),n=p(n,r,o,i,e[u+9],4,-640364487),i=p(i,n,r,o,e[u+12],11,-421815835),o=p(o,i,n,r,e[u+15],16,530742520),n=g(n,r=p(r,o,i,n,e[u+2],23,-995338651),o,i,e[u+0],6,-198630844),i=g(i,n,r,o,e[u+7],10,1126891415),o=g(o,i,n,r,e[u+14],15,-1416354905),r=g(r,o,i,n,e[u+5],21,-57434055),n=g(n,r,o,i,e[u+12],6,1700485571),i=g(i,n,r,o,e[u+3],10,-1894986606),o=g(o,i,n,r,e[u+10],15,-1051523),r=g(r,o,i,n,e[u+1],21,-2054922799),n=g(n,r,o,i,e[u+8],6,1873313359),i=g(i,n,r,o,e[u+15],10,-30611744),o=g(o,i,n,r,e[u+6],15,-1560198380),r=g(r,o,i,n,e[u+13],21,1309151649),n=g(n,r,o,i,e[u+4],6,-145523070),i=g(i,n,r,o,e[u+11],10,-1120210379),o=g(o,i,n,r,e[u+2],15,718787259),r=g(r,o,i,n,e[u+9],21,-343485551),n=y(n,a),r=y(r,s),o=y(o,f),i=y(i,c)}return Array(n,r,o,i)}function l(e,t,n,r,o,i){return y((u=y(y(t,e),y(r,i)))<<(a=o)|u>>>32-a,n);var u,a}function d(e,t,n,r,o,i,u){return l(t&n|~t&r,e,t,o,i,u)}function h(e,t,n,r,o,i,u){return l(t&r|n&~r,e,t,o,i,u)}function p(e,t,n,r,o,i,u){return l(t^n^r,e,t,o,i,u)}function g(e,t,n,r,o,i,u){return l(n^(t|~r),e,t,o,i,u)}function y(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}b.exports=function(e){return f.hash(e,c,16)}}).call(this,w("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},w("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/md5.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:10}],7:[function(e,l,t){(function(e,t,n,r,o,i,u,a,s){var f,c;f=function(e){for(var t,n=new Array(e),r=0;r<e;r++)0==(3&r)&&(t=4294967296*Math.random()),n[r]=t>>>((3&r)<<3)&255;return n},l.exports=c||f}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/rng.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{buffer:3,lYpoI2:10}],8:[function(l,d,e){(function(e,t,n,r,o,i,u,a,s){var f=l("./helpers");function c(e,t){e[t>>5]|=128<<24-t%32,e[15+(t+64>>9<<4)]=t;for(var n,r=Array(80),o=1732584193,i=-271733879,u=-1732584194,a=271733878,s=-1009589776,f=0;f<e.length;f+=16){for(var c=o,l=i,d=u,h=a,p=s,g=0;g<80;g++){r[g]=g<16?e[f+g]:m(r[g-3]^r[g-8]^r[g-14]^r[g-16],1);var y=b(b(m(o,5),w(g,i,u,a)),b(b(s,r[g]),(n=g)<20?1518500249:n<40?1859775393:n<60?-1894007588:-899497514));s=a,a=u,u=m(i,30),i=o,o=y}o=b(o,c),i=b(i,l),u=b(u,d),a=b(a,h),s=b(s,p)}return Array(o,i,u,a,s)}function w(e,t,n,r){return e<20?t&n|~t&r:!(e<40)&&e<60?t&n|t&r|n&r:t^n^r}function b(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function m(e,t){return e<<t|e>>>32-t}d.exports=function(e){return f.hash(e,c,20,!0)}}).call(this,l("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},l("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:10}],9:[function(l,d,e){(function(e,t,n,r,o,i,u,a,s){function B(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function L(e,t){return e>>>t|e<<32-t}function U(e,t){return e>>>t}function f(e,t){var n,r,o,i,u,a,s,f,c,l,d,h,p,g,y,w,b,m,v=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),_=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),E=new Array(64);e[t>>5]|=128<<24-t%32,e[15+(t+64>>9<<4)]=t;for(var I=0;I<e.length;I+=16){n=_[0],r=_[1],o=_[2],i=_[3],u=_[4],a=_[5],s=_[6],f=_[7];for(var A=0;A<64;A++)E[A]=A<16?e[A+I]:B(B(B((m=E[A-2],L(m,17)^L(m,19)^U(m,10)),E[A-7]),(b=E[A-15],L(b,7)^L(b,18)^U(b,3))),E[A-16]),c=B(B(B(B(f,L(w=u,6)^L(w,11)^L(w,25)),(y=u)&a^~y&s),v[A]),E[A]),l=B(L(g=n,2)^L(g,13)^L(g,22),(d=n)&(h=r)^d&(p=o)^h&p),f=s,s=a,a=u,u=B(i,c),i=o,o=r,r=n,n=B(c,l);_[0]=B(n,_[0]),_[1]=B(r,_[1]),_[2]=B(o,_[2]),_[3]=B(i,_[3]),_[4]=B(u,_[4]),_[5]=B(a,_[5]),_[6]=B(s,_[6]),_[7]=B(f,_[7])}return _}var c=l("./helpers");d.exports=function(e){return c.hash(e,f,32,!0)}}).call(this,l("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},l("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha256.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:10}],10:[function(e,c,t){(function(e,t,n,r,o,i,u,a,s){function f(){}(e=c.exports={}).nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){var t=e.source;t!==window&&null!==t||"process-tick"!==e.data||(e.stopPropagation(),0<n.length&&n.shift()())},!0),function(e){n.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),e.title="browser",e.browser=!0,e.env={},e.argv=[],e.on=f,e.addListener=f,e.once=f,e.off=f,e.removeListener=f,e.removeAllListeners=f,e.emit=f,e.binding=function(e){throw new Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(e){throw new Error("process.chdir is not supported")}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/process/browser.js","/node_modules/gulp-browserify/node_modules/process")},{buffer:3,lYpoI2:10}],11:[function(e,t,f){(function(e,t,n,r,o,i,u,a,s){f.read=function(e,t,n,r,o){var i,u,a=8*o-r-1,s=(1<<a)-1,f=s>>1,c=-7,l=n?o-1:0,d=n?-1:1,h=e[t+l];for(l+=d,i=h&(1<<-c)-1,h>>=-c,c+=a;0<c;i=256*i+e[t+l],l+=d,c-=8);for(u=i&(1<<-c)-1,i>>=-c,c+=r;0<c;u=256*u+e[t+l],l+=d,c-=8);if(0===i)i=1-f;else{if(i===s)return u?NaN:1/0*(h?-1:1);u+=Math.pow(2,r),i-=f}return(h?-1:1)*u*Math.pow(2,i-r)},f.write=function(e,t,n,r,o,i){var u,a,s,f=8*i-o-1,c=(1<<f)-1,l=c>>1,d=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?0:i-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,u=c):(u=Math.floor(Math.log(t)/Math.LN2),t*(s=Math.pow(2,-u))<1&&(u--,s*=2),2<=(t+=1<=u+l?d/s:d*Math.pow(2,1-l))*s&&(u++,s/=2),c<=u+l?(a=0,u=c):1<=u+l?(a=(t*s-1)*Math.pow(2,o),u+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,o),u=0));8<=o;e[n+h]=255&a,h+=p,a/=256,o-=8);for(u=u<<o|a,f+=o;0<f;e[n+h]=255&u,h+=p,u/=256,f-=8);e[n+h-p]|=128*g}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/ieee754/index.js","/node_modules/ieee754")},{buffer:3,lYpoI2:10}]},{},[1])(1)});
\ No newline at end of file
'use strict';
var crypto = require('crypto');
/**
* Exported function
*
* Options:
*
* - `algorithm` hash algo to be used by this instance: *'sha1', 'md5'
* - `excludeValues` {true|*false} hash object keys, values ignored
* - `encoding` hash encoding, supports 'buffer', '*hex', 'binary', 'base64'
* - `ignoreUnknown` {true|*false} ignore unknown object types
* - `replacer` optional function that replaces values before hashing
* - `respectFunctionProperties` {*true|false} consider function properties when hashing
* - `respectFunctionNames` {*true|false} consider 'name' property of functions for hashing
* - `respectType` {*true|false} Respect special properties (prototype, constructor)
* when hashing to distinguish between types
* - `unorderedArrays` {true|*false} Sort all arrays before hashing
* - `unorderedSets` {*true|false} Sort `Set` and `Map` instances before hashing
* * = default
*
* @param {object} object value to hash
* @param {object} options hashing options
* @return {string} hash value
* @api public
*/
exports = module.exports = objectHash;
function objectHash(object, options){
options = applyDefaults(object, options);
return hash(object, options);
}
/**
* Exported sugar methods
*
* @param {object} object value to hash
* @return {string} hash value
* @api public
*/
exports.sha1 = function(object){
return objectHash(object);
};
exports.keys = function(object){
return objectHash(object, {excludeValues: true, algorithm: 'sha1', encoding: 'hex'});
};
exports.MD5 = function(object){
return objectHash(object, {algorithm: 'md5', encoding: 'hex'});
};
exports.keysMD5 = function(object){
return objectHash(object, {algorithm: 'md5', encoding: 'hex', excludeValues: true});
};
// Internals
var hashes = crypto.getHashes ? crypto.getHashes().slice() : ['sha1', 'md5'];
hashes.push('passthrough');
var encodings = ['buffer', 'hex', 'binary', 'base64'];
function applyDefaults(object, sourceOptions){
sourceOptions = sourceOptions || {};
// create a copy rather than mutating
var options = {};
options.algorithm = sourceOptions.algorithm || 'sha1';
options.encoding = sourceOptions.encoding || 'hex';
options.excludeValues = sourceOptions.excludeValues ? true : false;
options.algorithm = options.algorithm.toLowerCase();
options.encoding = options.encoding.toLowerCase();
options.ignoreUnknown = sourceOptions.ignoreUnknown !== true ? false : true; // default to false
options.respectType = sourceOptions.respectType === false ? false : true; // default to true
options.respectFunctionNames = sourceOptions.respectFunctionNames === false ? false : true;
options.respectFunctionProperties = sourceOptions.respectFunctionProperties === false ? false : true;
options.unorderedArrays = sourceOptions.unorderedArrays !== true ? false : true; // default to false
options.unorderedSets = sourceOptions.unorderedSets === false ? false : true; // default to false
options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true; // default to true
options.replacer = sourceOptions.replacer || undefined;
options.excludeKeys = sourceOptions.excludeKeys || undefined;
if(typeof object === 'undefined') {
throw new Error('Object argument required.');
}
// if there is a case-insensitive match in the hashes list, accept it
// (i.e. SHA256 for sha256)
for (var i = 0; i < hashes.length; ++i) {
if (hashes[i].toLowerCase() === options.algorithm.toLowerCase()) {
options.algorithm = hashes[i];
}
}
if(hashes.indexOf(options.algorithm) === -1){
throw new Error('Algorithm "' + options.algorithm + '" not supported. ' +
'supported values: ' + hashes.join(', '));
}
if(encodings.indexOf(options.encoding) === -1 &&
options.algorithm !== 'passthrough'){
throw new Error('Encoding "' + options.encoding + '" not supported. ' +
'supported values: ' + encodings.join(', '));
}
return options;
}
/** Check if the given function is a native function */
function isNativeFunction(f) {
if ((typeof f) !== 'function') {
return false;
}
var exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i;
return exp.exec(Function.prototype.toString.call(f)) != null;
}
function hash(object, options) {
var hashingStream;
if (options.algorithm !== 'passthrough') {
hashingStream = crypto.createHash(options.algorithm);
} else {
hashingStream = new PassThrough();
}
if (typeof hashingStream.write === 'undefined') {
hashingStream.write = hashingStream.update;
hashingStream.end = hashingStream.update;
}
var hasher = typeHasher(options, hashingStream);
hasher.dispatch(object);
if (!hashingStream.update) {
hashingStream.end('');
}
if (hashingStream.digest) {
return hashingStream.digest(options.encoding === 'buffer' ? undefined : options.encoding);
}
var buf = hashingStream.read();
if (options.encoding === 'buffer') {
return buf;
}
return buf.toString(options.encoding);
}
/**
* Expose streaming API
*
* @param {object} object Value to serialize
* @param {object} options Options, as for hash()
* @param {object} stream A stream to write the serializiation to
* @api public
*/
exports.writeToStream = function(object, options, stream) {
if (typeof stream === 'undefined') {
stream = options;
options = {};
}
options = applyDefaults(object, options);
return typeHasher(options, stream).dispatch(object);
};
function typeHasher(options, writeTo, context){
context = context || [];
var write = function(str) {
if (writeTo.update) {
return writeTo.update(str, 'utf8');
} else {
return writeTo.write(str, 'utf8');
}
};
return {
dispatch: function(value){
if (options.replacer) {
value = options.replacer(value);
}
var type = typeof value;
if (value === null) {
type = 'null';
}
//console.log("[DEBUG] Dispatch: ", value, "->", type, " -> ", "_" + type);
return this['_' + type](value);
},
_object: function(object) {
var pattern = (/\[object (.*)\]/i);
var objString = Object.prototype.toString.call(object);
var objType = pattern.exec(objString);
if (!objType) { // object type did not match [object ...]
objType = 'unknown:[' + objString + ']';
} else {
objType = objType[1]; // take only the class name
}
objType = objType.toLowerCase();
var objectNumber = null;
if ((objectNumber = context.indexOf(object)) >= 0) {
return this.dispatch('[CIRCULAR:' + objectNumber + ']');
} else {
context.push(object);
}
if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(object)) {
write('buffer:');
return write(object);
}
if(objType !== 'object' && objType !== 'function' && objType !== 'asyncfunction') {
if(this['_' + objType]) {
this['_' + objType](object);
} else if (options.ignoreUnknown) {
return write('[' + objType + ']');
} else {
throw new Error('Unknown object type "' + objType + '"');
}
}else{
var keys = Object.keys(object);
if (options.unorderedObjects) {
keys = keys.sort();
}
// Make sure to incorporate special properties, so
// Types with different prototypes will produce
// a different hash and objects derived from
// different functions (`new Foo`, `new Bar`) will
// produce different hashes.
// We never do this for native functions since some
// seem to break because of that.
if (options.respectType !== false && !isNativeFunction(object)) {
keys.splice(0, 0, 'prototype', '__proto__', 'constructor');
}
if (options.excludeKeys) {
keys = keys.filter(function(key) { return !options.excludeKeys(key); });
}
write('object:' + keys.length + ':');
var self = this;
return keys.forEach(function(key){
self.dispatch(key);
write(':');
if(!options.excludeValues) {
self.dispatch(object[key]);
}
write(',');
});
}
},
_array: function(arr, unordered){
unordered = typeof unordered !== 'undefined' ? unordered :
options.unorderedArrays !== false; // default to options.unorderedArrays
var self = this;
write('array:' + arr.length + ':');
if (!unordered || arr.length <= 1) {
return arr.forEach(function(entry) {
return self.dispatch(entry);
});
}
// the unordered case is a little more complicated:
// since there is no canonical ordering on objects,
// i.e. {a:1} < {a:2} and {a:1} > {a:2} are both false,
// we first serialize each entry using a PassThrough stream
// before sorting.
// also: we can’t use the same context array for all entries
// since the order of hashing should *not* matter. instead,
// we keep track of the additions to a copy of the context array
// and add all of them to the global context array when we’re done
var contextAdditions = [];
var entries = arr.map(function(entry) {
var strm = new PassThrough();
var localContext = context.slice(); // make copy
var hasher = typeHasher(options, strm, localContext);
hasher.dispatch(entry);
// take only what was added to localContext and append it to contextAdditions
contextAdditions = contextAdditions.concat(localContext.slice(context.length));
return strm.read().toString();
});
context = context.concat(contextAdditions);
entries.sort();
return this._array(entries, false);
},
_date: function(date){
return write('date:' + date.toJSON());
},
_symbol: function(sym){
return write('symbol:' + sym.toString());
},
_error: function(err){
return write('error:' + err.toString());
},
_boolean: function(bool){
return write('bool:' + bool.toString());
},
_string: function(string){
write('string:' + string.length + ':');
write(string.toString());
},
_function: function(fn){
write('fn:');
if (isNativeFunction(fn)) {
this.dispatch('[native]');
} else {
this.dispatch(fn.toString());
}
if (options.respectFunctionNames !== false) {
// Make sure we can still distinguish native functions
// by their name, otherwise String and Function will
// have the same hash
this.dispatch("function-name:" + String(fn.name));
}
if (options.respectFunctionProperties) {
this._object(fn);
}
},
_number: function(number){
return write('number:' + number.toString());
},
_xml: function(xml){
return write('xml:' + xml.toString());
},
_null: function() {
return write('Null');
},
_undefined: function() {
return write('Undefined');
},
_regexp: function(regex){
return write('regex:' + regex.toString());
},
_uint8array: function(arr){
write('uint8array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_uint8clampedarray: function(arr){
write('uint8clampedarray:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_int8array: function(arr){
write('uint8array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_uint16array: function(arr){
write('uint16array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_int16array: function(arr){
write('uint16array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_uint32array: function(arr){
write('uint32array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_int32array: function(arr){
write('uint32array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_float32array: function(arr){
write('float32array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_float64array: function(arr){
write('float64array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_arraybuffer: function(arr){
write('arraybuffer:');
return this.dispatch(new Uint8Array(arr));
},
_url: function(url) {
return write('url:' + url.toString(), 'utf8');
},
_map: function(map) {
write('map:');
var arr = Array.from(map);
return this._array(arr, options.unorderedSets !== false);
},
_set: function(set) {
write('set:');
var arr = Array.from(set);
return this._array(arr, options.unorderedSets !== false);
},
_blob: function() {
if (options.ignoreUnknown) {
return write('[blob]');
}
throw Error('Hashing Blob objects is currently not supported\n' +
'(see https://github.com/puleos/object-hash/issues/26)\n' +
'Use "options.replacer" or "options.ignoreUnknown"\n');
},
_domwindow: function() { return write('domwindow'); },
/* Node.js standard native objects */
_process: function() { return write('process'); },
_timer: function() { return write('timer'); },
_pipe: function() { return write('pipe'); },
_tcp: function() { return write('tcp'); },
_udp: function() { return write('udp'); },
_tty: function() { return write('tty'); },
_statwatcher: function() { return write('statwatcher'); },
_securecontext: function() { return write('securecontext'); },
_connection: function() { return write('connection'); },
_zlib: function() { return write('zlib'); },
_context: function() { return write('context'); },
_nodescript: function() { return write('nodescript'); },
_httpparser: function() { return write('httpparser'); },
_dataview: function() { return write('dataview'); },
_signal: function() { return write('signal'); },
_fsevent: function() { return write('fsevent'); },
_tlswrap: function() { return write('tlswrap'); }
};
}
// Mini-implementation of stream.PassThrough
// We are far from having need for the full implementation, and we can
// make assumptions like "many writes, then only one final read"
// and we can ignore encoding specifics
function PassThrough() {
return {
buf: '',
write: function(b) {
this.buf += b;
},
end: function(b) {
this.buf += b;
},
read: function() {
return this.buf;
}
};
}
{
"_args": [
[
"object-hash@2.0.3",
"/private/var/www/db/coutch_db_create"
]
],
"_from": "object-hash@2.0.3",
"_id": "object-hash@2.0.3",
"_inBundle": false,
"_integrity": "sha512-JPKn0GMu+Fa3zt3Bmr66JhokJU5BaNBIh4ZeTlaCBzrBsOeXzwcKKAK1tbLiPKgvwmPXsDvvLHoWh5Bm7ofIYg==",
"_location": "/object-hash",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "object-hash@2.0.3",
"name": "object-hash",
"escapedName": "object-hash",
"rawSpec": "2.0.3",
"saveSpec": null,
"fetchSpec": "2.0.3"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.0.3.tgz",
"_spec": "2.0.3",
"_where": "/private/var/www/db/coutch_db_create",
"author": {
"name": "Scott Puleo",
"email": "puleos@gmail.com"
},
"browser": "./dist/object_hash.js",
"bugs": {
"url": "https://github.com/puleos/object-hash/issues"
},
"description": "Generate hashes from javascript objects in node and the browser.",
"devDependencies": {
"browserify": "^16.2.3",
"gulp": "^4.0.0",
"gulp-browserify": "^0.5.1",
"gulp-coveralls": "^0.1.4",
"gulp-exec": "^3.0.1",
"gulp-istanbul": "^1.1.3",
"gulp-jshint": "^2.0.0",
"gulp-mocha": "^5.0.0",
"gulp-rename": "^1.2.0",
"gulp-replace": "^1.0.0",
"gulp-uglify": "^3.0.0",
"jshint": "^2.8.0",
"jshint-stylish": "^2.1.0",
"karma": "^4.2.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"mocha": "^6.2.0"
},
"engines": {
"node": ">= 6"
},
"files": [
"index.js",
"dist/object_hash.js"
],
"homepage": "https://github.com/puleos/object-hash",
"keywords": [
"object",
"hash",
"sha1",
"md5"
],
"license": "MIT",
"main": "./index.js",
"name": "object-hash",
"repository": {
"type": "git",
"url": "git+https://github.com/puleos/object-hash.git"
},
"scripts": {
"prepublish": "gulp dist",
"test": "node ./node_modules/.bin/mocha test"
},
"version": "2.0.3"
}
# object-hash
Generate hashes from objects and values in node and the browser. Uses node.js
crypto module for hashing. Supports SHA1 and many others (depending on the platform)
as well as custom streams (e.g. CRC32).
[![NPM](https://nodei.co/npm/object-hash.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/object-hash)
[![Travis CI](https://secure.travis-ci.org/puleos/object-hash.png?branch=master)](https://secure.travis-ci.org/puleos/object-hash?branch=master)
[![Coverage Status](https://coveralls.io/repos/puleos/object-hash/badge.svg?branch=master&service=github)](https://coveralls.io/github/puleos/object-hash?branch=master)
* Hash values of any type.
* Supports a keys only option for grouping similar objects with different values.
```js
var hash = require('object-hash');
hash({foo: 'bar'}) // => '67b69634f9880a282c14a0f0cb7ba20cf5d677e9'
hash([1, 2, 2.718, 3.14159]) // => '136b9b88375971dff9f1af09d7356e3e04281951'
```
## Versioning Disclaimer
Starting with version `1.1.8` (released April 2017), new versions will consider
the exact returned hash part of the API contract, i.e. changes that will affect
hash values will be considered `semver-major`. Previous versions may violate
that expectation.
For more information, see [this discussion](https://github.com/puleos/object-hash/issues/30).
## hash(value, options);
Generate a hash from any object or type. Defaults to sha1 with hex encoding.
* `algorithm` hash algo to be used: 'sha1', 'md5'. default: sha1
* This supports the algorithms returned by `crypto.getHashes()`. Note that the default of SHA-1 is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
* `excludeValues` {true|false} hash object keys, values ignored. default: false
* `encoding` hash encoding, supports 'buffer', 'hex', 'binary', 'base64'. default: hex
* `ignoreUnknown` {true|*false} ignore unknown object types. default: false
* `replacer` optional function that replaces values before hashing. default: accept all values
* `respectFunctionProperties` {true|false} Whether properties on functions are considered when hashing. default: true
* `respectFunctionNames` {true|false} consider `name` property of functions for hashing. default: true
* `respectType` {true|false} Whether special type attributes (`.prototype`, `.__proto__`, `.constructor`)
are hashed. default: true
* `unorderedArrays` {true|false} Sort all arrays using before hashing. Note that this affects *all* collections,
i.e. including typed arrays, Sets, Maps, etc. default: false
* `unorderedSets` {true|false} Sort `Set` and `Map` instances before hashing, i.e. make
`hash(new Set([1, 2])) == hash(new Set([2, 1]))` return `true`. default: true
* `unorderedObjects` {true|false} Sort objects before hashing, i.e. make `hash({ x: 1, y: 2 }) === hash({ y: 2, x: 1 })`. default: true
* `excludeKeys` optional function for exclude specific key(s) from hashing, if returns true then exclude from hash. default: include all keys
## hash.sha1(value);
Hash using the sha1 algorithm.
Note that SHA-1 is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
*Sugar method, equivalent to hash(value, {algorithm: 'sha1'})*
## hash.keys(value);
Hash object keys using the sha1 algorithm, values ignored.
*Sugar method, equivalent to hash(value, {excludeValues: true})*
## hash.MD5(value);
Hash using the md5 algorithm.
Note that the MD5 is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
*Sugar method, equivalent to hash(value, {algorithm: 'md5'})*
## hash.keysMD5(value);
Hash object keys using the md5 algorithm, values ignored.
Note that the MD5 is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
*Sugar method, equivalent to hash(value, {algorithm: 'md5', excludeValues: true})*
## hash.writeToStream(value, [options,] stream):
Write the information that would otherwise have been hashed to a stream, e.g.:
```js
hash.writeToStream({foo: 'bar', a: 42}, {respectType: false}, process.stdout)
// => e.g. 'object:a:number:42foo:string:bar'
```
## Installation
node:
```js
npm install object-hash
```
browser: */dist/object_hash.js*
```
<script src="object_hash.js" type="text/javascript"></script>
<script>
var hash = objectHash.sha1({foo:'bar'});
console.log(hash); // e003c89cdf35cdf46d8239b4692436364b7259f9
</script>
```
## Example usage
```js
var hash = require('object-hash');
var peter = {name: 'Peter', stapler: false, friends: ['Joanna', 'Michael', 'Samir'] };
var michael = {name: 'Michael', stapler: false, friends: ['Peter', 'Samir'] };
var bob = {name: 'Bob', stapler: true, friends: [] };
/***
* sha1 hex encoding (default)
*/
hash(peter);
// 14fa461bf4b98155e82adc86532938553b4d33a9
hash(michael);
// 4b2b30e27699979ce46714253bc2213010db039c
hash(bob);
// 38d96106bc8ef3d8bd369b99bb6972702c9826d5
/***
* hash object keys, values ignored
*/
hash(peter, { excludeValues: true });
// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c
hash(michael, { excludeValues: true });
// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c
hash.keys(bob);
// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c
/***
* hash object, ignore specific key(s)
*/
hash(peter, { excludeKeys: function(key) {
if ( key === 'friends') {
return true;
}
return false;
}
});
// 66b7d7e64871aa9fda1bdc8e88a28df797648d80
/***
* md5 base64 encoding
*/
hash(peter, { algorithm: 'md5', encoding: 'base64' });
// 6rkWaaDiG3NynWw4svGH7g==
hash(michael, { algorithm: 'md5', encoding: 'base64' });
// djXaWpuWVJeOF8Sb6SFFNg==
hash(bob, { algorithm: 'md5', encoding: 'base64' });
// lFzkw/IJ8/12jZI0rQeS3w==
```
## Legacy Browser Support
IE <= 8 and Opera <= 11 support dropped in version 0.3.0. If you require
legacy browser support you must either use an ES5 shim or use version 0.2.5
of this module.
## Development
```
git clone https://github.com/puleos/object-hash
```
## Node Docker Wrapper
If you want to stand this up in a docker container, you should take at look
at the [![node-object-hash](https://github.com/bean5/node-object-hash)](https://github.com/bean5/node-object-hash) project.
### gulp tasks
* `gulp watch` (default) watch files, test and lint on change/add
* `gulp test` unit tests
* `gulp karma` browser unit tests
* `gulp lint` jshint
* `gulp dist` create browser version in /dist
## License
MIT
## Changelog
### v2.0.0
Only Node.js versions `>= 6.0.0` are being tested in CI now.
No other breaking changes were introduced.
node_modules
\ No newline at end of file
test:
@./node_modules/.bin/mocha \
--reporter spec \
--bail
.PHONY: test
\ No newline at end of file
{
"name": "typecast",
"repo": "eivindfjeldstad/typecast",
"description": "Simple typecasting",
"version": "0.0.1",
"license": "MIT",
"main": "index.js",
"scripts": [
"index.js"
]
}
\ No newline at end of file
module.exports = typecast;
/**
* Cast given `val` to `type`
*
* @param {Mixed} val
* @param {String} type
* @api public
*/
function typecast (val, type) {
var fn = typecast[type];
if (typeof fn != 'function') throw new Error('cannot cast to ' + type);
return fn(val);
}
/**
* Cast `val` to `String`
*
* @param {Mixed} val
* @api public
*/
typecast.string = function (val) {
return val.toString();
};
/**
* Cast `val` to `Number`
*
* @param {Mixed} val
* @api public
*/
typecast.number = function (val) {
var num = parseFloat(val);
return isNaN(num)
? null
: num;
};
/**
* Cast `val` to a`Date`
*
* @param {Mixed} val
* @api public
*/
typecast.date = function (val) {
var date = new Date(val);
return isNaN(date.valueOf())
? null
: date;
};
/**
* Cast `val` to `Array`
*
* @param {Mixed} val
* @api public
*/
typecast.array = function (val) {
if (val instanceof Array) return val;
var arr = val.toString().split(',');
for (var i = 0; i < arr.length; i++) {
arr[i] = arr[i].trim();
}
return arr;
};
/**
* Cast `val` to `Boolean`
*
* @param {Mixed} val
* @api public
*/
typecast.boolean = function (val) {
return !! val && val !== 'false';
};
\ No newline at end of file
{
"_args": [
[
"typecast@0.0.1",
"/private/var/www/db/coutch_db_create"
]
],
"_from": "typecast@0.0.1",
"_id": "typecast@0.0.1",
"_inBundle": false,
"_integrity": "sha1-//t13La98d744pO2tuiT1sHtGd4=",
"_location": "/typecast",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "typecast@0.0.1",
"name": "typecast",
"escapedName": "typecast",
"rawSpec": "0.0.1",
"saveSpec": null,
"fetchSpec": "0.0.1"
},
"_requiredBy": [
"/validate"
],
"_resolved": "https://registry.npmjs.org/typecast/-/typecast-0.0.1.tgz",
"_spec": "0.0.1",
"_where": "/private/var/www/db/coutch_db_create",
"bugs": {
"url": "https://github.com/eivindfjeldstad/typecast/issues"
},
"description": "Simple typecasting",
"devDependencies": {
"mocha": "~1.17.0"
},
"homepage": "https://github.com/eivindfjeldstad/typecast#readme",
"license": "MIT",
"name": "typecast",
"repository": {
"type": "git",
"url": "git+https://github.com/eivindfjeldstad/typecast.git"
},
"version": "0.0.1"
}
#typecast
Simple typecasting in javascript.
##Example
```js
var typecast = require('typecast');
typecast(123, 'string') // => '123'
typecast('123', 'number') // => 123
typecast('a, b, c', 'array') // => ['a', 'b', 'c']
typecast('false', 'boolean') // => false
```
##API
###typecast(val, type)
Cast given `val` to `type`
###.string(val)
Cast `val` to `String`
###.number(val)
Cast `val` to `Number`
###.array(val)
Cast `val` to `Array`
###.boolean(val)
Cast `val` to `Boolean`
##Licence
MIT
\ No newline at end of file
var typecast = require('./');
var assert = require('assert');
describe('.string()', function () {
it('should return a string', function () {
assert(typecast.string(2) === '2');
assert(typeof typecast.string({}) == 'string');
})
})
describe('.number()', function () {
it('should return a number', function () {
assert(typecast.number('123') === 123);
})
it('should return null if typecasting fails', function () {
assert(typecast.number('abc') === null);
})
})
describe('.date()', function () {
it('should return a date', function () {
assert(typecast.date('2010 10 01').valueOf() === 1285884000000);
})
it('should return null if typecasting fails', function () {
assert(typecast.date('abc') === null);
})
})
describe('.array()', function () {
it('should return an array', function () {
var arr = [1, 2, 3];
assert(typecast.array(arr) === arr);
assert(typecast.array(1) instanceof Array);
assert(typecast.array('a, b, c').length == 3);
assert(typecast.array('a, b, c')[1] === 'b');
})
})
describe('.boolean()', function () {
it('should return a boolean', function () {
assert(typecast.boolean('abc') === true);
assert(typecast.boolean(0) === false);
assert(typecast.boolean('false') === false);
})
})
describe('typecast()', function () {
it('should work', function () {
assert(typecast(123, 'string') === '123');
});
it('should throw when given an invalid type', function () {
var err;
try {
typecast(1, 'invalid');
} catch (e) {
err = e;
}
assert(err);
});
});
\ No newline at end of file
MIT License
Copyright (c) 2018 Eivind Fjeldstad
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* Custom errors.
*
* @private
*/
var ValidationError =
/*#__PURE__*/
function (_Error) {
_inherits(ValidationError, _Error);
function ValidationError(message, path) {
var _this;
_classCallCheck(this, ValidationError);
_this = _possibleConstructorReturn(this, _getPrototypeOf(ValidationError).call(this, message));
defineProp(_assertThisInitialized(_this), 'path', path);
defineProp(_assertThisInitialized(_this), 'expose', true);
defineProp(_assertThisInitialized(_this), 'status', 400);
if (Error.captureStackTrace) {
Error.captureStackTrace(_assertThisInitialized(_this), ValidationError);
}
return _this;
}
return ValidationError;
}(_wrapNativeSuper(Error));
exports["default"] = ValidationError;
var defineProp = function defineProp(obj, prop, val) {
Object.defineProperty(obj, prop, {
enumerable: false,
configurable: true,
writable: true,
value: val
});
};
module.exports = exports.default;
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
/**
* Default error messages.
*
* @private
*/
var Messages = {
// Type message
type: function type(prop, ctx, _type) {
if (typeof _type == 'function') {
_type = _type.name;
}
return "".concat(prop, " must be of type ").concat(_type, ".");
},
// Required message
required: function required(prop) {
return "".concat(prop, " is required.");
},
// Match message
match: function match(prop, ctx, regexp) {
return "".concat(prop, " must match ").concat(regexp, ".");
},
// Length message
length: function length(prop, ctx, len) {
if (typeof len == 'number') {
return "".concat(prop, " must have a length of ").concat(len, ".");
}
var min = len.min,
max = len.max;
if (min && max) {
return "".concat(prop, " must have a length between ").concat(min, " and ").concat(max, ".");
}
if (max) {
return "".concat(prop, " must have a maximum length of ").concat(max, ".");
}
if (min) {
return "".concat(prop, " must have a minimum length of ").concat(min, ".");
}
},
// Size message
size: function size(prop, ctx, _size) {
if (typeof _size == 'number') {
return "".concat(prop, " must have a size of ").concat(_size, ".");
}
var min = _size.min,
max = _size.max;
if (min !== undefined && max !== undefined) {
return "".concat(prop, " must be between ").concat(min, " and ").concat(max, ".");
}
if (max !== undefined) {
return "".concat(prop, " must be less than ").concat(max, ".");
}
if (min !== undefined) {
return "".concat(prop, " must be greater than ").concat(min, ".");
}
},
// Enum message
"enum": function _enum(prop, ctx, enums) {
var copy = enums.slice();
var last = copy.pop();
return "".concat(prop, " must be either ").concat(copy.join(', '), " or ").concat(last, ".");
},
// Default message
"default": function _default(prop) {
return "Validation failed for ".concat(prop, ".");
}
};
var _default2 = Messages;
exports["default"] = _default2;
module.exports = exports.default;
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _error2 = _interopRequireDefault(require("./error"));
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* A property instance gets returned whenever you call `schema.path()`.
* Properties are also created internally when an object is passed to the Schema constructor.
*
* @param {String} name - the name of the property
* @param {Schema} schema - parent schema
*/
var Property =
/*#__PURE__*/
function () {
function Property(name, schema) {
_classCallCheck(this, Property);
this.name = name;
this.registry = {};
this._schema = schema;
this._type = null;
this.messages = {};
}
/**
* Registers messages.
*
* @example
* prop.message('something is wrong')
* prop.message({ required: 'thing is required.' })
*
* @param {Object|String} messages
* @return {Property}
*/
_createClass(Property, [{
key: "message",
value: function message(messages) {
if (typeof messages == 'string') {
messages = {
"default": messages
};
}
var entries = Object.entries(messages);
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
var _entries$_i = _slicedToArray(_entries[_i], 2),
key = _entries$_i[0],
val = _entries$_i[1];
this.messages[key] = val;
}
return this;
}
/**
* Mount given `schema` on current path.
*
* @example
* const user = new Schema({ email: String })
* prop.schema(user)
*
* @param {Schema} schema - the schema to mount
* @return {Property}
*/
}, {
key: "schema",
value: function schema(_schema) {
this._schema.path(this.name, _schema);
return this;
}
/**
* Validate using named functions from the given object.
* Error messages can be defined by providing an object with
* named error messages/generators to `schema.message()`
*
* The message generator receives the value being validated,
* the object it belongs to and any additional arguments.
*
* @example
* const schema = new Schema()
* const prop = schema.path('some.path')
*
* schema.message({
* binary: (path, ctx) => `${path} must be binary.`,
* bits: (path, ctx, bits) => `${path} must be ${bits}-bit`
* })
*
* prop.use({
* binary: (val, ctx) => /^[01]+$/i.test(val),
* bits: [(val, ctx, bits) => val.length == bits, 32]
* })
*
* @param {Object} fns - object with named validation functions to call
* @return {Property}
*/
}, {
key: "use",
value: function use(fns) {
var _this = this;
Object.keys(fns).forEach(function (name) {
var arr = fns[name];
if (!Array.isArray(arr)) arr = [arr];
var fn = arr.shift();
_this._register(name, arr, fn);
});
return this;
}
/**
* Registers a validator that checks for presence.
*
* @example
* prop.required()
*
* @param {Boolean} [bool] - `true` if required, `false` otherwise
* @return {Property}
*/
}, {
key: "required",
value: function required() {
var bool = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
return this._register('required', [bool]);
}
/**
* Registers a validator that checks if a value is of a given `type`
*
* @example
* prop.type(String)
*
* @example
* prop.type('string')
*
* @param {String|Function} type - type to check for
* @return {Property}
*/
}, {
key: "type",
value: function type(_type) {
this._type = _type;
return this._register('type', [_type]);
}
/**
* Convenience method for setting type to `String`
*
* @example
* prop.string()
*
* @return {Property}
*/
}, {
key: "string",
value: function string() {
return this.type(String);
}
/**
* Convenience method for setting type to `Number`
*
* @example
* prop.number()
*
* @return {Property}
*/
}, {
key: "number",
value: function number() {
return this.type(Number);
}
/**
* Convenience method for setting type to `Array`
*
* @example
* prop.array()
*
* @return {Property}
*/
}, {
key: "array",
value: function array() {
return this.type(Array);
}
/**
* Convenience method for setting type to `Date`
*
* @example
* prop.date()
*
* @return {Property}
*/
}, {
key: "date",
value: function date() {
return this.type(Date);
}
/**
* Registers a validator that checks length.
*
* @example
* prop.length({ min: 8, max: 255 })
* prop.length(10)
*
* @param {Object|Number} rules - object with `.min` and `.max` properties or a number
* @param {Number} rules.min - minimum length
* @param {Number} rules.max - maximum length
* @return {Property}
*/
}, {
key: "length",
value: function length(rules) {
return this._register('length', [rules]);
}
/**
* Registers a validator that checks size.
*
* @example
* prop.size({ min: 8, max: 255 })
* prop.size(10)
*
* @param {Object|Number} rules - object with `.min` and `.max` properties or a number
* @param {Number} rules.min - minimum size
* @param {Number} rules.max - maximum size
* @return {Property}
*/
}, {
key: "size",
value: function size(rules) {
return this._register('size', [rules]);
}
/**
* Registers a validator for enums.
*
* @example
* prop.enum(['cat', 'dog'])
*
* @param {Array} rules - allowed values
* @return {Property}
*/
}, {
key: "enum",
value: function _enum(enums) {
return this._register('enum', [enums]);
}
/**
* Registers a validator that checks if a value matches given `regexp`.
*
* @example
* prop.match(/some\sregular\sexpression/)
*
* @param {RegExp} regexp - regular expression to match
* @return {Property}
*/
}, {
key: "match",
value: function match(regexp) {
return this._register('match', [regexp]);
}
/**
* Registers a validator that checks each value in an array against given `rules`.
*
* @example
* prop.each({ type: String })
* prop.each([{ type: Number }])
* prop.each({ things: [{ type: String }]})
* prop.each(schema)
*
* @param {Array|Object|Schema|Property} rules - rules to use
* @return {Property}
*/
}, {
key: "each",
value: function each(rules) {
this._schema.path((0, _utils.join)('$', this.name), rules);
return this;
}
/**
* Registers paths for array elements on the parent schema, with given array of rules.
*
* @example
* prop.elements([{ type: String }, { type: Number }])
*
* @param {Array} arr - array of rules to use
* @return {Property}
*/
}, {
key: "elements",
value: function elements(arr) {
var _this2 = this;
arr.forEach(function (rules, i) {
_this2._schema.path((0, _utils.join)(i, _this2.name), rules);
});
return this;
}
/**
* Registers all properties from the given object as nested properties
*
* @example
* prop.properties({
* name: String,
* email: String
* })
*
* @param {Object} props - properties with rules
* @return {Property}
*/
}, {
key: "properties",
value: function properties(props) {
for (var _i2 = 0, _Object$entries = Object.entries(props); _i2 < _Object$entries.length; _i2++) {
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
prop = _Object$entries$_i[0],
rule = _Object$entries$_i[1];
this._schema.path((0, _utils.join)(prop, this.name), rule);
}
return this;
}
/**
* Proxy method for schema path. Makes chaining properties together easier.
*
* @example
* schema
* .path('name').type(String).required()
* .path('email').type(String).required()
*
*/
}, {
key: "path",
value: function path() {
var _this$_schema;
return (_this$_schema = this._schema).path.apply(_this$_schema, arguments);
}
/**
* Typecast given `value`
*
* @example
* prop.type(String)
* prop.typecast(123) // => '123'
*
* @param {Mixed} value - value to typecast
* @return {Mixed}
*/
}, {
key: "typecast",
value: function typecast(value) {
var schema = this._schema;
var type = this._type;
if (!type) return value;
if (typeof type == 'function') {
type = type.name;
}
var cast = schema.typecasters[type] || schema.typecasters[type.toLowerCase()];
if (typeof cast != 'function') {
throw new Error("Typecasting failed: No typecaster defined for ".concat(type, "."));
}
return cast(value);
}
/**
* Validate given `value`
*
* @example
* prop.type(Number)
* assert(prop.validate(2) == null)
* assert(prop.validate('hello world') instanceof Error)
*
* @param {Mixed} value - value to validate
* @param {Object} ctx - the object containing the value
* @param {String} [path] - path of the value being validated
* @return {ValidationError}
*/
}, {
key: "validate",
value: function validate(value, ctx) {
var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.name;
var types = Object.keys(this.registry);
for (var _i3 = 0, _types = types; _i3 < _types.length; _i3++) {
var type = _types[_i3];
var err = this._run(type, value, ctx, path);
if (err) return err;
}
return null;
}
/**
* Run validator of given `type`
*
* @param {String} type - type of validator
* @param {Mixed} value - value to validate
* @param {Object} ctx - the object containing the value
* @param {String} path - path of the value being validated
* @return {ValidationError}
* @private
*/
}, {
key: "_run",
value: function _run(type, value, ctx, path) {
if (!this.registry[type]) return;
var schema = this._schema;
var _this$registry$type = this.registry[type],
args = _this$registry$type.args,
fn = _this$registry$type.fn;
var validator = fn || schema.validators[type];
var valid = validator.apply(void 0, [value, ctx].concat(_toConsumableArray(args), [path]));
if (!valid) return this._error(type, ctx, args, path);
}
/**
* Register validator
*
* @param {String} type - type of validator
* @param {Array} args - argument to pass to validator
* @param {Function} [fn] - custom validation function to call
* @return {Property}
* @private
*/
}, {
key: "_register",
value: function _register(type, args, fn) {
this.registry[type] = {
args: args,
fn: fn
};
return this;
}
/**
* Create an error
*
* @param {String} type - type of validator
* @param {Object} ctx - the object containing the value
* @param {Array} args - arguments to pass
* @param {String} path - path of the value being validated
* @return {ValidationError}
* @private
*/
}, {
key: "_error",
value: function _error(type, ctx, args, path) {
var schema = this._schema;
var message = this.messages[type] || this.messages["default"] || schema.messages[type] || schema.messages["default"];
if (typeof message == 'function') {
message = message.apply(void 0, [path, ctx].concat(_toConsumableArray(args)));
}
return new _error2["default"](message, path);
}
}]);
return Property;
}();
exports["default"] = Property;
module.exports = exports.default;
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _componentType = _interopRequireDefault(require("component-type"));
var _eivindfjeldstadDot = _interopRequireDefault(require("eivindfjeldstad-dot"));
var _typecast = _interopRequireDefault(require("typecast"));
var _property = _interopRequireDefault(require("./property"));
var _messages = _interopRequireDefault(require("./messages"));
var _validators = _interopRequireDefault(require("./validators"));
var _error = _interopRequireDefault(require("./error"));
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* A Schema defines the structure that objects should be validated against.
*
* @example
* const post = new Schema({
* title: {
* type: String,
* required: true,
* length: { min: 1, max: 255 }
* },
* content: {
* type: String,
* required: true
* },
* published: {
* type: Date,
* required: true
* },
* keywords: [{ type: String }]
* })
*
* @example
* const author = new Schema({
* name: {
* type: String,
* required: true
* },
* email: {
* type: String,
* required: true
* },
* posts: [post]
* })
*
* @param {Object} [obj] - schema definition
* @param {Object} [opts] - options
* @param {Boolean} [opts.typecast=false] - typecast values before validation
* @param {Boolean} [opts.strip=true] - strip properties not defined in the schema
*/
var Schema =
/*#__PURE__*/
function () {
function Schema() {
var _this = this;
var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Schema);
this.opts = opts;
this.hooks = [];
this.props = {};
this.messages = Object.assign({}, _messages["default"]);
this.validators = Object.assign({}, _validators["default"]);
this.typecasters = Object.assign({}, _typecast["default"]);
Object.keys(obj).forEach(function (k) {
return _this.path(k, obj[k]);
});
}
/**
* Create or update `path` with given `rules`.
*
* @example
* const schema = new Schema()
* schema.path('name.first', { type: String })
* schema.path('name.last').type(String).required()
*
* @param {String} path - full path using dot-notation
* @param {Object|Array|String|Schema|Property} [rules] - rules to apply
* @return {Property}
*/
_createClass(Schema, [{
key: "path",
value: function path(_path, rules) {
var _this2 = this;
var parts = _path.split('.');
var suffix = parts.pop();
var prefix = parts.join('.'); // Make sure full path is created
if (prefix) {
this.path(prefix);
} // Array index placeholder
if (suffix === '$') {
this.path(prefix).type(Array);
} // Nested schema
if (rules instanceof Schema) {
rules.hook(function (k, v) {
return _this2.path((0, _utils.join)(k, _path), v);
});
return this.path(_path, rules.props);
} // Return early when given a `Property`
if (rules instanceof _property["default"]) {
this.props[_path] = rules; // Notify parents if mounted
this.propagate(_path, rules);
return rules;
}
var prop = this.props[_path] || new _property["default"](_path, this);
this.props[_path] = prop; // Notify parents if mounted
this.propagate(_path, prop); // No rules?
if (!rules) return prop; // type shorthand
// `{ name: String }`
if (typeof rules == 'string' || typeof rules == 'function') {
prop.type(rules);
return prop;
} // Allow arrays to be passed implicitly:
// `{ keywords: [String] }`
// `{ keyVal: [[String, Number]] }`
if (Array.isArray(rules)) {
prop.type(Array);
if (rules.length === 1) {
prop.each(rules[0]);
} else {
prop.elements(rules);
}
return prop;
}
var nested = false; // Check for nested objects
for (var key in rules) {
if (!rules.hasOwnProperty(key)) continue;
if (typeof prop[key] == 'function') continue;
prop.type(Object);
nested = true;
break;
}
Object.keys(rules).forEach(function (key) {
var rule = rules[key];
if (nested) {
return _this2.path((0, _utils.join)(key, _path), rule);
}
prop[key](rule);
});
return prop;
}
/**
* Typecast given `obj`.
*
* @param {Object} obj - the object to typecast
* @return {Schema}
* @private
*/
}, {
key: "typecast",
value: function typecast(obj) {
var _loop = function _loop() {
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
path = _Object$entries$_i[0],
prop = _Object$entries$_i[1];
(0, _utils.walk)(path, obj, function (key, value) {
if (value == null) return;
var cast = prop.typecast(value);
if (cast === value) return;
_eivindfjeldstadDot["default"].set(obj, key, cast);
});
};
for (var _i = 0, _Object$entries = Object.entries(this.props); _i < _Object$entries.length; _i++) {
_loop();
}
return this;
}
/**
* Strip all keys not defined in the schema
*
* @param {Object} obj - the object to strip
* @param {String} [prefix]
* @return {Schema}
* @private
*/
}, {
key: "strip",
value: function strip(obj, prefix) {
var _this3 = this;
var type = (0, _componentType["default"])(obj);
if (type === 'array') {
obj.forEach(function (v, i) {
return _this3.strip(v, (0, _utils.join)('$', prefix));
});
return this;
}
if (type !== 'object') {
return this;
}
for (var _i2 = 0, _Object$entries2 = Object.entries(obj); _i2 < _Object$entries2.length; _i2++) {
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
key = _Object$entries2$_i[0],
val = _Object$entries2$_i[1];
var path = (0, _utils.join)(key, prefix);
if (!this.props[path]) {
delete obj[key];
continue;
}
this.strip(val, path);
}
return this;
}
/**
* Validate given `obj`.
*
* @example
* const schema = new Schema({ name: { required: true }})
* const errors = schema.validate({})
* assert(errors.length == 1)
* assert(errors[0].message == 'name is required')
* assert(errors[0].path == 'name')
*
* @param {Object} obj - the object to validate
* @param {Object} [opts] - options, see [Schema](#schema-1)
* @return {Array}
*/
}, {
key: "validate",
value: function validate(obj) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
opts = Object.assign(this.opts, opts);
var errors = [];
if (opts.typecast) {
this.typecast(obj);
}
if (opts.strip !== false) {
this.strip(obj);
}
var _loop2 = function _loop2() {
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
path = _Object$entries3$_i[0],
prop = _Object$entries3$_i[1];
(0, _utils.walk)(path, obj, function (key, value) {
var err = prop.validate(value, obj, key);
if (err) errors.push(err);
});
};
for (var _i3 = 0, _Object$entries3 = Object.entries(this.props); _i3 < _Object$entries3.length; _i3++) {
_loop2();
}
return errors;
}
/**
* Assert that given `obj` is valid.
*
* @example
* const schema = new Schema({ name: String })
* schema.assert({ name: 1 }) // Throws an error
*
* @param {Object} obj
* @param {Object} [opts]
*/
}, {
key: "assert",
value: function assert(obj, opts) {
var _this$validate = this.validate(obj, opts),
_this$validate2 = _slicedToArray(_this$validate, 1),
err = _this$validate2[0];
if (err) throw err;
}
/**
* Override default error messages.
*
* @example
* const hex = (val) => /^0x[0-9a-f]+$/.test(val)
* schema.path('some.path').use({ hex })
* schema.message('hex', path => `${path} must be hexadecimal`)
*
* @example
* schema.message({ hex: path => `${path} must be hexadecimal` })
*
* @param {String|Object} name - name of the validator or an object with name-message pairs
* @param {String|Function} [message] - the message or message generator to use
* @return {Schema}
*/
}, {
key: "message",
value: function message(name, _message) {
(0, _utils.assign)(name, _message, this.messages);
return this;
}
/**
* Override default validators.
*
* @example
* schema.validator('required', val => val != null)
*
* @example
* schema.validator({ required: val => val != null })
*
* @param {String|Object} name - name of the validator or an object with name-function pairs
* @param {Function} [fn] - the function to use
* @return {Schema}
*/
}, {
key: "validator",
value: function validator(name, fn) {
(0, _utils.assign)(name, fn, this.validators);
return this;
}
/**
* Override default typecasters.
*
* @example
* schema.typecaster('SomeClass', val => new SomeClass(val))
*
* @example
* schema.typecaster({ SomeClass: val => new SomeClass(val) })
*
* @param {String|Object} name - name of the validator or an object with name-function pairs
* @param {Function} [fn] - the function to use
* @return {Schema}
*/
}, {
key: "typecaster",
value: function typecaster(name, fn) {
(0, _utils.assign)(name, fn, this.typecasters);
return this;
}
/**
* Accepts a function that is called whenever new props are added.
*
* @param {Function} fn - the function to call
* @return {Schema}
* @private
*/
}, {
key: "hook",
value: function hook(fn) {
this.hooks.push(fn);
return this;
}
/**
* Notify all subscribers that a property has been added.
*
* @param {String} path - the path of the property
* @param {Property} prop - the new property
* @return {Schema}
* @private
*/
}, {
key: "propagate",
value: function propagate(path, prop) {
this.hooks.forEach(function (fn) {
return fn(path, prop);
});
return this;
}
}]);
return Schema;
}(); // Export ValidationError
exports["default"] = Schema;
Schema.ValidationError = _error["default"];
module.exports = exports.default;
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.assign = assign;
exports.walk = walk;
exports.join = join;
var _eivindfjeldstadDot = _interopRequireDefault(require("eivindfjeldstad-dot"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Assign given key and value (or object) to given object
*
* @private
*/
function assign(key, val, obj) {
if (typeof key == 'string') {
obj[key] = val;
return;
}
Object.keys(key).forEach(function (k) {
return obj[k] = key[k];
});
}
/**
* Walk path
*
* @private
*/
function walk(path, obj, callback) {
var parts = path.split(/\.\$(?=\.|$)/);
var first = parts.shift();
var arr = _eivindfjeldstadDot["default"].get(obj, first);
if (!parts.length) {
return callback(first, arr);
}
if (!Array.isArray(arr)) {
return;
}
for (var i = 0; i < arr.length; i++) {
var current = join(i, first);
var next = current + parts.join('.$');
walk(next, obj, callback);
}
}
/**
* Join `path` with `prefix`
*
* @private
*/
function join(path, prefix) {
return prefix ? "".concat(prefix, ".").concat(path) : path;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _componentType = _interopRequireDefault(require("component-type"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Default validators.
*
* @private
*/
var Validators = {
/**
* Validates presence.
*
* @param {Mixed} value - the value being validated
* @param {Object} ctx - the object being validated
* @param {Bolean} required
* @return {Boolean}
*/
required: function required(value, ctx, _required) {
if (_required === false) return true;
return value != null && value !== '';
},
/**
* Validates type.
*
* @param {Mixed} value - the value being validated
* @param {Object} ctx - the object being validated
* @param {String|Function} name name of the type or a constructor
* @return {Boolean}
*/
type: function type(value, ctx, name) {
if (value == null) return true;
if (typeof name == 'function') {
return value.constructor === name;
}
return (0, _componentType["default"])(value) === name;
},
/**
* Validates length.
*
* @param {String} value the string being validated
* @param {Object} ctx the object being validated
* @param {Object|Number} rules object with .min and/or .max props or a number
* @param {Number} [rules.min] - minimum length
* @param {Number} [rules.max] - maximum length
* @return {Boolean}
*/
length: function length(value, ctx, len) {
if (value == null) return true;
if (typeof len == 'number') {
return value.length === len;
}
var min = len.min,
max = len.max;
if (min && value.length < min) return false;
if (max && value.length > max) return false;
return true;
},
/**
* Validates size.
*
* @param {Number} value the number being validated
* @param {Object} ctx the object being validated
* @param {Object|Number} size object with .min and/or .max props or a number
* @param {String|Number} [size.min] - minimum size
* @param {String|Number} [size.max] - maximum size
* @return {Boolean}
*/
size: function size(value, ctx, _size) {
if (value == null) return true;
if (typeof _size == 'number') {
return value === _size;
}
var min = _size.min,
max = _size.max;
if (parseInt(min) != null && value < min) return false;
if (parseInt(max) != null && value > max) return false;
return true;
},
/**
* Validates enums.
*
* @param {String} value the string being validated
* @param {Object} ctx the object being validated
* @param {Array} enums array with allowed values
* @return {Boolean}
*/
"enum": function _enum(value, ctx, enums) {
if (value == null) return true;
return enums.includes(value);
},
/**
* Validates against given `regexp`.
*
* @param {String} value the string beign validated
* @param {Object} ctx the object being validated
* @param {RegExp} regexp the regexp to validate against
* @return {Boolean}
*/
match: function match(value, ctx, regexp) {
if (value == null) return true;
return regexp.test(value);
}
};
var _default = Validators;
exports["default"] = _default;
module.exports = exports.default;
\ No newline at end of file
type Type = Function | string
interface PropertyDefinition {
type?: Type;
required?: boolean;
length?: number | { min?: number; max?: number };
size?: number | { min?: number; max?: number };
enum?: string[];
each?: Rule;
elements?: Rule[];
match?: RegExp;
use?: { [key: string]: ValidationFunction };
message?: string | MessageFunction | { [key: string]: string | MessageFunction };
schema?: Schema;
properties?: SchemaDefinition;
}
type Rule = Type
| PropertyDefinition
| SchemaDefinition
| Schema
| RuleArray
// Remove when ts 3.7 is released
interface RuleArray extends Array<Rule> {}
interface SchemaDefinition {
[key: string]: Rule
}
interface ValidationFunction {
(value: any, ctx: object, ...args: any): boolean;
}
interface TypecastFunction {
(value: any): unknown;
}
interface MessageFunction {
(path: string, ctx: object, ...args: any): string;
}
interface ValidationOptions {
typecast?: boolean;
strip?: boolean;
}
export class ValidationError {
constructor(message: string, path: string);
path: string;
status: number;
expose: boolean;
}
export default class Schema {
constructor(definition?: SchemaDefinition, options?: ValidationOptions);
path(path: string, rules?: Rule): Property;
assert(target: { [key: string]: any }, options?: ValidationOptions): void;
validate(target: { [key: string]: any }, options?: ValidationOptions): ValidationError[];
message(validator: string, message: string | MessageFunction): Schema;
message(messages: { [validator: string]: string | MessageFunction }): Schema;
validator(name: string, fn: ValidationFunction): Schema;
validator(validators: { [name: string]: ValidationFunction }): Schema;
typecaster(name: string, fn: TypecastFunction): Schema;
typecaster(typecasters: { [name: string]: TypecastFunction }): Schema;
}
declare class Property {
constructor(name: string, schema: Schema);
message(messages: (string | MessageFunction) | { [validator: string]: string | MessageFunction }): Property;
schema(schema: Schema): Property;
use(fns: { [name: string]: ValidationFunction }): Property;
required(bool?: boolean): Property;
type(type: Type): Property;
string(): Property;
number(): Property;
array(): Property;
date(): Property;
length(rule: number | { min?: number; max?: number }): Property;
size(rule: number | { min?: number; max?: number }): Property;
enum(enums: string[]): Property;
match(regexp: RegExp): Property;
each(rules: Rule): Property;
elements(arr: Rule[]): Property;
properties(props: SchemaDefinition): Property;
path(path: string, rules?: Rule): Schema;
typecast<T>(value: any): T;
validate(value: any, ctx: object, path: string): ValidationError | null;
}
\ No newline at end of file
{
"_args": [
[
"validate@5.1.0",
"/private/var/www/db/coutch_db_create"
]
],
"_from": "validate@5.1.0",
"_id": "validate@5.1.0",
"_inBundle": false,
"_integrity": "sha512-Y+vJv+xR3XsaQM8W1rQvwc6is/sgCUBv3lvNKc2DZ1HcVcEWAaHVSFB5uoxkQnw2riUq77Rg5nv1u8YuuSu/Zw==",
"_location": "/validate",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "validate@5.1.0",
"name": "validate",
"escapedName": "validate",
"rawSpec": "5.1.0",
"saveSpec": null,
"fetchSpec": "5.1.0"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/validate/-/validate-5.1.0.tgz",
"_spec": "5.1.0",
"_where": "/private/var/www/db/coutch_db_create",
"author": {
"name": "Eivind Fjeldstad"
},
"bugs": {
"url": "https://github.com/eivindfjeldstad/validate/issues"
},
"dependencies": {
"component-type": "1.2.1",
"eivindfjeldstad-dot": "0.0.1",
"typecast": "0.0.1"
},
"description": "Validate object properties in javascript.",
"devDependencies": {
"@babel/cli": "^7.6.0",
"@babel/core": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"babel-jest": "^24.9.0",
"babel-plugin-add-module-exports": "^1.0.2",
"documentation": "^12.1.2",
"eslint": "^6.4.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"jest": "^24.9.0"
},
"engines": {
"node": ">=7.6"
},
"files": [
"build",
"index.d.ts"
],
"homepage": "https://github.com/eivindfjeldstad/validate#readme",
"jest": {
"testMatch": [
"**/test/**/*.js"
],
"coverageReporters": [
"text-summary",
"lcov"
],
"bail": true,
"testEnvironment": "node"
},
"keywords": [
"validation",
"validate",
"valid",
"object"
],
"license": "MIT",
"main": "build/schema.js",
"name": "validate",
"repository": {
"type": "git",
"url": "git+https://github.com/eivindfjeldstad/validate.git"
},
"scripts": {
"build": "babel -d build src",
"docs": "documentation readme ./src/*.js --section=API",
"lint": "eslint src test",
"prepublish": "npm run build",
"test": "jest",
"test-cov": "jest --coverage --runInBand --forceExit"
},
"version": "5.1.0"
}
# validate
Validate object properties in javascript.
[![npm version](http://img.shields.io/npm/v/validate.svg?style=flat-square)](https://npmjs.org/package/validate)
[![Build Status](http://img.shields.io/travis/eivindfjeldstad/validate.svg?style=flat-square)](https://travis-ci.org/eivindfjeldstad/validate)
[![Codecov](https://img.shields.io/codecov/c/github/eivindfjeldstad/validate.svg?style=flat-square)](https://codecov.io/gh/eivindfjeldstad/validate)
## Usage
Define a schema and call `.validate()` with the object you want to validate.
The `.validate()` function returns an array of validation errors.
```js
import Schema from 'validate'
const user = new Schema({
username: {
type: String,
required: true,
length: { min: 3, max: 32 }
},
pets: [{
name: {
type: String
required: true
},
animal: {
type: String
enum: ['cat', 'dog', 'cow']
}
}],
address: {
street: {
type: String,
required: true
},
city: {
type: String,
required: true
}
zip: {
type: String,
match: /^[0-9]+$/,
required: true
}
}
})
const errors = user.validate(obj)
```
Each error has a `.path`, describing the full path of the property that failed validation, and a `.message` describing the error.
```js
errors[0].path //=> 'address.street'
errors[0].message //=> 'address.street is required.'
```
### Custom error messages
You can override the default error messages by passing an object to `Schema#message()`.
```js
const post = new Schema({
title: { required: true }
})
post.message({
required: (path) => `${path} can not be empty.`
})
const [error] = post.validate({})
assert(error.message = 'title can not be empty.')
```
It is also possible to define messages for individual properties:
```js
const post = new Schema({
title: {
required: true,
message: 'Title is required.'
}
})
```
And for individual validators:
```js
const post = new Schema({
title: {
type: String,
required: true,
message: {
type: 'Title must be a string.',
required: 'Title is required.'
}
}
})
```
### Nesting
Objects and arrays can be nested as deep as you want:
```js
const event = new Schema({
title: {
type: String,
required: true
},
participants: [{
name: String,
email: {
type: String,
required: true
},
things: [{
name: String,
amount: Number
}]
}]
})
```
Arrays can be defined implicitly, like in the above example, or explicitly:
```js
const post = new Schema({
keywords: {
type: Array,
each: { type: String }
}
})
```
Array elements can also be defined individually:
```js
const user = new Schema({
something: {
type: Array,
elements: [
{ type: Number },
{ type: String }
]
}
})
```
Nesting also works with schemas:
```js
const user = new Schema({
name: {
type: String,
required: true
},
email: {
type: String,
required: true
}
})
const post = new Schema({
title: {
type: String,
required: true
},
content: {
type: String,
required: true
},
author: user
})
```
If you think it should work, it probably works.
#### Naming conflicts
Validate will naively assume that a nested object where *all* property names are validators is not a nested object.
```js
const schema = new Schema({
pet: {
type: {
required: true,
type: String,
enum: ['cat', 'dog']
}
}
});
```
In this example, the `pet.type` property will be interpreted as a `type` rule, and the validations will not work as intended. To work around this we could use the slightly more verbose `properties` rule:
```js
const schema = new Schema({
pet: {
properties: {
type: {
required: true,
type: String,
enum: ['cat', 'dog']
}
}
}
});
```
In this case the `type` property of `pets.properties` will be interpreted as a nested property, and the validations will work as intended.
### Custom validators
Custom validators can be defined by passing an object with named validators to `.use`:
```js
const hexColor = val => /^#[0-9a-fA-F]$/.test(val)
const car = new Schema({
color: {
type: String,
use: { hexColor }
}
})
```
Define a custom error message for the validator:
```js
car.message({
hexColor: path => `${path} must be a valid color.`
})
```
### Custom types
Pass a constructor to `.type` to validate against a custom type:
```js
class Car {}
const user = new Schema({
car: { type: Car }
})
```
### Chainable API
If you want to avoid constructing large objects, you can add paths to a schema by using the chainable API:
```js
const user = new Schema()
user
.path('username').type(String).required()
.path('address.zip').type(String).required()
```
Array elements can be defined by using `$` as a placeholder for indices:
```js
const user = new Schema()
user.path('pets.$').type(String)
```
This is equivalent to writing
```js
const user = new Schema({ pets: [{ type: String }]})
```
### Typecasting
Values can be automatically typecast before validation.
To enable typecasting, pass an options object to the `Schema` constructor with `typecast` set to `true`.
```js
const user = new Schema(definition, { typecast: true })
```
You can override this setting by passing an option to `.validate()`.
```js
user.validate(obj, { typecast: false })
```
To typecast custom types, you can register a typecaster:
```js
class Car {}
const user = new Schema({
car: { type: Car }
})
user.typecaster({
Car: (val) => new Car(val)
})
```
### Property stripping
By default, all values not defined in the schema will be stripped from the object.
Set `.strip = false` on the options object to disable this behavior.
## API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
#### Table of Contents
- [Property](#property)
- [Parameters](#parameters)
- [message](#message)
- [Parameters](#parameters-1)
- [Examples](#examples)
- [schema](#schema)
- [Parameters](#parameters-2)
- [Examples](#examples-1)
- [use](#use)
- [Parameters](#parameters-3)
- [Examples](#examples-2)
- [required](#required)
- [Parameters](#parameters-4)
- [Examples](#examples-3)
- [type](#type)
- [Parameters](#parameters-5)
- [Examples](#examples-4)
- [string](#string)
- [Examples](#examples-5)
- [number](#number)
- [Examples](#examples-6)
- [array](#array)
- [Examples](#examples-7)
- [date](#date)
- [Examples](#examples-8)
- [length](#length)
- [Parameters](#parameters-6)
- [Examples](#examples-9)
- [size](#size)
- [Parameters](#parameters-7)
- [Examples](#examples-10)
- [enum](#enum)
- [Parameters](#parameters-8)
- [Examples](#examples-11)
- [match](#match)
- [Parameters](#parameters-9)
- [Examples](#examples-12)
- [each](#each)
- [Parameters](#parameters-10)
- [Examples](#examples-13)
- [elements](#elements)
- [Parameters](#parameters-11)
- [Examples](#examples-14)
- [properties](#properties)
- [Parameters](#parameters-12)
- [Examples](#examples-15)
- [path](#path)
- [Parameters](#parameters-13)
- [Examples](#examples-16)
- [typecast](#typecast)
- [Parameters](#parameters-14)
- [Examples](#examples-17)
- [validate](#validate)
- [Parameters](#parameters-15)
- [Examples](#examples-18)
- [Schema](#schema-1)
- [Parameters](#parameters-16)
- [Examples](#examples-19)
- [path](#path-1)
- [Parameters](#parameters-17)
- [Examples](#examples-20)
- [validate](#validate-1)
- [Parameters](#parameters-18)
- [Examples](#examples-21)
- [assert](#assert)
- [Parameters](#parameters-19)
- [Examples](#examples-22)
- [message](#message-1)
- [Parameters](#parameters-20)
- [Examples](#examples-23)
- [validator](#validator)
- [Parameters](#parameters-21)
- [Examples](#examples-24)
- [typecaster](#typecaster)
- [Parameters](#parameters-22)
- [Examples](#examples-25)
### Property
A property instance gets returned whenever you call `schema.path()`.
Properties are also created internally when an object is passed to the Schema constructor.
#### Parameters
- `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the property
- `schema` **[Schema](#schema)** parent schema
#### message
Registers messages.
##### Parameters
- `messages` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**
##### Examples
```javascript
prop.message('something is wrong')
prop.message({ required: 'thing is required.' })
```
Returns **[Property](#property)**
#### schema
Mount given `schema` on current path.
##### Parameters
- `schema` **[Schema](#schema)** the schema to mount
##### Examples
```javascript
const user = new Schema({ email: String })
prop.schema(user)
```
Returns **[Property](#property)**
#### use
Validate using named functions from the given object.
Error messages can be defined by providing an object with
named error messages/generators to `schema.message()`
The message generator receives the value being validated,
the object it belongs to and any additional arguments.
##### Parameters
- `fns` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object with named validation functions to call
##### Examples
```javascript
const schema = new Schema()
const prop = schema.path('some.path')
schema.message({
binary: (path, ctx) => `${path} must be binary.`,
bits: (path, ctx, bits) => `${path} must be ${bits}-bit`
})
prop.use({
binary: (val, ctx) => /^[01]+$/i.test(val),
bits: [(val, ctx, bits) => val.length == bits, 32]
})
```
Returns **[Property](#property)**
#### required
Registers a validator that checks for presence.
##### Parameters
- `bool` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** `true` if required, `false` otherwise (optional, default `true`)
##### Examples
```javascript
prop.required()
```
Returns **[Property](#property)**
#### type
Registers a validator that checks if a value is of a given `type`
##### Parameters
- `type` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))** type to check for
##### Examples
```javascript
prop.type(String)
```
```javascript
prop.type('string')
```
Returns **[Property](#property)**
#### string
Convenience method for setting type to `String`
##### Examples
```javascript
prop.string()
```
Returns **[Property](#property)**
#### number
Convenience method for setting type to `Number`
##### Examples
```javascript
prop.number()
```
Returns **[Property](#property)**
#### array
Convenience method for setting type to `Array`
##### Examples
```javascript
prop.array()
```
Returns **[Property](#property)**
#### date
Convenience method for setting type to `Date`
##### Examples
```javascript
prop.date()
```
Returns **[Property](#property)**
#### length
Registers a validator that checks length.
##### Parameters
- `rules` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** object with `.min` and `.max` properties or a number
- `rules.min` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** minimum length
- `rules.max` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** maximum length
##### Examples
```javascript
prop.length({ min: 8, max: 255 })
prop.length(10)
```
Returns **[Property](#property)**
#### size
Registers a validator that checks size.
##### Parameters
- `rules` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** object with `.min` and `.max` properties or a number
- `rules.min` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** minimum size
- `rules.max` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** maximum size
##### Examples
```javascript
prop.size({ min: 8, max: 255 })
prop.size(10)
```
Returns **[Property](#property)**
#### enum
Registers a validator for enums.
##### Parameters
- `enums`
- `rules` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** allowed values
##### Examples
```javascript
prop.enum(['cat', 'dog'])
```
Returns **[Property](#property)**
#### match
Registers a validator that checks if a value matches given `regexp`.
##### Parameters
- `regexp` **[RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)** regular expression to match
##### Examples
```javascript
prop.match(/some\sregular\sexpression/)
```
Returns **[Property](#property)**
#### each
Registers a validator that checks each value in an array against given `rules`.
##### Parameters
- `rules` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Schema](#schema) \| [Property](#property))** rules to use
##### Examples
```javascript
prop.each({ type: String })
prop.each([{ type: Number }])
prop.each({ things: [{ type: String }]})
prop.each(schema)
```
Returns **[Property](#property)**
#### elements
Registers paths for array elements on the parent schema, with given array of rules.
##### Parameters
- `arr` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array of rules to use
##### Examples
```javascript
prop.elements([{ type: String }, { type: Number }])
```
Returns **[Property](#property)**
#### properties
Registers all properties from the given object as nested properties
##### Parameters
- `props` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** properties with rules
##### Examples
```javascript
prop.properties({
name: String,
email: String
})
```
Returns **[Property](#property)**
#### path
Proxy method for schema path. Makes chaining properties together easier.
##### Parameters
- `args` **...any**
##### Examples
```javascript
schema
.path('name').type(String).required()
.path('email').type(String).required()
```
#### typecast
Typecast given `value`
##### Parameters
- `value` **Mixed** value to typecast
##### Examples
```javascript
prop.type(String)
prop.typecast(123) // => '123'
```
Returns **Mixed**
#### validate
Validate given `value`
##### Parameters
- `value` **Mixed** value to validate
- `ctx` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the object containing the value
- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path of the value being validated (optional, default `this.name`)
##### Examples
```javascript
prop.type(Number)
assert(prop.validate(2) == null)
assert(prop.validate('hello world') instanceof Error)
```
Returns **ValidationError**
### Schema
A Schema defines the structure that objects should be validated against.
#### Parameters
- `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** schema definition (optional, default `{}`)
- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** options (optional, default `{}`)
- `opts.typecast` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** typecast values before validation (optional, default `false`)
- `opts.strip` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** strip properties not defined in the schema (optional, default `true`)
#### Examples
```javascript
const post = new Schema({
title: {
type: String,
required: true,
length: { min: 1, max: 255 }
},
content: {
type: String,
required: true
},
published: {
type: Date,
required: true
},
keywords: [{ type: String }]
})
```
```javascript
const author = new Schema({
name: {
type: String,
required: true
},
email: {
type: String,
required: true
},
posts: [post]
})
```
#### path
Create or update `path` with given `rules`.
##### Parameters
- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** full path using dot-notation
- `rules` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Schema](#schema) \| [Property](#property))?** rules to apply
##### Examples
```javascript
const schema = new Schema()
schema.path('name.first', { type: String })
schema.path('name.last').type(String).required()
```
Returns **[Property](#property)**
#### validate
Validate given `obj`.
##### Parameters
- `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the object to validate
- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** options, see [Schema](#schema-1) (optional, default `{}`)
##### Examples
```javascript
const schema = new Schema({ name: { required: true }})
const errors = schema.validate({})
assert(errors.length == 1)
assert(errors[0].message == 'name is required')
assert(errors[0].path == 'name')
```
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)**
#### assert
Assert that given `obj` is valid.
##### Parameters
- `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
##### Examples
```javascript
const schema = new Schema({ name: String })
schema.assert({ name: 1 }) // Throws an error
```
#### message
Override default error messages.
##### Parameters
- `name` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** name of the validator or an object with name-message pairs
- `message` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))?** the message or message generator to use
##### Examples
```javascript
const hex = (val) => /^0x[0-9a-f]+$/.test(val)
schema.path('some.path').use({ hex })
schema.message('hex', path => `${path} must be hexadecimal`)
```
```javascript
schema.message({ hex: path => `${path} must be hexadecimal` })
```
Returns **[Schema](#schema)**
#### validator
Override default validators.
##### Parameters
- `name` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** name of the validator or an object with name-function pairs
- `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** the function to use
##### Examples
```javascript
schema.validator('required', val => val != null)
```
```javascript
schema.validator({ required: val => val != null })
```
Returns **[Schema](#schema)**
#### typecaster
Override default typecasters.
##### Parameters
- `name` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** name of the validator or an object with name-function pairs
- `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** the function to use
##### Examples
```javascript
schema.typecaster('SomeClass', val => new SomeClass(val))
```
```javascript
schema.typecaster({ SomeClass: val => new SomeClass(val) })
```
Returns **[Schema](#schema)**
## Licence
MIT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment