Comparing version 9.5.1 to 9.6.0
@@ -30,2 +30,3 @@ module.exports = { | ||
inferDisplayType: require('./lib/infer-display-type'), | ||
validateExemplarStrict: require('./lib/validate-exemplar-strict'), | ||
}; | ||
@@ -32,0 +33,0 @@ |
@@ -24,9 +24,16 @@ /** | ||
* @param {Anything} val | ||
* @param {Anything} handleLeafTransform | ||
* | ||
* @param {Function} handleLeafTransform [run AFTER stringification of Errors, Dates, etc.] | ||
* @param {Anything} leafVal | ||
* @param {String} leafType [either string, number, boolean, null, or lamda] | ||
* @param {String} leafType [either 'string', 'number', 'boolean', 'null', or 'lamda'] | ||
* @return {Anything} [transformed version of `leafVal`] | ||
* | ||
* @param {Function} handleCompositeTransform [run BEFORE recursion and stripping of undefined items/props] | ||
* @param {Dictionary|Array} compositeVal | ||
* @param {String} leafType [either 'array' or 'dictionary'] | ||
* @return {Dictionary|Array} [transformed version of `compositeVal`-- MUST BE A DICTONARY OR ARRAY THAT IS SAFE TO RECURSIVELY DIVE INTO!!!] | ||
* | ||
* @returns {JSON} | ||
*/ | ||
module.exports = function rebuildRecursive(val, handleLeafTransform) { | ||
module.exports = function rebuildRecursive(val, handleLeafTransform, handleCompositeTransform) { | ||
// If an invalid transformer function was provided, throw a usage error. | ||
@@ -71,4 +78,9 @@ if (!_.isFunction(handleLeafTransform)){ | ||
// If this is an array, rebuild and strip undefined items. | ||
// If this is an array, we'll recursively rebuild and strip undefined items. | ||
if (_.isArray(thisVal)) { | ||
// But first, run the composite transform handler, if one was provided. | ||
if (!_.isUndefined(handleCompositeTransform)) { | ||
thisVal = handleCompositeTransform(thisVal, 'array'); | ||
} | ||
// Now recursively rebuild and strip undefined items. | ||
return _.reduce(thisVal,function (memo, item, i) { | ||
@@ -150,2 +162,10 @@ if (!_.isUndefined(item)) { | ||
} | ||
// Now we're about to take the the recursive step..! | ||
// | ||
// But first, run the composite transform handler, if one was provided. | ||
if (!_.isUndefined(handleCompositeTransform)) { | ||
thisVal = handleCompositeTransform(thisVal, 'dictionary'); | ||
} | ||
// Then recursively rebuild and strip undefined keys. | ||
return _.reduce(_.keys(thisVal),function (memo, key) { | ||
@@ -152,0 +172,0 @@ var subVal = thisVal[key]; |
@@ -12,10 +12,15 @@ /** | ||
* | ||
* Check out the provided example and see if it fails inference via rttc.infer(). | ||
* | ||
* Note: | ||
* Although `undefined` technically is inferred as "ref", this function | ||
* considers it an invalid example | ||
* considers it an invalid example. | ||
* | ||
* @param {*} example | ||
* ---------------------------------------------------------------------------- | ||
* @param {JSON} example | ||
* | ||
* @return {===} truthy if the provided example is invalid, | ||
* false otherwise. | ||
*/ | ||
module.exports = function isInvalidExample(example){ | ||
module.exports = function isInvalidExample(example, tolerateMultiItemArrays){ | ||
@@ -22,0 +27,0 @@ if (_.isUndefined(example)) { |
@@ -16,11 +16,39 @@ /** | ||
* | ||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
* @param {Anything} val | ||
* @param {Anything} handleLeafTransform | ||
* | ||
* @param {Function} handleLeafTransform [run AFTER stringification of Errors, Dates, etc.] | ||
* @param {Anything} leafVal | ||
* @param {String} leafType [either string, number, boolean, null, or lamda] | ||
* @param {String} leafType [either 'string', 'number', 'boolean', 'null', or 'lamda'] | ||
* @return {Anything} [transformed version of `leafVal`] | ||
* | ||
* @returns {JSON} | ||
* @param {Function} handleCompositeTransform [run BEFORE recursion and stripping of undefined items/props] | ||
* @param {Dictionary|Array} compositeVal | ||
* @param {String} leafType [either 'array' or 'dictionary'] | ||
* @return {Dictionary|Array} [transformed version of `compositeVal`-- MUST BE A DICTONARY OR ARRAY THAT IS SAFE TO RECURSIVELY DIVE INTO!!!] | ||
* | ||
* @returns {JSONCompatible} | ||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
* Example usage: | ||
* | ||
* ``` | ||
* rttc.rebuild({ | ||
* foo: [ | ||
* 3, | ||
* ['hey', 'yo', 235, {}] | ||
* ] | ||
* }, | ||
* function transformPrimitive(val, type){ return val;}, | ||
* function transformDictOrArray(compositeThing, type) { | ||
* if (type === 'array') { return compositeThing.slice(1); } | ||
* else { return compositeThing; } | ||
* }) | ||
* | ||
* // Yields: | ||
* // { foo: [ [ 'yo', 235, {} ] ] } | ||
* ``` | ||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
*/ | ||
module.exports = function rebuild(val, handleLeafTransform){ | ||
return rebuildRecursive(val, handleLeafTransform); | ||
module.exports = function rebuild(val, handleLeafTransform, handleCompositeTransform){ | ||
return rebuildRecursive(val, handleLeafTransform, handleCompositeTransform); | ||
}; |
{ | ||
"name": "rttc", | ||
"version": "9.5.1", | ||
"version": "9.6.0", | ||
"description": "Runtime type-checking for JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
243755
49
5220