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.6.3 to 9.7.0

lib/get-noun-phrase.js

1

index.js

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

getDisplayTypeLabel: require('./lib/get-display-type-label'),
getNounPhrase: require('./lib/get-noun-phrase'),
inferDisplayType: require('./lib/infer-display-type'),

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

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

if (typeof type !== 'string') {
throw new Error('Usage error: rttc.getDisplayTypeLabel() expects a string display type such as `dictionary` or `ref`. If you are trying to get the display type label for an exemplar, do `rttc.getDisplayTypeLabel(rttc.inferDisplayType(exemplar))`.');
throw new Error('Usage error: rttc.getDisplayTypeLabel() expects a string display type such as '+
'`dictionary` or `ref`. If you are trying to get the display type label for an exemplar, do '+
'`rttc.getDisplayTypeLabel(rttc.inferDisplayType(exemplar))`. If you are trying to get a display '+
'type label to represent voidness (i.e. a null exemplar), then you should determine that on a '+
'case-by-case basis-- there\'s no good sane default.');
}

@@ -25,0 +29,0 @@

12

package.json
{
"name": "rttc",
"version": "9.6.3",
"version": "9.7.0",
"description": "Runtime type-checking for JavaScript.",
"main": "index.js",
"scripts": {
"test": "node ./node_modules/mocha/bin/mocha --recursive -R dot"
"test": "node ./node_modules/mocha/bin/mocha --recursive -R dot",
"browserify": "browserify -s rttc -o rttc.browser.js ./"
},

@@ -14,6 +15,9 @@ "keywords": [

],
"author": "Cody Stoltman <@particlebanana>",
"author": "The Treeline Company",
"contributors": [
"Mike McNeil <@mikermcneil>",
"Scott Gress <@sgress454>"
"Scott Gress <@sgress454>",
"Cody Stoltman <@particlebanana>",
"Rachael Shaw <@rachaelshaw>",
"Irl Nathan <@irlnathan>"
],

@@ -20,0 +24,0 @@ "license": "MIT",

@@ -1,5 +0,5 @@

# rttc
# RTTC
Runtime (recursive) type-checking for JavaScript.
This package is the official SDK for working with the RTTC type system. It includes a lot of methods that suitable for everyday use, as well as some lower-level methods that are intended for developers building tools which leverage the [machine specification](http://node-machine.org).
This package is the official SDK for working with the RTTC type system. It includes a lot of methods suitable for everyday use, as well as some lower-level methods that are intended for developers building tools which leverage the [machine specification](http://node-machine.org).

@@ -14,3 +14,3 @@ ## What is RTTC?

+ the Node-Machine project's core utility packages, including the [`machine` runner](https://github.com/node-machine/machine)
+ throughout the [Sails.js framework](http://sailsjs.org)
+ the [Sails.js framework core](http://sailsjs.org)
+ every [Waterline driver](https://github.com/node-machine/driver-interface)

@@ -36,24 +36,25 @@ + every [machinepack published on NPM](http://node-machine.org/machinepacks), and

```javascript
// If the value is valid vs. the specified type schema, then `.validateStrict()` simply returns undefined
rttc.validateStrict('number', 999);
// (If the value is valid vs. the specified type schema, then `.validateStrict()` simply returns undefined)
// => undefined
// But if the provided value is **even slightly off**, then `.validateStrict()` throws.
rttc.validateStrict('number', '999');
// throws Error
// (but if the provided value is **even slightly off**, then `.validateStrict()` throws).
// If the provided value is close-ish, `.validate()` coerces as needed to make it fit.
rttc.validate('number', '999');
// => 999
// (if the provided value is close-ish, `.validate()` coerces as needed to make it fit.)
// But when confronted with **major** differences, `.validate()` throws too.
rttc.validate('number', { x: 32, y: 79 });
// throws Error
// (but when confronted with **major** differences, `.validate()` throws too.)
// As long as the provided type schema is valid, `.coerce()` **never** throws
rttc.coerce('number', '999');
// => 999
// (as long as the provided type schema is valid, `.coerce()` **never** throws)
// When confronted with **major** differences, `.coerce()` returns the _base value_ for the given type
rttc.coerce('number', { x: 32, y: 79 });
// => 0
// (when confronted with **major** differences, `.coerce()` returns the _base value_ for the given type)
```

@@ -65,3 +66,3 @@

are _themselves_ dictionaries or arrays, then `rttc` recursively dives into them too (and
so on and so forth).
so on and so forth).

@@ -155,3 +156,3 @@

The **number** type accepts numbers like `0`, `-4`, or `235.3`. Anathemas like `Infinity`, `-Infinity`, `NaN`, and `-0` are all coerced to zero.
The **number** type accepts integers and decimal numbers like `0`, `-4`, or `235.3`. Number-ish properties like `Infinity`, `-Infinity` and `NaN` (as well as `-0`) are all coerced to zero.

@@ -199,3 +200,3 @@ ## Booleans

Dictionaries that have been validated/coerced against the generic dictionary type:
+ will have no prototypal properties, getters, or setters, as well as a complete deficit of any other sort of deceit, lies, or magic
+ will have no prototypal properties, getters, or setters, as well as a complete deficit of any other sort of dark magic
+ are guaranteed to be JSON-serializable, with a few additional affordances:

@@ -213,3 +214,3 @@ + normally, `Error` instances get stringified into empty objects. Instead, rttc turns them into human-readable strings by reducing them to their `.stack` property (this includes the error message and the stack trace w/ line numbers)

When validating or coercing a value vs. a generic dictionary exemplar or type schema, keys with `undefined` values _will always be stripped out_. For example, coercing `{ name: 'Rob', age: undefined, weight: undefined }` vs. the type schema `{}` would result in `{ name: 'Rob' }`. This ensures consistency with the behavior of the native JSON.stringify() and JSON.parse() methods in browser-side JavaScript and Node.js.
When validating or coercing a value vs. a generic dictionary exemplar or type schema, keys with `undefined` values _will always be stripped out_. For example, coercing `{ name: 'Rob', age: undefined, weight: undefined }` vs. the type schema `{}` would result in `{ name: 'Rob' }`. This ensures consistency with the behavior of the native JSON.stringify() and JSON.parse() methods in browser-side JavaScript and Node.js.

@@ -247,3 +248,3 @@ > Note that `undefined` array items are stripped out _even if you are using `['===']`_.

The **faceted dictionary** type is any dictionary type schema with at least one key. Extra keys in the actual value that are not in the type schema will be stripped out. Missing keys will cause `.validate()` to throw.
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.

@@ -323,3 +324,3 @@ Dictionary type schemas (i.e. plain old JavaScript objects nested like `{a:{}}`) can be infinitely nested. Type validation and coercion will proceed through the nested objects recursively.

```js
var alfred = rttc.coerce(rttc.infer(USER_SCHEMA), {
var alfred = rttc.cast(USER_SCHEMA, {
id: 100,

@@ -410,3 +411,3 @@ name: 'Alfred Roberts',

When validating or coercing a value vs. an array exemplar or type schema, `undefined` items in the array _will always be stripped out_. For example, coercing `['Jerry', undefined, undefined, 'Robin']` vs. the type schema `['string']` would result in `['Jerry', 'Robbin']`. This ensures consistency with the behavior of the native JSON.stringify() and JSON.parse() methods in browser-side JavaScript and Node.js.
When validating or coercing a value vs. an array exemplar or type schema, `undefined` items in the array _will always be stripped out_. For example, coercing `['Jerry', undefined, undefined, 'Robin']` vs. the type schema `['string']` would result in `['Jerry', 'Robbin']`. This ensures consistency with the behavior of the native JSON.stringify() and JSON.parse() methods in browser-side JavaScript and Node.js.

@@ -434,4 +435,3 @@ > Note that `undefined` array items are stripped out _even if you are using `['===']`_.

+ `NaN` is only valid against the mutable reference type (`'==='`)
+ `Infinity` and `-Infinity` is only valid against the mutable reference type (`'==='`)
+ `Infinity` and `-Infinity` are only valid against `example: '==='`
+ `Infinity` and `-Infinity` are only valid against the mutable reference type (`'==='`)
+ `+0` and `-0` are always coerced to `0` (except against the mutable reference type)

@@ -482,3 +482,3 @@

Throws if the provided value is not the right type (recursive).
Throw an error if the provided value is not the right type (recursive).

@@ -488,3 +488,3 @@

Either returns a (potentially "lightly" coerced) version of the value that was accepted, or it throws. The "lightly" coerced value turns `"3"` into `3`, `"true"` into `true`, `-4.5` into `"-4.5"`, etc.
Either return a (potentially "lightly" coerced) version of the value that was accepted, or throw an error. The "lightly" coerced value turns `"3"` into `3`, `"true"` into `true`, `-4.5` into `"-4.5"`, etc.

@@ -497,3 +497,3 @@

This is the method used by `rttc`'s own tests to validate that expected values and actual values match.
If the third argument was provided, also look for expected `lamda` values in the optional type schema and call `toString()` on functions before comparing them.
If the third argument is provided, `.isEqual` also looks for expected `lamda` values in the optional type schema and calls `toString()` on functions before comparing them.

@@ -507,3 +507,3 @@

ALWAYS returns an acceptable version of the value, even if it has to mangle it to get there (i.e. by using the "base value" for the expected type schema).
ALWAYS return an acceptable version of the value, even if it has to be mangled (i.e. by using the "base value" for the expected type schema).

@@ -546,14 +546,14 @@

This takes care of a few serialization edge-cases, such as:
Prepare a value for serialization by taking care of a few edge-cases, such as:
+ stringifies regexps, errors (grabs the `.stack` property), and functions (unless `dontStringifyFunctions` is set)
+ stringifying regexps, errors (grabs the `.stack` property), and functions (unless `dontStringifyFunctions` is set)
+ replacing circular references with a string (e.g. `[Circular]`)
+ replaces `-Infinity`, `Infinity`, and `NaN` with 0
+ strips keys and array items with `undefined` or `null` values. If `allowNull` is set to true, `null` values will not be stripped from the encoded string.
+ replacing `-Infinity`, `Infinity`, and `NaN` with 0
+ stripping keys and array items with `undefined` or `null` values. If `allowNull` is set to true, `null` values will not be stripped from the encoded string.
Note that arrays, dictionaries and literals are _not_ stringified by `dehydrate`. Rather, `dehydrate` prepares a value for stringification (see `rttc.stringify()` below).
##### .hydrate(value, [_typeSchema_=`undefined`])
This function will use the provided `typeSchema` to figure out where "lamda" values (functions) are expected, then will use `eval()` to bring them back to life. Use with care.
Use the provided `typeSchema` to figure out where "lamda" values (functions) are expected, then use `eval()` to bring them back to life. Use with care.

@@ -651,4 +651,6 @@

Convert a JavaScript value into a string that can be parsed by `stringifyHuman()`. Specifically, this method is an inverse operation of `.parseHuman()`; that is, if you take the stringified result from this function and pass that in to `.parseHuman()` using the same type schema, you'll end up back where you started: with the original JavaScript value you passed in to `rttc.stringifyHuman()`.
Convert a JavaScript value into a string that can be parsed by `parseHuman()`.
Specifically, this method is an inverse operation of `.parseHuman()`; that is, if you take the stringified result from this function and pass that in to `.parseHuman()` using the same type schema, you'll end up back where you started: with the original JavaScript value you passed in to `rttc.stringifyHuman()`.
> This losslessness is guaranteed by two factors: that `stringifyHuman()` (1) enforces _strict_ RTTC validation

@@ -655,0 +657,0 @@ > rules (i.e. `rttc.validateStrict(typeSchema, value)`) and (2) the fact that it rejects values which cannot be safely

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