@h3ravel/support 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/index.cjs +245 -245
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -25
- package/dist/index.d.ts +25 -25
- package/dist/index.js +231 -231
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/Helpers/Arr.ts","../src/Helpers/Number.ts","../src/Helpers/Obj.ts","../src/Helpers/Str.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './Contracts/ObjContract';\nexport * from './Contracts/StrContract';\nexport * from './Helpers/Arr';\nexport * from './Helpers/Number';\nexport * from './Helpers/Obj';\nexport * from './Helpers/Str';\n","/**\n * Splits an array into chunks of a specified size.\n *\n * @template T - Type of elements in the array\n * @param arr - The input array\n * @param size - Size of each chunk (default: 2)\n * @returns An array of chunks (arrays)\n */\nexport const chunk = <T> (arr: T[], size: number = 2): T[][] => {\n if (size <= 0) throw new Error(\"Chunk size must be greater than 0\")\n\n const chunks: T[][] = []\n\n for (let i = 0; i < arr.length; i += size) {\n chunks.push(arr.slice(i, i + size))\n }\n\n return chunks\n}\n\n\n/**\n * Generates an array of sequential numbers.\n *\n * @param size - Number of elements in the range\n * @param startAt - Starting number (default: 0)\n * @returns An array of numbers from startAt to startAt + size - 1\n */\nexport const range = (size: number, startAt: number = 0): number[] => {\n if (size <= 0 || !Number.isFinite(size)) return []\n\n return Array.from({ length: size }, (_, i) => startAt + i)\n}\n","/**\n * Abbreviates large numbers using SI symbols (K, M, B...) \n * and formats the output according to the given locale.\n *\n * @param value - The number to abbreviate\n * @param locale - Optional locale string (default: \"en-US\")\n * @returns A localized, abbreviated number string\n */\nexport const abbreviate = (value?: number, locale: string = 'en-US'): string => {\n if (!value) return '0'\n\n // Numbers less than 1000 don't need abbreviation\n if (value < 1000) {\n return new Intl.NumberFormat(locale).format(value)\n }\n\n const si = [\n { v: 1e18, s: 'E' },\n { v: 1e15, s: 'P' },\n { v: 1e12, s: 'T' },\n { v: 1e9, s: 'B' },\n { v: 1e6, s: 'M' },\n { v: 1e3, s: 'K' },\n ]\n\n const match = si.find(scale => value >= scale.v)\n if (!match) return new Intl.NumberFormat(locale).format(value)\n\n const formatted = value / match.v\n\n return (\n new Intl.NumberFormat(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 2,\n }).format(formatted) + match.s\n )\n}\n\n/**\n * Concverts a number into human readable string\n *\n * @param num The number to convert\n * @param slugify convert the ouput into a slug using this as a separator\n * @returns\n */\nexport const humanize = (num: number, slugify?: '-' | '_'): string => {\n if (!num) {\n return ''\n }\n\n if (slugify === '-' || slugify === '_') {\n const h = humanize(num)\n return typeof h === 'string' ? h.replace(' ', slugify).toLowerCase() : h\n }\n\n const ones = [\n '',\n 'one',\n 'two',\n 'three',\n 'four',\n 'five',\n 'six',\n 'seven',\n 'eight',\n 'nine',\n 'ten',\n 'eleven',\n 'twelve',\n 'thirteen',\n 'fourteen',\n 'fifteen',\n 'sixteen',\n 'seventeen',\n 'eighteen',\n 'nineteen',\n ]\n const tens = [\n '',\n '',\n 'twenty',\n 'thirty',\n 'forty',\n 'fifty',\n 'sixty',\n 'seventy',\n 'eighty',\n 'ninety',\n ]\n\n const numString: string = num.toString()\n\n if (num < 0) throw new Error('Negative numbers are not supported.')\n\n if (num === 0) return 'zero'\n\n //the case of 1 - 20\n if (num < 20) {\n return ones[num] ?? ''\n }\n\n if (numString.length === 2) {\n return tens[numString[0] as unknown as number] + ' ' + ones[numString[1] as unknown as number]\n }\n\n //100 and more\n if (numString.length == 3) {\n if (numString[1] === '0' && numString[2] === '0')\n return ones[numString[0] as unknown as number] + ' hundred'\n else\n return (\n ones[numString[0] as unknown as number] +\n ' hundred and ' +\n humanize(+((numString[1] || '') + numString[2]), slugify)\n )\n }\n\n if (numString.length === 4) {\n const end = +((numString[1] || '') + numString[2] + numString[3])\n if (end === 0) return ones[numString[0] as unknown as number] + ' thousand'\n if (end < 100)\n return ones[numString[0] as unknown as number] + ' thousand and ' + humanize(end, slugify)\n return ones[numString[0] as unknown as number] + ' thousand ' + humanize(end, slugify)\n }\n\n return num as unknown as string\n}\n\n/**\n * Converts a number of bytes into a human-readable string.\n *\n * @param bytes - The size in bytes to convert\n * @param decimals - Number of decimal places to display (default: 2)\n * @param bits - If true, uses 1000-based (SI) units (B, KB, MB...); \n * otherwise uses 1024-based binary units (Bytes, KiB...)\n * @returns A formatted string with the appropriate unit\n */\nexport const toBytes = (\n bytes?: number,\n decimals: number = 2,\n bits: boolean = false\n): string => {\n if (!bytes || isNaN(bytes)) {\n return bits ? '0 B' : '0 Bytes'\n }\n\n const base = bits ? 1000 : 1024\n const dm = decimals < 0 ? 0 : decimals\n const sizes = bits\n ? ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] // SI units\n : ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] // Binary units\n\n const index = Math.floor(Math.log(bytes) / Math.log(base))\n\n const value = parseFloat((bytes / Math.pow(base, index)).toFixed(dm))\n return `${value} ${sizes[index]}`\n}\n\n/**\n * Formats a duration (in seconds) into a human-readable string.\n *\n * @param seconds - Duration in seconds\n * @param worded - If true, outputs worded format (e.g., \"1hr 2min 3sec\"),\n * otherwise HH:MM:SS (e.g., \"01:02:03\")\n * @returns A formatted time string\n */\nexport const toHumanTime = (\n seconds: number = 0,\n worded: boolean = false\n): string => {\n // Ensure seconds is a number and not negative\n if (isNaN(seconds) || seconds < 0) seconds = 0\n\n const hours = Math.floor(seconds / 3600)\n const minutes = Math.floor((seconds % 3600) / 60)\n const secs = Math.floor(seconds % 60)\n\n // Worded format → \"1hr 2min 3sec\"\n if (worded) {\n const parts = []\n if (hours) parts.push(`${hours}hr`)\n if (minutes) parts.push(`${minutes}min`)\n if (secs || (!hours && !minutes)) parts.push(`${secs}sec`)\n return parts.join(' ')\n }\n\n // HH:MM:SS format → zero-padded\n const hh = hours > 0 ? `${hours}:` : ''\n const mm = (hours > 0 && minutes < 10 ? `0${minutes}` : minutes) + ':'\n const ss = secs < 10 ? `0${secs}` : secs\n\n return `${hh}${mm}${ss}`\n}\n\n","import { DotFlatten, DotNestedKeys, DotNestedValue, KeysToSnakeCase } from \"../Contracts/ObjContract\"\n\n/**\n * Flattens a nested object into a single-level object\n * with dot-separated keys.\n *\n * Example:\n * doter({\n * user: { name: \"John\", address: { city: \"NY\" } },\n * active: true\n * })\n * \n * Output:\n * {\n * \"user.name\": \"John\",\n * \"user.address.city\": \"NY\",\n * \"active\": true\n * }\n *\n * @template T - The type of the input object\n * @param obj - The nested object to flatten\n * @returns A flattened object with dotted keys and inferred types\n */\nexport const dot = <T extends Record<string, any>> (obj: T): DotFlatten<T> => {\n const result = {} as Record<string, unknown>\n\n /**\n * Internal recursive function to traverse and flatten the object.\n * \n * @param o - Current object to flatten\n * @param prefix - Key path accumulated so far\n */\n const recurse = (o: Record<string, any>, prefix = ''): void => {\n for (const [key, value] of Object.entries(o)) {\n const newKey = prefix ? `${prefix}.${key}` : key\n\n /**\n * Recurse if the value is a plain object\n */\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n recurse(value, newKey)\n } else {\n /**\n * Otherwise, assign directly\n */\n result[newKey] = value\n }\n }\n }\n\n recurse(obj)\n return result as DotFlatten<T>\n}\n\n/**\n * Extracts a subset of properties from an object.\n *\n * @template T - Type of the source object\n * @template K - Keys of T to extract\n * @param obj - The source object\n * @param keys - Array of keys to extract\n * @returns A new object with only the specified keys\n */\nexport const extractProperties = <T extends object, K extends keyof T> (\n obj: T,\n keys: readonly K[] = []\n): Pick<T, K> => {\n return Object.fromEntries(\n keys.map(key => [key, obj[key]])\n ) as Pick<T, K>\n}\n\n/**\n * Safely retrieves a value from an object by key or nested keys.\n *\n * @template T - Type of the source object\n * @param key - Single key or tuple [parentKey, childKey]\n * @param item - The source object\n * @returns The found value as a string or the key itself if not found\n */\nexport const getValue = <\n T extends Record<string, any> // Allow nested objects\n> (\n key: string | [keyof T, keyof T[string]],\n item: T\n): string => {\n if (Array.isArray(key)) {\n const [parent, child] = key\n\n if (child !== undefined) {\n // Access nested property: item[parent][child]\n return (\n String(item?.[parent]?.[child] ??\n item?.[parent] ??\n `${String(parent)}.${String(child)}`)\n )\n }\n\n // Only top-level key\n return String(item?.[parent] ?? parent)\n }\n\n // Single key access\n return String(item?.[key] ?? key)\n}\n\n/**\n * Maps over an object's entries and returns a new object \n * with transformed keys and/or values.\n *\n * @template T - Type of the input object\n * @template R - Type of the new values\n * @param obj - The object to transform\n * @param callback - Function that receives [key, value] and returns [newKey, newValue]\n * @returns A new object with transformed entries\n */\nexport const modObj = <T extends object, R> (\n obj: T,\n callback: (entry: [keyof T & string, T[keyof T]]) => [string, R]\n): Record<string, R> => {\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) =>\n callback([key as keyof T & string, value as T[keyof T]])\n )\n ) as Record<string, R>\n}\n\n\nexport function safeDot<T extends Record<string, any>> (data: T): T\nexport function safeDot<\n T extends Record<string, any>,\n K extends DotNestedKeys<T>\n> (data: T, key?: K): DotNestedValue<T, K>\nexport function safeDot<\n T extends Record<string, any>,\n K extends DotNestedKeys<T>\n> (data: T, key?: K): any {\n if (!key) return data\n return key.split('.').reduce((acc: any, k) => acc?.[k], data)\n}\n\n/**\n * Sets a nested property on an object using dot notation.\n * \n * @example\n * const obj = {}\n * setNested(obj, 'app.user.name', 'Legacy')\n * console.log(obj)\n * // Output: { app: { user: { name: 'Legacy' } } }\n * \n * @param obj - The target object to modify.\n * @param key - The dot-separated key (e.g., 'app.user.name').\n * @param value - The value to set at the specified path.\n */\nexport const setNested = (\n obj: Record<string, any>,\n key: string,\n value: any\n): void => {\n if (!key.includes('.')) {\n obj[key] = value\n return\n }\n\n const parts = key.split('.')\n let current = obj\n\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i]\n\n /**\n * If we're at the last key, assign the value\n */\n if (i === parts.length - 1) {\n current[part] = value\n } else {\n /**\n * If the key doesn't exist or isn't an object, create it\n */\n if (typeof current[part] !== 'object' || current[part] === null) {\n current[part] = {}\n }\n current = current[part]\n }\n }\n}\n\n/**\n * Converts object keys to a slugified format (e.g., snake_case).\n *\n * @template T - Type of the input object\n * @param obj - The object whose keys will be slugified\n * @param only - Optional array of keys to slugify (others remain unchanged)\n * @param separator - Separator for slugified keys (default: \"_\")\n * @returns A new object with slugified keys\n */\nexport const slugifyKeys = <T extends object> (\n obj: T,\n only: string[] = [],\n separator: string = '_'\n): KeysToSnakeCase<T> => {\n const slugify = (key: string): string =>\n key\n .replace(/([a-z])([A-Z])/g, `$1${separator}$2`) // Handle camelCase\n .replace(/[\\s\\W]+/g, separator) // Replace spaces/symbols\n .replace(new RegExp(`${separator}{2,}`, 'g'), separator) // Remove duplicate separators\n .replace(new RegExp(`^${separator}|${separator}$`, 'g'), '') // Trim edges\n .toLowerCase()\n\n let entries = Object.entries(obj)\n\n // Filter if `only` is provided\n if (only.length) {\n entries = entries.filter(([key]) => only.includes(key))\n }\n\n return Object.fromEntries(\n entries.map(([key, value]) => [slugify(key), value])\n ) as KeysToSnakeCase<T>\n}\n","import { dot } from \"./Obj\"\n\n/**\n * Get the portion of the string after the first occurrence of the given value.\n * \n * @param value \n * @param search \n * @returns \n */\nexport const after = (value: string, search: string): string => {\n if (!search) return value\n const index = value.indexOf(search)\n return index !== -1 ? value.slice(index + search.length) : value\n}\n\n/**\n * Get the portion of the string after the last occurrence of the given value.\n * \n * @param value \n * @param search \n * @returns \n */\nexport const afterLast = (value: string, search: string): string => {\n if (!search) return value\n const lastIndex = value.lastIndexOf(search)\n return lastIndex !== -1 ? value.slice(lastIndex + search.length) : value\n}\n\n/**\n * Get the portion of the string before the first occurrence of the given value.\n * \n * @param value \n * @param search \n * @returns \n */\nexport const before = (value: string, search: string): string => {\n if (!search) return value\n const index = value.indexOf(search)\n return index !== -1 ? value.slice(0, index) : value\n}\n\n/**\n * Get the portion of the string before the last occurrence of the given value.\n * \n * @param value \n * @param search \n * @returns \n */\nexport const beforeLast = (value: string, search: string): string => {\n if (!search) return value\n const lastIndex = value.lastIndexOf(search)\n return lastIndex !== -1 ? value.slice(0, lastIndex) : value\n}\n\n/**\n * Capitalizes the first character of a string.\n *\n * @param str - The input string\n * @returns The string with the first character capitalized\n */\nexport function capitalize (str: string): string {\n if (!str) return '' // Handle empty or undefined strings safely\n return str[0].toUpperCase() + str.slice(1)\n}\n\n\n/**\n * Returns the pluralized form of a word based on the given number.\n *\n * @param word - The word to pluralize\n * @param count - The number determining pluralization\n * @returns Singular if count === 1, otherwise plural form\n */\nexport const pluralize = (word: string, count: number): string => {\n // If count is exactly 1 → singular\n if (count === 1) return word\n\n // Irregular plurals map\n const irregularPlurals: Record<string, string> = {\n foot: 'feet',\n child: 'children',\n mouse: 'mice',\n goose: 'geese',\n person: 'people',\n man: 'men',\n woman: 'women',\n }\n\n // Handle irregular cases first\n if (word in irregularPlurals) {\n return irregularPlurals[word]\n }\n\n // If word ends with consonant + \"y\" → replace \"y\" with \"ies\"\n if (\n word.endsWith('y') &&\n !['a', 'e', 'i', 'o', 'u'].includes(word[word.length - 2]?.toLowerCase() ?? '')\n ) {\n return word.slice(0, -1) + 'ies'\n }\n\n // If word ends in \"s\", \"ss\", \"sh\", \"ch\", \"x\", or \"z\" → add \"es\"\n if (/(s|ss|sh|ch|x|z)$/i.test(word)) {\n return word + 'es'\n }\n\n // Default: just add \"s\"\n return word + 's'\n}\n\n/**\n * Converts a plural English word into its singular form.\n *\n * @param word - The word to singularize\n * @returns The singular form of the word\n */\nexport const singularize = (word: string): string => {\n // Irregular plurals map (reverse of pluralize)\n const irregulars: Record<string, string> = {\n feet: 'foot',\n children: 'child',\n mice: 'mouse',\n geese: 'goose',\n people: 'person',\n men: 'man',\n women: 'woman',\n }\n\n // Handle irregular cases\n if (word in irregulars) return irregulars[word]\n\n // Words ending in \"ies\" → change to \"y\" (e.g., \"bodies\" → \"body\")\n if (/ies$/i.test(word) && word.length > 3) {\n return word.replace(/ies$/i, 'y')\n }\n\n // Words ending in \"es\" after certain consonants → remove \"es\"\n if (/(ches|shes|sses|xes|zes)$/i.test(word)) {\n return word.replace(/es$/i, '')\n }\n\n // Generic case: remove trailing \"s\"\n if (/s$/i.test(word) && word.length > 1) {\n return word.replace(/s$/i, '')\n }\n\n return word\n}\n\n/**\n * Converts a string into a slug format.\n * Handles camelCase, spaces, and non-alphanumeric characters.\n *\n * @param str - The input string to slugify\n * @param joiner - The character used to join words (default: \"_\")\n * @returns A slugified string\n */\nexport const slugify = (str: string, joiner = '_'): string => {\n return str\n // Handle camelCase by adding joiner between lowercase → uppercase\n .replace(/([a-z])([A-Z])/g, `$1${joiner}$2`)\n // Replace spaces and non-alphanumeric characters with joiner\n .replace(/[\\s\\W]+/g, joiner)\n // Remove duplicate joiners\n .replace(new RegExp(`${joiner}{2,}`, 'g'), joiner)\n // Trim joiners from start/end\n .replace(new RegExp(`^${joiner}|${joiner}$`, 'g'), '')\n .toLowerCase()\n}\n\n/**\n * Truncates a string to a specified length and appends an ellipsis if needed.\n *\n * @param str - The input string\n * @param len - Maximum length of the result (including ellipsis)\n * @param ellipsis - String to append if truncated (default: \"...\")\n * @returns The truncated string\n */\nexport const subString = (\n str: string,\n len: number,\n ellipsis: string = '...'\n): string => {\n if (!str) return ''\n if (len <= ellipsis.length) return ellipsis // Avoid negative slicing\n\n return str.length > len\n ? str.substring(0, len - ellipsis.length).trimEnd() + ellipsis\n : str\n}\n\n/**\n * Replaces placeholders in a string with corresponding values from a data object.\n * \n * Example:\n * substitute(\"Hello { user.name }!\", { user: { name: \"John\" } })\n * // \"Hello John!\"\n *\n * @param str - The string containing placeholders wrapped in { } braces.\n * @param data - Object containing values to substitute. Supports nested keys via dot notation.\n * @param def - Default value to use if a key is missing. (Optional)\n * @returns The substituted string or undefined if the input string or data is invalid.\n */\nexport const substitute = (\n str: string,\n data: Record<string, unknown> = {},\n def?: string\n): string | undefined => {\n if (!str || !data) return undefined\n\n // Matches { key } or { nested.key } placeholders\n const regex = /{\\s*([a-zA-Z0-9_.]+)\\s*}/g\n\n // Flatten the data so we can directly access dot notation keys\n const flattened = dot(data)\n\n // Replace each placeholder with its value or the default\n const out = str.replace(regex, (_, key: string) => {\n const value = flattened[key]\n return value !== undefined ? String(value) : def ?? ''\n })\n\n return out\n}\n\n/**\n * Truncates a string to a specified length, removing HTML tags and \n * appending a suffix if the string exceeds the length.\n *\n * @param str - The string to truncate\n * @param len - Maximum length (default: 20)\n * @param suffix - Suffix to append if truncated (default: \"...\")\n * @returns The truncated string\n */\nexport const truncate = (\n str: string,\n len: number = 20,\n suffix: string = '...'\n): string => {\n if (!str) return ''\n\n // Remove any HTML tags\n const clean = str.replace(/<[^>]+>/g, '')\n\n // Determine if we need to truncate\n const truncated =\n clean.length > len\n ? clean.substring(0, len - suffix.length) + suffix\n : clean\n\n // Normalize spaces and line breaks\n return truncated\n .replace(/\\n/g, ' ') // Replace all line breaks\n .replace(new RegExp(`\\\\s+${suffix.replace(/\\./g, '\\\\.')}$`), suffix) // Avoid extra space before suffix\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACQO,IAAMA,QAAQ,wBAAKC,KAAUC,OAAe,MAAC;AAChD,MAAIA,QAAQ;AAAG,UAAM,IAAIC,MAAM,mCAAA;AAE/B,QAAMC,SAAgB,CAAA;AAEtB,WAASC,IAAI,GAAGA,IAAIJ,IAAIK,QAAQD,KAAKH,MAAM;AACvCE,WAAOG,KAAKN,IAAIO,MAAMH,GAAGA,IAAIH,IAAAA,CAAAA;EACjC;AAEA,SAAOE;AACX,GAVqB;AAoBd,IAAMK,QAAQ,wBAACP,MAAcQ,UAAkB,MAAC;AACnD,MAAIR,QAAQ,KAAK,CAACS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AW;AACpB,GAXuB;AAqBhB,IAAMe,YAAY,wBACrB9B,KACA+B,KACAC,WAAmB,UAAK;AAExB,MAAI,CAAChC;AAAK,WAAO;AACjB,MAAI+B,OAAOC,SAASvC;AAAQ,WAAOuC;AAEnC,SAAOhC,IAAIP,SAASsC,MACd/B,IAAIiC,UAAU,GAAGF,MAAMC,SAASvC,MAAM,EAAEyC,QAAO,IAAKF,WACpDhC;AACV,GAXyB;AAyBlB,IAAMmC,aAAa,wBACtBnC,KACAoC,OAAgC,CAAC,GACjCC,QAAAA;AAEA,MAAI,CAACrC,OAAO,CAACoC;AAAM,WAAOE;AAG1B,QAAMC,QAAQ;AAGd,QAAMC,YAAYC,IAAIL,IAAAA;AAGtB,QAAMM,MAAM1C,IAAI0B,QAAQa,OAAO,CAACI,GAAGC,QAAAA;AAC/B,UAAMxD,QAAQoD,UAAUI,GAAAA;AACxB,WAAOxD,UAAUkD,SAAYO,OAAOzD,KAAAA,IAASiD,OAAO;EACxD,CAAA;AAEA,SAAOK;AACX,GApB0B;AA+BnB,IAAMI,WAAW,wBACpB9C,KACA+B,MAAc,IACdgB,SAAiB,UAAK;AAEtB,MAAI,CAAC/C;AAAK,WAAO;AAGjB,QAAMgD,QAAQhD,IAAI0B,QAAQ,YAAY,EAAA;AAGtC,QAAMuB,YACFD,MAAMvD,SAASsC,MACTiB,MAAMf,UAAU,GAAGF,MAAMgB,OAAOtD,MAAM,IAAIsD,SAC1CC;AAGV,SAAOC,UACFvB,QAAQ,OAAO,GAAA,EACfA,QAAQ,IAAIG,OAAO,OAAOkB,OAAOrB,QAAQ,OAAO,KAAA,CAAA,GAAS,GAAGqB,MAAAA;AACrE,GApBwB;","names":["chunk","arr","size","Error","chunks","i","length","push","slice","range","startAt","Number","isFinite","Array","from","_","abbreviate","value","locale","Intl","NumberFormat","format","si","v","s","match","find","scale","formatted","minimumFractionDigits","maximumFractionDigits","humanize","num","slugify","h","replace","toLowerCase","ones","tens","numString","toString","Error","length","end","toBytes","bytes","decimals","bits","isNaN","base","dm","sizes","index","Math","floor","log","parseFloat","pow","toFixed","toHumanTime","seconds","worded","hours","minutes","secs","parts","push","join","hh","mm","ss","dot","obj","result","recurse","o","prefix","key","value","Object","entries","newKey","Array","isArray","extractProperties","keys","fromEntries","map","getValue","item","parent","child","undefined","String","modObj","callback","safeDot","data","split","reduce","acc","k","setNested","includes","parts","current","i","length","part","slugifyKeys","only","separator","slugify","replace","RegExp","toLowerCase","filter","after","value","search","index","indexOf","slice","length","afterLast","lastIndex","lastIndexOf","before","beforeLast","capitalize","str","toUpperCase","pluralize","word","count","irregularPlurals","foot","child","mouse","goose","person","man","woman","endsWith","includes","toLowerCase","test","singularize","irregulars","feet","children","mice","geese","people","men","women","replace","slugify","joiner","RegExp","subString","len","ellipsis","substring","trimEnd","substitute","data","def","undefined","regex","flattened","dot","out","_","key","String","truncate","suffix","clean","truncated"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/Helpers/Arr.ts","../src/Helpers/Number.ts","../src/Helpers/Obj.ts","../src/Helpers/Str.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './Contracts/ObjContract';\nexport * from './Contracts/StrContract';\nexport * from './Helpers/Arr';\nexport * from './Helpers/Number';\nexport * from './Helpers/Obj';\nexport * from './Helpers/Str';\n","/**\n * Splits an array into chunks of a specified size.\n *\n * @template T - Type of elements in the array\n * @param arr - The input array\n * @param size - Size of each chunk (default: 2)\n * @returns An array of chunks (arrays)\n */\nexport const chunk = <T> (arr: T[], size: number = 2): T[][] => {\n if (size <= 0) throw new Error('Chunk size must be greater than 0')\n\n const chunks: T[][] = []\n\n for (let i = 0; i < arr.length; i += size) {\n chunks.push(arr.slice(i, i + size))\n }\n\n return chunks\n}\n\n\n/**\n * Generates an array of sequential numbers.\n *\n * @param size - Number of elements in the range\n * @param startAt - Starting number (default: 0)\n * @returns An array of numbers from startAt to startAt + size - 1\n */\nexport const range = (size: number, startAt: number = 0): number[] => {\n if (size <= 0 || !Number.isFinite(size)) return []\n\n return Array.from({ length: size }, (_, i) => startAt + i)\n}\n","/**\n * Abbreviates large numbers using SI symbols (K, M, B...) \n * and formats the output according to the given locale.\n *\n * @param value - The number to abbreviate\n * @param locale - Optional locale string (default: \"en-US\")\n * @returns A localized, abbreviated number string\n */\nexport const abbreviate = (value?: number, locale: string = 'en-US'): string => {\n if (!value) return '0'\n\n // Numbers less than 1000 don't need abbreviation\n if (value < 1000) {\n return new Intl.NumberFormat(locale).format(value)\n }\n\n const si = [\n { v: 1e18, s: 'E' },\n { v: 1e15, s: 'P' },\n { v: 1e12, s: 'T' },\n { v: 1e9, s: 'B' },\n { v: 1e6, s: 'M' },\n { v: 1e3, s: 'K' },\n ]\n\n const match = si.find(scale => value >= scale.v)\n if (!match) return new Intl.NumberFormat(locale).format(value)\n\n const formatted = value / match.v\n\n return (\n new Intl.NumberFormat(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 2,\n }).format(formatted) + match.s\n )\n}\n\n/**\n * Concverts a number into human readable string\n *\n * @param num The number to convert\n * @param slugify convert the ouput into a slug using this as a separator\n * @returns\n */\nexport const humanize = (num: number, slugify?: '-' | '_'): string => {\n if (!num) {\n return ''\n }\n\n if (slugify === '-' || slugify === '_') {\n const h = humanize(num)\n return typeof h === 'string' ? h.replace(' ', slugify).toLowerCase() : h\n }\n\n const ones = [\n '',\n 'one',\n 'two',\n 'three',\n 'four',\n 'five',\n 'six',\n 'seven',\n 'eight',\n 'nine',\n 'ten',\n 'eleven',\n 'twelve',\n 'thirteen',\n 'fourteen',\n 'fifteen',\n 'sixteen',\n 'seventeen',\n 'eighteen',\n 'nineteen',\n ]\n const tens = [\n '',\n '',\n 'twenty',\n 'thirty',\n 'forty',\n 'fifty',\n 'sixty',\n 'seventy',\n 'eighty',\n 'ninety',\n ]\n\n const numString: string = num.toString()\n\n if (num < 0) throw new Error('Negative numbers are not supported.')\n\n if (num === 0) return 'zero'\n\n //the case of 1 - 20\n if (num < 20) {\n return ones[num] ?? ''\n }\n\n if (numString.length === 2) {\n return tens[numString[0] as unknown as number] + ' ' + ones[numString[1] as unknown as number]\n }\n\n //100 and more\n if (numString.length == 3) {\n if (numString[1] === '0' && numString[2] === '0')\n return ones[numString[0] as unknown as number] + ' hundred'\n else\n return (\n ones[numString[0] as unknown as number] +\n ' hundred and ' +\n humanize(+((numString[1] || '') + numString[2]), slugify)\n )\n }\n\n if (numString.length === 4) {\n const end = +((numString[1] || '') + numString[2] + numString[3])\n if (end === 0) return ones[numString[0] as unknown as number] + ' thousand'\n if (end < 100)\n return ones[numString[0] as unknown as number] + ' thousand and ' + humanize(end, slugify)\n return ones[numString[0] as unknown as number] + ' thousand ' + humanize(end, slugify)\n }\n\n return num as unknown as string\n}\n\n/**\n * Converts a number of bytes into a human-readable string.\n *\n * @param bytes - The size in bytes to convert\n * @param decimals - Number of decimal places to display (default: 2)\n * @param bits - If true, uses 1000-based (SI) units (B, KB, MB...); \n * otherwise uses 1024-based binary units (Bytes, KiB...)\n * @returns A formatted string with the appropriate unit\n */\nexport const toBytes = (\n bytes?: number,\n decimals: number = 2,\n bits: boolean = false\n): string => {\n if (!bytes || isNaN(bytes)) {\n return bits ? '0 B' : '0 Bytes'\n }\n\n const base = bits ? 1000 : 1024\n const dm = decimals < 0 ? 0 : decimals\n const sizes = bits\n ? ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] // SI units\n : ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] // Binary units\n\n const index = Math.floor(Math.log(bytes) / Math.log(base))\n\n const value = parseFloat((bytes / Math.pow(base, index)).toFixed(dm))\n return `${value} ${sizes[index]}`\n}\n\n/**\n * Formats a duration (in seconds) into a human-readable string.\n *\n * @param seconds - Duration in seconds\n * @param worded - If true, outputs worded format (e.g., \"1hr 2min 3sec\"),\n * otherwise HH:MM:SS (e.g., \"01:02:03\")\n * @returns A formatted time string\n */\nexport const toHumanTime = (\n seconds: number = 0,\n worded: boolean = false\n): string => {\n // Ensure seconds is a number and not negative\n if (isNaN(seconds) || seconds < 0) seconds = 0\n\n const hours = Math.floor(seconds / 3600)\n const minutes = Math.floor((seconds % 3600) / 60)\n const secs = Math.floor(seconds % 60)\n\n // Worded format → \"1hr 2min 3sec\"\n if (worded) {\n const parts = []\n if (hours) parts.push(`${hours}hr`)\n if (minutes) parts.push(`${minutes}min`)\n if (secs || (!hours && !minutes)) parts.push(`${secs}sec`)\n return parts.join(' ')\n }\n\n // HH:MM:SS format → zero-padded\n const hh = hours > 0 ? `${hours}:` : ''\n const mm = (hours > 0 && minutes < 10 ? `0${minutes}` : minutes) + ':'\n const ss = secs < 10 ? `0${secs}` : secs\n\n return `${hh}${mm}${ss}`\n}\n\n","import { DotFlatten, DotNestedKeys, DotNestedValue, KeysToSnakeCase } from '../Contracts/ObjContract'\n\n/**\n * Flattens a nested object into a single-level object\n * with dot-separated keys.\n *\n * Example:\n * doter({\n * user: { name: \"John\", address: { city: \"NY\" } },\n * active: true\n * })\n * \n * Output:\n * {\n * \"user.name\": \"John\",\n * \"user.address.city\": \"NY\",\n * \"active\": true\n * }\n *\n * @template T - The type of the input object\n * @param obj - The nested object to flatten\n * @returns A flattened object with dotted keys and inferred types\n */\nexport const dot = <T extends Record<string, any>> (obj: T): DotFlatten<T> => {\n const result = {} as Record<string, unknown>\n\n /**\n * Internal recursive function to traverse and flatten the object.\n * \n * @param o - Current object to flatten\n * @param prefix - Key path accumulated so far\n */\n const recurse = (o: Record<string, any>, prefix = ''): void => {\n for (const [key, value] of Object.entries(o)) {\n const newKey = prefix ? `${prefix}.${key}` : key\n\n /**\n * Recurse if the value is a plain object\n */\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n recurse(value, newKey)\n } else {\n /**\n * Otherwise, assign directly\n */\n result[newKey] = value\n }\n }\n }\n\n recurse(obj)\n return result as DotFlatten<T>\n}\n\n/**\n * Extracts a subset of properties from an object.\n *\n * @template T - Type of the source object\n * @template K - Keys of T to extract\n * @param obj - The source object\n * @param keys - Array of keys to extract\n * @returns A new object with only the specified keys\n */\nexport const extractProperties = <T extends object, K extends keyof T> (\n obj: T,\n keys: readonly K[] = []\n): Pick<T, K> => {\n return Object.fromEntries(\n keys.map(key => [key, obj[key]])\n ) as Pick<T, K>\n}\n\n/**\n * Safely retrieves a value from an object by key or nested keys.\n *\n * @template T - Type of the source object\n * @param key - Single key or tuple [parentKey, childKey]\n * @param item - The source object\n * @returns The found value as a string or the key itself if not found\n */\nexport const getValue = <\n T extends Record<string, any> // Allow nested objects\n> (\n key: string | [keyof T, keyof T[string]],\n item: T\n): string => {\n if (Array.isArray(key)) {\n const [parent, child] = key\n\n if (child !== undefined) {\n // Access nested property: item[parent][child]\n return (\n String(item?.[parent]?.[child] ??\n item?.[parent] ??\n `${String(parent)}.${String(child)}`)\n )\n }\n\n // Only top-level key\n return String(item?.[parent] ?? parent)\n }\n\n // Single key access\n return String(item?.[key] ?? key)\n}\n\n/**\n * Maps over an object's entries and returns a new object \n * with transformed keys and/or values.\n *\n * @template T - Type of the input object\n * @template R - Type of the new values\n * @param obj - The object to transform\n * @param callback - Function that receives [key, value] and returns [newKey, newValue]\n * @returns A new object with transformed entries\n */\nexport const modObj = <T extends object, R> (\n obj: T,\n callback: (_entry: [keyof T & string, T[keyof T]]) => [string, R]\n): Record<string, R> => {\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) =>\n callback([key as keyof T & string, value as T[keyof T]])\n )\n ) as Record<string, R>\n}\n\n\nexport function safeDot<T extends Record<string, any>> (_data: T): T\nexport function safeDot<\n T extends Record<string, any>,\n K extends DotNestedKeys<T>\n> (_data: T, _key?: K): DotNestedValue<T, K>\nexport function safeDot<\n T extends Record<string, any>,\n K extends DotNestedKeys<T>\n> (data: T, key?: K): any {\n if (!key) return data\n return key.split('.').reduce((acc: any, k) => acc?.[k], data)\n}\n\n/**\n * Sets a nested property on an object using dot notation.\n * \n * @example\n * const obj = {}\n * setNested(obj, 'app.user.name', 'Legacy')\n * console.log(obj)\n * // Output: { app: { user: { name: 'Legacy' } } }\n * \n * @param obj - The target object to modify.\n * @param key - The dot-separated key (e.g., 'app.user.name').\n * @param value - The value to set at the specified path.\n */\nexport const setNested = (\n obj: Record<string, any>,\n key: string,\n value: any\n): void => {\n if (!key.includes('.')) {\n obj[key] = value\n return\n }\n\n const parts = key.split('.')\n let current = obj\n\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i]\n\n /**\n * If we're at the last key, assign the value\n */\n if (i === parts.length - 1) {\n current[part] = value\n } else {\n /**\n * If the key doesn't exist or isn't an object, create it\n */\n if (typeof current[part] !== 'object' || current[part] === null) {\n current[part] = {}\n }\n current = current[part]\n }\n }\n}\n\n/**\n * Converts object keys to a slugified format (e.g., snake_case).\n *\n * @template T - Type of the input object\n * @param obj - The object whose keys will be slugified\n * @param only - Optional array of keys to slugify (others remain unchanged)\n * @param separator - Separator for slugified keys (default: \"_\")\n * @returns A new object with slugified keys\n */\nexport const slugifyKeys = <T extends object> (\n obj: T,\n only: string[] = [],\n separator: string = '_'\n): KeysToSnakeCase<T> => {\n const slugify = (key: string): string =>\n key\n .replace(/([a-z])([A-Z])/g, `$1${separator}$2`) // Handle camelCase\n .replace(/[\\s\\W]+/g, separator) // Replace spaces/symbols\n .replace(new RegExp(`${separator}{2,}`, 'g'), separator) // Remove duplicate separators\n .replace(new RegExp(`^${separator}|${separator}$`, 'g'), '') // Trim edges\n .toLowerCase()\n\n let entries = Object.entries(obj)\n\n // Filter if `only` is provided\n if (only.length) {\n entries = entries.filter(([key]) => only.includes(key))\n }\n\n return Object.fromEntries(\n entries.map(([key, value]) => [slugify(key), value])\n ) as KeysToSnakeCase<T>\n}\n","import { dot } from './Obj'\n\n/**\n * Get the portion of the string after the first occurrence of the given value.\n * \n * @param value \n * @param search \n * @returns \n */\nexport const after = (value: string, search: string): string => {\n if (!search) return value\n const index = value.indexOf(search)\n return index !== -1 ? value.slice(index + search.length) : value\n}\n\n/**\n * Get the portion of the string after the last occurrence of the given value.\n * \n * @param value \n * @param search \n * @returns \n */\nexport const afterLast = (value: string, search: string): string => {\n if (!search) return value\n const lastIndex = value.lastIndexOf(search)\n return lastIndex !== -1 ? value.slice(lastIndex + search.length) : value\n}\n\n/**\n * Get the portion of the string before the first occurrence of the given value.\n * \n * @param value \n * @param search \n * @returns \n */\nexport const before = (value: string, search: string): string => {\n if (!search) return value\n const index = value.indexOf(search)\n return index !== -1 ? value.slice(0, index) : value\n}\n\n/**\n * Get the portion of the string before the last occurrence of the given value.\n * \n * @param value \n * @param search \n * @returns \n */\nexport const beforeLast = (value: string, search: string): string => {\n if (!search) return value\n const lastIndex = value.lastIndexOf(search)\n return lastIndex !== -1 ? value.slice(0, lastIndex) : value\n}\n\n/**\n * Capitalizes the first character of a string.\n *\n * @param str - The input string\n * @returns The string with the first character capitalized\n */\nexport function capitalize (str: string): string {\n if (!str) return '' // Handle empty or undefined strings safely\n return str[0].toUpperCase() + str.slice(1)\n}\n\n\n/**\n * Returns the pluralized form of a word based on the given number.\n *\n * @param word - The word to pluralize\n * @param count - The number determining pluralization\n * @returns Singular if count === 1, otherwise plural form\n */\nexport const pluralize = (word: string, count: number): string => {\n // If count is exactly 1 → singular\n if (count === 1) return word\n\n // Irregular plurals map\n const irregularPlurals: Record<string, string> = {\n foot: 'feet',\n child: 'children',\n mouse: 'mice',\n goose: 'geese',\n person: 'people',\n man: 'men',\n woman: 'women',\n }\n\n // Handle irregular cases first\n if (word in irregularPlurals) {\n return irregularPlurals[word]\n }\n\n // If word ends with consonant + \"y\" → replace \"y\" with \"ies\"\n if (\n word.endsWith('y') &&\n !['a', 'e', 'i', 'o', 'u'].includes(word[word.length - 2]?.toLowerCase() ?? '')\n ) {\n return word.slice(0, -1) + 'ies'\n }\n\n // If word ends in \"s\", \"ss\", \"sh\", \"ch\", \"x\", or \"z\" → add \"es\"\n if (/(s|ss|sh|ch|x|z)$/i.test(word)) {\n return word + 'es'\n }\n\n // Default: just add \"s\"\n return word + 's'\n}\n\n/**\n * Converts a plural English word into its singular form.\n *\n * @param word - The word to singularize\n * @returns The singular form of the word\n */\nexport const singularize = (word: string): string => {\n // Irregular plurals map (reverse of pluralize)\n const irregulars: Record<string, string> = {\n feet: 'foot',\n children: 'child',\n mice: 'mouse',\n geese: 'goose',\n people: 'person',\n men: 'man',\n women: 'woman',\n }\n\n // Handle irregular cases\n if (word in irregulars) return irregulars[word]\n\n // Words ending in \"ies\" → change to \"y\" (e.g., \"bodies\" → \"body\")\n if (/ies$/i.test(word) && word.length > 3) {\n return word.replace(/ies$/i, 'y')\n }\n\n // Words ending in \"es\" after certain consonants → remove \"es\"\n if (/(ches|shes|sses|xes|zes)$/i.test(word)) {\n return word.replace(/es$/i, '')\n }\n\n // Generic case: remove trailing \"s\"\n if (/s$/i.test(word) && word.length > 1) {\n return word.replace(/s$/i, '')\n }\n\n return word\n}\n\n/**\n * Converts a string into a slug format.\n * Handles camelCase, spaces, and non-alphanumeric characters.\n *\n * @param str - The input string to slugify\n * @param joiner - The character used to join words (default: \"_\")\n * @returns A slugified string\n */\nexport const slugify = (str: string, joiner = '_'): string => {\n return str\n // Handle camelCase by adding joiner between lowercase → uppercase\n .replace(/([a-z])([A-Z])/g, `$1${joiner}$2`)\n // Replace spaces and non-alphanumeric characters with joiner\n .replace(/[\\s\\W]+/g, joiner)\n // Remove duplicate joiners\n .replace(new RegExp(`${joiner}{2,}`, 'g'), joiner)\n // Trim joiners from start/end\n .replace(new RegExp(`^${joiner}|${joiner}$`, 'g'), '')\n .toLowerCase()\n}\n\n/**\n * Truncates a string to a specified length and appends an ellipsis if needed.\n *\n * @param str - The input string\n * @param len - Maximum length of the result (including ellipsis)\n * @param ellipsis - String to append if truncated (default: \"...\")\n * @returns The truncated string\n */\nexport const subString = (\n str: string,\n len: number,\n ellipsis: string = '...'\n): string => {\n if (!str) return ''\n if (len <= ellipsis.length) return ellipsis // Avoid negative slicing\n\n return str.length > len\n ? str.substring(0, len - ellipsis.length).trimEnd() + ellipsis\n : str\n}\n\n/**\n * Replaces placeholders in a string with corresponding values from a data object.\n * \n * Example:\n * substitute(\"Hello { user.name }!\", { user: { name: \"John\" } })\n * // \"Hello John!\"\n *\n * @param str - The string containing placeholders wrapped in { } braces.\n * @param data - Object containing values to substitute. Supports nested keys via dot notation.\n * @param def - Default value to use if a key is missing. (Optional)\n * @returns The substituted string or undefined if the input string or data is invalid.\n */\nexport const substitute = (\n str: string,\n data: Record<string, unknown> = {},\n def?: string\n): string | undefined => {\n if (!str || !data) return undefined\n\n // Matches { key } or { nested.key } placeholders\n const regex = /{\\s*([a-zA-Z0-9_.]+)\\s*}/g\n\n // Flatten the data so we can directly access dot notation keys\n const flattened = dot(data)\n\n // Replace each placeholder with its value or the default\n const out = str.replace(regex, (_, key: string) => {\n const value = flattened[key]\n return value !== undefined ? String(value) : def ?? ''\n })\n\n return out\n}\n\n/**\n * Truncates a string to a specified length, removing HTML tags and \n * appending a suffix if the string exceeds the length.\n *\n * @param str - The string to truncate\n * @param len - Maximum length (default: 20)\n * @param suffix - Suffix to append if truncated (default: \"...\")\n * @returns The truncated string\n */\nexport const truncate = (\n str: string,\n len: number = 20,\n suffix: string = '...'\n): string => {\n if (!str) return ''\n\n // Remove any HTML tags\n const clean = str.replace(/<[^>]+>/g, '')\n\n // Determine if we need to truncate\n const truncated =\n clean.length > len\n ? clean.substring(0, len - suffix.length) + suffix\n : clean\n\n // Normalize spaces and line breaks\n return truncated\n .replace(/\\n/g, ' ') // Replace all line breaks\n .replace(new RegExp(`\\\\s+${suffix.replace(/\\./g, '\\\\.')}$`), suffix) // Avoid extra space before suffix\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACQO,IAAMA,QAAQ,wBAAKC,KAAUC,OAAe,MAAC;AAChD,MAAIA,QAAQ;AAAG,UAAM,IAAIC,MAAM,mCAAA;AAE/B,QAAMC,SAAgB,CAAA;AAEtB,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CAAA,GAAS,GAAGqB,MAAAA;AACrE,GApBwB;","names":["chunk","arr","size","Error","chunks","i","length","push","slice","range","startAt","Number","isFinite","Array","from","_","abbreviate","value","locale","Intl","NumberFormat","format","si","v","s","match","find","scale","formatted","minimumFractionDigits","maximumFractionDigits","humanize","num","slugify","h","replace","toLowerCase","ones","tens","numString","toString","Error","length","end","toBytes","bytes","decimals","bits","isNaN","base","dm","sizes","index","Math","floor","log","parseFloat","pow","toFixed","toHumanTime","seconds","worded","hours","minutes","secs","parts","push","join","hh","mm","ss","dot","obj","result","recurse","o","prefix","key","value","Object","entries","newKey","Array","isArray","extractProperties","keys","fromEntries","map","getValue","item","parent","child","undefined","String","modObj","callback","safeDot","data","split","reduce","acc","k","setNested","includes","parts","current","i","length","part","slugifyKeys","only","separator","slugify","replace","RegExp","toLowerCase","filter","after","value","search","index","indexOf","slice","length","afterLast","lastIndex","lastIndexOf","before","beforeLast","capitalize","str","toUpperCase","pluralize","word","count","irregularPlurals","foot","child","mouse","goose","person","man","woman","endsWith","includes","toLowerCase","test","singularize","irregulars","feet","children","mice","geese","people","men","women","replace","slugify","joiner","RegExp","subString","len","ellipsis","substring","trimEnd","substitute","data","def","undefined","regex","flattened","dot","out","_","key","String","truncate","suffix","clean","truncated"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -46,7 +46,7 @@ type KeysToSnakeCase<T> = {
|
|
|
46
46
|
* @param size - Size of each chunk (default: 2)
|
|
47
47
|
* @returns An array of chunks (arrays)
|
|
48
48
|
*/
|
|
49
|
-
declare const chunk: <T>(arr: T[], size?: number) => T[][]
|
|
49
|
+
declare const chunk: <T>(arr: T[], size?: number) => T[][];
|
|
50
50
|
/**
|
|
51
51
|
* Generates an array of sequential numbers.
|
|
52
52
|
*
|
|
@@ -54,7 +54,7 @@ declare const chunk: <T>(arr: T[], size?: number) => T[][]
|
|
|
54
54
|
* @param startAt - Starting number (default: 0)
|
|
55
55
|
* @returns An array of numbers from startAt to startAt + size - 1
|
|
56
56
|
*/
|
|
57
|
-
declare const range: (size: number, startAt?: number) => number[]
|
|
57
|
+
declare const range: (size: number, startAt?: number) => number[];
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Abbreviates large numbers using SI symbols (K, M, B...)
|
|
@@ -64,7 +64,7 @@ declare const range: (size: number, startAt?: number) => number[]
|
|
|
64
64
|
* @param locale - Optional locale string (default: "en-US")
|
|
65
65
|
* @returns A localized, abbreviated number string
|
|
66
66
|
*/
|
|
67
|
-
declare const abbreviate: (value?: number, locale?: string) => string
|
|
67
|
+
declare const abbreviate: (value?: number, locale?: string) => string;
|
|
68
68
|
/**
|
|
69
69
|
* Concverts a number into human readable string
|
|
70
70
|
*
|
|
@@ -72,7 +72,7 @@ declare const abbreviate: (value?: number, locale?: string) => string
|
|
|
72
72
|
* @param slugify convert the ouput into a slug using this as a separator
|
|
73
73
|
* @returns
|
|
74
74
|
*/
|
|
75
|
-
declare const humanize: (num: number, slugify?:
|
|
75
|
+
declare const humanize: (num: number, slugify?: "-" | "_") => string;
|
|
76
76
|
/**
|
|
77
77
|
* Converts a number of bytes into a human-readable string.
|
|
78
78
|
*
|
|
@@ -82,7 +82,7 @@ declare const humanize: (num: number, slugify?: '-' | '_') => string
|
|
|
82
82
|
* otherwise uses 1024-based binary units (Bytes, KiB...)
|
|
83
83
|
* @returns A formatted string with the appropriate unit
|
|
84
84
|
*/
|
|
85
|
-
declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => string
|
|
85
|
+
declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => string;
|
|
86
86
|
/**
|
|
87
87
|
* Formats a duration (in seconds) into a human-readable string.
|
|
88
88
|
*
|
|
@@ -91,7 +91,7 @@ declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => st
|
|
|
91
91
|
* otherwise HH:MM:SS (e.g., "01:02:03")
|
|
92
92
|
* @returns A formatted time string
|
|
93
93
|
*/
|
|
94
|
-
declare const toHumanTime: (seconds?: number, worded?: boolean) => string
|
|
94
|
+
declare const toHumanTime: (seconds?: number, worded?: boolean) => string;
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
97
|
* Flattens a nested object into a single-level object
|
|
@@ -114,7 +114,7 @@ declare const toHumanTime: (seconds?: number, worded?: boolean) => string
|
|
|
114
114
|
* @param obj - The nested object to flatten
|
|
115
115
|
* @returns A flattened object with dotted keys and inferred types
|
|
116
116
|
*/
|
|
117
|
-
declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T
|
|
117
|
+
declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>;
|
|
118
118
|
/**
|
|
119
119
|
* Extracts a subset of properties from an object.
|
|
120
120
|
*
|
|
@@ -124,7 +124,7 @@ declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>
|
|
|
124
124
|
* @param keys - Array of keys to extract
|
|
125
125
|
* @returns A new object with only the specified keys
|
|
126
126
|
*/
|
|
127
|
-
declare const extractProperties: <T extends object, K extends keyof T>(obj: T, keys?: readonly K[]) => Pick<T, K
|
|
127
|
+
declare const extractProperties: <T extends object, K extends keyof T>(obj: T, keys?: readonly K[]) => Pick<T, K>;
|
|
128
128
|
/**
|
|
129
129
|
* Safely retrieves a value from an object by key or nested keys.
|
|
130
130
|
*
|
|
@@ -133,7 +133,7 @@ declare const extractProperties: <T extends object, K extends keyof T>(obj: T, k
|
|
|
133
133
|
* @param item - The source object
|
|
134
134
|
* @returns The found value as a string or the key itself if not found
|
|
135
135
|
*/
|
|
136
|
-
declare const getValue: <T extends Record<string, any>>(key: string | [keyof T, keyof T[string]], item: T) => string
|
|
136
|
+
declare const getValue: <T extends Record<string, any>>(key: string | [keyof T, keyof T[string]], item: T) => string;
|
|
137
137
|
/**
|
|
138
138
|
* Maps over an object's entries and returns a new object
|
|
139
139
|
* with transformed keys and/or values.
|
|
@@ -144,9 +144,9 @@ declare const getValue: <T extends Record<string, any>>(key: string | [keyof T,
|
|
|
144
144
|
* @param callback - Function that receives [key, value] and returns [newKey, newValue]
|
|
145
145
|
* @returns A new object with transformed entries
|
|
146
146
|
*/
|
|
147
|
-
declare const modObj: <T extends object, R>(obj: T, callback: (
|
|
148
|
-
declare function safeDot<T extends Record<string, any>>(
|
|
149
|
-
declare function safeDot<T extends Record<string, any>, K extends DotNestedKeys<T>>(
|
|
147
|
+
declare const modObj: <T extends object, R>(obj: T, callback: (_entry: [keyof T & string, T[keyof T]]) => [string, R]) => Record<string, R>;
|
|
148
|
+
declare function safeDot<T extends Record<string, any>>(_data: T): T;
|
|
149
|
+
declare function safeDot<T extends Record<string, any>, K extends DotNestedKeys<T>>(_data: T, _key?: K): DotNestedValue<T, K>;
|
|
150
150
|
/**
|
|
151
151
|
* Sets a nested property on an object using dot notation.
|
|
152
152
|
*
|
|
@@ -160,7 +160,7 @@ declare function safeDot<T extends Record<string, any>, K extends DotNestedKeys<
|
|
|
160
160
|
* @param key - The dot-separated key (e.g., 'app.user.name').
|
|
161
161
|
* @param value - The value to set at the specified path.
|
|
162
162
|
*/
|
|
163
|
-
declare const setNested: (obj: Record<string, any>, key: string, value: any) => void
|
|
163
|
+
declare const setNested: (obj: Record<string, any>, key: string, value: any) => void;
|
|
164
164
|
/**
|
|
165
165
|
* Converts object keys to a slugified format (e.g., snake_case).
|
|
166
166
|
*
|
|
@@ -170,7 +170,7 @@ declare const setNested: (obj: Record<string, any>, key: string, value: any) =>
|
|
|
170
170
|
* @param separator - Separator for slugified keys (default: "_")
|
|
171
171
|
* @returns A new object with slugified keys
|
|
172
172
|
*/
|
|
173
|
-
declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator?: string) => KeysToSnakeCase<T
|
|
173
|
+
declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator?: string) => KeysToSnakeCase<T>;
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
176
|
* Get the portion of the string after the first occurrence of the given value.
|
|
@@ -179,7 +179,7 @@ declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator
|
|
|
179
179
|
* @param search
|
|
180
180
|
* @returns
|
|
181
181
|
*/
|
|
182
|
-
declare const after: (value: string, search: string) => string
|
|
182
|
+
declare const after: (value: string, search: string) => string;
|
|
183
183
|
/**
|
|
184
184
|
* Get the portion of the string after the last occurrence of the given value.
|
|
185
185
|
*
|
|
@@ -187,7 +187,7 @@ declare const after: (value: string, search: string) => string
|
|
|
187
187
|
* @param search
|
|
188
188
|
* @returns
|
|
189
189
|
*/
|
|
190
|
-
declare const afterLast: (value: string, search: string) => string
|
|
190
|
+
declare const afterLast: (value: string, search: string) => string;
|
|
191
191
|
/**
|
|
192
192
|
* Get the portion of the string before the first occurrence of the given value.
|
|
193
193
|
*
|
|
@@ -195,7 +195,7 @@ declare const afterLast: (value: string, search: string) => string
|
|
|
195
195
|
* @param search
|
|
196
196
|
* @returns
|
|
197
197
|
*/
|
|
198
|
-
declare const before: (value: string, search: string) => string
|
|
198
|
+
declare const before: (value: string, search: string) => string;
|
|
199
199
|
/**
|
|
200
200
|
* Get the portion of the string before the last occurrence of the given value.
|
|
201
201
|
*
|
|
@@ -203,7 +203,7 @@ declare const before: (value: string, search: string) => string
|
|
|
203
203
|
* @param search
|
|
204
204
|
* @returns
|
|
205
205
|
*/
|
|
206
|
-
declare const beforeLast: (value: string, search: string) => string
|
|
206
|
+
declare const beforeLast: (value: string, search: string) => string;
|
|
207
207
|
/**
|
|
208
208
|
* Capitalizes the first character of a string.
|
|
209
209
|
*
|
|
@@ -218,14 +218,14 @@ declare function capitalize(str: string): string;
|
|
|
218
218
|
* @param count - The number determining pluralization
|
|
219
219
|
* @returns Singular if count === 1, otherwise plural form
|
|
220
220
|
*/
|
|
221
|
-
declare const pluralize: (word: string, count: number) => string
|
|
221
|
+
declare const pluralize: (word: string, count: number) => string;
|
|
222
222
|
/**
|
|
223
223
|
* Converts a plural English word into its singular form.
|
|
224
224
|
*
|
|
225
225
|
* @param word - The word to singularize
|
|
226
226
|
* @returns The singular form of the word
|
|
227
227
|
*/
|
|
228
|
-
declare const singularize: (word: string) => string
|
|
228
|
+
declare const singularize: (word: string) => string;
|
|
229
229
|
/**
|
|
230
230
|
* Converts a string into a slug format.
|
|
231
231
|
* Handles camelCase, spaces, and non-alphanumeric characters.
|
|
@@ -234,7 +234,7 @@ declare const singularize: (word: string) => string
|
|
|
234
234
|
* @param joiner - The character used to join words (default: "_")
|
|
235
235
|
* @returns A slugified string
|
|
236
236
|
*/
|
|
237
|
-
declare const slugify: (str: string, joiner?: string) => string
|
|
237
|
+
declare const slugify: (str: string, joiner?: string) => string;
|
|
238
238
|
/**
|
|
239
239
|
* Truncates a string to a specified length and appends an ellipsis if needed.
|
|
240
240
|
*
|
|
@@ -243,7 +243,7 @@ declare const slugify: (str: string, joiner?: string) => string
|
|
|
243
243
|
* @param ellipsis - String to append if truncated (default: "...")
|
|
244
244
|
* @returns The truncated string
|
|
245
245
|
*/
|
|
246
|
-
declare const subString: (str: string, len: number, ellipsis?: string) => string
|
|
246
|
+
declare const subString: (str: string, len: number, ellipsis?: string) => string;
|
|
247
247
|
/**
|
|
248
248
|
* Replaces placeholders in a string with corresponding values from a data object.
|
|
249
249
|
*
|
|
@@ -256,7 +256,7 @@ declare const subString: (str: string, len: number, ellipsis?: string) => string
|
|
|
256
256
|
* @param def - Default value to use if a key is missing. (Optional)
|
|
257
257
|
* @returns The substituted string or undefined if the input string or data is invalid.
|
|
258
258
|
*/
|
|
259
|
-
declare const substitute: (str: string, data?: Record<string, unknown>, def?: string) => string | undefined
|
|
259
|
+
declare const substitute: (str: string, data?: Record<string, unknown>, def?: string) => string | undefined;
|
|
260
260
|
/**
|
|
261
261
|
* Truncates a string to a specified length, removing HTML tags and
|
|
262
262
|
* appending a suffix if the string exceeds the length.
|
|
@@ -266,6 +266,6 @@ declare const substitute: (str: string, data?: Record<string, unknown>, def?: st
|
|
|
266
266
|
* @param suffix - Suffix to append if truncated (default: "...")
|
|
267
267
|
* @returns The truncated string
|
|
268
268
|
*/
|
|
269
|
-
declare const truncate: (str: string, len?: number, suffix?: string) => string
|
|
269
|
+
declare const truncate: (str: string, len?: number, suffix?: string) => string;
|
|
270
270
|
|
|
271
|
-
export { type CamelToSnakeCase, type DotFlatten, type DotNestedKeys, type DotNestedValue, type KeysToSnakeCase, abbreviate, after, afterLast, before, beforeLast, capitalize, chunk, dot, extractProperties, getValue, humanize, modObj, pluralize, range, safeDot, setNested, singularize, slugify, slugifyKeys, subString, substitute, toBytes, toHumanTime, truncate }
|
|
271
|
+
export { type CamelToSnakeCase, type DotFlatten, type DotNestedKeys, type DotNestedValue, type KeysToSnakeCase, abbreviate, after, afterLast, before, beforeLast, capitalize, chunk, dot, extractProperties, getValue, humanize, modObj, pluralize, range, safeDot, setNested, singularize, slugify, slugifyKeys, subString, substitute, toBytes, toHumanTime, truncate };
|
package/dist/index.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ type KeysToSnakeCase<T> = {
|
|
|
46
46
|
* @param size - Size of each chunk (default: 2)
|
|
47
47
|
* @returns An array of chunks (arrays)
|
|
48
48
|
*/
|
|
49
|
-
declare const chunk: <T>(arr: T[], size?: number) => T[][]
|
|
49
|
+
declare const chunk: <T>(arr: T[], size?: number) => T[][];
|
|
50
50
|
/**
|
|
51
51
|
* Generates an array of sequential numbers.
|
|
52
52
|
*
|
|
@@ -54,7 +54,7 @@ declare const chunk: <T>(arr: T[], size?: number) => T[][]
|
|
|
54
54
|
* @param startAt - Starting number (default: 0)
|
|
55
55
|
* @returns An array of numbers from startAt to startAt + size - 1
|
|
56
56
|
*/
|
|
57
|
-
declare const range: (size: number, startAt?: number) => number[]
|
|
57
|
+
declare const range: (size: number, startAt?: number) => number[];
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Abbreviates large numbers using SI symbols (K, M, B...)
|
|
@@ -64,7 +64,7 @@ declare const range: (size: number, startAt?: number) => number[]
|
|
|
64
64
|
* @param locale - Optional locale string (default: "en-US")
|
|
65
65
|
* @returns A localized, abbreviated number string
|
|
66
66
|
*/
|
|
67
|
-
declare const abbreviate: (value?: number, locale?: string) => string
|
|
67
|
+
declare const abbreviate: (value?: number, locale?: string) => string;
|
|
68
68
|
/**
|
|
69
69
|
* Concverts a number into human readable string
|
|
70
70
|
*
|
|
@@ -72,7 +72,7 @@ declare const abbreviate: (value?: number, locale?: string) => string
|
|
|
72
72
|
* @param slugify convert the ouput into a slug using this as a separator
|
|
73
73
|
* @returns
|
|
74
74
|
*/
|
|
75
|
-
declare const humanize: (num: number, slugify?:
|
|
75
|
+
declare const humanize: (num: number, slugify?: "-" | "_") => string;
|
|
76
76
|
/**
|
|
77
77
|
* Converts a number of bytes into a human-readable string.
|
|
78
78
|
*
|
|
@@ -82,7 +82,7 @@ declare const humanize: (num: number, slugify?: '-' | '_') => string
|
|
|
82
82
|
* otherwise uses 1024-based binary units (Bytes, KiB...)
|
|
83
83
|
* @returns A formatted string with the appropriate unit
|
|
84
84
|
*/
|
|
85
|
-
declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => string
|
|
85
|
+
declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => string;
|
|
86
86
|
/**
|
|
87
87
|
* Formats a duration (in seconds) into a human-readable string.
|
|
88
88
|
*
|
|
@@ -91,7 +91,7 @@ declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => st
|
|
|
91
91
|
* otherwise HH:MM:SS (e.g., "01:02:03")
|
|
92
92
|
* @returns A formatted time string
|
|
93
93
|
*/
|
|
94
|
-
declare const toHumanTime: (seconds?: number, worded?: boolean) => string
|
|
94
|
+
declare const toHumanTime: (seconds?: number, worded?: boolean) => string;
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
97
|
* Flattens a nested object into a single-level object
|
|
@@ -114,7 +114,7 @@ declare const toHumanTime: (seconds?: number, worded?: boolean) => string
|
|
|
114
114
|
* @param obj - The nested object to flatten
|
|
115
115
|
* @returns A flattened object with dotted keys and inferred types
|
|
116
116
|
*/
|
|
117
|
-
declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T
|
|
117
|
+
declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>;
|
|
118
118
|
/**
|
|
119
119
|
* Extracts a subset of properties from an object.
|
|
120
120
|
*
|
|
@@ -124,7 +124,7 @@ declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>
|
|
|
124
124
|
* @param keys - Array of keys to extract
|
|
125
125
|
* @returns A new object with only the specified keys
|
|
126
126
|
*/
|
|
127
|
-
declare const extractProperties: <T extends object, K extends keyof T>(obj: T, keys?: readonly K[]) => Pick<T, K
|
|
127
|
+
declare const extractProperties: <T extends object, K extends keyof T>(obj: T, keys?: readonly K[]) => Pick<T, K>;
|
|
128
128
|
/**
|
|
129
129
|
* Safely retrieves a value from an object by key or nested keys.
|
|
130
130
|
*
|
|
@@ -133,7 +133,7 @@ declare const extractProperties: <T extends object, K extends keyof T>(obj: T, k
|
|
|
133
133
|
* @param item - The source object
|
|
134
134
|
* @returns The found value as a string or the key itself if not found
|
|
135
135
|
*/
|
|
136
|
-
declare const getValue: <T extends Record<string, any>>(key: string | [keyof T, keyof T[string]], item: T) => string
|
|
136
|
+
declare const getValue: <T extends Record<string, any>>(key: string | [keyof T, keyof T[string]], item: T) => string;
|
|
137
137
|
/**
|
|
138
138
|
* Maps over an object's entries and returns a new object
|
|
139
139
|
* with transformed keys and/or values.
|
|
@@ -144,9 +144,9 @@ declare const getValue: <T extends Record<string, any>>(key: string | [keyof T,
|
|
|
144
144
|
* @param callback - Function that receives [key, value] and returns [newKey, newValue]
|
|
145
145
|
* @returns A new object with transformed entries
|
|
146
146
|
*/
|
|
147
|
-
declare const modObj: <T extends object, R>(obj: T, callback: (
|
|
148
|
-
declare function safeDot<T extends Record<string, any>>(
|
|
149
|
-
declare function safeDot<T extends Record<string, any>, K extends DotNestedKeys<T>>(
|
|
147
|
+
declare const modObj: <T extends object, R>(obj: T, callback: (_entry: [keyof T & string, T[keyof T]]) => [string, R]) => Record<string, R>;
|
|
148
|
+
declare function safeDot<T extends Record<string, any>>(_data: T): T;
|
|
149
|
+
declare function safeDot<T extends Record<string, any>, K extends DotNestedKeys<T>>(_data: T, _key?: K): DotNestedValue<T, K>;
|
|
150
150
|
/**
|
|
151
151
|
* Sets a nested property on an object using dot notation.
|
|
152
152
|
*
|
|
@@ -160,7 +160,7 @@ declare function safeDot<T extends Record<string, any>, K extends DotNestedKeys<
|
|
|
160
160
|
* @param key - The dot-separated key (e.g., 'app.user.name').
|
|
161
161
|
* @param value - The value to set at the specified path.
|
|
162
162
|
*/
|
|
163
|
-
declare const setNested: (obj: Record<string, any>, key: string, value: any) => void
|
|
163
|
+
declare const setNested: (obj: Record<string, any>, key: string, value: any) => void;
|
|
164
164
|
/**
|
|
165
165
|
* Converts object keys to a slugified format (e.g., snake_case).
|
|
166
166
|
*
|
|
@@ -170,7 +170,7 @@ declare const setNested: (obj: Record<string, any>, key: string, value: any) =>
|
|
|
170
170
|
* @param separator - Separator for slugified keys (default: "_")
|
|
171
171
|
* @returns A new object with slugified keys
|
|
172
172
|
*/
|
|
173
|
-
declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator?: string) => KeysToSnakeCase<T
|
|
173
|
+
declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator?: string) => KeysToSnakeCase<T>;
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
176
|
* Get the portion of the string after the first occurrence of the given value.
|
|
@@ -179,7 +179,7 @@ declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator
|
|
|
179
179
|
* @param search
|
|
180
180
|
* @returns
|
|
181
181
|
*/
|
|
182
|
-
declare const after: (value: string, search: string) => string
|
|
182
|
+
declare const after: (value: string, search: string) => string;
|
|
183
183
|
/**
|
|
184
184
|
* Get the portion of the string after the last occurrence of the given value.
|
|
185
185
|
*
|
|
@@ -187,7 +187,7 @@ declare const after: (value: string, search: string) => string
|
|
|
187
187
|
* @param search
|
|
188
188
|
* @returns
|
|
189
189
|
*/
|
|
190
|
-
declare const afterLast: (value: string, search: string) => string
|
|
190
|
+
declare const afterLast: (value: string, search: string) => string;
|
|
191
191
|
/**
|
|
192
192
|
* Get the portion of the string before the first occurrence of the given value.
|
|
193
193
|
*
|
|
@@ -195,7 +195,7 @@ declare const afterLast: (value: string, search: string) => string
|
|
|
195
195
|
* @param search
|
|
196
196
|
* @returns
|
|
197
197
|
*/
|
|
198
|
-
declare const before: (value: string, search: string) => string
|
|
198
|
+
declare const before: (value: string, search: string) => string;
|
|
199
199
|
/**
|
|
200
200
|
* Get the portion of the string before the last occurrence of the given value.
|
|
201
201
|
*
|
|
@@ -203,7 +203,7 @@ declare const before: (value: string, search: string) => string
|
|
|
203
203
|
* @param search
|
|
204
204
|
* @returns
|
|
205
205
|
*/
|
|
206
|
-
declare const beforeLast: (value: string, search: string) => string
|
|
206
|
+
declare const beforeLast: (value: string, search: string) => string;
|
|
207
207
|
/**
|
|
208
208
|
* Capitalizes the first character of a string.
|
|
209
209
|
*
|
|
@@ -218,14 +218,14 @@ declare function capitalize(str: string): string;
|
|
|
218
218
|
* @param count - The number determining pluralization
|
|
219
219
|
* @returns Singular if count === 1, otherwise plural form
|
|
220
220
|
*/
|
|
221
|
-
declare const pluralize: (word: string, count: number) => string
|
|
221
|
+
declare const pluralize: (word: string, count: number) => string;
|
|
222
222
|
/**
|
|
223
223
|
* Converts a plural English word into its singular form.
|
|
224
224
|
*
|
|
225
225
|
* @param word - The word to singularize
|
|
226
226
|
* @returns The singular form of the word
|
|
227
227
|
*/
|
|
228
|
-
declare const singularize: (word: string) => string
|
|
228
|
+
declare const singularize: (word: string) => string;
|
|
229
229
|
/**
|
|
230
230
|
* Converts a string into a slug format.
|
|
231
231
|
* Handles camelCase, spaces, and non-alphanumeric characters.
|
|
@@ -234,7 +234,7 @@ declare const singularize: (word: string) => string
|
|
|
234
234
|
* @param joiner - The character used to join words (default: "_")
|
|
235
235
|
* @returns A slugified string
|
|
236
236
|
*/
|
|
237
|
-
declare const slugify: (str: string, joiner?: string) => string
|
|
237
|
+
declare const slugify: (str: string, joiner?: string) => string;
|
|
238
238
|
/**
|
|
239
239
|
* Truncates a string to a specified length and appends an ellipsis if needed.
|
|
240
240
|
*
|
|
@@ -243,7 +243,7 @@ declare const slugify: (str: string, joiner?: string) => string
|
|
|
243
243
|
* @param ellipsis - String to append if truncated (default: "...")
|
|
244
244
|
* @returns The truncated string
|
|
245
245
|
*/
|
|
246
|
-
declare const subString: (str: string, len: number, ellipsis?: string) => string
|
|
246
|
+
declare const subString: (str: string, len: number, ellipsis?: string) => string;
|
|
247
247
|
/**
|
|
248
248
|
* Replaces placeholders in a string with corresponding values from a data object.
|
|
249
249
|
*
|
|
@@ -256,7 +256,7 @@ declare const subString: (str: string, len: number, ellipsis?: string) => string
|
|
|
256
256
|
* @param def - Default value to use if a key is missing. (Optional)
|
|
257
257
|
* @returns The substituted string or undefined if the input string or data is invalid.
|
|
258
258
|
*/
|
|
259
|
-
declare const substitute: (str: string, data?: Record<string, unknown>, def?: string) => string | undefined
|
|
259
|
+
declare const substitute: (str: string, data?: Record<string, unknown>, def?: string) => string | undefined;
|
|
260
260
|
/**
|
|
261
261
|
* Truncates a string to a specified length, removing HTML tags and
|
|
262
262
|
* appending a suffix if the string exceeds the length.
|
|
@@ -266,6 +266,6 @@ declare const substitute: (str: string, data?: Record<string, unknown>, def?: st
|
|
|
266
266
|
* @param suffix - Suffix to append if truncated (default: "...")
|
|
267
267
|
* @returns The truncated string
|
|
268
268
|
*/
|
|
269
|
-
declare const truncate: (str: string, len?: number, suffix?: string) => string
|
|
269
|
+
declare const truncate: (str: string, len?: number, suffix?: string) => string;
|
|
270
270
|
|
|
271
|
-
export { type CamelToSnakeCase, type DotFlatten, type DotNestedKeys, type DotNestedValue, type KeysToSnakeCase, abbreviate, after, afterLast, before, beforeLast, capitalize, chunk, dot, extractProperties, getValue, humanize, modObj, pluralize, range, safeDot, setNested, singularize, slugify, slugifyKeys, subString, substitute, toBytes, toHumanTime, truncate }
|
|
271
|
+
export { type CamelToSnakeCase, type DotFlatten, type DotNestedKeys, type DotNestedValue, type KeysToSnakeCase, abbreviate, after, afterLast, before, beforeLast, capitalize, chunk, dot, extractProperties, getValue, humanize, modObj, pluralize, range, safeDot, setNested, singularize, slugify, slugifyKeys, subString, substitute, toBytes, toHumanTime, truncate };
|