Skip to content package
type-registry v0.0.2 Provides a container which can hold different kinds of Type.
node any 1 deps cjs open source
overview readme
license MIT
deps 1
unpacked Unknown
files Unknown
node any $ npm install type-registry@0.0.2n npmREADME GitHub-flavored package documentation.
downloads Across all versions.
Download trend unavailable.
compatibility Runtime metadata.
keywords Tagged topics.
type types type system type registry static typing
install size Estimated unpacked size across 4 packages.
1.3 MB
Includes dependencies.
dependencies 1 direct dependencies.
versions Latest published Mar 26, 2016
maintainers Registry package owners.
contents type-registry
A simple container used to declare different kinds of Type.
What?
Yeah. This doesn't make much sense in isolation, it's part of a larger (soon to be released) project centering around typed objects.
Installation
Install via npm .
npm install type-registry copy
Usage
import TypeRegistry from "type-registry" ;
const Uint32 = {
id: 1 , // Unique id for this type, mandatory
name: 'UInt32' , // Unique name for this type, can be a string or symbol, mandatory.
anythingElseYouWant: 'goes here'
};
const Float64 = {
id: 2 ,
name: 'Float64'
};
const registry = new TypeRegistry ();
registry. has (Uint32); // false
registry. add (Uint32);
registry. has (Uint32); // true
let added =
License
Published by codemix under a permissive MIT License, see LICENSE.md .
false
;
registry. on ( 'add' , (newType) => {
added = true ;
});
added === false ;
registry. add (Float64);
added === true ;
registry. get ( 'Uint32' ) === Uint32;
registry. get ( 1 ) === Uint32;
registry. get ( 2 ) === Float64;
registry.T.Uint32 === Uint32;
registry.T.Float64 === Float64;
registry.I[ 1 ] === Uint32;
registry.I[ 2 ] === Float64;
registry. isValidType ({}); // false
registry. isValidType ({id: 123 }); // false
registry. isValidType ({id: 123 , name: 'User' }); // true
function User {};
registry. isValidType (User); // false
User.id = 456 ;
registry. isValidType (User); // true
console. log ( 'Total number of items in the registry:' , registry.size);
for ( const type of registry) {
console. log (type);
}
copy