@titocandradev/neatcore 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';function u(e,r){if(r<=0)return [];let t=[];for(let n=0;n<e.length;n+=r)t.push(e.slice(n,n+r));return t}function c(e){return [...new Set(e)]}function p(e,r){let t=new Set;return e.filter(n=>{let o=n[r];return t.has(o)?false:(t.add(o),true)})}function T(e,r){return e.reduce((t,n)=>{let o=String(n[r]);return t[o]||(t[o]=[]),t[o].push(n),t},{})}function y(e,r){let t;return function(...n){clearTimeout(t),t=setTimeout(()=>{e(...n);},r);}}function g(e){return Object.keys(e).length===0}function m(e,r){let t={};for(let n of r)n in e&&(t[n]=e[n]);return t}function k(e,r){let t={...e};for(let n of r)delete t[n];return t}function C(e,r,t){let n=r.split("."),o=e;for(let i of n){if(o==null)return t;o=o[i];}return o===void 0?t:o}function w(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function P(e){return e?e.trim().split(/\s+/).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" "):""}function j(e){return e?e.trim().replace(/[^a-zA-Z0-9]+(.)?/g,(r,t)=>t?t.toUpperCase():"").replace(/^(.)/,r=>r.toLowerCase()):""}function S(e){return e?e.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase():""}exports.capitalize=w;exports.capitalizeWords=P;exports.chunk=u;exports.debounce=y;exports.get=C;exports.groupBy=T;exports.isEmptyObject=g;exports.omit=k;exports.pick=m;exports.toCamelCase=j;exports.toKebabCase=S;exports.unique=c;exports.uniqueBy=p;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';function u(e,r){if(r<=0)return [];let t=[];for(let n=0;n<e.length;n+=r)t.push(e.slice(n,n+r));return t}function p(e){return [...new Set(e)]}function f(e,r){let t=new Set;return e.filter(n=>{let o=n[r];return t.has(o)?false:(t.add(o),true)})}function l(e,r){return e.reduce((t,n)=>{let o=String(n[r]);return t[o]||(t[o]=[]),t[o].push(n),t},{})}function g(e,r){let t;return function(...n){clearTimeout(t),t=setTimeout(()=>{e(...n);},r);}}function y(e){return Object.keys(e).length===0}function m(e,r){let t={};for(let n of r)n in e&&(t[n]=e[n]);return t}function k(e,r){let t={...e};for(let n of r)delete t[n];return t}function b(e,r,t){let n=r.split("."),o=e;for(let i of n){if(o==null)return t;o=o[i];}return o===void 0?t:o}function A(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function w(e){return e?e.trim().split(/\s+/).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" "):""}function R(e){return e?e.trim().replace(/[^a-zA-Z0-9]+(.)?/g,(r,t)=>t?t.toUpperCase():"").replace(/^(.)/,r=>r.toLowerCase()):""}function O(e){return e?e.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase():""}function q(e){return e?e.trim().split(/\s+/).map(r=>r.charAt(0).toUpperCase()).join(" "):""}exports.capitalize=A;exports.capitalizeWords=w;exports.chunk=u;exports.debounce=g;exports.get=b;exports.groupBy=l;exports.initialWords=q;exports.isEmptyObject=y;exports.omit=k;exports.pick=m;exports.toCamelCase=R;exports.toKebabCase=O;exports.unique=p;exports.uniqueBy=f;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/array/chunk.ts","../src/array/unique.ts","../src/array/uniqueBy.ts","../src/array/groupBy.ts","../src/function/debounce.ts","../src/object/isEmptyObject.ts","../src/object/pick.ts","../src/object/omit.ts","../src/object/get.ts","../src/string/capitalize.ts","../src/string/capitalizeWords.ts","../src/string/toCamelCase.ts","../src/string/toKebabCase.ts"],"names":["chunk","arr","size","result","i","unique","array","uniqueBy","key","seen","item","value","groupBy","acc","groupKey","debounce","fn","delay","timeout","args","isEmptyObject","obj","pick","keys","omit","get","path","defaultValue","capital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AAA,CACEA,CAAAA,CACJ,MAAK,CACL,KAAA,CAAM,KAAK,CAAA,CACX,GAAA,CAAKE,GAASA,CAAAA,CAAK,MAAA,CAAO,CAAC,CAAA,CAAE,aAAY,CAAIA,CAAAA,CAAK,KAAA,CAAM,CAAC,CAAC,CAAA,CAC1D,IAAA,CAAK,GAAG,CAAA,CALM,EAMnB,CCPO,SAASC,EAAYH,CAAAA,CAAqB,CAC/C,OAAKA,CAAAA,CAEEA,CAAAA,CACJ,IAAA,EAAK,CACL,QAAQ,oBAAA,CAAsB,CAACI,CAAAA,CAAGC,CAAAA,GAAkBA,EAAOA,CAAAA,CAAK,WAAA,EAAY,CAAI,EAAG,EACnF,OAAA,CAAQ,MAAA,CAASC,GAAUA,CAAAA,CAAM,WAAA,EAAa,CAAA,CALhC,EAMnB,CCPO,SAASC,EAAYP,CAAAA,CAAqB,CAC/C,OAAKA,CAAAA,CAEEA,CAAAA,CACJ,MAAK,CACL,OAAA,CAAQ,oBAAA,CAAsB,OAAO,EACrC,OAAA,CAAQ,SAAA,CAAW,GAAG,CAAA,CACtB,WAAA,GANc,EAOnB","file":"index.cjs","sourcesContent":["/**\r\n * Split an array into smaller arrays (chunks) of a given size.\r\n *\r\n * Does not mutate the original array.\r\n *\r\n * @typeParam T - Array element type.\r\n * @param array - The source array.\r\n * @param size - The size of each chunk. Must be greater than 0.\r\n *\r\n * @returns A new array containing chunked subarrays.\r\n *\r\n * @example\r\n * ```ts\r\n * chunk([1, 2, 3, 4, 5], 2);\r\n * // [[1, 2], [3, 4], [5]]\r\n * ```\r\n *\r\n * @throws If size is less than 1.\r\n */\r\nexport function chunk<T>(arr: T[], size: number): T[][] {\r\n if (size <= 0) return [];\r\n\r\n const result: T[][] = [];\r\n\r\n for (let i = 0; i < arr.length; i += size) {\r\n result.push(arr.slice(i, i + size));\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Remove duplicate values from an array.\r\n *\r\n * Uses strict equality comparison.\r\n * Does not mutate the original array.\r\n *\r\n * @typeParam T - Array element type.\r\n * @param array - The source array.\r\n *\r\n * @returns A new array with unique values.\r\n *\r\n * @example\r\n * ```ts\r\n * unique([1, 1, 2, 3]);\r\n * // [1, 2, 3]\r\n * ```\r\n */\r\nexport function unique<T>(array: T[]): T[] {\r\n return [...new Set(array)];\r\n}\r\n","/**\r\n * Remove duplicate values from an array based on a specific key.\r\n *\r\n * @typeParam T - Array element type.\r\n * @typeParam K - Key type (must be string | number | symbol).\r\n * @param array - The source array.\r\n * @param key - The key to determine uniqueness.\r\n * @returns A new array with unique values based on the specified key.\r\n *\r\n * @example\r\n * ```ts\r\n * uniqueBy([{ id: 1 }, { id: 2 }, { id: 1 }], \"id\");\r\n * // [{ id: 1 }, { id: 2 }]\r\n * ```\r\n */\r\nexport function uniqueBy<T, K extends keyof T>(array: readonly T[], key: K): T[] {\r\n const seen = new Set<T[K]>();\r\n\r\n return array.filter((item) => {\r\n const value = item[key];\r\n if (seen.has(value)) return false;\r\n seen.add(value);\r\n return true;\r\n });\r\n}\r\n","/**\r\n * Group array items by a specific key.\r\n *\r\n * @typeParam T - Array element type.\r\n * @typeParam K - Key type (must be string | number | symbol).\r\n * @param array - The source array.\r\n * @param key - The key to group by.\r\n * @returns An object where keys are group identifiers and values are arrays of grouped items.\r\n *\r\n * @example\r\n * ```ts\r\n * groupBy([{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }, { id: 1, name: \"Charlie\" }], \"id\");\r\n * // {\r\n * // 1: [{ id: 1, name: \"Alice\" }, { id: 1, name: \"Charlie\" }],\r\n * // 2: [{ id: 2, name: \"Bob\" }]\r\n * // }\r\n * ```\r\n */\r\nexport function groupBy<T, K extends keyof T>(array: readonly T[], key: K): Record<string, T[]> {\r\n return array.reduce(\r\n (acc, item) => {\r\n const groupKey = String(item[key]);\r\n\r\n if (!acc[groupKey]) {\r\n acc[groupKey] = [];\r\n }\r\n\r\n acc[groupKey].push(item);\r\n return acc;\r\n },\r\n {} as Record<string, T[]>,\r\n );\r\n}\r\n","/**\r\n * Debounce a function.\r\n *\r\n * @param fn - The function to debounce.\r\n * @param delay - The debounce delay in milliseconds.\r\n * @returns A debounced version of the input function.\r\n */\r\nexport function debounce<T extends (...args: any[]) => void>(fn: T, delay: number) {\r\n let timeout: ReturnType<typeof setTimeout>;\r\n\r\n return function (...args: Parameters<T>) {\r\n clearTimeout(timeout);\r\n\r\n timeout = setTimeout(() => {\r\n fn(...args);\r\n }, delay);\r\n };\r\n}\r\n","/**\r\n * Check if an object is empty.\r\n *\r\n * @param obj - The object to check.\r\n * @returns True if the object is empty, false otherwise.\r\n */\r\nexport function isEmptyObject(obj: Record<PropertyKey, unknown>): boolean {\r\n return Object.keys(obj).length === 0;\r\n}\r\n","/**\r\n * Create a new object by picking specified keys from the source object.\r\n *\r\n * @param obj - The source object.\r\n * @param keys - The keys to pick.\r\n * @returns A new object with only the picked keys.\r\n */\r\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K> {\r\n const result = {} as Pick<T, K>;\r\n\r\n for (const key of keys) {\r\n if (key in obj) {\r\n result[key] = obj[key];\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Create a new object by omitting specified keys from the source object.\r\n *\r\n * @param obj - The source object.\r\n * @param keys - The keys to omit.\r\n * @returns A new object without the omitted keys.\r\n */\r\nexport function omit<T, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K> {\r\n const result = { ...obj };\r\n\r\n for (const key of keys) {\r\n delete result[key];\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Get a nested property value from an object.\r\n *\r\n * @param obj - The source object.\r\n * @param path - The dot-separated path to the property.\r\n * @param defaultValue - The default value to return if the property is not found.\r\n * @returns The value of the property or the default value.\r\n */\r\nexport function get(obj: any, path: string, defaultValue?: any) {\r\n const keys = path.split(\".\");\r\n let result = obj;\r\n\r\n for (const key of keys) {\r\n if (result == null) return defaultValue;\r\n result = result[key];\r\n }\r\n\r\n return result === undefined ? defaultValue : result;\r\n}\r\n","/**\r\n * Capitalize the first letter of a string.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string with the first letter capitalized.\r\n */\r\nexport function capitalize(str: string): string {\r\n if (!str) return \"\";\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n","/**\r\n * Capitalize the first letter of each word in a string.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string with the first letter of each word capitalized.\r\n */\r\nexport function capitalizeWords(str: string): string {\r\n if (!str) return \"\";\r\n return str\r\n .trim()\r\n .split(/\\s+/)\r\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\r\n .join(\" \");\r\n}\r\n","/**\r\n * Convert a string to camel case.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string converted to camel case.\r\n */\r\nexport function toCamelCase(str: string): string {\r\n if (!str) return \"\";\r\n\r\n return str\r\n .trim()\r\n .replace(/[^a-zA-Z0-9]+(.)?/g, (_, char: string) => (char ? char.toUpperCase() : \"\"))\r\n .replace(/^(.)/, (match) => match.toLowerCase());\r\n}\r\n","/**\r\n * Convert a string to kebab case.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string converted to kebab case.\r\n */\r\nexport function toKebabCase(str: string): string {\r\n if (!str) return \"\";\r\n\r\n return str\r\n .trim()\r\n .replace(/([a-z0-9])([A-Z])/g, \"$1-$2\")\r\n .replace(/[_\\s]+/g, \"-\")\r\n .toLowerCase();\r\n}\r\n"]}
1
+ {"version":3,"sources":["../src/array/chunk.ts","../src/array/unique.ts","../src/array/uniqueBy.ts","../src/array/groupBy.ts","../src/function/debounce.ts","../src/object/isEmptyObject.ts","../src/object/pick.ts","../src/object/omit.ts","../src/object/get.ts","../src/string/capitalize.ts","../src/string/capitalizeWords.ts","../src/string/toCamelCase.ts","../src/string/toKebabCase.ts","../src/string/initialWords.ts"],"names":["chunk","arr","size","result","i","unique","array","uniqueBy","key","seen","item","value","groupBy","acc","groupKey","debounce","fn","delay","timeout","args","isEmptyObject","obj","pick","keys","omit","get","path","defaultValue","capitalize","str","capitalizeWords","word","toCamelCase","_","char","match","toKebabCase","initialWords"],"mappings":"aAmBO,SAASA,EAASC,CAAAA,CAAUC,CAAAA,CAAqB,CACtD,GAAIA,CAAAA,EAAQ,EAAG,OAAO,EAAC,CAEvB,IAAMC,EAAgB,EAAC,CAEvB,QAASC,CAAAA,CAAI,CAAA,CAAGA,EAAIH,CAAAA,CAAI,MAAA,CAAQG,CAAAA,EAAKF,CAAAA,CACnCC,EAAO,IAAA,CAAKF,CAAAA,CAAI,MAAMG,CAAAA,CAAGA,CAAAA,CAAIF,CAAI,CAAC,CAAA,CAGpC,OAAOC,CACT,CCZO,SAASE,CAAAA,CAAUC,CAAAA,CAAiB,CACzC,OAAO,CAAC,GAAG,IAAI,GAAA,CAAIA,CAAK,CAAC,CAC3B,CCJO,SAASC,EAA+BD,CAAAA,CAAqBE,CAAAA,CAAa,CAC/E,IAAMC,CAAAA,CAAO,IAAI,GAAA,CAEjB,OAAOH,CAAAA,CAAM,MAAA,CAAQI,GAAS,CAC5B,IAAMC,EAAQD,CAAAA,CAAKF,CAAG,CAAA,CACtB,OAAIC,EAAK,GAAA,CAAIE,CAAK,EAAU,KAAA,EAC5BF,CAAAA,CAAK,IAAIE,CAAK,CAAA,CACP,KACT,CAAC,CACH,CCNO,SAASC,CAAAA,CAA8BN,EAAqBE,CAAAA,CAA6B,CAC9F,OAAOF,CAAAA,CAAM,MAAA,CACX,CAACO,CAAAA,CAAKH,IAAS,CACb,IAAMI,EAAW,MAAA,CAAOJ,CAAAA,CAAKF,CAAG,CAAC,CAAA,CAEjC,OAAKK,CAAAA,CAAIC,CAAQ,CAAA,GACfD,CAAAA,CAAIC,CAAQ,CAAA,CAAI,IAGlBD,CAAAA,CAAIC,CAAQ,CAAA,CAAE,IAAA,CAAKJ,CAAI,CAAA,CAChBG,CACT,EACA,EACF,CACF,CCzBO,SAASE,EAA6CC,CAAAA,CAAOC,CAAAA,CAAe,CACjF,IAAIC,CAAAA,CA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AKA,CAAAA,CACEA,EACJ,IAAA,EAAK,CACL,MAAM,KAAK,CAAA,CACX,IAAKE,CAAAA,EAASA,CAAAA,CAAK,MAAA,CAAO,CAAC,EAAE,WAAA,EAAY,CAAIA,EAAK,KAAA,CAAM,CAAC,CAAC,CAAA,CAC1D,IAAA,CAAK,GAAG,CAAA,CALM,EAMnB,CCPO,SAASC,EAAYH,CAAAA,CAAqB,CAC/C,OAAKA,CAAAA,CAEEA,CAAAA,CACJ,IAAA,EAAK,CACL,QAAQ,oBAAA,CAAsB,CAACI,EAAGC,CAAAA,GAAkBA,CAAAA,CAAOA,EAAK,WAAA,EAAY,CAAI,EAAG,CAAA,CACnF,OAAA,CAAQ,OAASC,CAAAA,EAAUA,CAAAA,CAAM,aAAa,CAAA,CALhC,EAMnB,CCPO,SAASC,CAAAA,CAAYP,CAAAA,CAAqB,CAC/C,OAAKA,CAAAA,CAEEA,EACJ,IAAA,EAAK,CACL,QAAQ,oBAAA,CAAsB,OAAO,EACrC,OAAA,CAAQ,SAAA,CAAW,GAAG,CAAA,CACtB,WAAA,GANc,EAOnB,CCRO,SAASQ,CAAAA,CAAaR,CAAAA,CAAqB,CAChD,OAAKA,EACEA,CAAAA,CACJ,IAAA,GACA,KAAA,CAAM,KAAK,EACX,GAAA,CAAKE,CAAAA,EAASA,EAAK,MAAA,CAAO,CAAC,EAAE,WAAA,EAAa,EAC1C,IAAA,CAAK,GAAG,EALM,EAMnB","file":"index.cjs","sourcesContent":["/**\r\n * Split an array into smaller arrays (chunks) of a given size.\r\n *\r\n * Does not mutate the original array.\r\n *\r\n * @typeParam T - Array element type.\r\n * @param array - The source array.\r\n * @param size - The size of each chunk. Must be greater than 0.\r\n *\r\n * @returns A new array containing chunked subarrays.\r\n *\r\n * @example\r\n * ```ts\r\n * chunk([1, 2, 3, 4, 5], 2);\r\n * // [[1, 2], [3, 4], [5]]\r\n * ```\r\n *\r\n * @throws If size is less than 1.\r\n */\r\nexport function chunk<T>(arr: T[], size: number): T[][] {\r\n if (size <= 0) return [];\r\n\r\n const result: T[][] = [];\r\n\r\n for (let i = 0; i < arr.length; i += size) {\r\n result.push(arr.slice(i, i + size));\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Remove duplicate values from an array.\r\n *\r\n * Uses strict equality comparison.\r\n * Does not mutate the original array.\r\n *\r\n * @typeParam T - Array element type.\r\n * @param array - The source array.\r\n *\r\n * @returns A new array with unique values.\r\n *\r\n * @example\r\n * ```ts\r\n * unique([1, 1, 2, 3]);\r\n * // [1, 2, 3]\r\n * ```\r\n */\r\nexport function unique<T>(array: T[]): T[] {\r\n return [...new Set(array)];\r\n}\r\n","/**\r\n * Remove duplicate values from an array based on a specific key.\r\n *\r\n * @typeParam T - Array element type.\r\n * @typeParam K - Key type (must be string | number | symbol).\r\n * @param array - The source array.\r\n * @param key - The key to determine uniqueness.\r\n * @returns A new array with unique values based on the specified key.\r\n *\r\n * @example\r\n * ```ts\r\n * uniqueBy([{ id: 1 }, { id: 2 }, { id: 1 }], \"id\");\r\n * // [{ id: 1 }, { id: 2 }]\r\n * ```\r\n */\r\nexport function uniqueBy<T, K extends keyof T>(array: readonly T[], key: K): T[] {\r\n const seen = new Set<T[K]>();\r\n\r\n return array.filter((item) => {\r\n const value = item[key];\r\n if (seen.has(value)) return false;\r\n seen.add(value);\r\n return true;\r\n });\r\n}\r\n","/**\r\n * Group array items by a specific key.\r\n *\r\n * @typeParam T - Array element type.\r\n * @typeParam K - Key type (must be string | number | symbol).\r\n * @param array - The source array.\r\n * @param key - The key to group by.\r\n * @returns An object where keys are group identifiers and values are arrays of grouped items.\r\n *\r\n * @example\r\n * ```ts\r\n * groupBy([{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }, { id: 1, name: \"Charlie\" }], \"id\");\r\n * // {\r\n * // 1: [{ id: 1, name: \"Alice\" }, { id: 1, name: \"Charlie\" }],\r\n * // 2: [{ id: 2, name: \"Bob\" }]\r\n * // }\r\n * ```\r\n */\r\nexport function groupBy<T, K extends keyof T>(array: readonly T[], key: K): Record<string, T[]> {\r\n return array.reduce(\r\n (acc, item) => {\r\n const groupKey = String(item[key]);\r\n\r\n if (!acc[groupKey]) {\r\n acc[groupKey] = [];\r\n }\r\n\r\n acc[groupKey].push(item);\r\n return acc;\r\n },\r\n {} as Record<string, T[]>,\r\n );\r\n}\r\n","/**\r\n * Debounce a function.\r\n *\r\n * @param fn - The function to debounce.\r\n * @param delay - The debounce delay in milliseconds.\r\n * @returns A debounced version of the input function.\r\n */\r\nexport function debounce<T extends (...args: any[]) => void>(fn: T, delay: number) {\r\n let timeout: ReturnType<typeof setTimeout>;\r\n\r\n return function (...args: Parameters<T>) {\r\n clearTimeout(timeout);\r\n\r\n timeout = setTimeout(() => {\r\n fn(...args);\r\n }, delay);\r\n };\r\n}\r\n","/**\r\n * Check if an object is empty.\r\n *\r\n * @param obj - The object to check.\r\n * @returns True if the object is empty, false otherwise.\r\n */\r\nexport function isEmptyObject(obj: Record<PropertyKey, unknown>): boolean {\r\n return Object.keys(obj).length === 0;\r\n}\r\n","/**\r\n * Create a new object by picking specified keys from the source object.\r\n *\r\n * @param obj - The source object.\r\n * @param keys - The keys to pick.\r\n * @returns A new object with only the picked keys.\r\n */\r\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K> {\r\n const result = {} as Pick<T, K>;\r\n\r\n for (const key of keys) {\r\n if (key in obj) {\r\n result[key] = obj[key];\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Create a new object by omitting specified keys from the source object.\r\n *\r\n * @param obj - The source object.\r\n * @param keys - The keys to omit.\r\n * @returns A new object without the omitted keys.\r\n */\r\nexport function omit<T, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K> {\r\n const result = { ...obj };\r\n\r\n for (const key of keys) {\r\n delete result[key];\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Get a nested property value from an object.\r\n *\r\n * @param obj - The source object.\r\n * @param path - The dot-separated path to the property.\r\n * @param defaultValue - The default value to return if the property is not found.\r\n * @returns The value of the property or the default value.\r\n */\r\nexport function get(obj: any, path: string, defaultValue?: any) {\r\n const keys = path.split(\".\");\r\n let result = obj;\r\n\r\n for (const key of keys) {\r\n if (result == null) return defaultValue;\r\n result = result[key];\r\n }\r\n\r\n return result === undefined ? defaultValue : result;\r\n}\r\n","/**\r\n * Capitalize the first letter of a string.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string with the first letter capitalized.\r\n */\r\nexport function capitalize(str: string): string {\r\n if (!str) return \"\";\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n","/**\r\n * Capitalize the first letter of each word in a string.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string with the first letter of each word capitalized.\r\n */\r\nexport function capitalizeWords(str: string): string {\r\n if (!str) return \"\";\r\n return str\r\n .trim()\r\n .split(/\\s+/)\r\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\r\n .join(\" \");\r\n}\r\n","/**\r\n * Convert a string to camel case.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string converted to camel case.\r\n */\r\nexport function toCamelCase(str: string): string {\r\n if (!str) return \"\";\r\n\r\n return str\r\n .trim()\r\n .replace(/[^a-zA-Z0-9]+(.)?/g, (_, char: string) => (char ? char.toUpperCase() : \"\"))\r\n .replace(/^(.)/, (match) => match.toLowerCase());\r\n}\r\n","/**\r\n * Convert a string to kebab case.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string converted to kebab case.\r\n */\r\nexport function toKebabCase(str: string): string {\r\n if (!str) return \"\";\r\n\r\n return str\r\n .trim()\r\n .replace(/([a-z0-9])([A-Z])/g, \"$1-$2\")\r\n .replace(/[_\\s]+/g, \"-\")\r\n .toLowerCase();\r\n}\r\n","/**\r\n * Capitalize the first letter of each word in a string.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string with the only show first letter of each word capitalized.\r\n */\r\nexport function initialWords(str: string): string {\r\n if (!str) return \"\";\r\n return str\r\n .trim()\r\n .split(/\\s+/)\r\n .map((word) => word.charAt(0).toUpperCase())\r\n .join(\" \");\r\n}\r\n"]}
package/dist/index.d.cts CHANGED
@@ -152,4 +152,12 @@ declare function toCamelCase(str: string): string;
152
152
  */
153
153
  declare function toKebabCase(str: string): string;
154
154
 
155
- export { capitalize, capitalizeWords, chunk, debounce, get, groupBy, isEmptyObject, omit, pick, toCamelCase, toKebabCase, unique, uniqueBy };
155
+ /**
156
+ * Capitalize the first letter of each word in a string.
157
+ *
158
+ * @param str - The input string.
159
+ * @returns The input string with the only show first letter of each word capitalized.
160
+ */
161
+ declare function initialWords(str: string): string;
162
+
163
+ export { capitalize, capitalizeWords, chunk, debounce, get, groupBy, initialWords, isEmptyObject, omit, pick, toCamelCase, toKebabCase, unique, uniqueBy };
package/dist/index.d.ts CHANGED
@@ -152,4 +152,12 @@ declare function toCamelCase(str: string): string;
152
152
  */
153
153
  declare function toKebabCase(str: string): string;
154
154
 
155
- export { capitalize, capitalizeWords, chunk, debounce, get, groupBy, isEmptyObject, omit, pick, toCamelCase, toKebabCase, unique, uniqueBy };
155
+ /**
156
+ * Capitalize the first letter of each word in a string.
157
+ *
158
+ * @param str - The input string.
159
+ * @returns The input string with the only show first letter of each word capitalized.
160
+ */
161
+ declare function initialWords(str: string): string;
162
+
163
+ export { capitalize, capitalizeWords, chunk, debounce, get, groupBy, initialWords, isEmptyObject, omit, pick, toCamelCase, toKebabCase, unique, uniqueBy };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function u(e,r){if(r<=0)return [];let t=[];for(let n=0;n<e.length;n+=r)t.push(e.slice(n,n+r));return t}function c(e){return [...new Set(e)]}function p(e,r){let t=new Set;return e.filter(n=>{let o=n[r];return t.has(o)?false:(t.add(o),true)})}function T(e,r){return e.reduce((t,n)=>{let o=String(n[r]);return t[o]||(t[o]=[]),t[o].push(n),t},{})}function y(e,r){let t;return function(...n){clearTimeout(t),t=setTimeout(()=>{e(...n);},r);}}function g(e){return Object.keys(e).length===0}function m(e,r){let t={};for(let n of r)n in e&&(t[n]=e[n]);return t}function k(e,r){let t={...e};for(let n of r)delete t[n];return t}function C(e,r,t){let n=r.split("."),o=e;for(let i of n){if(o==null)return t;o=o[i];}return o===void 0?t:o}function w(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function P(e){return e?e.trim().split(/\s+/).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" "):""}function j(e){return e?e.trim().replace(/[^a-zA-Z0-9]+(.)?/g,(r,t)=>t?t.toUpperCase():"").replace(/^(.)/,r=>r.toLowerCase()):""}function S(e){return e?e.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase():""}export{w as capitalize,P as capitalizeWords,u as chunk,y as debounce,C as get,T as groupBy,g as isEmptyObject,k as omit,m as pick,j as toCamelCase,S as toKebabCase,c as unique,p as uniqueBy};//# sourceMappingURL=index.js.map
1
+ function u(e,r){if(r<=0)return [];let t=[];for(let n=0;n<e.length;n+=r)t.push(e.slice(n,n+r));return t}function p(e){return [...new Set(e)]}function f(e,r){let t=new Set;return e.filter(n=>{let o=n[r];return t.has(o)?false:(t.add(o),true)})}function l(e,r){return e.reduce((t,n)=>{let o=String(n[r]);return t[o]||(t[o]=[]),t[o].push(n),t},{})}function g(e,r){let t;return function(...n){clearTimeout(t),t=setTimeout(()=>{e(...n);},r);}}function y(e){return Object.keys(e).length===0}function m(e,r){let t={};for(let n of r)n in e&&(t[n]=e[n]);return t}function k(e,r){let t={...e};for(let n of r)delete t[n];return t}function b(e,r,t){let n=r.split("."),o=e;for(let i of n){if(o==null)return t;o=o[i];}return o===void 0?t:o}function A(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function w(e){return e?e.trim().split(/\s+/).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" "):""}function R(e){return e?e.trim().replace(/[^a-zA-Z0-9]+(.)?/g,(r,t)=>t?t.toUpperCase():"").replace(/^(.)/,r=>r.toLowerCase()):""}function O(e){return e?e.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase():""}function q(e){return e?e.trim().split(/\s+/).map(r=>r.charAt(0).toUpperCase()).join(" "):""}export{A as capitalize,w as capitalizeWords,u as chunk,g as debounce,b as get,l as groupBy,q as initialWords,y as isEmptyObject,k as omit,m as pick,R as toCamelCase,O as toKebabCase,p as unique,f as uniqueBy};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/array/chunk.ts","../src/array/unique.ts","../src/array/uniqueBy.ts","../src/array/groupBy.ts","../src/function/debounce.ts","../src/object/isEmptyObject.ts","../src/object/pick.ts","../src/object/omit.ts","../src/object/get.ts","../src/string/capitalize.ts","../src/string/capitalizeWords.ts","../src/string/toCamelCase.ts","../src/string/toKebabCase.ts"],"names":["chunk","arr","size","result","i","unique","array","uniqueBy","key","seen","item","value","groupBy","acc","groupKey","debounce","fn","delay","timeout","args","isEmptyObject","obj","pick","keys","omit","get","path","defaultValue","capitalize","str","capitalizeWords","word","toCamelCase","_","char","match","toKebabCase"],"mappings":"AAmBO,SAASA,EAASC,CAAAA,CAAUC,CAAAA,CAAqB,CACtD,GAAIA,GAAQ,CAAA,CAAG,OAAO,EAAC,CAEvB,IAAMC,CAAAA,CAAgB,GAEtB,IAAA,IAASC,CAAAA,CAAI,EAAGA,CAAAA,CAAIH,CAAAA,CAAI,MAAA,CAAQG,CAAAA,EAAKF,EACnCC,CAAAA,CAAO,IAAA,CAAKF,CAAAA,CAAI,KAAA,CAAMG,EAAGA,CAAAA,CAAIF,CAAI,CAAC,CAAA,CAGpC,OAAOC,CACT,CCZO,SAASE,CAAAA,CAAUC,CAAAA,CAAiB,CACzC,OAAO,CAAC,GAAG,IAAI,IAAIA,CAAK,CAAC,CAC3B,CCJO,SAASC,CAAAA,CAA+BD,CAAAA,CAAqBE,CAAAA,CAAa,CAC/E,IAAM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,CAAAA,CAEEA,CAAAA,CACJ,MAAK,CACL,OAAA,CAAQ,oBAAA,CAAsB,OAAO,EACrC,OAAA,CAAQ,SAAA,CAAW,GAAG,CAAA,CACtB,WAAA,GANc,EAOnB","file":"index.js","sourcesContent":["/**\r\n * Split an array into smaller arrays (chunks) of a given size.\r\n *\r\n * Does not mutate the original array.\r\n *\r\n * @typeParam T - Array element type.\r\n * @param array - The source array.\r\n * @param size - The size of each chunk. Must be greater than 0.\r\n *\r\n * @returns A new array containing chunked subarrays.\r\n *\r\n * @example\r\n * ```ts\r\n * chunk([1, 2, 3, 4, 5], 2);\r\n * // [[1, 2], [3, 4], [5]]\r\n * ```\r\n *\r\n * @throws If size is less than 1.\r\n */\r\nexport function chunk<T>(arr: T[], size: number): T[][] {\r\n if (size <= 0) return [];\r\n\r\n const result: T[][] = [];\r\n\r\n for (let i = 0; i < arr.length; i += size) {\r\n result.push(arr.slice(i, i + size));\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Remove duplicate values from an array.\r\n *\r\n * Uses strict equality comparison.\r\n * Does not mutate the original array.\r\n *\r\n * @typeParam T - Array element type.\r\n * @param array - The source array.\r\n *\r\n * @returns A new array with unique values.\r\n *\r\n * @example\r\n * ```ts\r\n * unique([1, 1, 2, 3]);\r\n * // [1, 2, 3]\r\n * ```\r\n */\r\nexport function unique<T>(array: T[]): T[] {\r\n return [...new Set(array)];\r\n}\r\n","/**\r\n * Remove duplicate values from an array based on a specific key.\r\n *\r\n * @typeParam T - Array element type.\r\n * @typeParam K - Key type (must be string | number | symbol).\r\n * @param array - The source array.\r\n * @param key - The key to determine uniqueness.\r\n * @returns A new array with unique values based on the specified key.\r\n *\r\n * @example\r\n * ```ts\r\n * uniqueBy([{ id: 1 }, { id: 2 }, { id: 1 }], \"id\");\r\n * // [{ id: 1 }, { id: 2 }]\r\n * ```\r\n */\r\nexport function uniqueBy<T, K extends keyof T>(array: readonly T[], key: K): T[] {\r\n const seen = new Set<T[K]>();\r\n\r\n return array.filter((item) => {\r\n const value = item[key];\r\n if (seen.has(value)) return false;\r\n seen.add(value);\r\n return true;\r\n });\r\n}\r\n","/**\r\n * Group array items by a specific key.\r\n *\r\n * @typeParam T - Array element type.\r\n * @typeParam K - Key type (must be string | number | symbol).\r\n * @param array - The source array.\r\n * @param key - The key to group by.\r\n * @returns An object where keys are group identifiers and values are arrays of grouped items.\r\n *\r\n * @example\r\n * ```ts\r\n * groupBy([{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }, { id: 1, name: \"Charlie\" }], \"id\");\r\n * // {\r\n * // 1: [{ id: 1, name: \"Alice\" }, { id: 1, name: \"Charlie\" }],\r\n * // 2: [{ id: 2, name: \"Bob\" }]\r\n * // }\r\n * ```\r\n */\r\nexport function groupBy<T, K extends keyof T>(array: readonly T[], key: K): Record<string, T[]> {\r\n return array.reduce(\r\n (acc, item) => {\r\n const groupKey = String(item[key]);\r\n\r\n if (!acc[groupKey]) {\r\n acc[groupKey] = [];\r\n }\r\n\r\n acc[groupKey].push(item);\r\n return acc;\r\n },\r\n {} as Record<string, T[]>,\r\n );\r\n}\r\n","/**\r\n * Debounce a function.\r\n *\r\n * @param fn - The function to debounce.\r\n * @param delay - The debounce delay in milliseconds.\r\n * @returns A debounced version of the input function.\r\n */\r\nexport function debounce<T extends (...args: any[]) => void>(fn: T, delay: number) {\r\n let timeout: ReturnType<typeof setTimeout>;\r\n\r\n return function (...args: Parameters<T>) {\r\n clearTimeout(timeout);\r\n\r\n timeout = setTimeout(() => {\r\n fn(...args);\r\n }, delay);\r\n };\r\n}\r\n","/**\r\n * Check if an object is empty.\r\n *\r\n * @param obj - The object to check.\r\n * @returns True if the object is empty, false otherwise.\r\n */\r\nexport function isEmptyObject(obj: Record<PropertyKey, unknown>): boolean {\r\n return Object.keys(obj).length === 0;\r\n}\r\n","/**\r\n * Create a new object by picking specified keys from the source object.\r\n *\r\n * @param obj - The source object.\r\n * @param keys - The keys to pick.\r\n * @returns A new object with only the picked keys.\r\n */\r\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K> {\r\n const result = {} as Pick<T, K>;\r\n\r\n for (const key of keys) {\r\n if (key in obj) {\r\n result[key] = obj[key];\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Create a new object by omitting specified keys from the source object.\r\n *\r\n * @param obj - The source object.\r\n * @param keys - The keys to omit.\r\n * @returns A new object without the omitted keys.\r\n */\r\nexport function omit<T, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K> {\r\n const result = { ...obj };\r\n\r\n for (const key of keys) {\r\n delete result[key];\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Get a nested property value from an object.\r\n *\r\n * @param obj - The source object.\r\n * @param path - The dot-separated path to the property.\r\n * @param defaultValue - The default value to return if the property is not found.\r\n * @returns The value of the property or the default value.\r\n */\r\nexport function get(obj: any, path: string, defaultValue?: any) {\r\n const keys = path.split(\".\");\r\n let result = obj;\r\n\r\n for (const key of keys) {\r\n if (result == null) return defaultValue;\r\n result = result[key];\r\n }\r\n\r\n return result === undefined ? defaultValue : result;\r\n}\r\n","/**\r\n * Capitalize the first letter of a string.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string with the first letter capitalized.\r\n */\r\nexport function capitalize(str: string): string {\r\n if (!str) return \"\";\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n","/**\r\n * Capitalize the first letter of each word in a string.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string with the first letter of each word capitalized.\r\n */\r\nexport function capitalizeWords(str: string): string {\r\n if (!str) return \"\";\r\n return str\r\n .trim()\r\n .split(/\\s+/)\r\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\r\n .join(\" \");\r\n}\r\n","/**\r\n * Convert a string to camel case.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string converted to camel case.\r\n */\r\nexport function toCamelCase(str: string): string {\r\n if (!str) return \"\";\r\n\r\n return str\r\n .trim()\r\n .replace(/[^a-zA-Z0-9]+(.)?/g, (_, char: string) => (char ? char.toUpperCase() : \"\"))\r\n .replace(/^(.)/, (match) => match.toLowerCase());\r\n}\r\n","/**\r\n * Convert a string to kebab case.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string converted to kebab case.\r\n */\r\nexport function toKebabCase(str: string): string {\r\n if (!str) return \"\";\r\n\r\n return str\r\n .trim()\r\n .replace(/([a-z0-9])([A-Z])/g, \"$1-$2\")\r\n .replace(/[_\\s]+/g, \"-\")\r\n .toLowerCase();\r\n}\r\n"]}
1
+ {"version":3,"sources":["../src/array/chunk.ts","../src/array/unique.ts","../src/array/uniqueBy.ts","../src/array/groupBy.ts","../src/function/debounce.ts","../src/object/isEmptyObject.ts","../src/object/pick.ts","../src/object/omit.ts","../src/object/get.ts","../src/string/capitalize.ts","../src/string/capitalizeWords.ts","../src/string/toCamelCase.ts","../src/string/toKebabCase.ts","../src/string/initialWords.ts"],"names":["chunk","arr","size","result","i","unique","array","uniqueBy","key","seen","item","value","groupBy","acc","groupKey","debounce","fn","delay","timeout","args","isEmptyObject","obj","pick","keys","omit","get","path","defaultValue","capitalize","str","capitalizeWords","word","toCamelCase","_","char","match","toKebabCase","initialWords"],"mappings":"AAmBO,SAASA,EAASC,CAAAA,CAAUC,CAAAA,CAAqB,CACtD,GAAIA,CAAAA,EAAQ,EAAG,OAAO,EAAC,CAEvB,IAAMC,EAAgB,EAAC,CAEvB,QAASC,CAAAA,CAAI,CAAA,CAAGA,EAAIH,CAAAA,CAAI,MAAA,CAAQG,CAAAA,EAAKF,CAAAA,CACnCC,EAAO,IAAA,CAAKF,CAAAA,CAAI,MAAMG,CAAAA,CAAGA,CAAAA,CAAIF,CAAI,CAAC,CAAA,CAGpC,OAAOC,CACT,CCZO,SAASE,CAAAA,CAAUC,CAAAA,CAAiB,CACzC,OAAO,CAAC,GAAG,IAAI,GAAA,CAAIA,CAAK,CAAC,CAC3B,CCJO,SAASC,EAA+BD,CAAAA,CAAqBE,CAAAA,CAA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,CAEEA,EACJ,IAAA,EAAK,CACL,QAAQ,oBAAA,CAAsB,OAAO,EACrC,OAAA,CAAQ,SAAA,CAAW,GAAG,CAAA,CACtB,WAAA,GANc,EAOnB,CCRO,SAASQ,CAAAA,CAAaR,CAAAA,CAAqB,CAChD,OAAKA,EACEA,CAAAA,CACJ,IAAA,GACA,KAAA,CAAM,KAAK,EACX,GAAA,CAAKE,CAAAA,EAASA,EAAK,MAAA,CAAO,CAAC,EAAE,WAAA,EAAa,EAC1C,IAAA,CAAK,GAAG,EALM,EAMnB","file":"index.js","sourcesContent":["/**\r\n * Split an array into smaller arrays (chunks) of a given size.\r\n *\r\n * Does not mutate the original array.\r\n *\r\n * @typeParam T - Array element type.\r\n * @param array - The source array.\r\n * @param size - The size of each chunk. Must be greater than 0.\r\n *\r\n * @returns A new array containing chunked subarrays.\r\n *\r\n * @example\r\n * ```ts\r\n * chunk([1, 2, 3, 4, 5], 2);\r\n * // [[1, 2], [3, 4], [5]]\r\n * ```\r\n *\r\n * @throws If size is less than 1.\r\n */\r\nexport function chunk<T>(arr: T[], size: number): T[][] {\r\n if (size <= 0) return [];\r\n\r\n const result: T[][] = [];\r\n\r\n for (let i = 0; i < arr.length; i += size) {\r\n result.push(arr.slice(i, i + size));\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Remove duplicate values from an array.\r\n *\r\n * Uses strict equality comparison.\r\n * Does not mutate the original array.\r\n *\r\n * @typeParam T - Array element type.\r\n * @param array - The source array.\r\n *\r\n * @returns A new array with unique values.\r\n *\r\n * @example\r\n * ```ts\r\n * unique([1, 1, 2, 3]);\r\n * // [1, 2, 3]\r\n * ```\r\n */\r\nexport function unique<T>(array: T[]): T[] {\r\n return [...new Set(array)];\r\n}\r\n","/**\r\n * Remove duplicate values from an array based on a specific key.\r\n *\r\n * @typeParam T - Array element type.\r\n * @typeParam K - Key type (must be string | number | symbol).\r\n * @param array - The source array.\r\n * @param key - The key to determine uniqueness.\r\n * @returns A new array with unique values based on the specified key.\r\n *\r\n * @example\r\n * ```ts\r\n * uniqueBy([{ id: 1 }, { id: 2 }, { id: 1 }], \"id\");\r\n * // [{ id: 1 }, { id: 2 }]\r\n * ```\r\n */\r\nexport function uniqueBy<T, K extends keyof T>(array: readonly T[], key: K): T[] {\r\n const seen = new Set<T[K]>();\r\n\r\n return array.filter((item) => {\r\n const value = item[key];\r\n if (seen.has(value)) return false;\r\n seen.add(value);\r\n return true;\r\n });\r\n}\r\n","/**\r\n * Group array items by a specific key.\r\n *\r\n * @typeParam T - Array element type.\r\n * @typeParam K - Key type (must be string | number | symbol).\r\n * @param array - The source array.\r\n * @param key - The key to group by.\r\n * @returns An object where keys are group identifiers and values are arrays of grouped items.\r\n *\r\n * @example\r\n * ```ts\r\n * groupBy([{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }, { id: 1, name: \"Charlie\" }], \"id\");\r\n * // {\r\n * // 1: [{ id: 1, name: \"Alice\" }, { id: 1, name: \"Charlie\" }],\r\n * // 2: [{ id: 2, name: \"Bob\" }]\r\n * // }\r\n * ```\r\n */\r\nexport function groupBy<T, K extends keyof T>(array: readonly T[], key: K): Record<string, T[]> {\r\n return array.reduce(\r\n (acc, item) => {\r\n const groupKey = String(item[key]);\r\n\r\n if (!acc[groupKey]) {\r\n acc[groupKey] = [];\r\n }\r\n\r\n acc[groupKey].push(item);\r\n return acc;\r\n },\r\n {} as Record<string, T[]>,\r\n );\r\n}\r\n","/**\r\n * Debounce a function.\r\n *\r\n * @param fn - The function to debounce.\r\n * @param delay - The debounce delay in milliseconds.\r\n * @returns A debounced version of the input function.\r\n */\r\nexport function debounce<T extends (...args: any[]) => void>(fn: T, delay: number) {\r\n let timeout: ReturnType<typeof setTimeout>;\r\n\r\n return function (...args: Parameters<T>) {\r\n clearTimeout(timeout);\r\n\r\n timeout = setTimeout(() => {\r\n fn(...args);\r\n }, delay);\r\n };\r\n}\r\n","/**\r\n * Check if an object is empty.\r\n *\r\n * @param obj - The object to check.\r\n * @returns True if the object is empty, false otherwise.\r\n */\r\nexport function isEmptyObject(obj: Record<PropertyKey, unknown>): boolean {\r\n return Object.keys(obj).length === 0;\r\n}\r\n","/**\r\n * Create a new object by picking specified keys from the source object.\r\n *\r\n * @param obj - The source object.\r\n * @param keys - The keys to pick.\r\n * @returns A new object with only the picked keys.\r\n */\r\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K> {\r\n const result = {} as Pick<T, K>;\r\n\r\n for (const key of keys) {\r\n if (key in obj) {\r\n result[key] = obj[key];\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Create a new object by omitting specified keys from the source object.\r\n *\r\n * @param obj - The source object.\r\n * @param keys - The keys to omit.\r\n * @returns A new object without the omitted keys.\r\n */\r\nexport function omit<T, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K> {\r\n const result = { ...obj };\r\n\r\n for (const key of keys) {\r\n delete result[key];\r\n }\r\n\r\n return result;\r\n}\r\n","/**\r\n * Get a nested property value from an object.\r\n *\r\n * @param obj - The source object.\r\n * @param path - The dot-separated path to the property.\r\n * @param defaultValue - The default value to return if the property is not found.\r\n * @returns The value of the property or the default value.\r\n */\r\nexport function get(obj: any, path: string, defaultValue?: any) {\r\n const keys = path.split(\".\");\r\n let result = obj;\r\n\r\n for (const key of keys) {\r\n if (result == null) return defaultValue;\r\n result = result[key];\r\n }\r\n\r\n return result === undefined ? defaultValue : result;\r\n}\r\n","/**\r\n * Capitalize the first letter of a string.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string with the first letter capitalized.\r\n */\r\nexport function capitalize(str: string): string {\r\n if (!str) return \"\";\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n","/**\r\n * Capitalize the first letter of each word in a string.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string with the first letter of each word capitalized.\r\n */\r\nexport function capitalizeWords(str: string): string {\r\n if (!str) return \"\";\r\n return str\r\n .trim()\r\n .split(/\\s+/)\r\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\r\n .join(\" \");\r\n}\r\n","/**\r\n * Convert a string to camel case.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string converted to camel case.\r\n */\r\nexport function toCamelCase(str: string): string {\r\n if (!str) return \"\";\r\n\r\n return str\r\n .trim()\r\n .replace(/[^a-zA-Z0-9]+(.)?/g, (_, char: string) => (char ? char.toUpperCase() : \"\"))\r\n .replace(/^(.)/, (match) => match.toLowerCase());\r\n}\r\n","/**\r\n * Convert a string to kebab case.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string converted to kebab case.\r\n */\r\nexport function toKebabCase(str: string): string {\r\n if (!str) return \"\";\r\n\r\n return str\r\n .trim()\r\n .replace(/([a-z0-9])([A-Z])/g, \"$1-$2\")\r\n .replace(/[_\\s]+/g, \"-\")\r\n .toLowerCase();\r\n}\r\n","/**\r\n * Capitalize the first letter of each word in a string.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string with the only show first letter of each word capitalized.\r\n */\r\nexport function initialWords(str: string): string {\r\n if (!str) return \"\";\r\n return str\r\n .trim()\r\n .split(/\\s+/)\r\n .map((word) => word.charAt(0).toUpperCase())\r\n .join(\" \");\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titocandradev/neatcore",
3
- "version": "0.2.9",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "description": "A clean, zero-dependency, TypeScript-first utility core.",
6
6
  "homepage": "https://github.com/tcandra24/neat-core#readme",