0.0.4 • Published 9 years ago

types-assert v0.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

types-assert

types-assert is dynamic type assertion library. Using TypeScript type definitions.

Installation

$ npm i types-assert -S

How To Use

Using TypeScript type definition files.

interface Test {
  stringProp: string;
  numProp: number;
}

in node.js

import compile from 'types-assert/compiler';
import assert from 'types-assert/assert';

// typescript interface to types-assert object
const type = compile('type.ts');

const obj1 = {
  stringProp: "hoge",
  numProp: 2
};

assert(obj1, type.Test);
// => through

const obj2 = {
  stringProp: "hoge",
  numProp: "2"
};

assert(obj2, type.Test);
// => throw Error!!

in browser

Use `types-assert-loader' for Webpack.

$ npm i types-assert-loader -D

Add webpack config.

{
  module: {
    loaders: [
      { test: /\.ts$/, loader: "types-assert" }
    ]
  }
}

Code

import { assert } from 'types-assert/assert';
import { Interface1 } from './type.ts';
  
const obj1 = {
  stringProp: "hoge",
  numProp: "2"
};
 
assert(obj1, Interface1);
// => throw Error!! 

Tests

$ git clone https://github.com/KeitaMoromizato/types-assert && cd types-assert
$ npm install
$ npm Test

License

MIT

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago