Comparing version 0.1.5 to 0.1.6
{ | ||
"name": "union-type", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Union types for JavaScript", | ||
@@ -10,7 +10,10 @@ "main": "union-type.js", | ||
"dependencies": { | ||
"ramda": "^0.14.0" | ||
"ramda": "^0.15.0" | ||
}, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"browserify": "^10.2.4" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha", | ||
"build": "browserify -s unionType ./union-type.js -o dist/union-type.js" | ||
}, | ||
@@ -17,0 +20,0 @@ "repository": { |
@@ -1,2 +0,2 @@ | ||
# union-type-js | ||
# union-type | ||
@@ -23,3 +23,3 @@ A small JavaScript library for defining and using union types. | ||
union-type-js exports a single function `Type`. Union types are created by | ||
union-type exports a single function `Type`. Union types are created by | ||
passing the `Type` function a definition object. | ||
@@ -39,5 +39,5 @@ | ||
Alternatively the fields can be specified by one of the standard built-in | ||
constructors `Number`, `String`, `Object`, `Array` or `Function`. union-type-js | ||
constructors `Number`, `String`, `Object`, `Array` or `Function`. union-type | ||
will detect these constructors and convert them to matching validator functions. | ||
Thus the above example is equivelant to this: | ||
Thus the above example is equivalent to this: | ||
@@ -59,3 +59,5 @@ ```javascript | ||
```javascript | ||
var NotifySetting = Type({Mute: [], Vibrate: [], Sound: [Number]}); | ||
``` | ||
@@ -148,2 +150,18 @@ ### Constructing a union type | ||
`caseOn` is similar to `case`, but allows passing additional data directly | ||
into each case function. With `caseOn`, the `advancePlayer` example from | ||
before could be written in "point-free style" like this: | ||
```javascript | ||
// No need to wrap this into a function that passes `player` | ||
const advancePlayer = Move.caseOn({ | ||
Up: (player) => ({x: player.x, y: player.y - 1}), | ||
Right: (player) => ({x: player.x + 1, y: player.y}), | ||
Down: (player) => ({x: player.x, y: player.y + 1}), | ||
Left: (player) => ({x: player.x - 1, y: player.y}) | ||
}); | ||
advancePlayer(Move.Up(), player); | ||
``` | ||
As a catch all you can supply a property with the key `_` to case. When a type | ||
@@ -205,4 +223,4 @@ doesn't match another handler `_` will be used. | ||
union-type-js was made by [paldepind](https://twitter.com/paldepind) and is | ||
union-type was made by [paldepind](https://twitter.com/paldepind) and is | ||
released under the MIT license. I hope you find it useful. | ||
@@ -6,3 +6,3 @@ var assert = require('assert'); | ||
function T() { return true; }; | ||
function T() { return true; } | ||
@@ -9,0 +9,0 @@ describe('union type', function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36519
9
755
222
1
4
+ Addedramda@0.15.1(transitive)
- Removedramda@0.14.0(transitive)
Updatedramda@^0.15.0