Comparing version 0.6.0 to 1.0.0
11
index.js
module.exports = { | ||
// Expose `validate()` and `coerce()` methods. | ||
validate: require('./lib/validate'), | ||
coerce: require('./lib/coerce'), | ||
// Support for rttc() and infer(). | ||
// (these are here for compatibility and will likely | ||
// be removed in a future version) | ||
rttc: require('./lib/rttc'), | ||
infer: require('./lib/infer'), | ||
// Also expose `types` object for compatibility. | ||
types: require('./lib/types') | ||
infer: require('./lib/infer') | ||
}; |
@@ -205,2 +205,5 @@ /** | ||
} | ||
if (coercedValue.length === 0) { | ||
return []; | ||
} | ||
var arrayItemTpl = expected[0]; | ||
@@ -207,0 +210,0 @@ return [_validateRecursive(arrayItemTpl, coercedValue[0], errors, ensureSerializable)]; |
{ | ||
"name": "rttc", | ||
"version": "0.6.0", | ||
"version": "1.0.0", | ||
"description": "Runtime type-checking for JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
107
README.md
@@ -211,3 +211,2 @@ # rttc | ||
```js | ||
@@ -236,3 +235,5 @@ rttc.coerce('string', 'foo'); | ||
If value cannot be properly coerced, defaults to base type: | ||
If value can't be properly coerced, the "base value" for the type will be used: | ||
``` | ||
@@ -265,103 +266,1 @@ rttc.coerce('number', 'asdf'); | ||
## Legacy Usage | ||
The usage of this module has been extended considerably, but backwards compatibility will be maintained up until the first major version bump (v1.0.0). | ||
See tests for more details. | ||
#### rttc.rttc(expectations, inputValues, [options]) | ||
Validate and/or coerce a set of input values against a set of expectations (defined as input definitions.) | ||
Two options may be provided: | ||
+ `coerce` - before failing, attempt to coerce not-quite-right input values to their expected type. | ||
+ `base` - if an input value is missing, fill in its place in the result to the "base type" (falsy value) | ||
```js | ||
require('rttc').rttc({ | ||
foo: { | ||
type: 'string', | ||
required: true | ||
}, | ||
bar: { | ||
type: { baz: {name: 'string'} }, | ||
required: false | ||
} | ||
}, { | ||
foo: 'hi', | ||
bar: { | ||
baz: { | ||
name: 'Rick' | ||
} | ||
} | ||
}); | ||
``` | ||
#### rttc.types | ||
```js | ||
require('rttc').types; | ||
// => | ||
/* | ||
{ nan: { is: [Function: isNaN], to: [Function] }, | ||
null: { is: [Function: isNull], to: [Function] }, | ||
undefined: | ||
{ is: [Function: isUndefined], | ||
to: [Function] }, | ||
bool: | ||
{ is: [Function: isBoolean], | ||
to: [Function], | ||
base: false }, | ||
defined: { is: [Function], to: [Function] }, | ||
int: | ||
{ is: [Function], | ||
to: [Function], | ||
base: 0 }, | ||
str: | ||
{ is: [Function: isString], | ||
to: [Function], | ||
base: '' }, | ||
obj: { is: [Function], to: [Function], base: {} }, | ||
arr: | ||
{ is: [Function: isArray], | ||
to: [Function], | ||
base: [] }, | ||
date: | ||
{ is: [Function: isDate], | ||
to: [Function], | ||
base: Tue Jan 13 2015 08:58:29 GMT-0800 (PST) }, | ||
number: | ||
{ is: [Function], | ||
to: [Function], | ||
base: 0 }, | ||
url: | ||
{ is: [Function: isString], | ||
to: [Function], | ||
base: '' }, | ||
email: | ||
{ is: [Function: isString], | ||
to: [Function], | ||
base: '' }, | ||
string: | ||
{ is: [Function: isString], | ||
to: [Function], | ||
base: '' }, | ||
boolean: | ||
{ is: [Function: isBoolean], | ||
to: [Function], | ||
base: false }, | ||
integer: | ||
{ is: [Function], | ||
to: [Function], | ||
base: 0 }, | ||
float: | ||
{ is: [Function], | ||
to: [Function], | ||
base: 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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
22120
9
531
264