Comparing version 3.1.1 to 3.1.2
@@ -279,14 +279,50 @@ var dlv = require('dlv'); | ||
for (var key in definition) { | ||
processed[key] = { | ||
regex: toRegexp(key), | ||
key: key | ||
}; | ||
var value = definition[key]; | ||
if (key.includes('{}') || key.includes('[]')) { | ||
var split = key.split('.'); | ||
var keysBeforeVariable = []; | ||
for (var _iterator = _createForOfIteratorHelperLoose(split), _step; !(_step = _iterator()).done;) { | ||
var part = _step.value; | ||
if (part === '{}' || part === '[]') { | ||
break; | ||
} | ||
keysBeforeVariable.push(part); | ||
} | ||
var startsWith = keysBeforeVariable.join('.') + '.'; | ||
if (!processed[startsWith]) { | ||
processed[startsWith] = []; | ||
} | ||
var regex = toRegexp(key); | ||
processed[startsWith].push({ | ||
value: value, | ||
test: regex.test.bind(regex) | ||
}); | ||
} | ||
} | ||
return function (path) { | ||
if (definition[path]) { | ||
return definition[path]; | ||
} | ||
for (var _key in processed) { | ||
var matches = processed[_key].regex.test(path); | ||
if (path.startsWith(_key)) { | ||
var limitedItemsToTest = processed[_key]; | ||
if (matches) { | ||
return definition[_key]; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(limitedItemsToTest), _step2; !(_step2 = _iterator2()).done;) { | ||
var _step2$value = _step2.value, | ||
test = _step2$value.test, | ||
_value = _step2$value.value; | ||
if (test(path)) { | ||
return _value; | ||
} | ||
} | ||
} | ||
@@ -437,7 +473,7 @@ } | ||
var _loop = function _loop(key) { | ||
for (var key in obj) { | ||
var value = obj[key]; | ||
if (value === null) { | ||
return "continue"; | ||
continue; | ||
} | ||
@@ -450,3 +486,3 @@ | ||
if (isEmpty(value) && !type) { | ||
throw Error('Invalid path: ' + extendedPath); | ||
throw Error('INVALID path: ' + extendedPath); | ||
} | ||
@@ -457,13 +493,29 @@ | ||
if (!type) { | ||
throw Error('Invalid path: ' + extendedPath); | ||
throw Error('INVALID path: ' + extendedPath); | ||
} | ||
var testFn; | ||
var testFn = void 0; | ||
if (Array.isArray(type)) { | ||
testFn = function testFn() { | ||
return type.some(function (typeEntry) { | ||
return fnsObject[typeEntry]; | ||
}); | ||
}; | ||
var found = false; | ||
var passed = false; | ||
for (var _iterator3 = _createForOfIteratorHelperLoose(type), _step3; !(_step3 = _iterator3()).done;) { | ||
var typeEntry = _step3.value; | ||
if (fnsObject[typeEntry]) { | ||
found = true; | ||
if (fnsObject[typeEntry](value)) { | ||
passed = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (!passed || !found) { | ||
throw Error("INVALID " + extendedPath + ": " + value); | ||
} | ||
return; | ||
} else { | ||
@@ -481,8 +533,2 @@ testFn = fnsObject[type]; | ||
} | ||
}; | ||
for (var key in obj) { | ||
var _ret = _loop(key); | ||
if (_ret === "continue") continue; | ||
} | ||
@@ -489,0 +535,0 @@ }; |
@@ -192,14 +192,47 @@ import dlv from 'dlv'; | ||
for (const key in definition) { | ||
processed[key] = { | ||
regex: toRegexp(key), | ||
key | ||
}; | ||
const value = definition[key]; | ||
if (key.includes('{}') || key.includes('[]')) { | ||
const split = key.split('.'); | ||
const keysBeforeVariable = []; | ||
for (const part of split) { | ||
if (part === '{}' || part === '[]') { | ||
break; | ||
} | ||
keysBeforeVariable.push(part); | ||
} | ||
const startsWith = keysBeforeVariable.join('.') + '.'; | ||
if (!processed[startsWith]) { | ||
processed[startsWith] = []; | ||
} | ||
const regex = toRegexp(key); | ||
processed[startsWith].push({ | ||
value, | ||
test: regex.test.bind(regex) | ||
}); | ||
} | ||
} | ||
return path => { | ||
if (definition[path]) { | ||
return definition[path]; | ||
} | ||
for (const key in processed) { | ||
const matches = processed[key].regex.test(path); | ||
if (path.startsWith(key)) { | ||
const limitedItemsToTest = processed[key]; | ||
if (matches) { | ||
return definition[key]; | ||
for (const { | ||
test, | ||
value | ||
} of limitedItemsToTest) { | ||
if (test(path)) { | ||
return value; | ||
} | ||
} | ||
} | ||
@@ -352,3 +385,3 @@ } | ||
if (isEmpty(value) && !type) { | ||
throw Error('Invalid path: ' + extendedPath); | ||
throw Error('INVALID path: ' + extendedPath); | ||
} | ||
@@ -359,3 +392,3 @@ | ||
if (!type) { | ||
throw Error('Invalid path: ' + extendedPath); | ||
throw Error('INVALID path: ' + extendedPath); | ||
} | ||
@@ -366,3 +399,21 @@ | ||
if (Array.isArray(type)) { | ||
testFn = () => type.some(typeEntry => fnsObject[typeEntry]); | ||
let found = false; | ||
let passed = false; | ||
for (const typeEntry of type) { | ||
if (fnsObject[typeEntry]) { | ||
found = true; | ||
if (fnsObject[typeEntry](value)) { | ||
passed = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (!passed || !found) { | ||
throw Error(`INVALID ${extendedPath}: ${value}`); | ||
} | ||
return; | ||
} else { | ||
@@ -369,0 +420,0 @@ testFn = fnsObject[type]; |
@@ -275,14 +275,50 @@ import dlv from 'dlv'; | ||
for (var key in definition) { | ||
processed[key] = { | ||
regex: toRegexp(key), | ||
key: key | ||
}; | ||
var value = definition[key]; | ||
if (key.includes('{}') || key.includes('[]')) { | ||
var split = key.split('.'); | ||
var keysBeforeVariable = []; | ||
for (var _iterator = _createForOfIteratorHelperLoose(split), _step; !(_step = _iterator()).done;) { | ||
var part = _step.value; | ||
if (part === '{}' || part === '[]') { | ||
break; | ||
} | ||
keysBeforeVariable.push(part); | ||
} | ||
var startsWith = keysBeforeVariable.join('.') + '.'; | ||
if (!processed[startsWith]) { | ||
processed[startsWith] = []; | ||
} | ||
var regex = toRegexp(key); | ||
processed[startsWith].push({ | ||
value: value, | ||
test: regex.test.bind(regex) | ||
}); | ||
} | ||
} | ||
return function (path) { | ||
if (definition[path]) { | ||
return definition[path]; | ||
} | ||
for (var _key in processed) { | ||
var matches = processed[_key].regex.test(path); | ||
if (path.startsWith(_key)) { | ||
var limitedItemsToTest = processed[_key]; | ||
if (matches) { | ||
return definition[_key]; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(limitedItemsToTest), _step2; !(_step2 = _iterator2()).done;) { | ||
var _step2$value = _step2.value, | ||
test = _step2$value.test, | ||
_value = _step2$value.value; | ||
if (test(path)) { | ||
return _value; | ||
} | ||
} | ||
} | ||
@@ -433,7 +469,7 @@ } | ||
var _loop = function _loop(key) { | ||
for (var key in obj) { | ||
var value = obj[key]; | ||
if (value === null) { | ||
return "continue"; | ||
continue; | ||
} | ||
@@ -446,3 +482,3 @@ | ||
if (isEmpty(value) && !type) { | ||
throw Error('Invalid path: ' + extendedPath); | ||
throw Error('INVALID path: ' + extendedPath); | ||
} | ||
@@ -453,13 +489,29 @@ | ||
if (!type) { | ||
throw Error('Invalid path: ' + extendedPath); | ||
throw Error('INVALID path: ' + extendedPath); | ||
} | ||
var testFn; | ||
var testFn = void 0; | ||
if (Array.isArray(type)) { | ||
testFn = function testFn() { | ||
return type.some(function (typeEntry) { | ||
return fnsObject[typeEntry]; | ||
}); | ||
}; | ||
var found = false; | ||
var passed = false; | ||
for (var _iterator3 = _createForOfIteratorHelperLoose(type), _step3; !(_step3 = _iterator3()).done;) { | ||
var typeEntry = _step3.value; | ||
if (fnsObject[typeEntry]) { | ||
found = true; | ||
if (fnsObject[typeEntry](value)) { | ||
passed = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (!passed || !found) { | ||
throw Error("INVALID " + extendedPath + ": " + value); | ||
} | ||
return; | ||
} else { | ||
@@ -477,8 +529,2 @@ testFn = fnsObject[type]; | ||
} | ||
}; | ||
for (var key in obj) { | ||
var _ret = _loop(key); | ||
if (_ret === "continue") continue; | ||
} | ||
@@ -485,0 +531,0 @@ }; |
@@ -282,14 +282,50 @@ (function (global, factory) { | ||
for (var key in definition) { | ||
processed[key] = { | ||
regex: toRegexp(key), | ||
key: key | ||
}; | ||
var value = definition[key]; | ||
if (key.includes('{}') || key.includes('[]')) { | ||
var split = key.split('.'); | ||
var keysBeforeVariable = []; | ||
for (var _iterator = _createForOfIteratorHelperLoose(split), _step; !(_step = _iterator()).done;) { | ||
var part = _step.value; | ||
if (part === '{}' || part === '[]') { | ||
break; | ||
} | ||
keysBeforeVariable.push(part); | ||
} | ||
var startsWith = keysBeforeVariable.join('.') + '.'; | ||
if (!processed[startsWith]) { | ||
processed[startsWith] = []; | ||
} | ||
var regex = toRegexp(key); | ||
processed[startsWith].push({ | ||
value: value, | ||
test: regex.test.bind(regex) | ||
}); | ||
} | ||
} | ||
return function (path) { | ||
if (definition[path]) { | ||
return definition[path]; | ||
} | ||
for (var _key in processed) { | ||
var matches = processed[_key].regex.test(path); | ||
if (path.startsWith(_key)) { | ||
var limitedItemsToTest = processed[_key]; | ||
if (matches) { | ||
return definition[_key]; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(limitedItemsToTest), _step2; !(_step2 = _iterator2()).done;) { | ||
var _step2$value = _step2.value, | ||
test = _step2$value.test, | ||
_value = _step2$value.value; | ||
if (test(path)) { | ||
return _value; | ||
} | ||
} | ||
} | ||
@@ -440,7 +476,7 @@ } | ||
var _loop = function _loop(key) { | ||
for (var key in obj) { | ||
var value = obj[key]; | ||
if (value === null) { | ||
return "continue"; | ||
continue; | ||
} | ||
@@ -453,3 +489,3 @@ | ||
if (isEmpty(value) && !type) { | ||
throw Error('Invalid path: ' + extendedPath); | ||
throw Error('INVALID path: ' + extendedPath); | ||
} | ||
@@ -460,13 +496,29 @@ | ||
if (!type) { | ||
throw Error('Invalid path: ' + extendedPath); | ||
throw Error('INVALID path: ' + extendedPath); | ||
} | ||
var testFn; | ||
var testFn = void 0; | ||
if (Array.isArray(type)) { | ||
testFn = function testFn() { | ||
return type.some(function (typeEntry) { | ||
return fnsObject[typeEntry]; | ||
}); | ||
}; | ||
var found = false; | ||
var passed = false; | ||
for (var _iterator3 = _createForOfIteratorHelperLoose(type), _step3; !(_step3 = _iterator3()).done;) { | ||
var typeEntry = _step3.value; | ||
if (fnsObject[typeEntry]) { | ||
found = true; | ||
if (fnsObject[typeEntry](value)) { | ||
passed = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (!passed || !found) { | ||
throw Error("INVALID " + extendedPath + ": " + value); | ||
} | ||
return; | ||
} else { | ||
@@ -484,8 +536,2 @@ testFn = fnsObject[type]; | ||
} | ||
}; | ||
for (var key in obj) { | ||
var _ret = _loop(key); | ||
if (_ret === "continue") continue; | ||
} | ||
@@ -492,0 +538,0 @@ }; |
{ | ||
"name": "sinks", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Tools for object sync (get it?!), validation, diffing, and immutable deep setting", | ||
@@ -5,0 +5,0 @@ "source": "src/index.js", |
@@ -320,2 +320,3 @@ # sinks | ||
- `3.1.2`: Bugfixes and 10x performance improvement of validate() function. | ||
- `3.1.1`: Now exporting `simpleObjectDeepEqual` as part of main export. | ||
@@ -322,0 +323,0 @@ - `3.1.0`: Added `simpleObjectDeepEqual` utility for lightweight object comparisons of simple objects. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
173925
1798
341