Socket
Socket
Sign inDemoInstall

rttc

Package Overview
Dependencies
Maintainers
4
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rttc - npm Package Compare versions

Comparing version 9.5.1 to 9.6.0

lib/validate-exemplar-strict.js

1

index.js

@@ -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];

11

lib/is-invalid-example.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc