Comparing version 8.1.3 to 8.1.4
@@ -14,6 +14,10 @@ /** | ||
* | ||
* If `allowSpecialSyntax` is set, '->', '*', and '===' take on their traditional special meaning. | ||
* Otherwise, they will be replaced with strings ('an arrow symbol', 'a star symbol', '3 equal signs') | ||
* | ||
* @param {*} value | ||
* @param {Boolean} allowSpecialSyntax | ||
* @return {*} | ||
*/ | ||
module.exports = function coerceExemplar (value) { | ||
module.exports = function coerceExemplar (value, allowSpecialSyntax) { | ||
@@ -45,9 +49,9 @@ // Top-level `undefined` becomes `===` | ||
else if (typeInfo('json').isExemplar(valuePart)) { | ||
return typeInfo('json').getExemplarDescription(); | ||
return allowSpecialSyntax ? valuePart : typeInfo('json').getExemplarDescription(); | ||
} | ||
else if (typeInfo('ref').isExemplar(valuePart)) { | ||
return typeInfo('ref').getExemplarDescription(); | ||
return allowSpecialSyntax ? valuePart : typeInfo('ref').getExemplarDescription(); | ||
} | ||
else if (typeInfo('lamda').isExemplar(valuePart)) { | ||
return typeInfo('lamda').getExemplarDescription(); | ||
return allowSpecialSyntax ? valuePart : typeInfo('lamda').getExemplarDescription(); | ||
} | ||
@@ -54,0 +58,0 @@ // arrays need a recursive step |
{ | ||
"name": "rttc", | ||
"version": "8.1.3", | ||
"version": "8.1.4", | ||
"description": "Runtime type-checking for JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -460,3 +460,3 @@ # rttc | ||
##### .coerceExemplar(value) | ||
##### .coerceExemplar(value, [allowSpecialSyntax=false]) | ||
@@ -478,7 +478,5 @@ Convert a normal value into an exemplar representative of the _most specific_ type schema which would accept it. In most cases, this leaves the value untouched-- however it does take care of a few special cases: | ||
If the `allowSpecialSyntax` flag is enabled, then `*`, `->`, and `===` will take on their traditional meaning instead of being replaced with strings (e.g. "a star symbol"). | ||
```js | ||
rttc.coerceExemplar({x:'*'}) | ||
// => { x: 'a star symbol' } | ||
rttc.coerceExemplar([{a:null}, {b: [[74,39,'surprise string!']] }]) | ||
@@ -489,2 +487,8 @@ // => [ {} ] | ||
// => [ 'surprise string!' ] | ||
rttc.coerceExemplar({x:'*'}) | ||
// => { x: 'a star symbol' } | ||
rttc.coerceExemplar({x:'*'}, true) | ||
// => { x: '*' } | ||
``` | ||
@@ -491,0 +495,0 @@ |
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
213724
4554
560