@codler/utils
TypeScript icon, indicating that this package has built-in type declarations

3.3.1 • Public • Published

@codler/utils

Install

npm i @codler/utils

Reference

adBlock

import { adBlock } from "@codler/utils";
await adBlock.checkIsEnabled();
adBlock.isEnabled();
Method Notes
checkIsEnabled Promise<boolean>
isEnabled boolean

color

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

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

import { debounce } from "@codler/utils";
debounce(() => void, 100);
Parameter Notes
func function
wait number

platform

import { platform } from "@codler/utils";
platform.isIos();
platform.isAndroid();
Method Notes
isIos boolean
isAndroid boolean

scrollToElement

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

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

useInViewport

import { useInViewport } from "@codler/utils";
const { isVisible, update } = useInViewport();
Variable Notes
isVisible boolean
update function

useLocalStorage

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

useWindowSize

import { useWindowSize } from "@codler/utils";
const { width, height } = useWindowSize();
Variable Notes
width number
height number

Maintainer

Han Lin Yap

Readme

Keywords

Package Sidebar

Install

npm i @codler/utils

Weekly Downloads

0

Version

3.3.1

License

ISC

Unpacked Size

35.1 kB

Total Files

37

Last publish

Collaborators

  • codler