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
- Host: GitHub
- URL: https://github.com/codler/utils
- Owner: codler
- Created: 2020-07-06T20:42:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-31T15:28:25.000Z (about 4 years ago)
- Last Synced: 2024-05-02T00:31:13.345Z (over 1 year ago)
- Language: TypeScript
- Size: 146 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)