voidlib
v0.0.6
Published
Collection of useful libraries for JavaScript and TypeScript.
Downloads
12
Readme
voidlib
Collection of useful libraries for JavaScript and TypeScript.
Most notably:
nonNullable
Useful function to filter out null and undefined values from a type.
import { nonNullable } from 'voidlib'
arr.filter(nonNullable) // arr is now of type T[]walk
Powerful utility to walk through directories and files in a given path.
import { walk } from 'voidlib/node'
for await (const file of walk('/path/to/dir', {
recursive: true,
// Only yield files, nothing else
include: entry => entry.isFile() && entry.name.endsWith('.ts'),
// Do not recurse into hidden directories
recurse: entry => !entry.name.startsWith('.'),
})) {
console.log(file) // file is a TypeScript (.ts) file
}deferPromise
Create a deferred promise that can be resolved or rejected later.
const p = deferPromise()
p.resolve('Hello, world!')
await p.promise // 'Hello, world!'task
Unwrap an inlined promise, return a promise task that can be awaited.
const t = task()
p.resolve('Hello, world!')
await p // 'Hello, world!'