Socket
Socket
Sign inDemoInstall

rttc

Package Overview
Dependencies
1
Maintainers
4
Versions
108
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 10.0.0-1 to 10.0.0-2

.eslintrc

3

index.js

@@ -17,2 +17,3 @@ module.exports = {

getDisplayType: require('./lib/get-display-type'),
getRdt: require('./lib/get-rdt'),
isSpecific: require('./lib/is-specific'),

@@ -31,2 +32,4 @@ isInvalidExample: require('./lib/is-invalid-example'),

getNounPhrase: require('./lib/get-noun-phrase'),
GRAMMAR: require('./lib/GRAMMAR'),
getInvalidityMessage: require('./lib/get-invalidity-message'),
inferDisplayType: require('./lib/infer-display-type'),

@@ -33,0 +36,0 @@ validateExemplarStrict: require('./lib/validate-exemplar-strict'),

13

lib/coerce-exemplar.js

@@ -73,11 +73,11 @@ /**

// since `===` doesn't accept `undefined` values as of rttc@9.3.0.)
return '===';
return typeInfo('ref').getExemplar();
}
// Otherwise: treat it as if it were `null`, and use `*`.
else { return '*'; }
else { return typeInfo('json').getExemplar(); }
}
// Dehydrate the wanna-be exemplar to avoid circular recursion
// (but allow null, and don't stringify functions)
value = dehydrate(value, true, true);
// (but allow null, and don't stringify functions, and allow NaN/Infinity/-Infinity/-0)
value = dehydrate(value, true, true, true);

@@ -92,2 +92,7 @@

}
// `Infinity`, `-Infinity`, and `NaN` SHOULD become '==='
// (because they are not JSON-compatible, and not "number"s, by rttc's definition)
if (valuePart === Infinity || valuePart === -Infinity || _.isNaN(valuePart)) {
return typeInfo('ref').getExemplar();
}
// functions become '->'

@@ -94,0 +99,0 @@ else if (_.isFunction(valuePart)) {

@@ -175,3 +175,3 @@ /**

if (keys.length === 0 && (!array || value.length == 0)) {
if (keys.length === 0 && (!array || value.length === 0)) {
return braces[0] + base + braces[1];

@@ -178,0 +178,0 @@ }

@@ -18,6 +18,7 @@ /**

* @param {Boolean} dontStringifyFunctions [defaults to false]
* @param {Boolean} allowNaNAndFriends [defaults to false]
* @return {String}
*/
module.exports = function dehydrate (value, allowNull, dontStringifyFunctions) {
return rebuildSanitized(value, allowNull, dontStringifyFunctions);
module.exports = function dehydrate (value, allowNull, dontStringifyFunctions, allowNaNAndFriends) {
return rebuildSanitized(value, allowNull, dontStringifyFunctions, allowNaNAndFriends);
};

@@ -6,4 +6,4 @@ /**

var _ = require('@sailshq/lodash');
var getRdt = require('./get-rdt');
/**

@@ -26,2 +26,4 @@ * Given an RTTC "display type" aka "typeclass" string,

*
* (Also tolerates type schemas.)
*
* @optional {Dictionary} options

@@ -44,3 +46,9 @@ *

module.exports = function getDisplayTypeLabel(type, options){
if (typeof type !== 'string') {
if (typeof type === 'string') {
// OK! This is probably an RDT, so we'll try it.
} else if (!!type && typeof type === 'object') {
// This might be a type schema, so we'll parsing an RDT from it first and use that.
type = getRdt(type);
} else {
throw new Error('Usage error: rttc.getDisplayTypeLabel() expects a string display type such as '+

@@ -117,5 +125,13 @@ '`dictionary` or `ref`. If you are trying to get the display type label for an exemplar, do '+

switch (options.capitalization) {
case 'title': return !options.plural ? 'Anything' : 'Any Values';
case 'start': return !options.plural ? 'Value of any type' : 'Values of any type';
case 'fragment': return !options.plural ? 'value of any type' : 'values of any type';
case 'title': return !options.plural ? 'Value' : 'Values';
case 'start': return !options.plural ? 'Value' : 'Values';
case 'fragment': return !options.plural ? 'value' : 'values';
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Note: This was changed for flexibility. Here's the old way, for reference:
// ```
// case 'title': return !options.plural ? 'Anything' : 'Any Values';
// case 'start': return !options.plural ? 'Value of any type' : 'Values of any type';
// case 'fragment': return !options.plural ? 'value of any type' : 'values of any type';
// ```
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
}

@@ -122,0 +138,0 @@ }

@@ -9,9 +9,18 @@ /**

/**
* Given a value, return a sorta human-readable type string representing **its type**.
* Given a value, return an INFORMAL type string loosely
* representing its data type.
*
* WARNING: THIS FUNCTION IS NOT ALL THAT IT SEEMS.
* It does not return an RDT ("RTTC display type")-- it returns a display string
* that might include other values as well, such as `'undefined'`, `'null',
* `'Date'`, etc.
*
* > ------------------------------------------------------------------------
* > THIS WILL LIKELY BE DEPRECATED IN FAVOR OF MORE SPECIFIC HELPER METHODS
* > IN A FUTURE VERSION OF RTTC.
* > NOTE:
* > THIS FUNCTION IS DEPRECATED AND WILL BE REMOVED IN FAVOR OF MORE
* > SPECIFIC UTILITY METHODS IN AN UPCOMING RELEASE OF RTTC.
* > ------------------------------------------------------------------------
*
* TODO: Remove this
*
* @param {===} val

@@ -18,0 +27,0 @@ * @return {String}

@@ -7,2 +7,3 @@ /**

var getDisplayTypeLabel = require('./get-display-type-label');
var getRdt = require('./get-rdt');

@@ -28,3 +29,5 @@

*
* (Also tolerates type schemas.)
*
*
* @optional {Dictionary} options

@@ -59,3 +62,8 @@ *

module.exports = function getNounPhrase(type, options){
if (typeof type !== 'string') {
if (typeof type === 'string') {
// OK! This is probably an RDT, so we'll try it.
} else if (!!type && typeof type === 'object') {
// This might be a type schema, so we'll parsing an RDT from it first and use that.
type = getRdt(type);
} else {
throw new Error('Usage error: rttc.getNounPhrase() expects a string display type such as '+

@@ -62,0 +70,0 @@ '`dictionary` or `ref`. If you are trying to get the noun phrase for an exemplar, do '+

@@ -20,4 +20,5 @@ /**

* @param {Boolean?} dontStringifyFunctions
* @param {Boolean?} allowNaNAndFriends
*/
module.exports = function rebuildSanitized(val, allowNull, dontStringifyFunctions) {
module.exports = function rebuildSanitized(val, allowNull, dontStringifyFunctions, allowNaNAndFriends) {

@@ -32,3 +33,3 @@ // Does not `allowNull` by default.

return _rebuild(val, allowNull, dontStringifyFunctions);
return _rebuild(val, allowNull, dontStringifyFunctions, allowNaNAndFriends);
};

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

function _rebuild(val, allowNull, dontStringifyFunctions) {
function _rebuild(val, allowNull, dontStringifyFunctions, allowNaNAndFriends) {
var stack = [];

@@ -119,15 +120,18 @@ var keys = [];

// Coerce NaN, Infinity, and -Infinity to 0:
if (_.isNaN(val)) {
val = 0;
// (unless "allowNaNAndFriends" is enabled)
if (!allowNaNAndFriends) {
if (_.isNaN(val)) {
val = 0;
}
else if (val === Infinity) {
val = 0;
}
else if (val === -Infinity) {
val = 0;
}
// Coerce -0 to +0
else if (val === 0) {
val = 0;
}
}
else if (val === Infinity) {
val = 0;
}
else if (val === -Infinity) {
val = 0;
}
// Coerce -0 to +0
else if (val === 0) {
val = 0;
}
}

@@ -134,0 +138,0 @@ else if (_.isObject(val)) {

@@ -110,3 +110,3 @@ /**

else {
msg += 'Specified value (a ' + getDisplayType(actual) + ': '+compile(actual)+') ';
msg += 'Specified value (a ' + getDisplayType(actual) + ': '+((actual===Infinity||actual===-Infinity||_.isNaN(actual))?actual:compile(actual))+') ';
msg += 'doesn\'t match the expected '+(_.isObject(expected)?getDisplayType(expected)+' ':'')+'type'+(_.isObject(expected)?' schema ':'')+ ': ' + compile(expected) + '';

@@ -113,0 +113,0 @@ }

@@ -40,3 +40,3 @@ /**

catch (e) {
throw new Error('Could not JSON.parse() provided value:'+value);
throw new Error('Could not JSON.parse() provided value: '+value);
}

@@ -43,0 +43,0 @@

@@ -24,3 +24,3 @@ /**

* understanding it as `['*']`, purely for backwards compatibility.
* @default true
* @default false
*

@@ -27,0 +27,0 @@ * @throws {Error} If the provided `supposedExemplar` is not a pure RTTC exemplar.

@@ -18,3 +18,3 @@ /**

var errors = [];
var result = validateRecursive(expected, actual, errors, [], true);
validateRecursive(expected, actual, errors, [], true);
// ( `true` => `strict` -- i.e. don't ignore minor type errors)

@@ -21,0 +21,0 @@

{
"name": "rttc",
"version": "10.0.0-1",
"version": "10.0.0-2",
"description": "Runtime type-checking for JavaScript.",

@@ -13,5 +13,6 @@ "main": "index.js",

"validation",
"static-analysis",
"typed-javascript"
],
"author": "The Treeline Company",
"author": "The Sails Company",
"contributors": [

@@ -40,4 +41,5 @@ "Mike McNeil <@mikermcneil>",

"devDependencies": {
"eslint": "3.19.0",
"mocha": "3.0.2"
}
}

@@ -106,13 +106,13 @@ # RTTC

| type | rttc exemplar syntax | base value |
|:------------------------|:-------------------------|:------------------------------------|
| string | `'any string like this'` | `''`
| number | `1337` _(any number)_ | `0`
| boolean | `false` _(or `true`)_ | `false`
| lamda (aka function) | `'->'` | `function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); };`
| generic dictionary | `{}` | `{}` _(empty dictionary)_
| json | `'*'` | `null`
| ref | `'==='` | `null`
| faceted dictionary _(recursive)_ | `{...}` _(i.e. w/ keys)_ | `{...}` (w/ all expected keys and _their_ base values)
| array _(recursive)_ | `[...]` _(i.e. w/ 1 item)_ | `[]` _(empty array)_
| type | rttc exemplar syntax | type schema | base value |
|:------------------------|:-------------------------|:----------------|:-------------------|
| string | `'any string like this'` | `'string'` | `''`
| number | `1337` _(any number)_ | `'number'` | `0`
| boolean | `false` _(or `true`)_ | `'boolean'` | `false`
| lamda (aka function) | `'->'` | `'lamda'` | `function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); };`
| generic dictionary | `{}` | `{}` | `{}` _(empty dictionary)_
| json | `'*'` | `'json'` | `null`
| ref | `'==='` | `'ref'` | `null`
| faceted dictionary _(recursive, w/ keys called "facets")_ | `{...}` _(i.e. w/ facet:nested-exemplar pairs)_ | `{...}` _(i.e. w/ facet:nested-type-schema pairs)_ | `{...}` _(w/ facet:nested-base-value pairs)_
| array _(recursive, w/ 1 item called the "pattern")_ | `[...]` _(i.e. w/ pattern exemplar)_ | `[...]` _(i.e. w/ pattern type schema)_ | `[]` _(empty array)_

@@ -190,5 +190,5 @@

| Exemplar | RTTC Display Type | Display Type Label | Base Value |
|:-----------------------|:-----------------------|:------------------------------|:----------------------------|
| `{}` | `'dictionary'` | `'Dictionary'` | `{}` _(empty dictionary)_ |
| Exemplar | Type Schema | RTTC Display Type | Display Type Label | Base Value |
|:-----------------------|:------------|:-----------------------|:------------------------------|:----------------------------|
| `{}` | `{}` | `'dictionary'` | `'Dictionary'` | `{}` _(empty dictionary)_ |

@@ -240,5 +240,5 @@ The **generic dictionary** type accepts any JSON-serializable dictionary.

| Exemplar | RTTC Display Type | Display Type Label | Base Value |
|:-----------------------|:-----------------------|:------------------------------|:----------------------|
| `{...}` _(recursive)_ | `'dictionary'` | `'Dictionary'` | `{...}` _(see below)_ |
| Exemplar | Type Schema | RTTC Display Type | Display Type Label | Base Value |
|:-----------------------|:----------------------|:-----------------------|:------------------------------|:----------------------|
| `{...}` _(recursive)_ | `{...}` _(see below)_ | `'dictionary'` | `'Dictionary'` | `{...}` _(see below)_ |

@@ -365,5 +365,5 @@ The **faceted dictionary** type is any dictionary type schema with at least one key. When coercing a value to a faceted dictionary, any keys in the value that are _not_ in the type schema will be stripped out. Missing keys in the value will cause `.validate()` to throw.

| Exemplar | RTTC Display Type | Display Type Label | Base Value |
|:-----------------------|:-----------------------|:------------------------------|:-----------------------|
| `[...]` _(recursive)_ | `'array'` | `'Array'` | `[]` _(empty array)_ |
| Exemplar | Type Schema | RTTC Display Type | Display Type Label | Base Value |
|:-----------------------|:-----------------------|:-----------------------|:------------------------------|:----------------------|
| `[...]` _(recursive)_ | `[...]` _(see below)_ | `'array'` | `'Array'` | `[]` _(empty array)_ |

@@ -370,0 +370,0 @@

@@ -57,3 +57,3 @@ /**

// Otherwise allow vanilla _.cloneDeep() behavior:
else return undefined;
else { return undefined; }
});

@@ -60,0 +60,0 @@ };

@@ -1,4 +0,2 @@

var util = require('util');
var assert = require('assert');
var _ = require('@sailshq/lodash');
var rttc = require('../');

@@ -5,0 +3,0 @@

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

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc