https://github.com/michealpearce/utils
https://github.com/michealpearce/utils
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/michealpearce/utils
- Owner: MichealPearce
- License: unlicense
- Created: 2023-02-11T15:53:18.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-13T02:35:21.000Z (about 2 years ago)
- Last Synced: 2025-03-17T08:02:33.614Z (7 months ago)
- Language: TypeScript
- Size: 55 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @michealpearce/utils
A collection of utility functions for use in node.js and the browser.
## Installation
```bash
yarn add @michealpearce/utils
# or
npm install @michealpearce/utils
```## Functions
### `noop`
A function that does nothing, no operation.
### `sleep`
A function that returns a promise that resolves after a given number of milliseconds.
#### Usage
```js
import { sleep } from '@michealpearce/utils'async function main() {
await sleep(1000)
console.log('Hello World')
}main()
```### `pick`
A function that returns a new object with the given keys.
#### Usage
```js
import { pick } from '@michealpearce/utils'const obj = {
a: 1,
b: 2,
c: 3,
}const newObj = pick(obj, ['a', 'c'])
console.log(newObj) // { a: 1, c: 3 }
```### `omit`
A function that returns a new object without the given keys.
#### Usage
```js
import { omit } from '@michealpearce/utils'const obj = {
a: 1,
b: 2,
c: 3,
}const newObj = omit(obj, ['a', 'c'])
console.log(newObj) // { b: 2 }
```### `once`
A function that returns a function that can only be called once.
#### Usage
```js
import { once } from '@michealpearce/utils'const fn = once(() => console.log('Hello World'))
fn() // Hello World
fn() // Does nothing
```## issers functions
### `is`
A function that returns true if the given value is truthy. Also has generics allowing for type narrowing
#### Usage
```js
import { is } from '@michealpearce/utils'is('string') // true
is(1) // true
is(true) // true
is(false) // false
is(null) // false
is(undefined) // falseconst test = null as string | null
if(is(test)) {
// test will be narrowed to string
}
```### `not`
A function that returns true if the given value is falsy. Also has generics allowing for type narrowing
#### Usage
```js
import { not } from '@michealpearce/utils'not('string') // false
not(1) // false
not(true) // false
not(false) // true
not(null) // true
not(undefined) // trueconst test = null as string | null
if(not(test)) {
// test will be narrowed to null
}
```### `isString`
A function that returns true if the given value is a string.
#### Usage
```js
import { isString } from '@michealpearce/utils'isString('string') // true
isString(1) // false
isString(true) // false
isString(false) // false
isString(null) // false
isString(undefined) // falseconst test = null as string | null
if(isString(test)) {
// test will be narrowed to string
}
```