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

https://github.com/codler/utils

https://www.npmjs.com/package/@codler/utils
https://github.com/codler/utils

Last synced: 11 months ago
JSON representation

https://www.npmjs.com/package/@codler/utils

Awesome Lists containing this project

README

          

# @codler/utils

## Install

```bash
npm i @codler/utils
```

## Reference

#### adBlock

```js
import { adBlock } from "@codler/utils";
await adBlock.checkIsEnabled();
adBlock.isEnabled();
```

| Method | Notes |
| -------------- | ------------------ |
| checkIsEnabled | `Promise` |
| isEnabled | `boolean` |

#### color

```js
import { color } from "@codler/utils";
color.linear(value, maxValue);
color.scaled(value, maxValue);
```

| Method | Notes |
| ------ | --------------------------------------------- |
| linear | `(value: number, maxValue: number): hexColor` |
| scaled | `(value: number, maxValue: number): hexColor` |

#### date

```js
import { date } from "@codler/utils";
date.format(new Date()); // 2020-01-01
date.today; // 2020-01-01
date.yesterday; // 2020-01-01
date.oneWeekAgo; // 2020-01-01
date.oneMonthAgo; // 2020-01-01
date.getWeek(new Date()); // { year: 2020, week: 1 }
date.getMondayFromWeek({ year: 2020, week: 1 }); // Date object
date.getSundayFromWeek({ year: 2020, week: 1 }); // Date object
```

| Method | Notes |
| ----------------- | ---------------------------------------------- |
| format | `(date: Date) => YYYY-MM-DD` |
| today | `YYYY-MM-DD` |
| yesterday | `YYYY-MM-DD` |
| oneWeekAgo | `YYYY-MM-DD` |
| oneMonthAgo | `YYYY-MM-DD` |
| getWeek | `(date: Date): { year: number; week: number }` |
| getMondayFromWeek | `({ year: number; week: number }): Date` |
| getSundayFromWeek | `({ year: number; week: number }): Date` |

#### debounce

```js
import { debounce } from "@codler/utils";
debounce(() => void, 100);
```

| Parameter | Notes |
| --------- | ---------- |
| func | `function` |
| wait | `number` |

#### platform

```js
import { platform } from "@codler/utils";
platform.isIos();
platform.isAndroid();
```

| Method | Notes |
| --------- | --------- |
| isIos | `boolean` |
| isAndroid | `boolean` |

#### scrollToElement

```js
import { scrollTo, scrollToElement, easing } from "@codler/utils";
// ...
```

| Method | Notes |
| --------------- | -------------------------------------------------------------------------------------- |
| scrollTo | `(targetPosition: number, scrollDistance: number, duration: number, easing: Function)` |
| scrollToElement | `(node: HTMLElement, duration: number, easing: Function)` |
| easing | `{easeInQuad}` |

### React Hooks

#### useAsyncStorage

```js
import { useAsyncStorage } from "@codler/utils";
const [get, set, isInit] = useAsyncStorage < T > (key, initialValue);
```

| Variable | Notes |
| -------- | ---------- |
| get | `T` |
| set | `function` |
| isInit | `boolean` |

#### useInViewport

```js
import { useInViewport } from "@codler/utils";
const { isVisible, update } = useInViewport();
```

| Variable | Notes |
| --------- | ---------- |
| isVisible | `boolean` |
| update | `function` |

#### useLocalStorage

```js
import { useLocalStorage } from "@codler/utils";
const [get, set] = useLocalStorage < T > (key, initialValue);
```

| Variable | Notes |
| -------- | ---------- |
| get | `T` |
| set | `function` |

#### useWindowSize

```js
import { useWindowSize } from "@codler/utils";
const { width, height } = useWindowSize();
```

| Variable | Notes |
| -------- | -------- |
| width | `number` |
| height | `number` |

## Maintainer

[Han Lin Yap](https://github.com/codler)