typescanner
Advanced tools
Comparing version 0.3.4 to 0.4.0
@@ -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
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
23739
241