@helios-lang/type-utils
Advanced tools
Comparing version 0.1.8 to 0.1.9
{ | ||
"name": "@helios-lang/type-utils", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Global utility types", | ||
@@ -9,3 +9,3 @@ "main": "src/index.js", | ||
"scripts": { | ||
"build": "npm test", | ||
"build": "npm run prettify && npm run test:types", | ||
"prepare": "npm run build", | ||
@@ -12,0 +12,0 @@ "prettify": "npx prettier . --write", |
declare global { | ||
type Option<T> = null | undefined | T | ||
type Either<L, R> = { left: L } | { right: R } // use right to represent a correct value, left for errors | ||
type JsonSafe = | ||
| (string | number | boolean | null) | ||
| JsonSafe[] | ||
| { [key: string]: JsonSafe } | ||
namespace Json { | ||
function parse( | ||
text: string, | ||
reviver?: ((this: any, key: string, value: any) => any) | undefined | ||
): JsonSafe | ||
function stringify( | ||
value: JsonSafe, | ||
replacer?: | ||
| ((this: any, key: string, value: any) => any) | ||
| undefined, | ||
space?: string | number | undefined | ||
): string | ||
} | ||
} | ||
@@ -5,0 +23,0 @@ |
@@ -77,3 +77,3 @@ /** | ||
either, | ||
msg = `expected Either.right, got ${either}` | ||
msg = `expected Either.right, got ${JSON.stringify(either)}` | ||
) { | ||
@@ -106,1 +106,9 @@ if ("right" in either) { | ||
} | ||
/** | ||
* Don't shadow `JSON` because that might break existing type-checks | ||
*/ | ||
export const Json = { | ||
parse: JSON.parse, | ||
stringify: JSON.stringify | ||
} |
6088
149