array-type
v0.1.0
Published
the array type info object.
Downloads
6
Maintainers
Readme
array-type
The array type. See the type-info for type info collections.
Usage
//register the array type to the TypeInfo..
require('array-type')
var TypeInfo = require('abstract-type')
//get the array type info:
var ArrayType = TypeInfo('array')
/*
//Just load array type only:
var ArrayTypeInfo = require('array-type')
var ArrayType = ArrayTypeInfo()
*/
var LimitedArrayType = TypeInfo('array', min:1, max:3)
var arr = ArrayType.create([1,2,3])
//var arr = ArrayType.createValue([1,2,3]) //it's the same.
console.log(arr)
//<type "array": "value":[1,2,3]>
console.log(arr.isValid())
//=true
console.log(arr.toJson()))
//='[1,2,3]'
console.log(arr.toJson({withType:true})))
//='{"value":[1,2,3],"name":"array"}'
console.log(LimitedArrayType.isValid([]))
//=false
console.log(LimitedArrayType.isValid([1]))
//=true
var n = arr.clone();
n.assign('aaa')
//=TypeError: "aaa" is an invalid array
API
- The ArrayType Class
- options:
- min: the minimum length of the array. null or undefined means unlimited.
- max: the maximum length of the array.
- options:
See abstract-type
TODO
of
option to limit the element's type.- eg,
ArrayType of: 'String'
- eg,
License
MIT