typescanner
Advanced tools
Comparing version
@@ -1,1 +0,2 @@ | ||
export declare const scan: <T>(value: unknown, condition: (value: unknown) => value is T) => T; | ||
import type { Condition } from "../types"; | ||
export declare const scan: <T>(value: unknown, condition: Condition<T>) => T; |
import type { Condition } from "../types"; | ||
export declare const scanner: <T extends Record<string, unknown>>(fields: { [K in keyof Required<T>]: Condition<T[K]> | Condition<T[K]>[]; }) => (value: unknown) => value is T; | ||
export declare const scanner: <T extends Record<string, unknown>>(fields: { [K in keyof Required<T>]: Condition<T[K]> | Condition<T[K]>[]; }, option?: { | ||
isUseWithUnion: boolean; | ||
} | undefined) => Condition<T>; |
@@ -5,3 +5,3 @@ "use strict"; | ||
var typeGuard_1 = require("../typeGuard"); | ||
var scanner = function (fields) { | ||
var scanner = function (fields, option) { | ||
return function (value) { | ||
@@ -12,2 +12,3 @@ // check each value | ||
var key = _a[0], condition = _a[1]; | ||
// if union type or not | ||
var isMeet = Array.isArray(condition) | ||
@@ -18,2 +19,5 @@ ? condition.some(function (cond) { return cond(value[key]); }) | ||
return true; | ||
// if use with union, return false | ||
if (option === null || option === void 0 ? void 0 : option.isUseWithUnion) | ||
return false; | ||
throw new Error("value." + key + " does not meet the condition."); | ||
@@ -23,2 +27,5 @@ }); | ||
return true; | ||
// if use with union, return false | ||
if (option === null || option === void 0 ? void 0 : option.isUseWithUnion) | ||
return false; | ||
throw new Error("value does not meet the condition."); | ||
@@ -25,0 +32,0 @@ }; |
{ | ||
"name": "typescanner", | ||
"version": "0.3.4", | ||
"version": "0.4.0", | ||
"description": "A simple library for implementing type guard in TypeScript.", | ||
@@ -5,0 +5,0 @@ "author": "yona3", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
23739
2.7%241
4.33%