From ea8956ed2d3c6e2c81f2b962f975d7345b178593 Mon Sep 17 00:00:00 2001 From: Alisue Date: Sat, 3 Aug 2024 05:38:05 +0900 Subject: [PATCH] :memo: Update usage --- README.md | 14 +++++--------- mod.ts | 5 +++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e45b921..b9d92be 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ A utility pack for handling `unknown` type. ## Usage -It provides `is` module for type predicate functions and `assert`, `ensure`, and -`maybe` helper functions. +It provides `is` and `as` module for type predicate functions and `assert`, +`ensure`, and `maybe` helper functions. -### is\* +### is\* and as\* Type predicate function is a function which returns `true` if a given value is expected type. For example, `isString` (or `is.String`) returns `true` if a @@ -28,7 +28,8 @@ if (is.String(a)) { } ``` -For more complex types, you can use `is*Of` (or `is.*Of`) functions like: +For more complex types, you can use `is*Of` (or `is.*Of`) functions and `as*` +(or `as.*`) like: ```typescript import { as, is, PredicateType } from "@core/unknownutil"; @@ -231,11 +232,6 @@ const a: unknown = "Hello"; const _: string = maybe(a, is.String) ?? "default value"; ``` -## Migration - -See [GitHub Wiki](https://github.com/jsr-core/unknownutil/wiki) for migration to -v3 from v2 or v2 from v1. - ## License The code follows MIT license written in [LICENSE](./LICENSE). Contributors need diff --git a/mod.ts b/mod.ts index 4507418..8f2d971 100644 --- a/mod.ts +++ b/mod.ts @@ -6,7 +6,7 @@ * It provides `is` module for type predicate functions and `assert`, `ensure`, and * `maybe` helper functions. * - * ### is\* + * ### is\* and as\* * * Type predicate function is a function which returns `true` if a given value is * expected type. For example, `isString` (or `is.String`) returns `true` if a @@ -21,7 +21,8 @@ * } * ``` * - * For more complex types, you can use `is*Of` (or `is.*Of`) functions like: + * For more complex types, you can use `is*Of` (or `is.*Of`) functions and `as*` + * (or `as.*`) functions like: * * ```typescript * import {