decode
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -0,1 +1,2 @@ | ||
import { Option } from 'kung-fu'; | ||
export declare class DecodeError extends Error { | ||
@@ -7,3 +8,4 @@ constructor(message: string); | ||
constructor(_run: (data: any) => T); | ||
decode(data: string): T; | ||
decodeObject(data: Object): T; | ||
decodeString(data: string): T; | ||
map<U>(f: (t: T) => U): Decoder<U>; | ||
@@ -13,7 +15,7 @@ andThen<U>(f: (t: T) => Decoder<U>): Decoder<U>; | ||
static succeed<T>(value: T): Decoder<T>; | ||
static string: Decoder<string>; | ||
static string: Decoder<String>; | ||
static number: Decoder<number>; | ||
static integer: Decoder<number>; | ||
static boolean: Decoder<boolean>; | ||
maybe(): Decoder<T>; | ||
maybe(): Decoder<Option<T>>; | ||
array(): Decoder<Array<T>>; | ||
@@ -20,0 +22,0 @@ at(path: Array<string>): Decoder<T>; |
"use strict"; | ||
const kung_fu_1 = require('kung-fu'); | ||
class DecodeError extends Error { | ||
@@ -15,3 +16,6 @@ constructor(message) { | ||
} | ||
decode(data) { | ||
decodeObject(data) { | ||
return this._run(data); | ||
} | ||
decodeString(data) { | ||
return this._run(JSON.parse(data)); | ||
@@ -77,5 +81,5 @@ } | ||
if (data === null) { | ||
return null; | ||
return kung_fu_1.Option.none(); | ||
} | ||
return this._run(data); | ||
return kung_fu_1.Option.some(this._run(data)); | ||
}); | ||
@@ -82,0 +86,0 @@ } |
{ | ||
"name": "decode", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Type-safe Decoding", | ||
@@ -14,3 +14,3 @@ "main": "out/index.js", | ||
"type": "git", | ||
"url": "git@github.com:srijs/node-dejson.git" | ||
"url": "git@github.com:srijs/node-decode.git" | ||
}, | ||
@@ -22,4 +22,7 @@ "devDependencies": { | ||
"bugs": { | ||
"url": "https://github.com/srijs/node-dejson/issues" | ||
"url": "https://github.com/srijs/node-decode/issues" | ||
}, | ||
"dependencies": { | ||
"kung-fu": "^0.1.0" | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
import {Option} from 'kung-fu'; | ||
export class DecodeError extends Error { | ||
@@ -13,3 +15,7 @@ constructor(message: string) { | ||
decode(data: string): T { | ||
decodeObject(data: Object): T { | ||
return this._run(data); | ||
} | ||
decodeString(data: string): T { | ||
return this._run(JSON.parse(data)); | ||
@@ -36,3 +42,3 @@ } | ||
static get string(): Decoder<string> { | ||
static get string(): Decoder<String> { | ||
return new Decoder(data => { | ||
@@ -82,8 +88,8 @@ if (data === null) { | ||
maybe(): Decoder<T> { | ||
maybe(): Decoder<Option<T>> { | ||
return new Decoder(data => { | ||
if (data === null) { | ||
return null; | ||
return Option.none<T>(); | ||
} | ||
return this._run(data); | ||
return Option.some(this._run(data)); | ||
}); | ||
@@ -90,0 +96,0 @@ } |
Sorry, the diff of this file is not supported yet
21446
401
1
+ Addedkung-fu@^0.1.0
+ Addedkung-fu@0.1.4(transitive)