@mreycode/utils

0.0.2 • Public • Published

MrEYCode utils

Available utilities:

Custom hooks

  • useEventListener

    useEventListener(eventType,callback,element = window)

import { useEventListener } from "@mreycode/utils";
  • useScreenType
Example Usage
import { useScreenType } from "@mreycode/utils";
const screentType = useScreenType();
console.log(screentType);
// type: mobile, tablet, laptop, desktop, largeDesktop
// Output:
// { type: "mobile", width: 552, height: 760 }
  • useWindowSize
Example Usage
import { useWindowSize } from "@mreycode/utils";
const {width, height} = useWindowSize();
  • useLocalStorage

    useLocalStorage(key = null, defaultValue = "")

import { useLocalStorage } from "@mreycode/utils";
const [appTheme, setAppTheme] = useLocalStorage("theme", "dark");

Checker

  • isBlank

    isBlank(value)

// Example Usage
import { isBlank } from "@mreycode/utils";
console.log(isBlank(null)); // true
console.log(isBlank(undefined)); // true
console.log(isBlank("")); // true
console.log(isBlank("   ")); // true
console.log(isBlank("hello")); // false
console.log(isBlank(123)); // false
console.log(isBlank([])); // false

Parser

  • stringJSON

    stringJSON(data, key = null, defaultValue = "")

// Example Usage
import { stringJSON } from "@mreycode/utils";
console.log(stringJSON("[]")); // []
console.log(stringJSON('{name:"MrEYCode"}')); // { name: "MrEYCode" }
console.log(stringJSON('{name:"MrEYCode"}', "name")); // MrEYCode
console.log(stringJSON('{"name": "MrEYCode"}', "country", "Philippines")); // Philippines

Package Sidebar

Install

npm i @mreycode/utils

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

7.15 kB

Total Files

4

Last publish

Collaborators

  • kabagis