@eeue56/adeilad
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -49,3 +49,3 @@ "use strict"; | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -73,3 +73,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -84,3 +84,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -100,3 +100,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -111,3 +111,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -126,7 +126,7 @@ catch (e) { | ||
var result = adeilad.decode(adeilad.number(), thing); | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
}); | ||
thingsThatShouldNotPass.forEach(function (thing) { | ||
var result = adeilad.decode(adeilad.number(), thing); | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
}); | ||
@@ -152,3 +152,3 @@ } | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -163,3 +163,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -200,3 +200,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -214,3 +214,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -225,3 +225,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -260,3 +260,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -295,3 +295,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -333,3 +333,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -344,3 +344,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -383,3 +383,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -394,3 +394,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -435,3 +435,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -446,3 +446,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -490,3 +490,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -501,3 +501,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -533,3 +533,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} | ||
@@ -565,3 +565,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -620,3 +620,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -730,3 +730,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -807,3 +807,3 @@ catch (e) { | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} | ||
@@ -810,0 +810,0 @@ catch (e) { |
@@ -75,7 +75,7 @@ "use strict"; | ||
var res = decode(innerDecoder, item); | ||
if (res.kind === "err") | ||
if (res.kind === "Err") | ||
return ts_core_1.Result.mapError(function (err) { | ||
return "Failed to decode list at index " + i + " due to " + err; | ||
}, res); | ||
if (res.kind === "ok") | ||
if (res.kind === "Ok") | ||
outArray.push(res.value); | ||
@@ -122,3 +122,3 @@ } | ||
var res = decode(innerDecoder, value); | ||
if (res.kind === "ok") | ||
if (res.kind === "Ok") | ||
return result_1.Ok(res.value); | ||
@@ -155,7 +155,7 @@ errors.push(res.error); | ||
var res = decode(innerDecoder, item); | ||
if (res.kind === "err") | ||
if (res.kind === "Err") | ||
return ts_core_1.Result.mapError(function (err) { | ||
return "Failed to decode value at index " + i + " due to " + err; | ||
}, res); | ||
if (res.kind === "ok") | ||
if (res.kind === "Ok") | ||
outRecord[key] = res.value; | ||
@@ -267,7 +267,7 @@ } | ||
var res = decode(pathDecoder, input); | ||
if (res.kind === "err" || typeof res.value === "undefined") { | ||
if (res.kind === "Err" || typeof res.value === "undefined") { | ||
return succeed(fallback); | ||
} | ||
var presentRes = decode(nullOrDecoder, res.value); | ||
if (presentRes.kind === "err") | ||
if (presentRes.kind === "Err") | ||
return fail(presentRes.error); | ||
@@ -334,3 +334,3 @@ return succeed(presentRes.value); | ||
var res = decode(innerDecoder, value); | ||
if (res.kind === "err") | ||
if (res.kind === "Err") | ||
return res; | ||
@@ -350,3 +350,3 @@ return mappedDecoder(res.value)(value); | ||
var res = decode(decoder, value); | ||
if (res.kind === "err") | ||
if (res.kind === "Err") | ||
return res; | ||
@@ -353,0 +353,0 @@ resultsToApply.push(res.value); |
@@ -25,6 +25,6 @@ "use strict"; | ||
var res = adeilad_1.decode(pathDecoder, input); | ||
if (res.kind === "err") | ||
if (res.kind === "Err") | ||
return adeilad_1.succeed(fallback); | ||
var presentRes = adeilad_1.decode(nullOrDecoder, input); | ||
if (presentRes.kind === "err") | ||
if (presentRes.kind === "Err") | ||
return adeilad_1.fail(presentRes.error); | ||
@@ -31,0 +31,0 @@ return adeilad_1.succeed(presentRes.value); |
{ | ||
"name": "@eeue56/adeilad", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Ensure JSON has the correct structure at runtime", | ||
@@ -36,4 +36,4 @@ "main": "build/adeilad.js", | ||
"dependencies": { | ||
"@eeue56/ts-core": "^1.1.0" | ||
"@eeue56/ts-core": "^3.0.1" | ||
} | ||
} |
@@ -12,3 +12,3 @@ # adeilad | ||
``` | ||
npm install --save @eeue56/coed | ||
npm install --save @eeue56/adeilad | ||
``` | ||
@@ -20,3 +20,6 @@ | ||
```javascript | ||
```typescript | ||
import { decode, pipeline, required, string, number, array } from "@eeue56/adeilad"; | ||
// fetched via a http request | ||
@@ -37,3 +40,3 @@ const someExampleData = { | ||
function Pet(name: string, age: number) { | ||
function Pet(name: string, age: number): Pet { | ||
return { | ||
@@ -51,3 +54,3 @@ name, | ||
function Person(name: string, age: number, pets: Pet[]){ | ||
function Person(name: string, age: number, pets: Pet[]): Person{ | ||
return { | ||
@@ -85,6 +88,8 @@ name, | ||
See [docs](./docs/adeilad.md) | ||
See [docs](./docs/src/adeilad.md) | ||
You may also want to see the Result type from [coed](https://github.com/eeue56/coed) | ||
## Name | ||
Adeilad is the Welsh word for buildings. For English speakers it'd be pronounced similar to "ah-dey-lad". |
@@ -1,2 +0,1 @@ | ||
import { Result } from "@eeue56/ts-core"; | ||
import { Err, Ok } from "@eeue56/ts-core/build/main/lib/result"; | ||
@@ -30,3 +29,3 @@ import * as assert from "assert"; | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -55,3 +54,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -66,3 +65,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -83,3 +82,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -94,3 +93,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -110,3 +109,3 @@ console.error(thing, result); | ||
const result = adeilad.decode(adeilad.number(), thing); | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
}); | ||
@@ -116,3 +115,3 @@ | ||
const result = adeilad.decode(adeilad.number(), thing); | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
}); | ||
@@ -140,3 +139,3 @@ } | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -151,3 +150,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -190,3 +189,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -209,3 +208,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -220,3 +219,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -280,3 +279,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -340,3 +339,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -390,3 +389,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -401,3 +400,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -447,3 +446,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -458,3 +457,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -508,3 +507,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -519,3 +518,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -576,3 +575,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -587,3 +586,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -620,3 +619,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "ok"); | ||
assert.deepStrictEqual(result.kind, "Ok"); | ||
} catch (e) { | ||
@@ -653,3 +652,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -721,3 +720,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -871,3 +870,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -977,3 +976,3 @@ console.error(thing, result); | ||
try { | ||
assert.deepStrictEqual(result.kind, "err"); | ||
assert.deepStrictEqual(result.kind, "Err"); | ||
} catch (e) { | ||
@@ -980,0 +979,0 @@ console.error(thing, result); |
import { Maybe, Result } from "@eeue56/ts-core"; | ||
import { Ok, Err } from "@eeue56/ts-core/build/main/lib/result"; | ||
import { second } from "@eeue56/ts-core/build/main/lib/tuple"; | ||
import { Err, Ok } from "@eeue56/ts-core/build/main/lib/result"; | ||
@@ -78,3 +77,3 @@ /** | ||
const res = decode(innerDecoder, item); | ||
if (res.kind === "err") | ||
if (res.kind === "Err") | ||
return Result.mapError( | ||
@@ -85,3 +84,3 @@ (err) => | ||
); | ||
if (res.kind === "ok") outArray.push(res.value); | ||
if (res.kind === "Ok") outArray.push(res.value); | ||
} | ||
@@ -131,3 +130,3 @@ | ||
if (res.kind === "ok") return Ok(res.value); | ||
if (res.kind === "Ok") return Ok(res.value); | ||
@@ -169,3 +168,3 @@ errors.push(res.error); | ||
const res = decode(innerDecoder, item); | ||
if (res.kind === "err") | ||
if (res.kind === "Err") | ||
return Result.mapError( | ||
@@ -176,3 +175,3 @@ (err) => | ||
); | ||
if (res.kind === "ok") outRecord[key] = res.value; | ||
if (res.kind === "Ok") outRecord[key] = res.value; | ||
} | ||
@@ -333,3 +332,3 @@ | ||
const res = decode(pathDecoder, input); | ||
if (res.kind === "err" || typeof res.value === "undefined") { | ||
if (res.kind === "Err" || typeof res.value === "undefined") { | ||
return succeed(fallback); | ||
@@ -339,3 +338,3 @@ } | ||
const presentRes = decode(nullOrDecoder, res.value); | ||
if (presentRes.kind === "err") return fail(presentRes.error); | ||
if (presentRes.kind === "Err") return fail(presentRes.error); | ||
@@ -410,3 +409,3 @@ return succeed(presentRes.value); | ||
if (res.kind === "err") return res; | ||
if (res.kind === "Err") return res; | ||
@@ -430,3 +429,3 @@ return mappedDecoder(res.value)(value); | ||
const res = decode(decoder, value); | ||
if (res.kind === "err") return res; | ||
if (res.kind === "Err") return res; | ||
@@ -433,0 +432,0 @@ resultsToApply.push(res.value); |
import { | ||
andThen, | ||
at, | ||
decode, | ||
Decoder, | ||
fail, | ||
fallbackIfNull, | ||
field, | ||
at, | ||
value, | ||
map2, | ||
oneOf, | ||
fallbackIfNull, | ||
decode, | ||
succeed, | ||
fail, | ||
andThen, | ||
map2, | ||
value, | ||
} from "./adeilad"; | ||
@@ -65,6 +65,6 @@ | ||
if (res.kind === "err") return succeed(fallback); | ||
if (res.kind === "Err") return succeed(fallback); | ||
const presentRes = decode(nullOrDecoder, input); | ||
if (presentRes.kind === "err") return fail(presentRes.error); | ||
if (presentRes.kind === "Err") return fail(presentRes.error); | ||
@@ -71,0 +71,0 @@ return succeed(presentRes.value); |
91
102658
18
2809
+ Added@eeue56/ts-core@3.0.1(transitive)
- Removed@eeue56/ts-core@1.1.0(transitive)
Updated@eeue56/ts-core@^3.0.1