Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2.0 #6

Merged
merged 4 commits into from
Aug 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ var foo = typify("foo :: number -> number.. -> number", function (a) {

## Documentation

### API

- `typify(functionSpec, fun)` - decorate function with run-time type check
- `typify.create()` - create new typify environment
- `typify.type(typename, checkFun)` - add new type with user-supplied existence check
- `typify.record(typename, recordspec)` - add new record type
- `typify.alias(typename, typespec)` - give name to the compound type
- `typify.check(typename, value) -> bool` - check membership of value in the type

### Checkable type

*Checkable* means, that given an object you can check whether an object is or isn't of the particular type.
Expand Down Expand Up @@ -102,6 +111,15 @@ console.log(add(1, 2)); // ok
console.log(add("foo", "bar")); // throws TypeError
```

#### Formal syntax of function type declaration:

- *function type* λ ::= ν μ | ν Γ (σ `->`)* ρ σ
- *action* μ ::= `->` τ
- *context* Γ ::= α `:` Σ (`,` α `:` Σ)* `=>` | ε
- *typeset* Σ ::= σ_poly (`|` σ_poly)*
- *rest parameters* ρ ::= σ `...` `->` | `...` `->` | ε
- *function name* ν ::= *identifier* `::` | ε

### New types

New types can be added with `typify.type` method:
Expand Down Expand Up @@ -136,7 +154,6 @@ typ.record("bst", {
});
```


### Hygiene usage

If you don't want to use global type database, you can create your own instance of *typify*:
Expand All @@ -154,22 +171,19 @@ var myTypify = typify.create();
var typify = require("typify").create();
```

#### Formal syntax of function type declaration:

- *function type* λ ::= ν μ | ν Γ (σ `->`)* ρ σ
- *action* μ ::= `->` τ
- *context* Γ ::= α `:` Σ (`,` α `:` Σ)* `=>` | ε
- *typeset* Σ ::= σ_poly (`|` σ_poly)*
- *rest parameters* ρ ::= σ `...` `->` | `...` `->` | ε
- *function name* ν ::= *identifier* `::` | ε

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).

- You can use `grunt jasmine-build` to generate `_SpecRunner.html` to run tests in your browser of choice.

## Release History

- 0.2.0
- Recursive record types
- Recursive aliases
- Intersection types
- Hygiene type environments

- 0.1.1
- Record type
- Fixed typos in README.md
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "typify",
"description": "Runtime type-checking for JavaScript.",
"version": "0.1.1",
"version": "0.2.0",
"homepage": "https://github.com/phadej/typify",
"author": "Oleg Grenrus <[email protected]>",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "typify",
"description": "Runtime type-checking for JavaScript.",
"version": "0.1.1",
"version": "0.2.0",
"homepage": "https://github.com/phadej/typify",
"author": {
"name": "Oleg Grenrus",
Expand Down