@untool/core
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.2.0](https://github.com/untool/untool/compare/v1.1.0...v1.2.0) (2019-02-27) | ||
### Features | ||
* **core:** introduce validation helpers ([c931a20](https://github.com/untool/untool/commit/c931a20)) | ||
# [1.1.0](https://github.com/untool/untool/compare/v1.0.0...v1.1.0) (2019-02-14) | ||
@@ -8,0 +19,0 @@ |
@@ -42,4 +42,4 @@ 'use strict'; | ||
if (config.mixins) { | ||
config.mixins = config.mixins.map( | ||
(mixin) => (mixin.startsWith('.') ? join(directory, mixin) : mixin) | ||
config.mixins = config.mixins.map((mixin) => | ||
mixin.startsWith('.') ? join(directory, mixin) : mixin | ||
); | ||
@@ -46,0 +46,0 @@ } |
@@ -8,2 +8,30 @@ 'use strict'; | ||
exports.invariant = (condition, message) => { | ||
if (condition) return; | ||
throw new Error(`Invariant violation: ${message}`); | ||
}; | ||
exports.validate = (strategy, checkArgs = () => {}, checkResult = () => {}) => | ||
Object.defineProperty( | ||
(functions, ...initialArgs) => | ||
strategy( | ||
functions.map((fn) => (...callArgs) => { | ||
checkArgs(callArgs, initialArgs); | ||
const result = fn(...callArgs); | ||
if (result && typeof result.then === 'function') { | ||
return result.then((result) => { | ||
checkResult(result, true, callArgs, initialArgs); | ||
return result; | ||
}); | ||
} else { | ||
checkResult(result, false, callArgs, initialArgs); | ||
return result; | ||
} | ||
}), | ||
...initialArgs | ||
), | ||
'name', | ||
{ value: strategy.name } | ||
); | ||
exports.merge = (...args) => | ||
@@ -10,0 +38,0 @@ mergeWith({}, ...args, (objValue, srcValue, key) => { |
{ | ||
"name": "@untool/core", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "untool core", | ||
@@ -35,3 +35,3 @@ "repository": { | ||
}, | ||
"gitHead": "e92a4e17440f172b7211c57d7bbf9badd34ec8b3" | ||
"gitHead": "0576dcfa7e743599b9f020024e1f479cdd7044b9" | ||
} |
29569
262