@titocandradev/neatcore 0.2.7 → 0.2.9
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/LICENSE +21 -0
- package/README.md +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +128 -0
- package/dist/index.d.ts +128 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tito Candra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -38,18 +38,18 @@ bun add @titocandradev/neatcore
|
|
|
38
38
|
### ES Module
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
|
-
import {
|
|
41
|
+
import { capitalizeWords } from "@titocandradev/neatcore";
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
capitalizeWords("tito candra");
|
|
44
44
|
// → "Tito Candra"
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
### CommonJS
|
|
48
48
|
|
|
49
49
|
```js
|
|
50
|
-
const {
|
|
50
|
+
const { capitalizeWords } = require("@titocandradev/neatcore");
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
capitalizeWords("tito candra");
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
---
|
|
@@ -58,12 +58,12 @@ firstUppercase("tito candra");
|
|
|
58
58
|
|
|
59
59
|
### 🔤 String
|
|
60
60
|
|
|
61
|
-
- `
|
|
61
|
+
- `capitalizeWords(str: string): string`
|
|
62
62
|
|
|
63
63
|
Example:
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
-
|
|
66
|
+
capitalizeWords("hello world");
|
|
67
67
|
// → "Hello World"
|
|
68
68
|
```
|
|
69
69
|
|
|
@@ -86,7 +86,7 @@ NeatCore is built with the following principles:
|
|
|
86
86
|
Import only what you need:
|
|
87
87
|
|
|
88
88
|
```ts
|
|
89
|
-
import {
|
|
89
|
+
import { capitalizeWords } from "@titocandradev/neatcore";
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
Modern bundlers like Vite, Webpack, and Rollup will automatically remove
|
package/dist/index.cjs.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":"aAAO,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,CCVO,SAASE,CAAAA,CAAUC,CAAAA,CAAiB,CACzC,OAAO,CAAC,GAAG,IAAI,IAAIA,CAAK,CAAC,CAC3B,CCFO,SAASC,CAAAA,CAA+BD,CAAAA,CAAqBE,CAAAA,CAAa,CAC/E,IAAMC,CAAAA,CAAO,IAAI,IAEjB,OAAOH,CAAAA,CAAM,OAAQI,CAAAA,EAAS,CAC5B,IAAMC,CAAAA,CAAQD,EAAKF,CAAG,CAAA,CACtB,OAAIC,CAAAA,CAAK,IAAIE,CAAK,CAAA,CAAU,KAAA,EAC5BF,CAAAA,CAAK,IAAIE,CAAK,CAAA,CACP,KACT,CAAC,CACH,CCTO,SAASC,CAAAA,CAA8BN,CAAAA,CAAqBE,CAAAA,CAA6B,CAC9F,OAAOF,CAAAA,CAAM,MAAA,CACX,CAACO,EAAKH,CAAAA,GAAS,CACb,IAAMI,CAAAA,CAAW,OAAOJ,CAAAA,CAAKF,CAAG,CAAC,CAAA,CAEjC,OAAKK,EAAIC,CAAQ,CAAA,GACfD,CAAAA,CAAIC,CAAQ,EAAI,EAAC,CAAA,CAGnBD,CAAAA,CAAIC,CAAQ,EAAE,IAAA,CAAKJ,CAAI,CAAA,CAChBG,CACT,EACA,EACF,CACF,CCdO,SAASE,EAA6CC,CAAAA,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AEnB,CCHO,SAASC,CAAAA,CAAgBD,EAAqB,CACnD,OAAKA,CAAAA,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":["export 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","export function unique<T>(array: T[]): T[] {\r\n return [...new Set(array)];\r\n}\r\n","export 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","export 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","export 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","export function isEmptyObject(obj: Record<PropertyKey, unknown>): boolean {\r\n return Object.keys(obj).length === 0;\r\n}\r\n","export 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","export 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","export 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","export function capitalize(str: string): string {\r\n if (!str) return \"\";\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n","export 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","export 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","export 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"],"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,IAAMC,CAAAA,CAAO,IAAI,IAEjB,OAAOH,CAAAA,CAAM,OAAQI,CAAAA,EAAS,CAC5B,IAAMC,CAAAA,CAAQD,EAAKF,CAAG,CAAA,CACtB,OAAIC,CAAAA,CAAK,IAAIE,CAAK,CAAA,CAAU,KAAA,EAC5BF,CAA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) 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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,27 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split an array into smaller arrays (chunks) of a given size.
|
|
3
|
+
*
|
|
4
|
+
* Does not mutate the original array.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam T - Array element type.
|
|
7
|
+
* @param array - The source array.
|
|
8
|
+
* @param size - The size of each chunk. Must be greater than 0.
|
|
9
|
+
*
|
|
10
|
+
* @returns A new array containing chunked subarrays.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* chunk([1, 2, 3, 4, 5], 2);
|
|
15
|
+
* // [[1, 2], [3, 4], [5]]
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @throws If size is less than 1.
|
|
19
|
+
*/
|
|
1
20
|
declare function chunk<T>(arr: T[], size: number): T[][];
|
|
2
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Remove duplicate values from an array.
|
|
24
|
+
*
|
|
25
|
+
* Uses strict equality comparison.
|
|
26
|
+
* Does not mutate the original array.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam T - Array element type.
|
|
29
|
+
* @param array - The source array.
|
|
30
|
+
*
|
|
31
|
+
* @returns A new array with unique values.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* unique([1, 1, 2, 3]);
|
|
36
|
+
* // [1, 2, 3]
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
3
39
|
declare function unique<T>(array: T[]): T[];
|
|
4
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Remove duplicate values from an array based on a specific key.
|
|
43
|
+
*
|
|
44
|
+
* @typeParam T - Array element type.
|
|
45
|
+
* @typeParam K - Key type (must be string | number | symbol).
|
|
46
|
+
* @param array - The source array.
|
|
47
|
+
* @param key - The key to determine uniqueness.
|
|
48
|
+
* @returns A new array with unique values based on the specified key.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* uniqueBy([{ id: 1 }, { id: 2 }, { id: 1 }], "id");
|
|
53
|
+
* // [{ id: 1 }, { id: 2 }]
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
5
56
|
declare function uniqueBy<T, K extends keyof T>(array: readonly T[], key: K): T[];
|
|
6
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Group array items by a specific key.
|
|
60
|
+
*
|
|
61
|
+
* @typeParam T - Array element type.
|
|
62
|
+
* @typeParam K - Key type (must be string | number | symbol).
|
|
63
|
+
* @param array - The source array.
|
|
64
|
+
* @param key - The key to group by.
|
|
65
|
+
* @returns An object where keys are group identifiers and values are arrays of grouped items.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* groupBy([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }, { id: 1, name: "Charlie" }], "id");
|
|
70
|
+
* // {
|
|
71
|
+
* // 1: [{ id: 1, name: "Alice" }, { id: 1, name: "Charlie" }],
|
|
72
|
+
* // 2: [{ id: 2, name: "Bob" }]
|
|
73
|
+
* // }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
7
76
|
declare function groupBy<T, K extends keyof T>(array: readonly T[], key: K): Record<string, T[]>;
|
|
8
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Debounce a function.
|
|
80
|
+
*
|
|
81
|
+
* @param fn - The function to debounce.
|
|
82
|
+
* @param delay - The debounce delay in milliseconds.
|
|
83
|
+
* @returns A debounced version of the input function.
|
|
84
|
+
*/
|
|
9
85
|
declare function debounce<T extends (...args: any[]) => void>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
10
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Check if an object is empty.
|
|
89
|
+
*
|
|
90
|
+
* @param obj - The object to check.
|
|
91
|
+
* @returns True if the object is empty, false otherwise.
|
|
92
|
+
*/
|
|
11
93
|
declare function isEmptyObject(obj: Record<PropertyKey, unknown>): boolean;
|
|
12
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Create a new object by picking specified keys from the source object.
|
|
97
|
+
*
|
|
98
|
+
* @param obj - The source object.
|
|
99
|
+
* @param keys - The keys to pick.
|
|
100
|
+
* @returns A new object with only the picked keys.
|
|
101
|
+
*/
|
|
13
102
|
declare function pick<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
|
|
14
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Create a new object by omitting specified keys from the source object.
|
|
106
|
+
*
|
|
107
|
+
* @param obj - The source object.
|
|
108
|
+
* @param keys - The keys to omit.
|
|
109
|
+
* @returns A new object without the omitted keys.
|
|
110
|
+
*/
|
|
15
111
|
declare function omit<T, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
16
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Get a nested property value from an object.
|
|
115
|
+
*
|
|
116
|
+
* @param obj - The source object.
|
|
117
|
+
* @param path - The dot-separated path to the property.
|
|
118
|
+
* @param defaultValue - The default value to return if the property is not found.
|
|
119
|
+
* @returns The value of the property or the default value.
|
|
120
|
+
*/
|
|
17
121
|
declare function get(obj: any, path: string, defaultValue?: any): any;
|
|
18
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Capitalize the first letter of a string.
|
|
125
|
+
*
|
|
126
|
+
* @param str - The input string.
|
|
127
|
+
* @returns The input string with the first letter capitalized.
|
|
128
|
+
*/
|
|
19
129
|
declare function capitalize(str: string): string;
|
|
20
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Capitalize the first letter of each word in a string.
|
|
133
|
+
*
|
|
134
|
+
* @param str - The input string.
|
|
135
|
+
* @returns The input string with the first letter of each word capitalized.
|
|
136
|
+
*/
|
|
21
137
|
declare function capitalizeWords(str: string): string;
|
|
22
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Convert a string to camel case.
|
|
141
|
+
*
|
|
142
|
+
* @param str - The input string.
|
|
143
|
+
* @returns The input string converted to camel case.
|
|
144
|
+
*/
|
|
23
145
|
declare function toCamelCase(str: string): string;
|
|
24
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Convert a string to kebab case.
|
|
149
|
+
*
|
|
150
|
+
* @param str - The input string.
|
|
151
|
+
* @returns The input string converted to kebab case.
|
|
152
|
+
*/
|
|
25
153
|
declare function toKebabCase(str: string): string;
|
|
26
154
|
|
|
27
155
|
export { capitalize, capitalizeWords, chunk, debounce, get, groupBy, isEmptyObject, omit, pick, toCamelCase, toKebabCase, unique, uniqueBy };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split an array into smaller arrays (chunks) of a given size.
|
|
3
|
+
*
|
|
4
|
+
* Does not mutate the original array.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam T - Array element type.
|
|
7
|
+
* @param array - The source array.
|
|
8
|
+
* @param size - The size of each chunk. Must be greater than 0.
|
|
9
|
+
*
|
|
10
|
+
* @returns A new array containing chunked subarrays.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* chunk([1, 2, 3, 4, 5], 2);
|
|
15
|
+
* // [[1, 2], [3, 4], [5]]
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @throws If size is less than 1.
|
|
19
|
+
*/
|
|
1
20
|
declare function chunk<T>(arr: T[], size: number): T[][];
|
|
2
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Remove duplicate values from an array.
|
|
24
|
+
*
|
|
25
|
+
* Uses strict equality comparison.
|
|
26
|
+
* Does not mutate the original array.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam T - Array element type.
|
|
29
|
+
* @param array - The source array.
|
|
30
|
+
*
|
|
31
|
+
* @returns A new array with unique values.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* unique([1, 1, 2, 3]);
|
|
36
|
+
* // [1, 2, 3]
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
3
39
|
declare function unique<T>(array: T[]): T[];
|
|
4
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Remove duplicate values from an array based on a specific key.
|
|
43
|
+
*
|
|
44
|
+
* @typeParam T - Array element type.
|
|
45
|
+
* @typeParam K - Key type (must be string | number | symbol).
|
|
46
|
+
* @param array - The source array.
|
|
47
|
+
* @param key - The key to determine uniqueness.
|
|
48
|
+
* @returns A new array with unique values based on the specified key.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* uniqueBy([{ id: 1 }, { id: 2 }, { id: 1 }], "id");
|
|
53
|
+
* // [{ id: 1 }, { id: 2 }]
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
5
56
|
declare function uniqueBy<T, K extends keyof T>(array: readonly T[], key: K): T[];
|
|
6
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Group array items by a specific key.
|
|
60
|
+
*
|
|
61
|
+
* @typeParam T - Array element type.
|
|
62
|
+
* @typeParam K - Key type (must be string | number | symbol).
|
|
63
|
+
* @param array - The source array.
|
|
64
|
+
* @param key - The key to group by.
|
|
65
|
+
* @returns An object where keys are group identifiers and values are arrays of grouped items.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* groupBy([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }, { id: 1, name: "Charlie" }], "id");
|
|
70
|
+
* // {
|
|
71
|
+
* // 1: [{ id: 1, name: "Alice" }, { id: 1, name: "Charlie" }],
|
|
72
|
+
* // 2: [{ id: 2, name: "Bob" }]
|
|
73
|
+
* // }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
7
76
|
declare function groupBy<T, K extends keyof T>(array: readonly T[], key: K): Record<string, T[]>;
|
|
8
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Debounce a function.
|
|
80
|
+
*
|
|
81
|
+
* @param fn - The function to debounce.
|
|
82
|
+
* @param delay - The debounce delay in milliseconds.
|
|
83
|
+
* @returns A debounced version of the input function.
|
|
84
|
+
*/
|
|
9
85
|
declare function debounce<T extends (...args: any[]) => void>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
10
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Check if an object is empty.
|
|
89
|
+
*
|
|
90
|
+
* @param obj - The object to check.
|
|
91
|
+
* @returns True if the object is empty, false otherwise.
|
|
92
|
+
*/
|
|
11
93
|
declare function isEmptyObject(obj: Record<PropertyKey, unknown>): boolean;
|
|
12
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Create a new object by picking specified keys from the source object.
|
|
97
|
+
*
|
|
98
|
+
* @param obj - The source object.
|
|
99
|
+
* @param keys - The keys to pick.
|
|
100
|
+
* @returns A new object with only the picked keys.
|
|
101
|
+
*/
|
|
13
102
|
declare function pick<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
|
|
14
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Create a new object by omitting specified keys from the source object.
|
|
106
|
+
*
|
|
107
|
+
* @param obj - The source object.
|
|
108
|
+
* @param keys - The keys to omit.
|
|
109
|
+
* @returns A new object without the omitted keys.
|
|
110
|
+
*/
|
|
15
111
|
declare function omit<T, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
16
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Get a nested property value from an object.
|
|
115
|
+
*
|
|
116
|
+
* @param obj - The source object.
|
|
117
|
+
* @param path - The dot-separated path to the property.
|
|
118
|
+
* @param defaultValue - The default value to return if the property is not found.
|
|
119
|
+
* @returns The value of the property or the default value.
|
|
120
|
+
*/
|
|
17
121
|
declare function get(obj: any, path: string, defaultValue?: any): any;
|
|
18
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Capitalize the first letter of a string.
|
|
125
|
+
*
|
|
126
|
+
* @param str - The input string.
|
|
127
|
+
* @returns The input string with the first letter capitalized.
|
|
128
|
+
*/
|
|
19
129
|
declare function capitalize(str: string): string;
|
|
20
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Capitalize the first letter of each word in a string.
|
|
133
|
+
*
|
|
134
|
+
* @param str - The input string.
|
|
135
|
+
* @returns The input string with the first letter of each word capitalized.
|
|
136
|
+
*/
|
|
21
137
|
declare function capitalizeWords(str: string): string;
|
|
22
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Convert a string to camel case.
|
|
141
|
+
*
|
|
142
|
+
* @param str - The input string.
|
|
143
|
+
* @returns The input string converted to camel case.
|
|
144
|
+
*/
|
|
23
145
|
declare function toCamelCase(str: string): string;
|
|
24
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Convert a string to kebab case.
|
|
149
|
+
*
|
|
150
|
+
* @param str - The input string.
|
|
151
|
+
* @returns The input string converted to kebab case.
|
|
152
|
+
*/
|
|
25
153
|
declare function toKebabCase(str: string): string;
|
|
26
154
|
|
|
27
155
|
export { capitalize, capitalizeWords, chunk, debounce, get, groupBy, isEmptyObject, omit, pick, toCamelCase, toKebabCase, unique, uniqueBy };
|
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":"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,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.js","sourcesContent":["export 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","export function unique<T>(array: T[]): T[] {\r\n return [...new Set(array)];\r\n}\r\n","export 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","export 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","export 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","export function isEmptyObject(obj: Record<PropertyKey, unknown>): boolean {\r\n return Object.keys(obj).length === 0;\r\n}\r\n","export 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","export 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","export 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","export function capitalize(str: string): string {\r\n if (!str) return \"\";\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n","export 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","export 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","export 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"],"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,IAAMC,CAAAA,CAAO,IAAI,IAEjB,OAAOH,CAAAA,CAAM,OAAQI,CAAAA,EAAS,CAC5B,IAAMC,CAAAA,CAAQD,EAAKF,CAAG,CAAA,CACtB,OAAIC,CAAAA,CAAK,IAAIE,CAAK,CAAA,CAAU,KAAA,EAC5BF,CAAAA,CAAK,IAAIE,CAAK,CAAA,CACP,KACT,CAAC,CACH,CCNO,SAASC,CAAAA,CAA8BN,CAAAA,CAAqBE,CAAAA,CAA6B,CAC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AAAA,CAAM,CACtB,GAAIpB,CAAAA,EAAU,KAAM,OAAOwB,CAAAA,CAC3BxB,EAASA,CAAAA,CAAOK,CAAG,EACrB,CAEA,OAAOL,CAAAA,GAAW,MAAA,CAAYwB,CAAAA,CAAexB,CAC/C,CCZO,SAASyB,CAAAA,CAAWC,CAAAA,CAAqB,CAC9C,OAAKA,CAAAA,CACEA,CAAAA,CAAI,OAAO,CAAC,CAAA,CAAE,aAAY,CAAIA,CAAAA,CAAI,KAAA,CAAM,CAAC,EAD/B,EAEnB,CCHO,SAASC,CAAAA,CAAgBD,EAAqB,CACnD,OAAKA,CAAAA,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.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"]}
|
package/package.json
CHANGED