Comparing version 9.3.4 to 9.4.0
@@ -27,2 +27,4 @@ module.exports = { | ||
rebuild: require('./lib/rebuild'), | ||
getDisplayTypeLabel: require('./lib/get-display-type-label'), | ||
inferDisplayType: require('./lib/infer-display-type'), | ||
}; | ||
@@ -29,0 +31,0 @@ |
@@ -9,5 +9,9 @@ /** | ||
/** | ||
* Given a value, return a human-readable type string representing **its type**. | ||
* Useful for error messages, user interfaces, etc. | ||
* Given a value, return a sorta human-readable type string representing **its type**. | ||
* | ||
* > ------------------------------------------------------------------------ | ||
* > THIS WILL LIKELY BE DEPRECATED IN FAVOR OF MORE SPECIFIC HELPER METHODS | ||
* > IN A FUTURE VERSION OF RTTC. | ||
* > ------------------------------------------------------------------------ | ||
* | ||
* @param {===} val | ||
@@ -14,0 +18,0 @@ * @return {String} |
@@ -76,3 +76,7 @@ /** | ||
} | ||
// Otherwise, this is a homogeneous array so take the recursive step. | ||
// Otherwise, this is a pattern array so take the recursive step. | ||
// (but first check to make sure both things are actually arrays) | ||
if (!_.isArray(firstValueSegment) || !_.isArray(secondValueSegment)){ | ||
return false; | ||
} | ||
return _.all(firstValueSegment, function checkEachItemIn1stArray(unused, i){ | ||
@@ -90,2 +94,8 @@ return _isEqualRecursive(firstValue, secondValue, typeSchemaHere[0], keypathArray, i); | ||
} | ||
// Otherwise, this is a facted dictionary so take the recursive step. | ||
// (but first check to make sure both things are actually dictionaries) | ||
if (_.isArray(firstValueSegment) || !_.isObject(firstValueSegment) || _.isArray(secondValueSegment) || !_.isObject(secondValueSegment)){ | ||
return false; | ||
} | ||
return _.all(firstValueSegment, function checkEachItemIn1stDict(unused, key){ | ||
@@ -92,0 +102,0 @@ return _isEqualRecursive(firstValue, secondValue, typeSchemaHere[key], keypathArray, key); |
{ | ||
"name": "rttc", | ||
"version": "9.3.4", | ||
"version": "9.4.0", | ||
"description": "Runtime type-checking for JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -464,5 +464,23 @@ # rttc | ||
##### .union(schema0, schema1, [isExemplar=false], [isStrict=false]) | ||
Given two rttc schemas (e.g. `A` and `B`), return the most specific schema that would accept the superset of what both schemas accept normally (`A ∪ B`). | ||
+ _schema0_ - the first schema | ||
+ _schema1_ - the second schema (order doesn't matter) | ||
+ _isExemplar_ - if set, the schemas will be treated as exemplars (rather than type schemas) | ||
+ _isStrict_ - if set, the schemas will be unioned using strict validation rules (i.e. like `validateStrict()`) | ||
##### .intersection(schema0, schema1, [isExemplar=false], [isStrict=false]) | ||
Given two rttc schemas, return the most specific schema that accepts the shared subset of values accepted by both. Formally, this subset is the intersection of A and B (A ∩ B), where A is the set of values accepted by `schema0` and B is the set of values accepted by `schema1`. If `A ∩ B` is the empty set, then this function will return `null`. Otherwise it will return the schema that precisely accepts `A ∩ B`. | ||
+ _schema0_ - the first schema | ||
+ _schema1_ - the second schema (order doesn't matter) | ||
+ _isExemplar_ - if set, the schemas will be treated as exemplars (rather than type schemas) | ||
+ _isStrict_ - if set, the schemas will be intersected using strict validation rules (i.e. like `validateStrict()`) | ||
### Experimental | ||
@@ -474,7 +492,5 @@ | ||
Rebuild (non-destructively) the specified value using the provided transformer function to change each primitive or function therein. | ||
Recursively rebuild (non-destructively) the specified value using the provided transformer function to change each primitive or function therein. Transformer function is provided the value as the first argument, and an rttc display type as the second (either 'string', 'number', 'boolean', 'lamda', or 'null'). The transformer function is not run for dictionaries or arrays, since they're recursed into automatically (in the rebuilt value, they will be normal dictionary and array literals, so any stuff about getters/setters/non-enumerable properties like prototypal methods and constructor information is all stripped out. `.rebuild()` also protects against endless recursion due to circular references. | ||
Transformer function is provided the value as the first argument, and an rttc display type as the second (either 'string', 'number', 'boolean', 'lamda', or 'null'). | ||
e.g. | ||
Example usage: | ||
```javascript | ||
@@ -489,3 +505,3 @@ return res.json(rttc.rebuild(someData, function transformLeaf(val, type){ | ||
Given a type schema, return an exemplar which accepts precisely the same set of values. | ||
Given a type schema, return a random exemplar which accepts precisely the same set of values. | ||
@@ -527,4 +543,17 @@ ##### .coerceExemplar(value, [allowSpecialSyntax=false]) | ||
Return truthy if the provided value is NOT a valid rttc exemplar. | ||
Return truthy if the provided value is NOT a valid rttc exemplar (e.g. `null`). | ||
##### .getDisplayTypeLabel(type) | ||
Given an RTTC "display type" aka "typeclass" string, return the appropriate human-readable label for that type. Useful for error messages, user interfaces, etc. | ||
```js | ||
rttc.getDisplayTypeLabel('ref'); | ||
// => 'Anything' | ||
rttc.getDisplayTypeLabel('string'); | ||
// => 'String' | ||
``` | ||
##### .getPathInfo(exemplar, path) | ||
@@ -534,2 +563,4 @@ | ||
> WARNING: Since hops in keypaths are represented by `.` (dots), this method is not safe to use on exemplars which contain any keys which contain dots. This may be improved in future versions. | ||
```js | ||
@@ -561,24 +592,7 @@ var SOME_EXEMPLAR = { | ||
##### .union(schema0, schema1, [isExemplar=false], [isStrict=false]) | ||
Given two rttc schemas (e.g. `A` and `B`), return the most specific schema that would accept the superset of what both schemas accept normally (`A ∪ B`). | ||
##### .reify(typeSchema) | ||
+ _schema0_ - the first schema | ||
+ _schema1_ - the second schema (order doesn't matter) | ||
+ _isExemplar_ - if set, the schemas will be treated as exemplars (rather than type schemas) | ||
+ _isStrict_ - if set, the schemas will be unioned using strict validation rules (i.e. like `validateStrict()`) | ||
> **DEPRECATED**. This method will become an alias for `coerceExemplar` in future versions of rttc, and its current implementation will be removed. | ||
##### .intersection(schema0, schema1, [isExemplar=false], [isStrict=false]) | ||
Given two rttc schemas, return the most specific schema that accepts the shared subset of values accepted by both. Formally, this subset is the intersection of A and B (A ∩ B), where A is the set of values accepted by `schema0` and B is the set of values accepted by `schema1`. If `A ∩ B` is the empty set, then this function will return `null`. Otherwise it will return the schema that precisely accepts `A ∩ B`. | ||
+ _schema0_ - the first schema | ||
+ _schema1_ - the second schema (order doesn't matter) | ||
+ _isExemplar_ - if set, the schemas will be treated as exemplars (rather than type schemas) | ||
+ _isStrict_ - if set, the schemas will be intersected using strict validation rules (i.e. like `validateStrict()`) | ||
##### .reify(typeSchema) | ||
Given a type schema, strip out generics ("ref", "json", {}, and []) to convert it into a "specific" type. In other words, the result of this function always passes `rttc.isSpecific()`. | ||
@@ -589,3 +603,3 @@ | ||
A convenience method to return the base value for the given exemplar. | ||
A convenience method to return the base value for the given exemplar. This is effectively the same thing as calling `rttc.infer()` to get its type schema, then coercing `undefined` to match (i.e. passing the type schema to `rttc.coerce()` without a second argument). | ||
@@ -592,0 +606,0 @@ ##### .cast(exemplar, actualValue) |
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
234514
47
5022
609