npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typling-core

v0.1.2

Published

Create and verify typlings on Esprima-style nodes

Downloads

8

Readme

typling-core

Create and verify typlings on Esprima-style nodes

var esprima = require('esprima')
var typling = require('typling-core')

var node = esprima.parse(
  `// Number, Number -> Number
   function foo (x, y) { return x + y }
   foo(123, 'hello world')`,
   { attachComment: true }
 )

var types = typling.create(node)
var report = typling.verify(node, types)
// [ 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 from create) against a tree of nodes, returning an array of errors if any.
  • check: A type checking function for nodes. Shortcut for create then verify 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 (estree Node): A Node created from any ESTree-compatible parser
  • options (Object): Optional object for creating context
  • options.definitions (Object): An object mapping type names (e.g. String, Number) to a type definition. Has built-in definitions
  • options.typlings (Array): Preloading typlings. Typlings from the node are added in.
// Create context and generate reports:
var result = typling.check(node)

// Result is context object:
console.log(result.report)
console.log(result.source)

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.create(node)

// Has necessary props, with no report
console.log(context.typlings)
console.log(context.definitions)
// ...

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 typligns
var context = typling.create(node)
var typlings = context.typlings

// Verify context
typling.verify(context)

// Log any reports:
console.log(context.reports)

License

MIT © Jamen Marz


version travis downloads license follow