typling-core
Create and verify typlings on Esprima-style nodes
var esprima = var typling = var node = esprima var types = typlingvar report = typling// [ TypeError { ... } ]
Takes Esprima-style nodes (see Estree) and can do 3 things of your choosing:
create
: Parses typlings (e.g.// String -> String
) into array of types that optionally point back to the nodes.verify
: Verify typlings (probably fromcreate
) against a tree of nodes, returning an array of errors if any.check
: A type checking function for nodes. Shortcut forcreate
thenverify
on the same node.
Notice: Typling requires comments to be attached to the nodes with Esprima's attachComment
option (or similar in others)
Installation
$ npm install --save typling-core
Usage
typling.check(node, [options])
Type check the node, and return a context object with all the results.
node
(estreeNode
): A Node created from any ESTree-compatible parseroptions
(Object
): Optional object for creating contextoptions.definitions
(Object
): An object mapping type names (e.g.String
,Number
) to a type definition. Has built-in definitionsoptions.typlings
(Array
): Preloading typlings. Typlings from the node are added in.
// Create context and generate reports:var result = typling // Result is context object:consoleconsole
This is typling.create
and typling.verify
turned into one step if you want simple type checker.
typling.create(node, [options])
Create a context object. Contains definitions
, typlings
, source
, report
. Same options as typling.check
// Create context (generates typlings):var context = typling // Has necessary props, with no reportconsoleconsole// ...
Note: report
will be empty until you use typling.verify
or use typling.check
instead.
typling.verify(context)
Verify a context from typling.create
. Creates objects on report
, otherwise empty.
// Create context, and cache typlignsvar context = typlingvar typlings = contexttyplings // Verify contexttypling // Log any reports:console
License
MIT © Jamen Marz