typescanner
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,1 +0,1 @@ | ||
export declare const scan: <T>(value: T, condition: (value: unknown) => value is T, callback?: ((value: unknown) => void) | undefined) => T; | ||
export declare const scan: <T>(value: unknown, condition: (value: unknown) => value is T, handleError?: ((value: unknown) => void) | undefined) => T; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.scan = void 0; | ||
var scan = function (value, condition, callback) { | ||
var scan = function (value, condition, handleError) { | ||
if (condition(value)) | ||
return value; | ||
if (callback) | ||
callback(value); | ||
if (handleError) | ||
handleError(value); | ||
throw new Error("type assertion is failed. (value: " + value + ")"); | ||
@@ -10,0 +10,0 @@ }; |
{ | ||
"name": "typescanner", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A simple library for implementing type guards in TypeScript.", | ||
@@ -26,3 +26,3 @@ "author": "yona3", | ||
"dev": "ts-node-dev --respawn src/index.ts", | ||
"build": "tsc", | ||
"build": "tsc -p tsconfig.production.json", | ||
"test": "jest" | ||
@@ -29,0 +29,0 @@ }, |
export const scan = <T>( | ||
value: T, | ||
value: unknown, | ||
condition: (value: unknown) => value is T, | ||
callback?: (value: unknown) => void | ||
handleError?: (value: unknown) => void | ||
): T => { | ||
if (condition(value)) return value; | ||
if (callback) callback(value); | ||
if (handleError) handleError(value); | ||
throw new Error(`type assertion is failed. (value: ${value})`); | ||
}; |
@@ -15,3 +15,3 @@ import { | ||
describe("scan test", () => { | ||
const lang = { | ||
const Lang = { | ||
ja: "ja", | ||
@@ -21,4 +21,4 @@ en: "en", | ||
type Lang = keyof typeof lang; | ||
const langList = Object.values(lang); | ||
type Lang = typeof Lang[keyof typeof Lang]; | ||
const langList = Object.values(Lang); | ||
@@ -25,0 +25,0 @@ type Post = { |
@@ -16,3 +16,3 @@ { | ||
"include": ["src/**/*.ts", ".eslintrc.js"], | ||
"exclude": ["node_modules", "dist", "src/**/*.spec.ts"] | ||
"exclude": ["node_modules", "dist"] | ||
} |
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
30861
40
751