Coder Social home page Coder Social logo

adt-typecheck.js's Introduction

adt-typecheck.js

Practical run-time type checking using adt.js.

Usage

adt.typecheck.js syntax is designed for CoffeeScript. It is certainly possible to use the library with JavaScript proper, however as an EDSL adt.typecheck is easiest to read using CoffeeScript shorthands. For this reason all of the examples here use CoffeeScript notation.

Two words of warning:

  • Debugging wrapped up function calls can be painful. When debugging it is occasionally helpful to comment out the signature to avoid stepping through lots of this typechecking code.
  • adt-typecheck.js is designed for flexibility rather than performance, especially since ADT's aren't natively implemented in JavaScript. If JavaScript performance is an issue for you, you may want to reconsider using a run-time typechecker.

Also, please note that adt-typecheck.js does not have an official release yet. Parts of the API can and will change over time.

Typecheck simple types

# TODO

Typecheck composite objects

# TODO

Typecheck arguments using function signatures

# TODO

Note that adt-typecheck.js will add some overhead to all of your functions signed in this way and is not appropriate for situations where high performance is required. This style of typechecking is probably more appropriate for server-side code than browser-side code (especially in situations where old and inefficient browsers need to be supported).

A proxy can be used in place of adt.typecheck.signature.function in production mode if performance is a concern. E.g.

if isDevelopmentMode
  fn = adt.typecheck.signature.function
else
  fn = (schema, f) -> f

Typecheck arguments to Node.js style chained functions

# TODO

The same proxy as the one for adt.typecheck.signature.function can be used in place of adt.typecheck.signature.chainFunction.

if isDevelopmentMode
  cfn = adt.typecheck.signature.chainFunction
else
  cfn = (schema, f) -> f

Typecheck your REST API's with an express middleware

The following snippet of code can be used to create a middleware for express that typechecks your incoming request body.

# TODO

Use it like this:

# TODO

adt-typecheck.js's People

Contributors

rehno-lindeque avatar andrewseddon avatar

Watchers

Ollie Charles avatar Gary Pamparà avatar  avatar Theunis Kotze avatar  avatar James Cloos avatar Handré Stolp avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.