Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pixiedevpraveen/utiljs-pro

TypeScript friendly Utility functions for Developers.
https://github.com/pixiedevpraveen/utiljs-pro

bun bun-test deno functions javascript jsr npm utility

Last synced: 10 days ago
JSON representation

TypeScript friendly Utility functions for Developers.

Awesome Lists containing this project

README

        

# utiljs-pro
![Package Size](https://deno.bundlejs.com/badge?q=utiljs-pro)
[![JSR](https://jsr.io/badges/@praveen/utiljs-pro)](https://jsr.io/@praveen/utiljs-pro)
[![JSR Score](https://jsr.io/badges/@praveen/utiljs-pro/score)](https://jsr.io/@praveen/utiljs-pro/score)

TypeScript friendly Utility functions for Developers.

To install:

```bash
# npm
npm install utiljs-pro

# bun
bun add utiljs-pro

# yarn
yarn add utiljs-pro

# pnpm
pnpm add utiljs-pro

# CDN
https://unpkg.com/[email protected]/build/index.js
```

```ts
// isPromise
const promise = new Promise(res => setTimeout(() => res(1), 50)) as Promise | number

if (isPromise(obj)) { // true
obj; // hovering on obj shows the type as Promise
const d = await obj; // now hovering on d shows the type as number
} else {
obj; // hovering on obj shows the type as number
}

```

```ts
// isAsyncFunction
const asyncFn = (async () => { }) as unknown as (() => Promise) | (() => number)
if (isAsyncFunction Promise>(asyncFn)) { // true
const p = asyncFn(); // hovering on function shows the type as (() => Promise) and on p as Promise
const d = await p; // now hovering on d shows the type as Promise
} else {
const d = asyncFn(); // hovering on function shows the type as (() => number) and on d as number
}
```