@asherng/utils
Advanced tools
+23
-14
| { | ||
| "name": "@asherng/utils", | ||
| "version": "0.1.7", | ||
| "version": "1.0.6", | ||
| "description": "UI Utils", | ||
@@ -18,19 +18,28 @@ "keywords": [ | ||
| "author": "Asher Nguyen <phucnguyenhoang1985@gmail.com>", | ||
| "main": "lib/index", | ||
| "types": "lib/index.d.ts", | ||
| "main": "dist/index", | ||
| "types": "dist/index.d.ts", | ||
| "files": [ | ||
| "/*.d.ts", | ||
| "/*.js", | ||
| "utils" | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "build": "tsc -p tsconfig.build.json" | ||
| "exports": { | ||
| "./*": { | ||
| "types": "./dist/*/index.d.ts", | ||
| "require": "./dist/*/index.js", | ||
| "import": { | ||
| "types": "./dist/*/index.d.mts", | ||
| "default": "./dist/*/index.mjs" | ||
| } | ||
| } | ||
| }, | ||
| "devDependencies": { | ||
| "typescript": "5.1.6" | ||
| "typescript": "5.4.3", | ||
| "@asherng/common-types": "^1.0.6" | ||
| }, | ||
| "dependencies": { | ||
| "@asherng/common-types": "^0.1.3" | ||
| }, | ||
| "gitHead": "5147f95a8849f7176622f3abd2874cfaa8b19568" | ||
| } | ||
| "gitHead": "c4702ddc44863e127b8f57ceee1141daecad5d35", | ||
| "scripts": { | ||
| "build": "tsup", | ||
| "build:fast": "pnpm build --no-splitting --shims", | ||
| "dev": "pnpm clean && pnpm build:fast --watch src", | ||
| "clean": "rimraf dist" | ||
| } | ||
| } |
+3
-4
@@ -1,3 +0,2 @@ | ||
| @asherng/utils | ||
| ============== | ||
| # @asherng/utils | ||
@@ -9,3 +8,3 @@ A collection of frontend utils. | ||
| ```bash | ||
| yarn add @asherng/utils | ||
| pnpm add @asherng/utils | ||
| ``` | ||
@@ -17,2 +16,2 @@ | ||
| import isObject from "@asherng/utils/isObject"; | ||
| ``` | ||
| ``` |
| export { default } from './utils/arrayFromNumber'; | ||
| export * from './utils/arrayFromNumber/types'; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var arrayFromNumber_1 = require("./utils/arrayFromNumber"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(arrayFromNumber_1).default; } }); | ||
| __exportStar(require("./utils/arrayFromNumber/types"), exports); |
| export { default } from './utils/canUseDOM'; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var canUseDOM_1 = require("./utils/canUseDOM"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(canUseDOM_1).default; } }); |
| export { default } from './utils/canUseIntersectionObserver'; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var canUseIntersectionObserver_1 = require("./utils/canUseIntersectionObserver"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(canUseIntersectionObserver_1).default; } }); |
| export { default as cv, cx } from './utils/classNameVariant'; | ||
| export * from './utils/classNameVariant/types'; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.cx = exports.cv = void 0; | ||
| var classNameVariant_1 = require("./utils/classNameVariant"); | ||
| Object.defineProperty(exports, "cv", { enumerable: true, get: function () { return __importDefault(classNameVariant_1).default; } }); | ||
| Object.defineProperty(exports, "cx", { enumerable: true, get: function () { return classNameVariant_1.cx; } }); | ||
| __exportStar(require("./utils/classNameVariant/types"), exports); |
| export { default } from './utils/flattenObject'; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var flattenObject_1 = require("./utils/flattenObject"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(flattenObject_1).default; } }); |
| export { default } from './utils/getNestedObjectValue'; | ||
| export * from './utils/getNestedObjectValue/types'; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var getNestedObjectValue_1 = require("./utils/getNestedObjectValue"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(getNestedObjectValue_1).default; } }); | ||
| __exportStar(require("./utils/getNestedObjectValue/types"), exports); |
| export { default } from './utils/isEmpty'; | ||
| export * from './utils/isEmpty/types'; |
-23
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var isEmpty_1 = require("./utils/isEmpty"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(isEmpty_1).default; } }); | ||
| __exportStar(require("./utils/isEmpty/types"), exports); |
| export { default } from './utils/isFunction'; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var isFunction_1 = require("./utils/isFunction"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(isFunction_1).default; } }); |
| export { default } from './utils/isNil'; | ||
| export * from './utils/isNil/types'; |
-23
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var isNil_1 = require("./utils/isNil"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(isNil_1).default; } }); | ||
| __exportStar(require("./utils/isNil/types"), exports); |
| export { default } from './utils/isObject'; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var isObject_1 = require("./utils/isObject"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(isObject_1).default; } }); |
| export { default } from './utils/limitNumber'; | ||
| export * from './utils/limitNumber/types'; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var limitNumber_1 = require("./utils/limitNumber"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(limitNumber_1).default; } }); | ||
| __exportStar(require("./utils/limitNumber/types"), exports); |
| export { default } from './utils/pick'; |
-8
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var pick_1 = require("./utils/pick"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(pick_1).default; } }); |
| export { default } from './utils/pickBy'; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var pickBy_1 = require("./utils/pickBy"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(pickBy_1).default; } }); |
| export { default } from './utils/runIfFn'; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var runIfFn_1 = require("./utils/runIfFn"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(runIfFn_1).default; } }); |
| export { default } from './utils/setRef'; | ||
| export * from './utils/setRef/types'; |
-23
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = void 0; | ||
| var setRef_1 = require("./utils/setRef"); | ||
| Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(setRef_1).default; } }); | ||
| __exportStar(require("./utils/setRef/types"), exports); |
| import { ArrayFromNumber } from './types'; | ||
| /** | ||
| * Generate array containing from 1...num. | ||
| * | ||
| * @param num length of the array. | ||
| * @returns array of numbers from 1...num. | ||
| */ | ||
| declare const arrayFromNumber: ArrayFromNumber; | ||
| export default arrayFromNumber; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| /** | ||
| * Generate array containing from 1...num. | ||
| * | ||
| * @param num length of the array. | ||
| * @returns array of numbers from 1...num. | ||
| */ | ||
| const arrayFromNumber = num => Array.from(Array(num), (_, x) => x); | ||
| exports.default = arrayFromNumber; |
| export type ArrayFromNumber = (num: number) => number[]; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| /** | ||
| * @desc Check if the current environment is a browser | ||
| * @return {Boolean} | ||
| */ | ||
| declare const canUseDOM: () => boolean; | ||
| export default canUseDOM; |
| "use strict"; | ||
| /** | ||
| * @desc Check if the current environment is a browser | ||
| * @return {Boolean} | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const canUseDOM = () => !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
| exports.default = canUseDOM; |
| /** | ||
| * @desc Check if the current environment supports IntersectionObserver | ||
| * @return {Boolean} | ||
| */ | ||
| declare const canUseIntersectionObserver: () => boolean; | ||
| export default canUseIntersectionObserver; |
| "use strict"; | ||
| /** | ||
| * @desc Check if the current environment supports IntersectionObserver | ||
| * @return {Boolean} | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const canUseIntersectionObserver = () => typeof window !== 'undefined' && 'IntersectionObserver' in window; | ||
| exports.default = canUseIntersectionObserver; |
| import type { ClassValue, Config, Props, Cx } from './types'; | ||
| export declare const cx: Cx; | ||
| declare const cv: <T>(base?: ClassValue, config?: Config<T> | undefined) => (props?: Props<T> | undefined) => string; | ||
| export default cv; |
| "use strict"; | ||
| var __rest = (this && this.__rest) || function (s, e) { | ||
| var t = {}; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
| t[p] = s[p]; | ||
| if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
| for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
| if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
| t[p[i]] = s[p[i]]; | ||
| } | ||
| return t; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.cx = void 0; | ||
| const falsyToString = (value) => typeof value === 'boolean' ? `${value}` : value === 0 ? '0' : value; | ||
| const cx = (...classes) => classes.flat(Infinity).filter(Boolean).join(' '); | ||
| exports.cx = cx; | ||
| const cv = (base, config) => (props) => { | ||
| var _a; | ||
| if ((config === null || config === void 0 ? void 0 : config.variants) == null) { | ||
| return (0, exports.cx)(base, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className); | ||
| } | ||
| const { variants, defaultVariants } = config; | ||
| const getVariantClassNames = Object.keys(variants).map((variant) => { | ||
| const variantProp = props === null || props === void 0 ? void 0 : props[variant]; | ||
| const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant]; | ||
| if (variantProp === null) { | ||
| return null; | ||
| } | ||
| const variantKey = (falsyToString(variantProp) || | ||
| falsyToString(defaultVariantProp)); | ||
| return variants[variant][variantKey]; | ||
| }); | ||
| const propsWithoutUndefined = props && | ||
| Object.entries(props).reduce((acc, [key, value]) => { | ||
| if (value === undefined) { | ||
| return acc; | ||
| } | ||
| acc[key] = value; | ||
| return acc; | ||
| }, {}); | ||
| const getCompoundVariantClassNames = (_a = config === null || config === void 0 ? void 0 : config.compoundVariants) === null || _a === void 0 ? void 0 : _a.reduce((acc, _a) => { | ||
| var { class: cvClass, className: cvClassName } = _a, compoundVariantOptions = __rest(_a, ["class", "className"]); | ||
| return Object.entries(compoundVariantOptions).every(([key, value]) => Array.isArray(value) | ||
| ? value.includes(Object.assign(Object.assign({}, defaultVariants), propsWithoutUndefined)[key]) | ||
| : Object.assign(Object.assign({}, defaultVariants), propsWithoutUndefined)[key] === value) | ||
| ? [...acc, cvClass, cvClassName] | ||
| : acc; | ||
| }, []); | ||
| return (0, exports.cx)(base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className); | ||
| }; | ||
| exports.default = cv; |
| export type ClassPropKey = 'class' | 'className'; | ||
| export type ClassValue = string | null | undefined | ClassValue[]; | ||
| export type ClassProp = { | ||
| class: ClassValue; | ||
| className?: never; | ||
| } | { | ||
| class?: never; | ||
| className: ClassValue; | ||
| } | { | ||
| class?: never; | ||
| className?: never; | ||
| }; | ||
| export type OmitUndefined<T> = T extends undefined ? never : T; | ||
| export type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T; | ||
| export type VariantProps<Component extends (...args: any) => any> = Omit<OmitUndefined<Parameters<Component>[0]>, 'class' | 'className'>; | ||
| export type Cx = (...classes: ClassValue[]) => string; | ||
| type ConfigSchema = Record<string, Record<string, ClassValue>>; | ||
| type ConfigVariants<T extends ConfigSchema> = { | ||
| [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined; | ||
| }; | ||
| type ConfigVariantsMulti<T extends ConfigSchema> = { | ||
| [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[] | undefined; | ||
| }; | ||
| export type Config<T> = T extends ConfigSchema ? { | ||
| variants?: T; | ||
| defaultVariants?: ConfigVariants<T>; | ||
| compoundVariants?: (T extends ConfigSchema ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp : ClassProp)[]; | ||
| } : never; | ||
| export type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp; | ||
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| import { MayBe } from '@asherng/common-types'; | ||
| /** | ||
| * Flatten nested object with max depth | ||
| * | ||
| * @param target Object | ||
| * @param maxDepth max depth | ||
| * | ||
| * @returns A flattened object. | ||
| */ | ||
| declare const flattenObject: <Value = any>(target: Record<string, Value> | null | undefined, maxDepth?: number) => MayBe<Partial<Record<string, any>>>; | ||
| export default flattenObject; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const isObject_1 = __importDefault(require("../isObject")); | ||
| /** | ||
| * Flatten nested object with max depth | ||
| * | ||
| * @param target Object | ||
| * @param maxDepth max depth | ||
| * | ||
| * @returns A flattened object. | ||
| */ | ||
| const flattenObject = (target, maxDepth = Infinity) => { | ||
| if ((!(0, isObject_1.default)(target) && !Array.isArray(target)) || !maxDepth) { | ||
| return target; | ||
| } | ||
| return Object.entries(target).reduce((result, [key, value]) => { | ||
| if ((0, isObject_1.default)(value) || Array.isArray(value)) { | ||
| Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => { | ||
| result[`${key}.${childKey}`] = childValue; | ||
| }); | ||
| } | ||
| else { | ||
| result[key] = value; | ||
| } | ||
| return result; | ||
| }, {}); | ||
| }; | ||
| exports.default = flattenObject; |
| "use strict"; |
| import { GetNestedObjectValue } from './types'; | ||
| /** | ||
| * Get nested object value by path | ||
| * | ||
| * @param {data} params.data - Object or array | ||
| * @param {path} params.path - String or number | ||
| * @param {fallback} params.fallback - A fallback value | ||
| * | ||
| * @returns Value or undefined | ||
| */ | ||
| declare const getNestedObjectValue: GetNestedObjectValue; | ||
| export default getNestedObjectValue; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const memoizeGetValue = () => { | ||
| const cache = new WeakMap(); | ||
| const fn = ({ data, path, fallback }) => { | ||
| if (path === undefined) { | ||
| return fallback; | ||
| } | ||
| const key = typeof path === 'string' ? path.split('.') : [path]; | ||
| let current = data; | ||
| for (let i = 0; i < key.length; i += 1) { | ||
| if (!current) { | ||
| break; | ||
| } | ||
| current = current[key[i]]; | ||
| } | ||
| return current !== null && current !== void 0 ? current : fallback; | ||
| }; | ||
| const _memoizedGetValue = ({ data, path, fallback }) => { | ||
| if (typeof data === 'undefined') { | ||
| return fn({ data, path, fallback }); | ||
| } | ||
| if (!cache.has(data)) { | ||
| cache.set(data, new Map()); | ||
| } | ||
| const map = cache.get(data); | ||
| if (map.has(path)) { | ||
| return map.get(path); | ||
| } | ||
| const value = fn({ data, path, fallback }); | ||
| map.set(path, value); | ||
| return value; | ||
| }; | ||
| return _memoizedGetValue; | ||
| }; | ||
| /** | ||
| * Get nested object value by path | ||
| * | ||
| * @param {data} params.data - Object or array | ||
| * @param {path} params.path - String or number | ||
| * @param {fallback} params.fallback - A fallback value | ||
| * | ||
| * @returns Value or undefined | ||
| */ | ||
| const getNestedObjectValue = memoizeGetValue(); | ||
| exports.default = getNestedObjectValue; |
| export interface GetNestedObjectValueParams<T = any> { | ||
| data: any; | ||
| path?: string | number; | ||
| fallback?: T; | ||
| } | ||
| export type GetNestedObjectValue = <T = any>(params: GetNestedObjectValueParams<T>) => T | undefined; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| import { EmptyObjectOf } from './types'; | ||
| declare const isEmpty: <T extends object>(obj: T | null | undefined) => obj is EmptyObjectOf<T> | null | undefined; | ||
| export default isEmpty; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const isEmpty = (obj) => [Object, Array].includes((obj || {}).constructor) && !Object.entries(obj || {}).length; | ||
| exports.default = isEmpty; |
| export type EmptyObject<T> = { | ||
| [K in keyof T]?: never; | ||
| }; | ||
| export type EmptyObjectOf<T> = EmptyObject<T> extends T ? EmptyObject<T> : never; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| /** | ||
| * @desc check if value is function | ||
| * @param value | ||
| * @returns {boolean} | ||
| */ | ||
| declare const isFunction: <T extends {}>(value: unknown) => value is T; | ||
| export default isFunction; |
| "use strict"; | ||
| /** | ||
| * @desc check if value is function | ||
| * @param value | ||
| * @returns {boolean} | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const isFunction = (value) => typeof value === 'function'; | ||
| exports.default = isFunction; |
| import { IsNil } from './types'; | ||
| declare const isNil: IsNil; | ||
| export default isNil; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const isNil = value => value === null || value === undefined; | ||
| exports.default = isNil; |
| export type IsNil = (value: unknown) => boolean; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| /** | ||
| * @desc check if value is object | ||
| * @param value | ||
| * @returns {boolean} | ||
| * @example | ||
| * isObject({}); // true | ||
| * isObject(null); // false | ||
| * isObject(undefined); // false | ||
| * isObject(1); // false | ||
| */ | ||
| declare const isObject: (value: unknown) => value is Record<string, any>; | ||
| export default isObject; |
| "use strict"; | ||
| /** | ||
| * @desc check if value is object | ||
| * @param value | ||
| * @returns {boolean} | ||
| * @example | ||
| * isObject({}); // true | ||
| * isObject(null); // false | ||
| * isObject(undefined); // false | ||
| * isObject(1); // false | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const isObject = (value) => { | ||
| const type = typeof value; | ||
| return value != null && (type === 'object' || type === 'function') && !Array.isArray(value); | ||
| }; | ||
| exports.default = isObject; |
| import { LimitNumber } from './types'; | ||
| declare const limitNumber: LimitNumber; | ||
| export default limitNumber; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const limitNumber = ({ value, max, min }) => Math.max(min, Math.min(max, value)); | ||
| exports.default = limitNumber; |
| interface LimitNumberParams { | ||
| value: number; | ||
| min: number; | ||
| max: number; | ||
| } | ||
| export type LimitNumber = (params: LimitNumberParams) => number; | ||
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| /** | ||
| * pick | ||
| * @desc Returns a partial copy of an object containing only the keys specified. | ||
| * @param {Object} object | ||
| * @param {Array} keys | ||
| * @returns {Object} | ||
| */ | ||
| declare const pick: <T extends {}>(object: T, keys: (keyof T)[]) => T; | ||
| export default pick; |
| "use strict"; | ||
| /** | ||
| * pick | ||
| * @desc Returns a partial copy of an object containing only the keys specified. | ||
| * @param {Object} object | ||
| * @param {Array} keys | ||
| * @returns {Object} | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const pick = (object, keys) => keys.reduce((obj, key) => { | ||
| if (object && Object.hasOwnProperty.call(object, key)) { | ||
| obj[key] = object[key]; | ||
| } | ||
| return obj; | ||
| }, {}); | ||
| exports.default = pick; |
| /** | ||
| * @desc Returns a partial copy of an object containing only the keys that satisfy the provided testing function. | ||
| * @param obj | ||
| * @param predicate | ||
| * @returns Partial<T> | ||
| */ | ||
| declare const pickBy: <T extends {}>(obj: T, predicate: (value: unknown, key: keyof T) => boolean) => Partial<T>; | ||
| export default pickBy; |
| "use strict"; | ||
| /** | ||
| * @desc Returns a partial copy of an object containing only the keys that satisfy the provided testing function. | ||
| * @param obj | ||
| * @param predicate | ||
| * @returns Partial<T> | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const pickBy = (obj, predicate) => { | ||
| const result = {}; | ||
| for (const [key, value] of Object.entries(obj)) { | ||
| if (predicate(value, key)) { | ||
| result[key] = value; | ||
| } | ||
| } | ||
| return result; | ||
| }; | ||
| exports.default = pickBy; |
| /** | ||
| * Run if the passed parameter is a function or return it if not. | ||
| * | ||
| * @param {valueOrFn} - Input as function or other data type | ||
| * @param {arguments} - Arguments of the input function | ||
| * | ||
| * @returns The same input or returned value of input function | ||
| */ | ||
| declare const runIfFn: <T, U>(valueOrFn: T | ((...fnArgs: U[]) => T), ...args: U[]) => T; | ||
| export default runIfFn; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const isFunction_1 = __importDefault(require("../isFunction")); | ||
| /** | ||
| * Run if the passed parameter is a function or return it if not. | ||
| * | ||
| * @param {valueOrFn} - Input as function or other data type | ||
| * @param {arguments} - Arguments of the input function | ||
| * | ||
| * @returns The same input or returned value of input function | ||
| */ | ||
| const runIfFn = (valueOrFn, ...args) => (0, isFunction_1.default)(valueOrFn) ? valueOrFn(...args) : valueOrFn; | ||
| exports.default = runIfFn; |
| import { SetRef } from './types'; | ||
| declare const setRef: SetRef; | ||
| export default setRef; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const setRef = (ref, value) => { | ||
| if (typeof ref === 'function') { | ||
| ref(value); | ||
| } | ||
| else if (ref) { | ||
| ref.current = value; | ||
| } | ||
| }; | ||
| exports.default = setRef; |
| import { RefType } from '@asherng/common-types'; | ||
| export type SetRef = <V>(ref: RefType<V>, value: V) => void; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
-100%1
-50%2240
-92.59%2
100%3
-96.2%0
-100%2
Infinity%- Removed
- Removed