Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fibo/minimal-type-guard-helpers
minimal type-guard helpers
https://github.com/fibo/minimal-type-guard-helpers
helpers minimal type-guards
Last synced: about 1 month ago
JSON representation
minimal type-guard helpers
- Host: GitHub
- URL: https://github.com/fibo/minimal-type-guard-helpers
- Owner: fibo
- License: mit
- Created: 2023-09-17T13:07:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-14T21:59:59.000Z (about 1 year ago)
- Last Synced: 2024-10-17T07:56:18.411Z (2 months ago)
- Topics: helpers, minimal, type-guards
- Language: TypeScript
- Homepage: https://npm.im/minimal-type-guard-helpers
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# minimal-type-guard-helpers
> provides few helpers to create _type guards_
This package is implemented with ECMAScript modules. CommonJS is not supported.
## Synopsis
```ts
import {
arrayTypeGuard,
isLiteralType,
isMaybeObject,
objectTypeGuard
} from "minimal-type-guard-helpers"export const myItems = ["foo", "bar"] as const
export type MyItem = (typeof myItems)[number]
export const isMyItem = isLiteralType(myItems)type MyItems = MyItem[]
const isMyItems = arrayTypeGuard(isMyItem)type Foo = { bar: boolean }
const getBar = (arg: unknown): Foo["bar"] | undefined => {
if (isMaybeObject(arg)) return arg.bar
}const isFoo = objectTypeGuard(({ bar }) => {
return typeof bar === "boolean"
})
```## License
[MIT](https://fibo.github.io/mit-license)