A collection of utility functions for use in node.js and the browser.
yarn add @sa-net/utils
# or
npm install @sa-net/utils
A function that does nothing, no operation.
A function that returns a promise that resolves after a given number of milliseconds.
import { sleep } from '@sa-net/utils'
async function main() {
await sleep(1000)
console.log('Hello World')
}
main()
A function that returns a new object with the given keys.
import { pick } from '@sa-net/utils'
const obj = {
a: 1,
b: 2,
c: 3,
}
const newObj = pick(obj, ['a', 'c'])
console.log(newObj) // { a: 1, c: 3 }
A function that returns a new object without the given keys.
import { omit } from '@sa-net/utils'
const obj = {
a: 1,
b: 2,
c: 3,
}
const newObj = omit(obj, ['a', 'c'])
console.log(newObj) // { b: 2 }
A function that returns a function that can only be called once.
import { once } from '@sa-net/utils'
const fn = once(() => console.log('Hello World'))
fn() // Hello World
fn() // Does nothing