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.3.0 to 9.3.1

14

lib/helpers/sanitize.js

@@ -21,4 +21,4 @@ /**

if (_.isUndefined(val)) {
if (allowNull) return null;
else return undefined;
if (allowNull) { return null; }
else { return undefined; }
}

@@ -64,3 +64,3 @@

var cycleReplacer = function(unused, value) {
if (stack[0] === value) return '[Circular ~]';
if (stack[0] === value) { return '[Circular ~]'; }
return '[Circular ~.' + keys.slice(0, stack.indexOf(value)).join('.') + ']';

@@ -81,3 +81,3 @@ };

}
else stack.push(val);
else { stack.push(val); }

@@ -128,12 +128,14 @@

else if (_.isObject(val)) {
// Reject readable streams out of hand
if (val instanceof Readable) {
return null;
}
// Reject buffers out of hand
if (val instanceof Buffer) {
return null;
}
// Reject RttcRefPlaceholders
// Reject `RttcRefPlaceholders` out of hand
// (this is a special case so there is a placeholder value that ONLY validates stricly against the "ref" type)
// (note that like anything else, RttcRefPlaceholders nested inside of a JSON/generic dict/generic array get sanitized into JSON-compatible things)
if (val.constructor.name === 'RttcRefPlaceholder') {
if (_.isObject(val.constructor) && val.constructor.name === 'RttcRefPlaceholder') {
return null;

@@ -140,0 +142,0 @@ }

@@ -270,3 +270,3 @@ /**

// (this is a special case so there is a placeholder value that ONLY validates against the "ref" type)
if (_.isObject(v) && v.constructor.name === 'RttcRefPlaceholder') {
if (_.isObject(v.constructor) && v.constructor.name === 'RttcRefPlaceholder') {
return false;

@@ -273,0 +273,0 @@ }

@@ -100,3 +100,3 @@ /**

// If the exemplar isn't an object or array, we will derive its primitive type.
// If the exemplar isn't a dictionary or array, we will derive its primitive type.
if(!types.dictionary.is(eg) && !types.array.is(eg)) {

@@ -103,0 +103,0 @@ return getTypeOfPrimitive(eg);

{
"name": "rttc",
"version": "9.3.0",
"version": "9.3.1",
"description": "Runtime type-checking for JavaScript.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -106,3 +106,3 @@ # rttc

| json | `'*'` | `null`
| ref | `'==='` | `undefined`
| ref | `'==='` | `null`
| faceted dictionary (recursive) | `{...}` _(i.e. w/ keys)_ | `{...}` (w/ all expected keys and _their_ base values)

@@ -259,4 +259,4 @@ | pattern array (recursive) | `[...]` _(i.e. w/ 1 item)_ | `[]` _(empty array)_

+ `undefined` _is never valid as a top-level value_ against ANY type, even mutable reference (`===`)
+ `undefined` IS, however, allowed as an item in a nested array or value in a nested dictionary, but only against the mutable reference type (`===`)
+ `null` is only valid at the top level against the JSON (`*`) and mutable reference (`===`) types.
+ `undefined` IS, however, allowed as an item in a nested array or value in a nested dictionary, but only _within a dictionary or array_ being validated against the mutable reference type (`===`)
+ `null` is only valid against the JSON (`*`) and mutable reference (`===`) types.

@@ -296,3 +296,3 @@ ##### Weird psuedo-numeric values

+ For the "json" type (`'*'`), base value is `null`.
+ For the "ref" type (`'==='`), base value is `undefined`.
+ For the "ref" type (`'==='`), base value is `null`.

@@ -428,3 +428,3 @@ > Note that, for both arrays and dictionaries, any keys in the schema will get the base value for their type (and their keys for their type, etc. -- recursive)

This is a lot like `util.inspect(val, false, null)`, but it also has special handling for Errors, Dates, and RegExps (using `dehydrate()` with `allowNull` enabled), as well as for Functions (making them `eval()`-ready.) The biggest difference is that the string you get back from `rttc.compile()` is ready for use as the right hand side of a variable initialization statement in JavaSript.
This is a lot like `util.inspect(val, {depth: null})` in the Node core util package. But there are a few differences. `rttc.compile()` also has special handling for Errors, Dates, and RegExps (using `dehydrate()` with `allowNull` enabled), as well as for Functions (making them `eval()`-ready.) The biggest difference is that the string you get back from `rttc.compile()` is ready for use as the right hand side of a variable initialization statement in JavaSript.

@@ -451,4 +451,4 @@ Useful for:

| undefined | `undefined` | `null` |
| [undefined] | `[undefined]` | [] |
| {foo: undefined} | `{foo: undefined}` | {} |
| [undefined] | `[undefined]` | `[]` |
| {foo: undefined} | `{foo: undefined}` | `{}` |
| Infinity | `Infinity` | `0` |

@@ -461,3 +461,3 @@ | -Infinity | `-Infinity` | `0` |

> Note that undefined values in arrays and undefined values of keys in dictionaries will be stripped out, and circular references will be handled as they are in `util.inspect(val, false, null)`.
> Note that undefined values in arrays and undefined values of keys in dictionaries will be stripped out, and circular references will be handled as they are in `util.inspect(val, {depth: null})`.

@@ -485,8 +485,8 @@

+ `null` becomes '*'.
+ If the top-level value is `undefined`, it becomes '==='.
+ '->' becomes 'an arrow symbol'.
+ '*' becomes 'a star symbol'.
+ '===' becomes '3 equal signs'.
+ If the top-level value is `undefined`, it becomes '==='. (however this behavior is subject to change in an upcoming release; since `undefined` is not supported by any exemplar)
+ '->' becomes the string: `'an arrow symbol'`.
+ '*' becomes the string: `'a star symbol'`.
+ '===' becomes the string: `'3 equal signs'`.
+ `NaN`, `Infinity`, `-Infinity`, and `-0` become 0.
+ Nested items and keys with `undefined` values are stripped.
+ Nested array items and keys with `undefined` values are stripped.
+ Other than the exceptions mentioned above, non-JSON-serializable things (like circular references) are boiled away when this calls `dehydrate` internally.

@@ -512,3 +512,3 @@

Return `true` if the provided value is NOT a valid rttc exemplar.
Return truthy if the provided value is NOT a valid rttc exemplar.

@@ -515,0 +515,0 @@ ##### .getPathInfo(exemplar, path)

@@ -151,3 +151,7 @@ // Export the array of tests below.

////////////////////////////////////////////
// DICTIONARIES (json-serializable, except `null` not allowed)
// DICTIONARIES (w/ json-serializable contents)
// (note that `{}` in an exemplar indicates that any keys are permitted, but that their values must be json-serializable)
// (there is no way to specifically indicate a dictionary of literally anything, including a mix of functions and other stuff
// so in that scenario, just use `'==='` instead of `{}` and add additional checks in relevant code to ensure you're dealing
// with a dictionary vs the other things `===` might produce; e.g. strings/functions/streams/whatever - literally anything.)
////////////////////////////////////////////

@@ -197,4 +201,5 @@

////////////////////////////////////////////
// ARRAYS (json-serializable, except `null` not allowed)
// (all of the tests below pass w/ [], not necessarily ['==='])
// ARRAYS (with json-serializable contents)
// (note that `[]` in an exemplar is actually just shorthand for `['*']`)
// (to indicate an array of literally anything, including a mix of functions and other stuff, use `['===']`)
////////////////////////////////////////////

@@ -339,3 +344,3 @@

////////////////////////////////////////////
// example: '->'
// example: '->' (any function)
////////////////////////////////////////////

@@ -391,3 +396,4 @@

////////////////////////////////////////////
// example: === (aka undefined)
// example: === (literally anything)
// (undefined changes to '===' automatically)
////////////////////////////////////////////

@@ -921,2 +927,34 @@

////////////////////////////////////////////////
// objects which contain other crazy objects
// with no `constructor` should not throw errors
////////////////////////////////////////////////
{
example: [{
id: 123,
title: 'Robinson Crusoe',
surprise: {}
}],
actual: [{
title: 'Hank the Cowdog',
surprise: (function(){
function Dog(){}
var rover = new Dog();
rover.coolProps = 'wow so cool';
rover.constructo = 'hmm maybe ill try really annoying property names!';
rover.prototype = null;
rover.__proto__ = null;
rover.constructor = null;
// hehehehehhe
return rover;
})()
}],
result: [{
id: 0,
title: 'Hank the Cowdog',
surprise: {}
}]
}
];
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc