@titocandradev/neatcore 0.3.3 → 0.4.1

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/README.md CHANGED
@@ -145,4 +145,4 @@ NeatCore is designed as a strongly-typed engineering utility foundation
145
145
 
146
146
  Read full API Design Guideline here:
147
147
 
148
- 👉 https://github.com/tcandra24/neat-core/blob/main/docs/API_DESIGN_GUIDELINE.md
148
+ 👉 https://tcandra24.github.io/neat-core/
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';function u(e,t){if(t<=0)return [];let r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function c(e){return [...new Set(e)]}function p(e,t){let r=new Set;return e.filter(n=>{let o=n[t];return r.has(o)?false:(r.add(o),true)})}function f(e,t){return e.reduce((r,n)=>{let o=String(n[t]);return r[o]||(r[o]=[]),r[o].push(n),r},{})}function y(e,t){let r;return function(...n){clearTimeout(r),r=setTimeout(()=>{e(...n);},t);}}async function m(e){try{return [null,typeof e=="function"?await e():await e]}catch(t){return [t,null]}}function d(e){return Object.keys(e).length===0}function C(e,t){let r={};for(let n of t)n in e&&(r[n]=e[n]);return r}function k(e,t){let r={...e};for(let n of t)delete r[n];return r}function b(e,t,r){let n=t.split("."),o=e;for(let i of n){if(o==null)return r;o=o[i];}return o===void 0?r:o}function w(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function j(e){return e?e.trim().split(/\s+/).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" "):""}function E(e){return e?e.trim().replace(/[^a-zA-Z0-9]+(.)?/g,(t,r)=>r?r.toUpperCase():"").replace(/^(.)/,t=>t.toLowerCase()):""}function S(e){return e?e.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase():""}function v(e){return e?e.trim().split(/\s+/).map(t=>t.charAt(0).toUpperCase()).join(" "):""}exports.capitalize=w;exports.capitalizeWords=j;exports.chunk=u;exports.debounce=y;exports.get=b;exports.groupBy=f;exports.initialWords=v;exports.isEmptyObject=d;exports.omit=k;exports.pick=C;exports.toCamelCase=E;exports.toKebabCase=S;exports.tryCatch=m;exports.unique=c;exports.uniqueBy=p;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';function u(e,t){if(t<=0)return [];let r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function a(e){return [...new Set(e)]}function T(e,t){let r=new Set;return e.filter(n=>{let o=n[t];return r.has(o)?false:(r.add(o),true)})}function l(e,t){return e.reduce((r,n)=>{let o=String(n[t]);return r[o]||(r[o]=[]),r[o].push(n),r},{})}function g(e,t){let r=new Set(t);return e.filter(n=>!r.has(n))}function m(e,t){let r=new Set(t);return e.filter(n=>r.has(n))}function C(e,t,r="asc"){return [...e].sort((n,o)=>{let i=t(n),s=t(o);return i<s?r==="asc"?-1:1:i>s?r==="asc"?1:-1:0})}function k(e,t){let r;return function(...n){clearTimeout(r),r=setTimeout(()=>{e(...n);},t);}}async function b(e){try{return [null,typeof e=="function"?await e():await e]}catch(t){return [t,null]}}function w(e){return Object.keys(e).length===0}function R(e,t){let r={};for(let n of t)n in e&&(r[n]=e[n]);return r}function S(e,t){let r={...e};for(let n of t)delete r[n];return r}function z(e,t,r){let n=t.split("."),o=e;for(let i of n){if(o==null)return r;o=o[i];}return o===void 0?r:o}function $(...e){return e.reduce((t,r)=>({...t,...r}),{})}function E(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function B(e){return e?e.trim().split(/\s+/).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" "):""}function O(e){return e?e.trim().replace(/[^a-zA-Z0-9]+(.)?/g,(t,r)=>r?r.toUpperCase():"").replace(/^(.)/,t=>t.toLowerCase()):""}function q(e){return e?e.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase():""}function D(e){return e?e.trim().split(/\s+/).map(t=>t.charAt(0).toUpperCase()).join(" "):""}function N(e,t,r="..."){return e.length<=t?e:e.slice(0,t).trimEnd()+r}function G(e){return e.toLowerCase().trim().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function J(e){return e?e.trim().replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/[_\s]+/g,"_").toLowerCase():""}exports.capitalize=E;exports.capitalizeWords=B;exports.chunk=u;exports.debounce=k;exports.difference=g;exports.get=z;exports.groupBy=l;exports.initialWords=D;exports.intersection=m;exports.isEmptyObject=w;exports.merge=$;exports.omit=S;exports.pick=R;exports.slugify=G;exports.sortBy=C;exports.toCamelCase=O;exports.toKebabCase=q;exports.toSnakeCase=J;exports.truncate=N;exports.tryCatch=b;exports.unique=a;exports.uniqueBy=T;//# 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/function/tryCatch.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","tryCatch","input","error","isEmptyObject","obj","pick","keys","omit","get","path","defaultValue","capitalize","str","capitalizeWords","word","toCamelCase","_","char","match","toKebabCase","initialWords"],"mappings":"aAmBO,SAASA,CAAAA,CAASC,EAAUC,CAAAA,CAAqB,CACtD,GAAIA,CAAAA,EAAQ,CAAA,CAAG,OAAO,EAAC,CAEvB,IAAMC,CAAAA,CAAgB,GAEtB,IAAA,IAASC,CAAAA,CAAI,EAAGA,CAAAA,CAAIH,CAAAA,CAAI,OAAQG,CAAAA,EAAKF,CAAAA,CACnCC,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AA,CAAKE,CAAAA,EAASA,EAAK,MAAA,CAAO,CAAC,EAAE,WAAA,EAAY,CAAIA,EAAK,KAAA,CAAM,CAAC,CAAC,CAAA,CAC1D,IAAA,CAAK,GAAG,CAAA,CALM,EAMnB,CCPO,SAASC,CAAAA,CAAYH,EAAqB,CAC/C,OAAKA,EAEEA,CAAAA,CACJ,IAAA,GACA,OAAA,CAAQ,oBAAA,CAAsB,CAACI,CAAAA,CAAGC,CAAAA,GAAkBA,EAAOA,CAAAA,CAAK,WAAA,GAAgB,EAAG,CAAA,CACnF,QAAQ,MAAA,CAASC,CAAAA,EAAUA,CAAAA,CAAM,WAAA,EAAa,CAAA,CALhC,EAMnB,CCPO,SAASC,EAAYP,CAAAA,CAAqB,CAC/C,OAAKA,CAAAA,CAEEA,CAAAA,CACJ,MAAK,CACL,OAAA,CAAQ,qBAAsB,OAAO,CAAA,CACrC,QAAQ,SAAA,CAAW,GAAG,EACtB,WAAA,EAAY,CANE,EAOnB,CCRO,SAASQ,EAAaR,CAAAA,CAAqB,CAChD,OAAKA,CAAAA,CACEA,CAAAA,CACJ,MAAK,CACL,KAAA,CAAM,KAAK,CAAA,CACX,GAAA,CAAKE,GAASA,CAAAA,CAAK,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,EAAa,CAAA,CAC1C,IAAA,CAAK,GAAG,CAAA,CALM,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 * Tries to execute a promise and catches any errors that occur.\r\n *\r\n * @param promise - The promise to execute.\r\n * @returns A tuple containing either an error or the result.\r\n */\r\nexport async function tryCatch<T>(input: Promise<T>): Promise<TryCatchResult<T>>;\r\n\r\nexport async function tryCatch<T>(input: () => Promise<T>): Promise<TryCatchResult<T>>;\r\n\r\nexport async function tryCatch<T>(input: Promise<T> | (() => Promise<T>)): Promise<TryCatchResult<T>> {\r\n try {\r\n const result = typeof input === \"function\" ? await input() : await input;\r\n\r\n return [null, result];\r\n } catch (error) {\r\n return [error as Error, null];\r\n }\r\n}\r\n\r\nexport type TryCatchResult<T> = [Error | null, T | null];\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"]}
1
+ {"version":3,"sources":["../src/array/chunk.ts","../src/array/unique.ts","../src/array/uniqueBy.ts","../src/array/groupBy.ts","../src/array/difference.ts","../src/array/intersection.ts","../src/array/sortBy.ts","../src/function/debounce.ts","../src/function/tryCatch.ts","../src/object/isEmptyObject.ts","../src/object/pick.ts","../src/object/omit.ts","../src/object/get.ts","../src/object/merge.ts","../src/string/capitalize.ts","../src/string/capitalizeWords.ts","../src/string/toCamelCase.ts","../src/string/toKebabCase.ts","../src/string/initialWords.ts","../src/string/truncate.ts","../src/string/slugify.ts","../src/string/toSnakeCase.ts"],"names":["chunk","arr","size","result","i","unique","array","uniqueBy","key","seen","item","value","groupBy","acc","groupKey","difference","values","set","intersection","sortBy","selector","direction","a","b","aValue","bValue","debounce","fn","delay","timeout","args","tryCatch","input","error","isEmptyObject","obj","pick","keys","omit","get","path","defaultValue","merge","objects","capitalize","str","capitalizeWords","word","toCamelCase","_","char","match","toKebabCase","initialWords","truncate","maxLength","suffix","slugify","toSnakeCase"],"mappings":"aAmBO,SAASA,CAAAA,CAASC,CAAAA,CAAUC,CAAAA,CAAqB,CACtD,GAAIA,CAAAA,EAAQ,CAAA,CAAG,OAAO,EAAC,CAEvB,IAAMC,CAAAA,CAAgB,EAAC,CAEvB,IAAA,IAASC,CAAAA,CAA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AG4C,CAAS,CAAA,CAAE,OAAA,EAAQ,CAAIC,CAC/C,CCLO,SAASC,CAAAA,CAAQ9C,CAAAA,CAAuB,CAC7C,OAAOA,CAAAA,CACJ,WAAA,EAAY,CACZ,MAAK,CACL,SAAA,CAAU,KAAK,CAAA,CACf,OAAA,CAAQ,kBAAA,CAAoB,EAAE,CAAA,CAC9B,QAAQ,aAAA,CAAe,GAAG,CAAA,CAC1B,OAAA,CAAQ,UAAA,CAAY,EAAE,CAC3B,CCRO,SAAS+C,CAAAA,CAAYb,CAAAA,CAAqB,CAC/C,OAAKA,CAAAA,CAEEA,CAAAA,CACJ,IAAA,EAAK,CACL,QAAQ,oBAAA,CAAsB,OAAO,CAAA,CACrC,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 * Computes the difference between two arrays.\r\n * @param array The original array.\r\n * @param values The array of values to exclude from the original array.\r\n * @returns A new array containing the values from the original array that are not in the values array.\r\n */\r\nexport function difference<T>(array: T[], values: T[]): T[] {\r\n const set = new Set(values);\r\n return array.filter((item) => !set.has(item));\r\n}\r\n","/**\r\n * Computes the intersection between two arrays.\r\n * @param array The original array.\r\n * @param values The array of values to include from the original array.\r\n * @returns A new array containing the values from the original array that are also in the values array.\r\n */\r\nexport function intersection<T>(array: T[], values: T[]): T[] {\r\n const set = new Set(values);\r\n return array.filter((item) => set.has(item));\r\n}\r\n","/**\r\n * Sorts an array of objects by a specified property.\r\n * @param array The array to sort.\r\n * @param selector A function that selects the property to sort by.\r\n * @returns A new array sorted by the specified property.\r\n */\r\nexport function sortBy<T>(array: T[], selector: (item: T) => string | number, direction: \"asc\" | \"desc\" = \"asc\"): T[] {\r\n return [...array].sort((a, b) => {\r\n const aValue = selector(a);\r\n const bValue = selector(b);\r\n\r\n if (aValue < bValue) return direction === \"asc\" ? -1 : 1;\r\n if (aValue > bValue) return direction === \"asc\" ? 1 : -1;\r\n return 0;\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 * Tries to execute a promise and catches any errors that occur.\r\n *\r\n * @param promise - The promise to execute.\r\n * @returns A tuple containing either an error or the result.\r\n */\r\nexport async function tryCatch<T>(input: Promise<T>): Promise<TryCatchResult<T>>;\r\n\r\nexport async function tryCatch<T>(input: () => Promise<T>): Promise<TryCatchResult<T>>;\r\n\r\nexport async function tryCatch<T>(input: Promise<T> | (() => Promise<T>)): Promise<TryCatchResult<T>> {\r\n try {\r\n const result = typeof input === \"function\" ? await input() : await input;\r\n\r\n return [null, result];\r\n } catch (error) {\r\n return [error as Error, null];\r\n }\r\n}\r\n\r\nexport type TryCatchResult<T> = [Error | null, T | null];\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 * Merges multiple objects into one.\r\n * @param objects The objects to merge.\r\n * @returns A new object containing the merged properties.\r\n */\r\nexport function merge<T extends object[]>(...objects: T): UnionToIntersection<T[number]> {\r\n return objects.reduce((acc, obj) => {\r\n return { ...acc, ...obj };\r\n }, {}) as any;\r\n}\r\n\r\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;\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","/**\r\n * Convert a long string to truncate string.\r\n *\r\n * @param value - The input string.\r\n * @param maxLength - Length on string to truncate\r\n * @param suffix - The string to append at the end of the truncated string\r\n * @returns The input string converted to truncate string.\r\n */\r\nexport function truncate(value: string, maxLength: number, suffix = \"...\"): string {\r\n if (value.length <= maxLength) return value;\r\n return value.slice(0, maxLength).trimEnd() + suffix;\r\n}\r\n","/**\r\n * Convert a string to a URL-friendly slug.\r\n *\r\n * @param value - The input string.\r\n * @returns The slugified string.\r\n */\r\nexport function slugify(value: string): string {\r\n return value\r\n .toLowerCase()\r\n .trim()\r\n .normalize(\"NFD\")\r\n .replace(/[\\u0300-\\u036f]/g, \"\")\r\n .replace(/[^a-z0-9]+/g, \"-\")\r\n .replace(/^-+|-+$/g, \"\");\r\n}\r\n","/**\r\n * Convert a string to snake case.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string converted to snake case.\r\n */\r\nexport function toSnakeCase(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
@@ -75,6 +75,30 @@ declare function uniqueBy<T, K extends keyof T>(array: readonly T[], key: K): T[
75
75
  */
76
76
  declare function groupBy<T, K extends keyof T>(array: readonly T[], key: K): Record<string, T[]>;
77
77
 
78
+ /**
79
+ * Computes the difference between two arrays.
80
+ * @param array The original array.
81
+ * @param values The array of values to exclude from the original array.
82
+ * @returns A new array containing the values from the original array that are not in the values array.
83
+ */
84
+ declare function difference<T>(array: T[], values: T[]): T[];
85
+
86
+ /**
87
+ * Computes the intersection between two arrays.
88
+ * @param array The original array.
89
+ * @param values The array of values to include from the original array.
90
+ * @returns A new array containing the values from the original array that are also in the values array.
91
+ */
92
+ declare function intersection<T>(array: T[], values: T[]): T[];
93
+
94
+ /**
95
+ * Sorts an array of objects by a specified property.
96
+ * @param array The array to sort.
97
+ * @param selector A function that selects the property to sort by.
98
+ * @returns A new array sorted by the specified property.
99
+ */
100
+ declare function sortBy<T>(array: T[], selector: (item: T) => string | number, direction?: "asc" | "desc"): T[];
101
+
78
102
  /**
79
103
  * Debounce a function.
80
104
  *
@@ -130,6 +154,14 @@ declare function omit<T, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T,
130
154
  */
131
155
  declare function get(obj: any, path: string, defaultValue?: any): any;
132
156
 
157
+ /**
158
+ * Merges multiple objects into one.
159
+ * @param objects The objects to merge.
160
+ * @returns A new object containing the merged properties.
161
+ */
162
+ declare function merge<T extends object[]>(...objects: T): UnionToIntersection<T[number]>;
163
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
164
+
133
165
  /**
134
166
  * Capitalize the first letter of a string.
135
167
  *
@@ -170,4 +202,30 @@ declare function toKebabCase(str: string): string;
170
202
  */
171
203
  declare function initialWords(str: string): string;
172
204
 
173
- export { type TryCatchResult, capitalize, capitalizeWords, chunk, debounce, get, groupBy, initialWords, isEmptyObject, omit, pick, toCamelCase, toKebabCase, tryCatch, unique, uniqueBy };
205
+ /**
206
+ * Convert a long string to truncate string.
207
+ *
208
+ * @param value - The input string.
209
+ * @param maxLength - Length on string to truncate
210
+ * @param suffix - The string to append at the end of the truncated string
211
+ * @returns The input string converted to truncate string.
212
+ */
213
+ declare function truncate(value: string, maxLength: number, suffix?: string): string;
214
+
215
+ /**
216
+ * Convert a string to a URL-friendly slug.
217
+ *
218
+ * @param value - The input string.
219
+ * @returns The slugified string.
220
+ */
221
+ declare function slugify(value: string): string;
222
+
223
+ /**
224
+ * Convert a string to snake case.
225
+ *
226
+ * @param str - The input string.
227
+ * @returns The input string converted to snake case.
228
+ */
229
+ declare function toSnakeCase(str: string): string;
230
+
231
+ export { type TryCatchResult, capitalize, capitalizeWords, chunk, debounce, difference, get, groupBy, initialWords, intersection, isEmptyObject, merge, omit, pick, slugify, sortBy, toCamelCase, toKebabCase, toSnakeCase, truncate, tryCatch, unique, uniqueBy };
package/dist/index.d.ts CHANGED
@@ -75,6 +75,30 @@ declare function uniqueBy<T, K extends keyof T>(array: readonly T[], key: K): T[
75
75
  */
76
76
  declare function groupBy<T, K extends keyof T>(array: readonly T[], key: K): Record<string, T[]>;
77
77
 
78
+ /**
79
+ * Computes the difference between two arrays.
80
+ * @param array The original array.
81
+ * @param values The array of values to exclude from the original array.
82
+ * @returns A new array containing the values from the original array that are not in the values array.
83
+ */
84
+ declare function difference<T>(array: T[], values: T[]): T[];
85
+
86
+ /**
87
+ * Computes the intersection between two arrays.
88
+ * @param array The original array.
89
+ * @param values The array of values to include from the original array.
90
+ * @returns A new array containing the values from the original array that are also in the values array.
91
+ */
92
+ declare function intersection<T>(array: T[], values: T[]): T[];
93
+
94
+ /**
95
+ * Sorts an array of objects by a specified property.
96
+ * @param array The array to sort.
97
+ * @param selector A function that selects the property to sort by.
98
+ * @returns A new array sorted by the specified property.
99
+ */
100
+ declare function sortBy<T>(array: T[], selector: (item: T) => string | number, direction?: "asc" | "desc"): T[];
101
+
78
102
  /**
79
103
  * Debounce a function.
80
104
  *
@@ -130,6 +154,14 @@ declare function omit<T, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T,
130
154
  */
131
155
  declare function get(obj: any, path: string, defaultValue?: any): any;
132
156
 
157
+ /**
158
+ * Merges multiple objects into one.
159
+ * @param objects The objects to merge.
160
+ * @returns A new object containing the merged properties.
161
+ */
162
+ declare function merge<T extends object[]>(...objects: T): UnionToIntersection<T[number]>;
163
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
164
+
133
165
  /**
134
166
  * Capitalize the first letter of a string.
135
167
  *
@@ -170,4 +202,30 @@ declare function toKebabCase(str: string): string;
170
202
  */
171
203
  declare function initialWords(str: string): string;
172
204
 
173
- export { type TryCatchResult, capitalize, capitalizeWords, chunk, debounce, get, groupBy, initialWords, isEmptyObject, omit, pick, toCamelCase, toKebabCase, tryCatch, unique, uniqueBy };
205
+ /**
206
+ * Convert a long string to truncate string.
207
+ *
208
+ * @param value - The input string.
209
+ * @param maxLength - Length on string to truncate
210
+ * @param suffix - The string to append at the end of the truncated string
211
+ * @returns The input string converted to truncate string.
212
+ */
213
+ declare function truncate(value: string, maxLength: number, suffix?: string): string;
214
+
215
+ /**
216
+ * Convert a string to a URL-friendly slug.
217
+ *
218
+ * @param value - The input string.
219
+ * @returns The slugified string.
220
+ */
221
+ declare function slugify(value: string): string;
222
+
223
+ /**
224
+ * Convert a string to snake case.
225
+ *
226
+ * @param str - The input string.
227
+ * @returns The input string converted to snake case.
228
+ */
229
+ declare function toSnakeCase(str: string): string;
230
+
231
+ export { type TryCatchResult, capitalize, capitalizeWords, chunk, debounce, difference, get, groupBy, initialWords, intersection, isEmptyObject, merge, omit, pick, slugify, sortBy, toCamelCase, toKebabCase, toSnakeCase, truncate, tryCatch, unique, uniqueBy };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function u(e,t){if(t<=0)return [];let r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function c(e){return [...new Set(e)]}function p(e,t){let r=new Set;return e.filter(n=>{let o=n[t];return r.has(o)?false:(r.add(o),true)})}function f(e,t){return e.reduce((r,n)=>{let o=String(n[t]);return r[o]||(r[o]=[]),r[o].push(n),r},{})}function y(e,t){let r;return function(...n){clearTimeout(r),r=setTimeout(()=>{e(...n);},t);}}async function m(e){try{return [null,typeof e=="function"?await e():await e]}catch(t){return [t,null]}}function d(e){return Object.keys(e).length===0}function C(e,t){let r={};for(let n of t)n in e&&(r[n]=e[n]);return r}function k(e,t){let r={...e};for(let n of t)delete r[n];return r}function b(e,t,r){let n=t.split("."),o=e;for(let i of n){if(o==null)return r;o=o[i];}return o===void 0?r:o}function w(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function j(e){return e?e.trim().split(/\s+/).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" "):""}function E(e){return e?e.trim().replace(/[^a-zA-Z0-9]+(.)?/g,(t,r)=>r?r.toUpperCase():"").replace(/^(.)/,t=>t.toLowerCase()):""}function S(e){return e?e.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase():""}function v(e){return e?e.trim().split(/\s+/).map(t=>t.charAt(0).toUpperCase()).join(" "):""}export{w as capitalize,j as capitalizeWords,u as chunk,y as debounce,b as get,f as groupBy,v as initialWords,d as isEmptyObject,k as omit,C as pick,E as toCamelCase,S as toKebabCase,m as tryCatch,c as unique,p as uniqueBy};//# sourceMappingURL=index.js.map
1
+ function u(e,t){if(t<=0)return [];let r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function a(e){return [...new Set(e)]}function T(e,t){let r=new Set;return e.filter(n=>{let o=n[t];return r.has(o)?false:(r.add(o),true)})}function l(e,t){return e.reduce((r,n)=>{let o=String(n[t]);return r[o]||(r[o]=[]),r[o].push(n),r},{})}function g(e,t){let r=new Set(t);return e.filter(n=>!r.has(n))}function m(e,t){let r=new Set(t);return e.filter(n=>r.has(n))}function C(e,t,r="asc"){return [...e].sort((n,o)=>{let i=t(n),s=t(o);return i<s?r==="asc"?-1:1:i>s?r==="asc"?1:-1:0})}function k(e,t){let r;return function(...n){clearTimeout(r),r=setTimeout(()=>{e(...n);},t);}}async function b(e){try{return [null,typeof e=="function"?await e():await e]}catch(t){return [t,null]}}function w(e){return Object.keys(e).length===0}function R(e,t){let r={};for(let n of t)n in e&&(r[n]=e[n]);return r}function S(e,t){let r={...e};for(let n of t)delete r[n];return r}function z(e,t,r){let n=t.split("."),o=e;for(let i of n){if(o==null)return r;o=o[i];}return o===void 0?r:o}function $(...e){return e.reduce((t,r)=>({...t,...r}),{})}function E(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function B(e){return e?e.trim().split(/\s+/).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" "):""}function O(e){return e?e.trim().replace(/[^a-zA-Z0-9]+(.)?/g,(t,r)=>r?r.toUpperCase():"").replace(/^(.)/,t=>t.toLowerCase()):""}function q(e){return e?e.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase():""}function D(e){return e?e.trim().split(/\s+/).map(t=>t.charAt(0).toUpperCase()).join(" "):""}function N(e,t,r="..."){return e.length<=t?e:e.slice(0,t).trimEnd()+r}function G(e){return e.toLowerCase().trim().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function J(e){return e?e.trim().replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/[_\s]+/g,"_").toLowerCase():""}export{E as capitalize,B as capitalizeWords,u as chunk,k as debounce,g as difference,z as get,l as groupBy,D as initialWords,m as intersection,w as isEmptyObject,$ as merge,S as omit,R as pick,G as slugify,C as sortBy,O as toCamelCase,q as toKebabCase,J as toSnakeCase,N as truncate,b as tryCatch,a as unique,T 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/function/tryCatch.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","tryCatch","input","error","isEmptyObject","obj","pick","keys","omit","get","path","defaultValue","capitalize","str","capitalizeWords","word","toCamelCase","_","char","match","toKebabCase","initialWords"],"mappings":"AAmBO,SAASA,CAAAA,CAASC,EAAUC,CAAAA,CAAqB,CACtD,GAAIA,CAAAA,EAAQ,CAAA,CAAG,OAAO,EAAC,CAEvB,IAAMC,CAAAA,CAAgB,GAEtB,IAAA,IAASC,CAAAA,CAAI,EAAGA,CAAAA,CAAIH,CAAAA,CAAI,OAAQG,CAAAA,EAAKF,CAAAA,CACnCC,EAAO,IAAA,CAAKF,CAAAA,CAAI,MAAMG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AO,CAAC,EAAE,WAAA,EAAY,CAAIA,EAAK,KAAA,CAAM,CAAC,CAAC,CAAA,CAC1D,IAAA,CAAK,GAAG,CAAA,CALM,EAMnB,CCPO,SAASC,CAAAA,CAAYH,EAAqB,CAC/C,OAAKA,EAEEA,CAAAA,CACJ,IAAA,GACA,OAAA,CAAQ,oBAAA,CAAsB,CAACI,CAAAA,CAAGC,CAAAA,GAAkBA,EAAOA,CAAAA,CAAK,WAAA,GAAgB,EAAG,CAAA,CACnF,QAAQ,MAAA,CAASC,CAAAA,EAAUA,CAAAA,CAAM,WAAA,EAAa,CAAA,CALhC,EAMnB,CCPO,SAASC,EAAYP,CAAAA,CAAqB,CAC/C,OAAKA,CAAAA,CAEEA,CAAAA,CACJ,MAAK,CACL,OAAA,CAAQ,qBAAsB,OAAO,CAAA,CACrC,QAAQ,SAAA,CAAW,GAAG,EACtB,WAAA,EAAY,CANE,EAOnB,CCRO,SAASQ,EAAaR,CAAAA,CAAqB,CAChD,OAAKA,CAAAA,CACEA,CAAAA,CACJ,MAAK,CACL,KAAA,CAAM,KAAK,CAAA,CACX,GAAA,CAAKE,GAASA,CAAAA,CAAK,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,EAAa,CAAA,CAC1C,IAAA,CAAK,GAAG,CAAA,CALM,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 * Tries to execute a promise and catches any errors that occur.\r\n *\r\n * @param promise - The promise to execute.\r\n * @returns A tuple containing either an error or the result.\r\n */\r\nexport async function tryCatch<T>(input: Promise<T>): Promise<TryCatchResult<T>>;\r\n\r\nexport async function tryCatch<T>(input: () => Promise<T>): Promise<TryCatchResult<T>>;\r\n\r\nexport async function tryCatch<T>(input: Promise<T> | (() => Promise<T>)): Promise<TryCatchResult<T>> {\r\n try {\r\n const result = typeof input === \"function\" ? await input() : await input;\r\n\r\n return [null, result];\r\n } catch (error) {\r\n return [error as Error, null];\r\n }\r\n}\r\n\r\nexport type TryCatchResult<T> = [Error | null, T | null];\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"]}
1
+ {"version":3,"sources":["../src/array/chunk.ts","../src/array/unique.ts","../src/array/uniqueBy.ts","../src/array/groupBy.ts","../src/array/difference.ts","../src/array/intersection.ts","../src/array/sortBy.ts","../src/function/debounce.ts","../src/function/tryCatch.ts","../src/object/isEmptyObject.ts","../src/object/pick.ts","../src/object/omit.ts","../src/object/get.ts","../src/object/merge.ts","../src/string/capitalize.ts","../src/string/capitalizeWords.ts","../src/string/toCamelCase.ts","../src/string/toKebabCase.ts","../src/string/initialWords.ts","../src/string/truncate.ts","../src/string/slugify.ts","../src/string/toSnakeCase.ts"],"names":["chunk","arr","size","result","i","unique","array","uniqueBy","key","seen","item","value","groupBy","acc","groupKey","difference","values","set","intersection","sortBy","selector","direction","a","b","aValue","bValue","debounce","fn","delay","timeout","args","tryCatch","input","error","isEmptyObject","obj","pick","keys","omit","get","path","defaultValue","merge","objects","capitalize","str","capitalizeWords","word","toCamelCase","_","char","match","toKebabCase","initialWords","truncate","maxLength","suffix","slugify","toSnakeCase"],"mappings":"AAmBO,SAASA,CAAAA,CAASC,CAAAA,CAAUC,CAAAA,CAAqB,CACtD,GAAIA,CAAAA,EAAQ,CAAA,CAAG,OAAO,EAAC,CAEvB,IAAMC,CAAAA,CAAgB,EAAC,CAEvB,IAAA,IAASC,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAIH,CAAAA,CAA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IC,CAC/C,CCLO,SAASC,CAAAA,CAAQ9C,CAAAA,CAAuB,CAC7C,OAAOA,CAAAA,CACJ,WAAA,EAAY,CACZ,MAAK,CACL,SAAA,CAAU,KAAK,CAAA,CACf,OAAA,CAAQ,kBAAA,CAAoB,EAAE,CAAA,CAC9B,QAAQ,aAAA,CAAe,GAAG,CAAA,CAC1B,OAAA,CAAQ,UAAA,CAAY,EAAE,CAC3B,CCRO,SAAS+C,CAAAA,CAAYb,CAAAA,CAAqB,CAC/C,OAAKA,CAAAA,CAEEA,CAAAA,CACJ,IAAA,EAAK,CACL,QAAQ,oBAAA,CAAsB,OAAO,CAAA,CACrC,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 * Computes the difference between two arrays.\r\n * @param array The original array.\r\n * @param values The array of values to exclude from the original array.\r\n * @returns A new array containing the values from the original array that are not in the values array.\r\n */\r\nexport function difference<T>(array: T[], values: T[]): T[] {\r\n const set = new Set(values);\r\n return array.filter((item) => !set.has(item));\r\n}\r\n","/**\r\n * Computes the intersection between two arrays.\r\n * @param array The original array.\r\n * @param values The array of values to include from the original array.\r\n * @returns A new array containing the values from the original array that are also in the values array.\r\n */\r\nexport function intersection<T>(array: T[], values: T[]): T[] {\r\n const set = new Set(values);\r\n return array.filter((item) => set.has(item));\r\n}\r\n","/**\r\n * Sorts an array of objects by a specified property.\r\n * @param array The array to sort.\r\n * @param selector A function that selects the property to sort by.\r\n * @returns A new array sorted by the specified property.\r\n */\r\nexport function sortBy<T>(array: T[], selector: (item: T) => string | number, direction: \"asc\" | \"desc\" = \"asc\"): T[] {\r\n return [...array].sort((a, b) => {\r\n const aValue = selector(a);\r\n const bValue = selector(b);\r\n\r\n if (aValue < bValue) return direction === \"asc\" ? -1 : 1;\r\n if (aValue > bValue) return direction === \"asc\" ? 1 : -1;\r\n return 0;\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 * Tries to execute a promise and catches any errors that occur.\r\n *\r\n * @param promise - The promise to execute.\r\n * @returns A tuple containing either an error or the result.\r\n */\r\nexport async function tryCatch<T>(input: Promise<T>): Promise<TryCatchResult<T>>;\r\n\r\nexport async function tryCatch<T>(input: () => Promise<T>): Promise<TryCatchResult<T>>;\r\n\r\nexport async function tryCatch<T>(input: Promise<T> | (() => Promise<T>)): Promise<TryCatchResult<T>> {\r\n try {\r\n const result = typeof input === \"function\" ? await input() : await input;\r\n\r\n return [null, result];\r\n } catch (error) {\r\n return [error as Error, null];\r\n }\r\n}\r\n\r\nexport type TryCatchResult<T> = [Error | null, T | null];\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 * Merges multiple objects into one.\r\n * @param objects The objects to merge.\r\n * @returns A new object containing the merged properties.\r\n */\r\nexport function merge<T extends object[]>(...objects: T): UnionToIntersection<T[number]> {\r\n return objects.reduce((acc, obj) => {\r\n return { ...acc, ...obj };\r\n }, {}) as any;\r\n}\r\n\r\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;\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","/**\r\n * Convert a long string to truncate string.\r\n *\r\n * @param value - The input string.\r\n * @param maxLength - Length on string to truncate\r\n * @param suffix - The string to append at the end of the truncated string\r\n * @returns The input string converted to truncate string.\r\n */\r\nexport function truncate(value: string, maxLength: number, suffix = \"...\"): string {\r\n if (value.length <= maxLength) return value;\r\n return value.slice(0, maxLength).trimEnd() + suffix;\r\n}\r\n","/**\r\n * Convert a string to a URL-friendly slug.\r\n *\r\n * @param value - The input string.\r\n * @returns The slugified string.\r\n */\r\nexport function slugify(value: string): string {\r\n return value\r\n .toLowerCase()\r\n .trim()\r\n .normalize(\"NFD\")\r\n .replace(/[\\u0300-\\u036f]/g, \"\")\r\n .replace(/[^a-z0-9]+/g, \"-\")\r\n .replace(/^-+|-+$/g, \"\");\r\n}\r\n","/**\r\n * Convert a string to snake case.\r\n *\r\n * @param str - The input string.\r\n * @returns The input string converted to snake case.\r\n */\r\nexport function toSnakeCase(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
@@ -1,123 +1,127 @@
1
- {
2
- "name": "@titocandradev/neatcore",
3
- "version": "0.3.3",
4
- "private": false,
5
- "description": "A clean, zero-dependency, TypeScript-first utility core.",
6
- "homepage": "https://github.com/tcandra24/neat-core#readme",
7
- "bugs": {
8
- "url": "https://github.com/tcandra24/neat-core/issues"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/tcandra24/neat-core.git"
13
- },
14
- "license": "MIT",
15
- "author": "Tito Candra",
16
- "keywords": [
17
- "module",
18
- "util"
19
- ],
20
- "type": "module",
21
- "exports": {
22
- ".": {
23
- "import": "./dist/index.js",
24
- "require": "./dist/index.cjs"
25
- }
26
- },
27
- "main": "./dist/index.cjs",
28
- "types": "./dist/index.d.ts",
29
- "directories": {
30
- "test": "tests"
31
- },
32
- "files": [
33
- "dist"
34
- ],
35
- "scripts": {
36
- "dev": "tsup --watch",
37
- "build": "tsup",
38
- "test": "vitest",
39
- "test:run": "vitest run",
40
- "coverage": "vitest run --coverage"
41
- },
42
- "dependencies": {
43
- "acorn": "^8.15.0",
44
- "any-promise": "^1.3.0",
45
- "assertion-error": "^2.0.1",
46
- "ast-v8-to-istanbul": "^0.3.11",
47
- "bundle-require": "^5.1.0",
48
- "cac": "^6.7.14",
49
- "chai": "^6.2.2",
50
- "chokidar": "^4.0.3",
51
- "commander": "^4.1.1",
52
- "confbox": "^0.1.8",
53
- "consola": "^3.4.2",
54
- "debug": "^4.4.3",
55
- "es-module-lexer": "^1.7.0",
56
- "esbuild": "^0.27.3",
57
- "estree-walker": "^3.0.3",
58
- "expect-type": "^1.3.0",
59
- "fdir": "^6.5.0",
60
- "fix-dts-default-cjs-exports": "^1.0.1",
61
- "has-flag": "^4.0.0",
62
- "html-escaper": "^2.0.2",
63
- "istanbul-lib-coverage": "^3.2.2",
64
- "istanbul-lib-report": "^3.0.1",
65
- "istanbul-reports": "^3.2.0",
66
- "joycon": "^3.1.1",
67
- "js-tokens": "^10.0.0",
68
- "lilconfig": "^3.1.3",
69
- "lines-and-columns": "^1.2.4",
70
- "load-tsconfig": "^0.2.5",
71
- "magic-string": "^0.30.21",
72
- "magicast": "^0.5.2",
73
- "make-dir": "^4.0.0",
74
- "mlly": "^1.8.0",
75
- "ms": "^2.1.3",
76
- "mz": "^2.7.0",
77
- "nanoid": "^3.3.11",
78
- "object-assign": "^4.1.1",
79
- "obug": "^2.1.1",
80
- "pathe": "^2.0.3",
81
- "picocolors": "^1.1.1",
82
- "picomatch": "^4.0.3",
83
- "pirates": "^4.0.7",
84
- "pkg-types": "^1.3.1",
85
- "postcss": "^8.5.6",
86
- "postcss-load-config": "^6.0.1",
87
- "readdirp": "^4.1.2",
88
- "resolve-from": "^5.0.0",
89
- "rollup": "^4.57.1",
90
- "semver": "^7.7.4",
91
- "siginfo": "^2.0.0",
92
- "source-map": "^0.7.6",
93
- "source-map-js": "^1.2.1",
94
- "stackback": "^0.0.2",
95
- "std-env": "^3.10.0",
96
- "sucrase": "^3.35.1",
97
- "supports-color": "^7.2.0",
98
- "thenify": "^3.3.1",
99
- "thenify-all": "^1.6.0",
100
- "tinybench": "^2.9.0",
101
- "tinyexec": "^0.3.2",
102
- "tinyglobby": "^0.2.15",
103
- "tinyrainbow": "^3.0.3",
104
- "tree-kill": "^1.2.2",
105
- "ts-interface-checker": "^0.1.13",
106
- "ufo": "^1.6.3",
107
- "undici-types": "^7.16.0",
108
- "vite": "^7.3.1",
109
- "why-is-node-running": "^2.3.0"
110
- },
111
- "devDependencies": {
112
- "@types/node": "^25.2.3",
113
- "@vitest/coverage-v8": "^4.0.18",
114
- "tsup": "^8.5.1",
115
- "typescript": "^5.9.3",
116
- "vitest": "^4.0.18"
117
- },
118
- "publishConfig": {
119
- "access": "public"
120
- },
121
- "sideEffects": false,
122
- "module": "./dist/index.js"
123
- }
1
+ {
2
+ "name": "@titocandradev/neatcore",
3
+ "version": "0.4.1",
4
+ "private": false,
5
+ "description": "A clean, zero-dependency, TypeScript-first utility core.",
6
+ "homepage": "https://tcandra24.github.io/neat-core/",
7
+ "bugs": {
8
+ "url": "https://github.com/tcandra24/neat-core/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/tcandra24/neat-core.git"
13
+ },
14
+ "license": "MIT",
15
+ "author": "Tito Candra",
16
+ "keywords": [
17
+ "module",
18
+ "util"
19
+ ],
20
+ "type": "module",
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.cjs"
25
+ }
26
+ },
27
+ "main": "./dist/index.cjs",
28
+ "types": "./dist/index.d.ts",
29
+ "directories": {
30
+ "test": "tests"
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "scripts": {
36
+ "dev": "tsup --watch",
37
+ "build": "tsup",
38
+ "test": "vitest",
39
+ "test:run": "vitest run",
40
+ "coverage": "vitest run --coverage",
41
+ "docs:dev": "vitepress dev docs",
42
+ "docs:build": "vitepress build docs",
43
+ "docs:preview": "vitepress preview docs"
44
+ },
45
+ "dependencies": {
46
+ "acorn": "^8.15.0",
47
+ "any-promise": "^1.3.0",
48
+ "assertion-error": "^2.0.1",
49
+ "ast-v8-to-istanbul": "^0.3.11",
50
+ "bundle-require": "^5.1.0",
51
+ "cac": "^6.7.14",
52
+ "chai": "^6.2.2",
53
+ "chokidar": "^4.0.3",
54
+ "commander": "^4.1.1",
55
+ "confbox": "^0.1.8",
56
+ "consola": "^3.4.2",
57
+ "debug": "^4.4.3",
58
+ "es-module-lexer": "^1.7.0",
59
+ "esbuild": "^0.27.3",
60
+ "estree-walker": "^3.0.3",
61
+ "expect-type": "^1.3.0",
62
+ "fdir": "^6.5.0",
63
+ "fix-dts-default-cjs-exports": "^1.0.1",
64
+ "has-flag": "^4.0.0",
65
+ "html-escaper": "^2.0.2",
66
+ "istanbul-lib-coverage": "^3.2.2",
67
+ "istanbul-lib-report": "^3.0.1",
68
+ "istanbul-reports": "^3.2.0",
69
+ "joycon": "^3.1.1",
70
+ "js-tokens": "^10.0.0",
71
+ "lilconfig": "^3.1.3",
72
+ "lines-and-columns": "^1.2.4",
73
+ "load-tsconfig": "^0.2.5",
74
+ "magic-string": "^0.30.21",
75
+ "magicast": "^0.5.2",
76
+ "make-dir": "^4.0.0",
77
+ "mlly": "^1.8.0",
78
+ "ms": "^2.1.3",
79
+ "mz": "^2.7.0",
80
+ "nanoid": "^3.3.11",
81
+ "object-assign": "^4.1.1",
82
+ "obug": "^2.1.1",
83
+ "pathe": "^2.0.3",
84
+ "picocolors": "^1.1.1",
85
+ "picomatch": "^4.0.3",
86
+ "pirates": "^4.0.7",
87
+ "pkg-types": "^1.3.1",
88
+ "postcss": "^8.5.6",
89
+ "postcss-load-config": "^6.0.1",
90
+ "readdirp": "^4.1.2",
91
+ "resolve-from": "^5.0.0",
92
+ "rollup": "^4.57.1",
93
+ "semver": "^7.7.4",
94
+ "siginfo": "^2.0.0",
95
+ "source-map": "^0.7.6",
96
+ "source-map-js": "^1.2.1",
97
+ "stackback": "^0.0.2",
98
+ "std-env": "^3.10.0",
99
+ "sucrase": "^3.35.1",
100
+ "supports-color": "^7.2.0",
101
+ "thenify": "^3.3.1",
102
+ "thenify-all": "^1.6.0",
103
+ "tinybench": "^2.9.0",
104
+ "tinyexec": "^0.3.2",
105
+ "tinyglobby": "^0.2.15",
106
+ "tinyrainbow": "^3.0.3",
107
+ "tree-kill": "^1.2.2",
108
+ "ts-interface-checker": "^0.1.13",
109
+ "ufo": "^1.6.3",
110
+ "undici-types": "^7.16.0",
111
+ "vite": "^7.3.1",
112
+ "why-is-node-running": "^2.3.0"
113
+ },
114
+ "devDependencies": {
115
+ "@types/node": "^25.2.3",
116
+ "@vitest/coverage-v8": "^4.0.18",
117
+ "tsup": "^8.5.1",
118
+ "typescript": "^5.9.3",
119
+ "vitepress": "^2.0.0-alpha.16",
120
+ "vitest": "^4.0.18"
121
+ },
122
+ "publishConfig": {
123
+ "access": "public"
124
+ },
125
+ "sideEffects": false,
126
+ "module": "./dist/index.js"
127
+ }