UNPKG

custome_own-package

Version:
66 lines (51 loc) 1.99 kB
import emailValidator from 'email-validator'; import { isPlainObject } from 'is-plain-object'; import { v4 as uuidv4 } from 'uuid'; import { Base64 } from 'js-base64'; export const isUndefined = (value) => typeof value === 'undefined'; export const isFunction = (fn) => typeof fn === 'function'; export const isString = (value) => typeof value === 'string'; export const isNull = (value) => value === null; export const isArray = (value) => Array.isArray(value); export const isObject = (obj) => isPlainObject(obj); export function isEmpty(x) { if (isObject(x) && !Object.keys(x).length) return true; if (isArray(x) && !x?.length) return true; if (isString(x) && !x?.length) return true; if (isUndefined(x) || isNull(x)) return true; return false; } export const IS_DEV = process.env.NODE_ENV !== 'production'; export const isMobile = () => window.innerWidth <= 576; export const isValidEmail = (email) => emailValidator.validate(email); export const convertFirstLetterToCaps = (value) => value.charAt(0).toUpperCase() + value.slice(1); export const charsOnlyRegex = /^[a-zA-Z\s]{3,16}$/; export const getUniqueID = () => uuidv4(); export const getSmallerNumber = (value) => Math.ceil(value); export const convertToPascalCase = (value) => value .replace(/_/g, ' ') .split(' ') .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) .join(' '); export function shortenText(words, characters) { return (words.match(RegExp('.{' + characters + '}\\S*')) || [words])[0]; } export const getLabelText = (text, title) => { if (!title) { return shortenText(text, 100) + '...'; } return title.length >= 25 ? shortenText(title, 50) + '...' : title; }; export const decodeEntity = (entity) => { let decoded; try { decoded = JSON.parse(Base64.decode(entity)); } catch (e) { decoded = {}; } return decoded; }; export const encodeEntity = (param, urlSafe = true) => Base64.encode(JSON.stringify(param), urlSafe);