@seedcord/utils 0.3.8 → 0.4.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/README.md +2 -2
- package/dist/index.cjs +490 -273
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -265
- package/dist/index.d.mts +759 -0
- package/dist/index.mjs +461 -254
- package/dist/index.mjs.map +1 -1
- package/package.json +24 -20
- package/dist/index.d.ts +0 -265
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/misc/directory.ts","../src/misc/fyShuffle.ts","../src/numbers/currentTime.ts","../src/numbers/generateCode.ts","../src/numbers/hexToNumber.ts","../src/numbers/ordinal.ts","../src/numbers/percentage.ts","../src/numbers/round.ts","../src/numbers/roundToDenomination.ts","../src/objects/filterCirculars.ts","../src/objects/keepDefined.ts","../src/strings/capitalize.ts","../src/strings/longestStringLength.ts","../src/strings/generateAsciiTable.ts","../src/strings/prettify.ts","../src/strings/prettyDifference.ts"],"names":["isTsOrJsFile","entry","isFile","name","endsWith","traverseDirectory","dir","callback","logger","entries","readdir","withFileTypes","error","fullPath","join","relativePath","relative","process","cwd","isDirectory","imported","fyShuffle","items","array","slice","i","length","j","Math","floor","random","currentTime","Date","now","generateCode","digits","min","pow","max","hexToNumber","hex","SeedcordTypeError","SeedcordErrorCode","UtilHexInputType","normalized","replace","test","SeedcordError","UtilHexInvalid","converted","parseInt","Number","isNaN","ordinal","n","s","v","index","suffix","percentage","num1","num2","toFixed","round","num","precision","factor","EPSILON","roundToDenomination","opts","suffixes","toString","temp","result","adjustedTemp","ceil","substring","filterCirculars","value","options","marker","mode","json","decycle","seen","WeakSet","JSON","stringify","_k","obj","has","add","Object","keys","parse","input","recur","val","t","toISOString","RegExp","Array","isArray","map","item","Map","from","k","Set","out","keepDefined","source","selectedKeys","key","undefined","capitalize","word","charAt","toUpperCase","toLowerCase","longestStringLength","arr","el","generateAsciiTable","data","firstRow","table","columnWidths","maxWidth","row","cell","push","createLine","char","left","intersect","right","line","forEach","width","repeat","rowIndex","columnIndex","columnWidth","padEnd","prettify","trim","prettyDifference","numBefore","numAfter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWO,SAASA,aAAaC,KAAAA,EAAgB;AACzC,EAAA,OACIA,KAAAA,CAAMC,QAAM,KACXD,KAAAA,CAAME,KAAKC,QAAAA,CAAS,KAAA,CAAA,IAAUH,KAAAA,CAAME,IAAAA,CAAKC,QAAAA,CAAS,KAAA,CAAA,CAAA,IACnD,CAACH,KAAAA,CAAME,IAAAA,CAAKC,QAAAA,CAAS,OAAA,KACrB,CAACH,KAAAA,CAAME,IAAAA,CAAKC,QAAAA,CAAS,MAAA,CAAA;AAE7B;AAPgBJ,MAAAA,CAAAA,YAAAA,EAAAA,cAAAA,CAAAA;AAgBhB,eAAsBK,iBAAAA,CAClBC,GAAAA,EACAC,QAAAA,EACAC,MAAAA,EAAc;AAEd,EAAA,IAAIC,OAAAA;AAEJ,EAAA,IAAI;AACAA,IAAAA,OAAAA,GAAU,MAAMC,iBAAQJ,GAAAA,EAAK;MAAEK,aAAAA,EAAe;KAAK,CAAA;EACvD,CAAA,CAAA,MAAQ;AACJH,IAAAA,MAAAA,CAAOI,MAAM,+BAAA,CAAA;AACbH,IAAAA,OAAAA,GAAU,EAAA;AACd,EAAA;AAEA,EAAA,KAAA,MAAWR,SAASQ,OAAAA,EAAS;AACzB,IAAA,MAAMI,QAAAA,GAAgBC,eAAAA,CAAAA,IAAAA,CAAKR,GAAAA,EAAKL,KAAAA,CAAME,IAAI,CAAA;AAC1C,IAAA,MAAMY,YAAAA,GAAoBC,eAAAA,CAAAA,QAAAA,CAASC,OAAAA,CAAQC,GAAAA,IAAOL,QAAAA,CAAAA;AAElD,IAAA,IAAIZ,KAAAA,CAAMkB,aAAW,EAAI;AACrB,MAAA,MAAMd,iBAAAA,CAAkBQ,QAAAA,EAAUN,QAAAA,EAAUC,MAAA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;ACTT,SAASE,gBAAAA,CAAiBC,WAAmBC,QAAAA,EAAgB;AAChE,EAAA,OAAA,CAAQA,QAAAA,GAAWD,YAAY,CAAA,GAAI,CAAA,CAAA,EAAIC,WAAWD,SAAAA,CAAAA,CAAAA,GAAcC,QAAAA,GAAWD,SAAAA,EAAW7E,QAAAA,EAAQ;AAClG;AAFgB4E,MAAAA,CAAAA,gBAAAA,EAAAA,kBAAAA,CAAAA","file":"index.cjs","sourcesContent":["import { readdir } from 'node:fs/promises';\nimport * as path from 'node:path';\n\nimport type { Logger } from '@seedcord/services';\nimport type * as fs from 'node:fs';\n/**\n * Determines if a directory entry is a TypeScript or JavaScript file.\n *\n * @param entry - The directory entry to check.\n * @returns True if the entry is a file ending with .ts or .js.\n */\nexport function isTsOrJsFile(entry: fs.Dirent): boolean {\n return (\n entry.isFile() &&\n (entry.name.endsWith('.ts') || entry.name.endsWith('.js')) &&\n !entry.name.endsWith('.d.ts') &&\n !entry.name.endsWith('.map')\n );\n}\n\n/**\n * Recursively traverses through a directory, importing all .ts and .js files and applying a callback to each import.\n *\n * @param dir - The directory path to traverse.\n * @param callback - A function that will be called for each imported module. It receives the full file path, the file's relative path, and the imported module as arguments.\n * @returns A Promise that resolves when the traversal is complete.\n */\nexport async function traverseDirectory(\n dir: string,\n callback: (fullPath: string, relativePath: string, imported: Record<string, unknown>) => Promise<void> | void,\n logger: Logger\n): Promise<void> {\n let entries: fs.Dirent[];\n\n try {\n entries = await readdir(dir, { withFileTypes: true });\n } catch {\n logger.error('Failed to read this directory');\n entries = [];\n }\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n const relativePath = path.relative(process.cwd(), fullPath);\n\n if (entry.isDirectory()) {\n await traverseDirectory(fullPath, callback, logger);\n } else if (isTsOrJsFile(entry)) {\n const imported = (await import(fullPath)) as Record<string, unknown>;\n await callback(fullPath, relativePath, imported);\n }\n }\n}\n","/**\n * Shuffles an array using the Fisher-Yates algorithm.\n * This function creates a new array with the same elements in a random order,\n * without modifying the original array.\n *\n * @typeParam TArray - The type of elements in the array\n * @param items - The array to shuffle\n * @returns A new array with the same elements in a random order\n *\n * @example\n * ```typescript\n * const numbers = [1, 2, 3, 4, 5];\n * const shuffled = fyShuffle(numbers);\n * // shuffled might be [3, 1, 5, 2, 4]\n * // numbers is still [1, 2, 3, 4, 5]\n * ```\n */\nexport function fyShuffle<TArray>(items: TArray[]): TArray[] {\n const array = items.slice();\n for (let i = array.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n // @ts-expect-error - TypeScript doesn't recognize that TArray can be swapped\n [array[i], array[j]] = [array[j], array[i]];\n }\n return array;\n}\n","/**\n * Return current time in seconds\n */\nexport function currentTime(): number {\n return Math.floor(Date.now() / 1000);\n}\n","/**\n * Generates a random numeric code with the specified number of digits.\n *\n * @param digits - The number of digits for the generated code.\n * @returns A random numeric code with the specified number of digits.\n */\nexport function generateCode(digits: number): number {\n const min = Math.pow(10, digits - 1);\n const max = Math.pow(10, digits) - 1;\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n","import { SeedcordError, SeedcordErrorCode, SeedcordTypeError } from '@seedcord/services';\n\n/**\n * Converts hexcode to number\n *\n * @param hex - The hex code to convert.\n * @returns The converted number.\n */\nexport function hexToNumber(hex: string): number {\n if (typeof hex !== 'string') {\n throw new SeedcordTypeError(SeedcordErrorCode.UtilHexInputType);\n }\n\n const normalized = hex.replace(/^#/, '');\n if (!/^[0-9a-fA-F]+$/.test(normalized)) {\n throw new SeedcordError(SeedcordErrorCode.UtilHexInvalid);\n }\n\n const converted = parseInt(normalized, 16);\n if (Number.isNaN(converted)) {\n throw new SeedcordError(SeedcordErrorCode.UtilHexInvalid);\n }\n\n return converted;\n}\n","/**\n * Returns the ordinal suffix for a given number.\n *\n * @param n - The number to get the ordinal for\n * @returns The number with its ordinal suffix\n *\n * @example\n * ordinal(1); // \"1st\"\n * ordinal(22); // \"22nd\"\n * ordinal(13); // \"13th\"\n */\nexport function ordinal(n: number): string {\n const s = ['th', 'st', 'nd', 'rd'];\n const v = n % 100;\n const index = (v - 20) % 10;\n const suffix = s[index] ?? s[v] ?? s[0];\n if (!suffix) return `${n}th`;\n\n return `${n}${suffix}`;\n}\n","/**\n * Takes two numbers and returns the percentage of the first number in the second number with two decimal places.\n *\n * @param num1 - The first number.\n * @param num2 - The second number.\n *\n * @returns The percentage of the first number in the second number with two decimal places.\n */\nexport function percentage(num1: number, num2: number): number {\n return Number(((num1 / num2) * 100).toFixed(2));\n}\n","/**\n * Rounds a number to a specified number of decimal places.\n *\n * @param num - The number to be rounded.\n * @param precision - The number of decimal places to round to.\n * @returns The rounded number.\n */\nexport function round(num: number, precision: number): number {\n const factor = Math.pow(10, precision);\n return Math.round((num + Number.EPSILON) * factor) / factor;\n}\n","import type { TupleOf } from 'type-fest';\n\nexport interface RoundToDenomOptions {\n /**\n * Suffixes to use for each denomination level. Defaults to `['K', 'M', 'B', 'T', 'Q']`.\n */\n suffixes?: TupleOf<5, string>;\n /** Number of decimal places to include in the rounded result. Defaults to `1`. */\n precision?: number;\n}\n\n/**\n * Rounds a number to a string representation with a denomination suffix.\n * @param num - The number to round.\n * @example\n * ```ts\n * roundToDenomination(1234); // \"1.2K\"\n * roundToDenomination(10000, ['k', 'm', 'b', 't', 'q']); // \"10k\"\n * roundToDenomination(12345678); // \"12.3M\"\n * ```\n * @returns The rounded number as a string with a denomination suffix.\n */\nexport function roundToDenomination(num: number, opts?: RoundToDenomOptions): string {\n const { suffixes = ['K', 'M', 'B', 'T', 'Q'], precision = 1 } = opts ?? {};\n\n if (num < 10000) {\n return num.toString();\n }\n\n let index = -1;\n let temp = num;\n\n while (temp >= 1000 && index < suffixes.length - 1) {\n temp /= 1000;\n index++;\n }\n\n let result;\n\n if (temp % 1 === 0) {\n result = temp.toString();\n } else {\n const adjustedTemp = Math.round(temp * Math.pow(10, precision + 1)) / Math.pow(10, precision + 1);\n result = adjustedTemp.toFixed(precision);\n }\n\n if (result.endsWith('.9')) {\n result = Math.ceil(Number(result)).toString();\n }\n\n if (result.endsWith('.0')) {\n result = result.substring(0, result.length - 2);\n }\n\n if (result === '1000') {\n index += 1;\n result = '1';\n }\n\n return result + (index >= 0 ? suffixes[index] : '');\n}\n","import type { ILogger } from '@seedcord/types';\nimport type { JsonPrimitive } from 'type-fest';\n\n/**\n * JSONify an arbitrary type while allowing any object position to be replaced\n * by a circular marker. Optional keys stay optional.\n */\nexport type JsonifyWithCirculars<BaseType, Marker extends string = '[Circular]'> = BaseType extends JsonPrimitive\n ? BaseType\n : BaseType extends bigint\n ? string\n : BaseType extends Date\n ? string\n : BaseType extends { toJSON(): infer J }\n ? unknown extends J\n ? JsonifyObject<BaseType, Marker>\n : JsonifyWithCirculars<J, Marker>\n : BaseType extends readonly (infer U)[]\n ? (JsonifyWithCirculars<U, Marker> | Marker)[]\n : BaseType extends Map<infer K, infer V>\n ? [JsonifyWithCirculars<K, Marker> | Marker, JsonifyWithCirculars<V, Marker> | Marker][]\n : BaseType extends Set<infer U2>\n ? (JsonifyWithCirculars<U2, Marker> | Marker)[]\n : BaseType extends (...args: unknown[]) => unknown\n ? never\n : BaseType extends object\n ? JsonifyObject<BaseType, Marker>\n : never;\n\n/**\n * Helper to JSONify object types with circular markers.\n *\n * @internal\n */\nexport type JsonifyObject<BaseType, Marker extends string> = {\n [K in keyof BaseType as K extends symbol\n ? never\n : BaseType[K] extends (...args: unknown[]) => unknown\n ? never\n : K]:\n | JsonifyWithCirculars<Exclude<BaseType[K], undefined>, Marker>\n | Extract<BaseType[K], undefined>\n | Marker;\n};\n\n/**\n * Configuration for {@link filterCirculars}.\n */\nexport interface FilterCircularsOptions<Marker extends string = '[Circular]'> {\n /** Optional {@link ILogger} used to log stringify or parse errors. */\n logger?: ILogger;\n /** Override the circular placeholder. Default is `[Circular]`. */\n marker?: Marker;\n /** Processing mode. `json` uses stringify and parse (might end up using a `toJSON()` if found). `decycle` builds a safe clone first. Default is `decycle`. */\n mode?: 'json' | 'decycle';\n}\n\n/**\n * Creates a clean, JSON safe copy of a value and replaces circular references with a marker.\n *\n * In `json` mode it behaves like stringify then parse with a replacer that handles cycles and BigInt.\n * In `decycle` mode it first clones without using toJSON, then you can stringify the result later.\n *\n * @typeParam ObjType - Type of the input value.\n * @typeParam Marker - Marker string used for circular references.\n *\n * @param value - The value to clone safely.\n * @param options - Optional configuration.\n *\n * @returns A JSON safe structure with circular references replaced by the marker.\n *\n * @example\n * ```ts\n * interface Test {\n * name: string;\n * self?: Test;\n * }\n *\n * const obj: Test = { name: 'seedcord' };\n * obj.self = obj;\n *\n * const clean = filterCirculars(obj);\n * // ^? { name: string; self?: \"[Circular]\" | { ... } }\n * console.log(clean.self); // \"[Circular]\"\n * ```\n */\nexport function filterCirculars<ObjType, Marker extends string = '[Circular]'>(\n value: ObjType,\n options?: FilterCircularsOptions<Marker>\n): JsonifyWithCirculars<ObjType, Marker> {\n const logger = options?.logger;\n const marker = (options?.marker ?? '[Circular]') as Marker;\n const mode = options?.mode ?? 'decycle';\n\n if (mode === 'json') return json(value, marker, logger);\n\n try {\n return decycle(value, marker);\n } catch (error) {\n logger?.error('filterCirculars decycle error', error);\n return value as JsonifyWithCirculars<ObjType, Marker>;\n }\n}\n\n/**\n * Attempts to build a JSONified object using JSON.stringify and JSON.parse.\n *\n * @internal\n */\nfunction json<ObjType, Marker extends string>(\n value: ObjType,\n marker: Marker,\n logger?: ILogger\n): JsonifyWithCirculars<ObjType, Marker> {\n const seen = new WeakSet<object>();\n let json: string | undefined;\n\n try {\n json = JSON.stringify(value, (_k: string, v: unknown) => {\n if (typeof v === 'bigint') return v.toString();\n if (typeof v === 'object' && v !== null) {\n const obj = v;\n if (seen.has(obj)) return marker;\n seen.add(obj);\n }\n return v;\n });\n } catch (error) {\n logger?.error('filterCirculars stringify error', error);\n if (typeof value === 'object' && value !== null) {\n logger?.error('top level keys', Object.keys(value as Record<string, unknown>));\n }\n return value as JsonifyWithCirculars<ObjType, Marker>;\n }\n\n if (typeof json !== 'string') {\n return value as JsonifyWithCirculars<ObjType, Marker>;\n }\n\n try {\n return JSON.parse(json) as JsonifyWithCirculars<ObjType, Marker>;\n } catch (error) {\n logger?.error('filterCirculars parse error', error);\n logger?.error('bad JSON', json);\n return value as JsonifyWithCirculars<ObjType, Marker>;\n }\n}\n\n/**\n * Builds a JSON safe clone without calling toJSON on class instances.\n *\n * @internal\n */\nfunction decycle<ObjType, Marker extends string = '[Circular]'>(\n input: ObjType,\n marker: Marker,\n seen = new WeakSet<object>()\n): JsonifyWithCirculars<ObjType, Marker> {\n const recur = (val: unknown): unknown => {\n if (val === null) return null;\n const t = typeof val;\n\n // if bigint, return string representation\n if (t === 'bigint') return (val as bigint).toString();\n\n // if primitive, return as is\n if (t !== 'object') return val;\n\n const obj = val as Record<string | number | symbol, unknown>;\n\n if (seen.has(obj)) return marker;\n seen.add(obj);\n\n // if Date, return ISO string\n if (obj instanceof Date) return obj.toISOString();\n\n // if RegExp, return string representation\n if (obj instanceof RegExp) return obj.toString();\n\n // if array, recur on each item\n if (Array.isArray(obj)) {\n return obj.map((item) => recur(item));\n }\n\n // if Map, recur on entries/values\n if (obj instanceof Map) {\n return Array.from(obj, ([k, v]) => [recur(k), recur(v)]);\n }\n\n // if Set, recur on values\n if (obj instanceof Set) {\n return Array.from(obj, (v) => recur(v));\n }\n\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n if (typeof v === 'function') continue;\n out[k] = recur(v);\n }\n\n return out;\n };\n\n return recur(input) as JsonifyWithCirculars<ObjType, Marker>;\n}\n","/**\n * Pulls out only the keys from an object that actually have values.\n *\n * @typeParam TObject - the original object type you're pulling from\n * @typeParam TKey - the specific keys you want to copy if they're defined\n * @param source - the object to read values from\n * @param keys - optional list of keys you want to include if they exist. If omitted, all keys are considered\n *\n * @example\n * ```ts\n * interface Config {\n * host?: string;\n * port?: number;\n * user?: string;\n * password?: string;\n * }\n *\n * const config: Config = {\n * host: 'localhost',\n * port: undefined,\n * user: 'admin',\n * password: undefined\n * };\n *\n * const definedConfig = keepDefined(config, 'host', 'port', 'user', 'password');\n * // Result: { host: 'localhost', user: 'admin' }\n * ```\n */\nexport function keepDefined<TObject extends object, TKey extends keyof TObject>(\n source: TObject,\n ...keys: readonly TKey[]\n): Partial<Pick<TObject, TKey extends never ? keyof TObject : TKey>> {\n const selectedKeys = keys.length > 0 ? keys : (Object.keys(source) as TKey[]);\n const result: Partial<TObject> = {};\n\n for (const key of selectedKeys) {\n const value = source[key];\n if (value !== undefined && value !== null) {\n result[key] = value;\n }\n }\n return result;\n}\n","/**\n * Returns the word with its first letter capitalized and the rest in lowercase.\n * @param word - The word to be formatted.\n * @returns The formatted word.\n */\nexport function capitalize(word: string): string {\n return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n}\n","/**\n * Function takes an array of strings or numbers and returns the number of characters in the longest string/number\n *\n * @param arr - The array of strings or numbers\n * @returns The length of the longest element when converted to string\n */\nexport function longestStringLength(arr: (string | number)[]): number {\n return Math.max(...arr.map((el) => el.toString().length));\n}\n","/**\n * Generates an ASCII table from the provided data.\n *\n * @param data - The data to be displayed in the table.\n * @returns The generated ASCII table as a string.\n */\nexport function generateAsciiTable(data: string[][]): string {\n if (data.length === 0) return '';\n\n const firstRow = data[0];\n if (!firstRow || firstRow.length === 0) return '';\n\n let table = '';\n const columnWidths: number[] = [];\n\n // Determine the maximum width for each column\n for (let i = 0; i < firstRow.length; i++) {\n let maxWidth = 0;\n for (const row of data) {\n const cell = row[i];\n if (cell !== undefined) maxWidth = Math.max(maxWidth, cell.length);\n }\n columnWidths.push(maxWidth);\n }\n\n // Function to create a horizontal line\n const createLine = (char: string, left: string, intersect: string, right: string): string => {\n let line = left;\n columnWidths.forEach((width, index) => {\n line += char.repeat(width + 2);\n if (index < columnWidths.length - 1) line += intersect;\n else line += right;\n });\n line += '\\n';\n return line;\n };\n\n // Top border\n table += createLine('═', '╔', '╦', '╗');\n\n data.forEach((row, rowIndex) => {\n // Row content\n table += '║';\n row.forEach((cell, columnIndex) => {\n const columnWidth = columnWidths[columnIndex];\n if (columnWidth !== undefined) table += ` ${cell.padEnd(columnWidth)} ║`;\n });\n table += '\\n';\n\n // Separator or bottom border\n if (rowIndex < data.length - 1) table += createLine('─', '╠', '╬', '╣');\n else table += createLine('═', '╚', '╩', '╝');\n });\n\n return table;\n}\n","import { capitalize } from './capitalize';\n\n/**\n * Options for the `prettify` function.\n */\nexport interface PrettifyOptions {\n capitalize?: boolean;\n}\n/**\n * Converts a string from any common naming convention to human-readable format.\n * Handles camelCase, PascalCase, snake_case, and kebab-case.\n *\n * @param key - The string to convert\n * @param opts - Optional configuration\n * @returns A space-separated, human-readable string\n *\n * @example\n * prettify(\"camelCaseString\") // \"camel Case String\"\n * prettify(\"PascalCaseString\") // \"Pascal Case String\"\n * prettify(\"snake_case_string\") // \"snake case string\"\n * prettify(\"kebab-case-string\") // \"kebab case string\"\n * prettify(\"mixedCase_string-name\") // \"mixed Case string name\"\n */\n\nexport function prettify(key: string, opts?: PrettifyOptions): string {\n const result = key\n .replace(/([a-z])([A-Z])/g, '$1 $2') // camelCase/PascalCase\n .replace(/[_-]/g, ' ') // snake_case and kebab-case\n .trim();\n\n if (opts?.capitalize) return capitalize(result);\n\n return result;\n}\n","/**\n * Calculates the difference between two numbers and formats it as a string with a '+' prefix for positive differences.\n *\n * @param numBefore - The initial number value\n * @param numAfter - The final number value\n * @returns A string representing the difference, with a '+' sign for positive differences\n *\n * @example\n * // Returns \"+5\"\n * prettyDifference(10, 15);\n *\n * @example\n * // Returns \"-3\"\n * prettyDifference(10, 7);\n */\nexport function prettyDifference(numBefore: number, numAfter: number): string {\n return (numAfter - numBefore > 0 ? `+${numAfter - numBefore}` : numAfter - numBefore).toString();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["path"],"sources":["../src/misc/assertNever.ts","../src/misc/directory.ts","../src/misc/fyShuffle.ts","../src/numbers/currentTime.ts","../src/numbers/generateCode.ts","../src/numbers/ordinal.ts","../src/numbers/percentage.ts","../src/numbers/round.ts","../src/numbers/roundToDenomination.ts","../src/objects/filterCirculars.ts","../src/objects/hasKeys.ts","../src/objects/keepDefined.ts","../src/strings/capitalize.ts","../src/strings/longestStringLength.ts","../src/strings/generateAsciiTable.ts","../src/strings/prettify.ts","../src/strings/prettyDifference.ts","../src/index.ts"],"sourcesContent":["/**\n * Exhaustiveness guard for discriminated unions. Place in the `default` branch of a `switch` over a\n * union's discriminant: if a new variant is added without a matching case, the call fails to compile.\n * Throws at runtime if reached with a value the types said was impossible.\n */\nexport function assertNever(value: never): never {\n throw new Error(`Unhandled discriminated union member: ${JSON.stringify(value)}`);\n}\n","import { readdir } from 'node:fs/promises';\nimport * as path from 'node:path';\n\nimport type { ILogger } from '@seedcord/types';\nimport type * as fs from 'node:fs';\n\n/**\n * Determines if a directory entry is a TypeScript or JavaScript file.\n *\n * @param entry - The directory entry to check.\n * @returns True if the entry is a file ending with .ts or .js.\n */\nexport function isTsOrJsFile(entry: fs.Dirent): boolean {\n return (\n entry.isFile() &&\n (entry.name.endsWith('.ts') || entry.name.endsWith('.js')) &&\n !entry.name.endsWith('.d.ts') &&\n !entry.name.endsWith('.map')\n );\n}\n\n/**\n * Recursively traverses through a directory, importing all .ts and .js files and applying a callback to each import.\n *\n * @param dir - The directory path to traverse.\n * @param callback - A function that will be called for each imported module. It receives the full file path, the file's relative path, and the imported module as arguments.\n * @returns A Promise that resolves when the traversal is complete.\n */\nexport async function traverseDirectory(\n dir: string,\n callback: (fullPath: string, relativePath: string, imported: Record<string, unknown>) => Promise<void> | void,\n logger: ILogger\n): Promise<void> {\n let entries: fs.Dirent[];\n\n try {\n entries = await readdir(dir, { withFileTypes: true });\n } catch (err) {\n logger.error(`Failed to read directory ${dir}`, err);\n entries = [];\n }\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n const relativePath = path.relative(process.cwd(), fullPath);\n\n if (entry.isDirectory()) {\n await traverseDirectory(fullPath, callback, logger);\n } else if (isTsOrJsFile(entry)) {\n const imported = (await import(fullPath)) as Record<string, unknown>;\n await callback(fullPath, relativePath, imported);\n }\n }\n}\n\n/**\n * Options for formatting file paths.\n */\nexport interface FormatFileOptions {\n /**\n * Whether to return only the directory part of the path. {@default false}\n */\n onlyDir?: boolean;\n /**\n * A prefix to prepend to the formatted path. {@default ./}\n */\n prefix?: string;\n}\n\n/**\n * Formats a file path relative to the current working directory.\n * @param filePath - The file path to format.\n * @param options - Formatting options.\n * @returns The formatted file path.\n */\nexport function formatFilePath(filePath: string, options: FormatFileOptions = {}): string {\n const { onlyDir = false, prefix = './' } = options;\n\n const resolved = onlyDir\n ? path.relative(process.cwd(), filePath.replace(/\\/[^/]*$/, ''))\n : path.relative(process.cwd(), filePath);\n return `${prefix}${resolved}`;\n}\n","/**\n * Shuffles an array using the Fisher-Yates algorithm.\n * This function creates a new array with the same elements in a random order,\n * without modifying the original array.\n *\n * @typeParam TArray - The type of elements in the array\n * @param items - The array to shuffle\n * @returns A new array with the same elements in a random order\n *\n * @example\n * ```typescript\n * const numbers = [1, 2, 3, 4, 5];\n * const shuffled = fyShuffle(numbers);\n * // shuffled might be [3, 1, 5, 2, 4]\n * // numbers is still [1, 2, 3, 4, 5]\n * ```\n */\nexport function fyShuffle<TArray>(items: TArray[]): TArray[] {\n const array = items.slice();\n for (let i = array.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n // @ts-expect-error - TypeScript doesn't recognize that TArray can be swapped\n [array[i], array[j]] = [array[j], array[i]];\n }\n return array;\n}\n","/**\n * Return current time in seconds\n */\nexport function currentTime(): number {\n return Math.floor(Date.now() / 1000);\n}\n","/**\n * Generates a random numeric code with the specified number of digits.\n *\n * @param digits - The number of digits for the generated code.\n * @returns A random numeric code with the specified number of digits.\n */\nexport function generateCode(digits: number): number {\n const min = Math.pow(10, digits - 1);\n const max = Math.pow(10, digits) - 1;\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n","/**\n * Returns the ordinal suffix for a given number.\n *\n * @param n - The number to get the ordinal for\n * @returns The number with its ordinal suffix\n *\n * @example\n * ordinal(1); // \"1st\"\n * ordinal(22); // \"22nd\"\n * ordinal(13); // \"13th\"\n */\nexport function ordinal(n: number): string {\n const s = ['th', 'st', 'nd', 'rd'];\n const v = n % 100;\n const index = (v - 20) % 10;\n const suffix = s[index] ?? s[v] ?? s[0];\n if (!suffix) return `${n}th`;\n\n return `${n}${suffix}`;\n}\n","/**\n * Takes two numbers and returns the percentage of the first number in the second number with two decimal places.\n *\n * @param num1 - The first number.\n * @param num2 - The second number.\n *\n * @returns The percentage of the first number in the second number with two decimal places.\n */\nexport function percentage(num1: number, num2: number): number {\n return Number(((num1 / num2) * 100).toFixed(2));\n}\n","/**\n * Rounds a number to a specified number of decimal places.\n *\n * @param num - The number to be rounded.\n * @param precision - The number of decimal places to round to.\n * @returns The rounded number.\n */\nexport function round(num: number, precision: number): number {\n const factor = Math.pow(10, precision);\n return Math.round((num + Number.EPSILON) * factor) / factor;\n}\n","import type { TupleOf } from 'type-fest';\n\nexport interface RoundToDenomOptions {\n /**\n * Suffixes to use for each denomination level. Defaults to `['K', 'M', 'B', 'T', 'Q']`.\n */\n suffixes?: TupleOf<5, string>;\n /** Number of decimal places to include in the rounded result. Defaults to `1`. */\n precision?: number;\n}\n\n/**\n * Rounds a number to a string representation with a denomination suffix.\n * @param num - The number to round.\n * @example\n * ```ts\n * roundToDenomination(1234); // \"1.2K\"\n * roundToDenomination(10000, ['k', 'm', 'b', 't', 'q']); // \"10k\"\n * roundToDenomination(12345678); // \"12.3M\"\n * ```\n * @returns The rounded number as a string with a denomination suffix.\n */\nexport function roundToDenomination(num: number, opts?: RoundToDenomOptions): string {\n const { suffixes = ['K', 'M', 'B', 'T', 'Q'], precision = 1 } = opts ?? {};\n\n if (num < 10000) {\n return num.toString();\n }\n\n let index = -1;\n let temp = num;\n\n while (temp >= 1000 && index < suffixes.length - 1) {\n temp /= 1000;\n index++;\n }\n\n let result;\n\n if (temp % 1 === 0) {\n result = temp.toString();\n } else {\n const adjustedTemp = Math.round(temp * Math.pow(10, precision + 1)) / Math.pow(10, precision + 1);\n result = adjustedTemp.toFixed(precision);\n }\n\n if (result.endsWith('.9')) {\n result = Math.ceil(Number(result)).toString();\n }\n\n if (result.endsWith('.0')) {\n result = result.substring(0, result.length - 2);\n }\n\n if (result === '1000') {\n index += 1;\n result = '1';\n }\n\n return result + (index >= 0 ? suffixes[index] : '');\n}\n","import type { ILogger } from '@seedcord/types';\nimport type { JsonPrimitive } from 'type-fest';\n\n/**\n * JSONify an arbitrary type while allowing any object position to be replaced\n * by a circular marker. Optional keys stay optional.\n */\nexport type JsonifyWithCirculars<BaseType, Marker extends string = '[Circular]'> = BaseType extends JsonPrimitive\n ? BaseType\n : BaseType extends bigint\n ? string\n : BaseType extends Date\n ? string\n : BaseType extends { toJSON(): infer J }\n ? unknown extends J\n ? JsonifyObject<BaseType, Marker>\n : JsonifyWithCirculars<J, Marker>\n : BaseType extends readonly (infer U)[]\n ? (JsonifyWithCirculars<U, Marker> | Marker)[]\n : BaseType extends Map<infer K, infer V>\n ? [JsonifyWithCirculars<K, Marker> | Marker, JsonifyWithCirculars<V, Marker> | Marker][]\n : BaseType extends Set<infer U2>\n ? (JsonifyWithCirculars<U2, Marker> | Marker)[]\n : BaseType extends (...args: unknown[]) => unknown\n ? never\n : BaseType extends object\n ? JsonifyObject<BaseType, Marker>\n : never;\n\n/**\n * Helper to JSONify object types with circular markers.\n *\n * @internal\n */\nexport type JsonifyObject<BaseType, Marker extends string> = {\n [K in keyof BaseType as K extends symbol\n ? never\n : BaseType[K] extends (...args: unknown[]) => unknown\n ? never\n : K]:\n | JsonifyWithCirculars<Exclude<BaseType[K], undefined>, Marker>\n | Extract<BaseType[K], undefined>\n | Marker;\n};\n\n/**\n * Returned by {@link filterCirculars} when a value cannot be made JSON-safe. The original value is\n * never returned on failure, because it would re-throw in the caller's own `JSON.stringify`.\n */\nexport interface UnserializableValue {\n '[unserializable]': string;\n}\n\n/**\n * Configuration for {@link filterCirculars}.\n */\nexport interface FilterCircularsOptions<Marker extends string = '[Circular]'> {\n /** Optional {@link ILogger} used to log stringify or parse errors. */\n logger?: ILogger;\n /** Override the circular placeholder. Default is `[Circular]`. */\n marker?: Marker;\n /** Processing mode. `json` uses stringify and parse (might end up using a `toJSON()` if found). `decycle` builds a safe clone first. Default is `decycle`. */\n mode?: 'json' | 'decycle';\n}\n\n/**\n * Creates a clean, JSON safe copy of a value and replaces circular references with a marker.\n *\n * In `json` mode it behaves like stringify then parse with a replacer that handles cycles and BigInt.\n * In `decycle` mode it first clones without using toJSON, then you can stringify the result later.\n *\n * @typeParam ObjType - Type of the input value.\n * @typeParam Marker - Marker string used for circular references.\n *\n * @param value - The value to clone safely.\n * @param options - Optional configuration.\n *\n * @returns A JSON safe structure with circular references replaced by the marker.\n *\n * @example\n * ```ts\n * interface Test {\n * name: string;\n * self?: Test;\n * }\n *\n * const obj: Test = { name: 'seedcord' };\n * obj.self = obj;\n *\n * const clean = filterCirculars(obj);\n * // ^? { name: string; self?: \"[Circular]\" | { ... } }\n * console.log(clean.self); // \"[Circular]\"\n * ```\n */\nexport function filterCirculars<ObjType, Marker extends string = '[Circular]'>(\n value: ObjType,\n options?: FilterCircularsOptions<Marker>\n): JsonifyWithCirculars<ObjType, Marker> | UnserializableValue {\n const logger = options?.logger;\n const marker = (options?.marker ?? '[Circular]') as Marker;\n const mode = options?.mode ?? 'decycle';\n\n if (mode === 'json') return json(value, marker, logger);\n\n try {\n return decycle(value, marker);\n } catch (error) {\n logger?.error('filterCirculars decycle error', error);\n return { '[unserializable]': 'decycle failed' };\n }\n}\n\n/**\n * Attempts to build a JSONified object using JSON.stringify and JSON.parse.\n *\n * @internal\n */\nfunction json<ObjType, Marker extends string>(\n value: ObjType,\n marker: Marker,\n logger?: ILogger\n): JsonifyWithCirculars<ObjType, Marker> | UnserializableValue {\n const seen = new WeakSet<object>();\n let json: string | undefined;\n\n try {\n json = JSON.stringify(value, (_k: string, v: unknown) => {\n if (typeof v === 'bigint') return v.toString();\n if (typeof v === 'object' && v !== null) {\n const obj = v;\n if (seen.has(obj)) return marker;\n seen.add(obj);\n }\n return v;\n });\n } catch (error) {\n logger?.error('filterCirculars stringify error', error);\n if (typeof value === 'object' && value !== null) {\n logger?.error('top level keys', Object.keys(value));\n }\n return { '[unserializable]': 'stringify failed' };\n }\n\n if (typeof json !== 'string') {\n return { '[unserializable]': 'stringify returned undefined' };\n }\n\n try {\n return JSON.parse(json) as JsonifyWithCirculars<ObjType, Marker>;\n } catch (error) {\n logger?.error('filterCirculars parse error', error);\n logger?.error('bad JSON', json);\n return { '[unserializable]': 'parse failed' };\n }\n}\n\n/**\n * Builds a JSON safe clone without calling toJSON on class instances.\n *\n * @internal\n */\nfunction decycle<ObjType, Marker extends string = '[Circular]'>(\n input: ObjType,\n marker: Marker,\n seen = new WeakSet<object>()\n): JsonifyWithCirculars<ObjType, Marker> {\n const recur = (val: unknown): unknown => {\n if (val === null) return null;\n const t = typeof val;\n\n if (t === 'bigint') return (val as bigint).toString();\n if (t !== 'object') return val;\n\n const obj = val as Record<string | number | symbol, unknown>;\n\n if (seen.has(obj)) return marker;\n seen.add(obj);\n\n if (obj instanceof Date) return obj.toISOString();\n if (obj instanceof RegExp) return obj.toString();\n\n if (Array.isArray(obj)) {\n return obj.map((item) => recur(item));\n }\n\n if (obj instanceof Map) {\n return Array.from(obj, ([k, v]) => [recur(k), recur(v)]);\n }\n\n if (obj instanceof Set) {\n return Array.from(obj, (v) => recur(v));\n }\n\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n if (typeof v === 'function') continue;\n out[k] = recur(v);\n }\n\n return out;\n };\n\n return recur(input) as JsonifyWithCirculars<ObjType, Marker>;\n}\n","import type { UnionToIntersection } from 'type-fest';\n\n/**\n * Extracts the type of a nested property, distributing over unions.\n *\n * @internal\n */\nexport type DeepGet<Obj, Key extends string> = Obj extends unknown\n ? Key extends `${infer K}.${infer Rest}`\n ? K extends keyof Obj\n ? DeepGet<NonNullable<Obj[K]>, Rest>\n : never\n : Key extends keyof Obj\n ? Obj[Key]\n : never\n : never;\n\n/**\n * Converts a dot-notation path string into a nested object type with a specific leaf value.\n *\n * @internal\n */\nexport type PathToObj<Path extends string, Value> = Path extends `${infer Head}.${infer Tail}`\n ? { [K in Head]: PathToObj<Tail, Value> }\n : { [K in Path]: Value };\n\n/**\n * Checks for the presence of nested keys in an object that's possibly a distributed union, narrowing the object type accordingly.\n *\n * Checks if an object has the specified nested keys and that their values are not null or undefined. If they are not, the object type is narrowed to reflect the presence of these keys with their respective types from the original distributed union object.\n *\n * @param obj - The object to check.\n * @param keys - An array of dot-notation paths to check.\n * @returns True if all keys exist and are non-null/defined, narrowing the object type.\n *\n * @example\n * ```ts\n * interface Test {\n * a?: {\n * b?: {\n * c?: string;\n * };\n * } | null;\n * x?: number | null;\n * }\n *\n * const obj: Test = { a: { b: { c: 'hello' } }, x: 42 };\n *\n * if (hasKeys(obj, ['a.b.c', 'x'])) {\n * // Here, obj is narrowed to:\n * // {\n * // a: { b: { c: string } };\n * // x: number;\n * // }\n * console.log(obj.a.b.c.toUpperCase()); // Safe to access and use\n * console.log(obj.x.toFixed(2)); // Safe to access and use\n * }\n * ```\n */\nexport function hasKeys<Obj extends object, Keys extends string>(\n obj: Obj,\n keys: Keys[]\n): obj is Obj &\n UnionToIntersection<\n Keys extends unknown ? PathToObj<Keys, UnionToIntersection<NonNullable<DeepGet<Obj, Keys>>>> : never\n > {\n return keys.every((key) => {\n const parts = key.split('.');\n let current: unknown = obj;\n\n for (const part of parts) {\n if (\n current === null ||\n current === undefined ||\n (typeof current !== 'object' && typeof current !== 'function')\n ) {\n return false;\n }\n if (!(part in current)) {\n return false;\n }\n current = (current as Record<string, unknown>)[part];\n }\n\n return current !== null && current !== undefined;\n });\n}\n","/**\n * Copies only the keys whose values are defined.\n *\n * @typeParam TObject - the original object type you're pulling from\n * @typeParam TKey - the keys to copy when defined\n * @param source - the object to read values from\n * @param keys - optional list of keys to include when present. If omitted, all keys are considered\n *\n * @example\n * ```ts\n * interface Config {\n * host?: string;\n * port?: number;\n * user?: string;\n * password?: string;\n * }\n *\n * const config: Config = {\n * host: 'localhost',\n * port: undefined,\n * user: 'admin',\n * password: undefined\n * };\n *\n * const definedConfig = keepDefined(config, 'host', 'port', 'user', 'password');\n * // Result: { host: 'localhost', user: 'admin' }\n * ```\n */\nexport function keepDefined<TObject extends object, TKey extends keyof TObject>(\n source: TObject,\n ...keys: readonly TKey[]\n): Partial<Pick<TObject, TKey extends never ? keyof TObject : TKey>> {\n const selectedKeys = keys.length > 0 ? keys : (Object.keys(source) as TKey[]);\n const result: Partial<TObject> = {};\n\n for (const key of selectedKeys) {\n const value = source[key];\n if (value !== undefined && value !== null) {\n result[key] = value;\n }\n }\n return result;\n}\n","/**\n * Returns the word with its first letter capitalized and the rest in lowercase.\n * @param word - The word to be formatted.\n * @returns The formatted word.\n */\nexport function capitalize(word: string): string {\n return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n}\n","/**\n * Function takes an array of strings or numbers and returns the number of characters in the longest string/number\n *\n * @param arr - The array of strings or numbers\n * @returns The length of the longest element when converted to string\n */\nexport function longestStringLength(arr: (string | number)[]): number {\n return Math.max(...arr.map((el) => el.toString().length));\n}\n","/**\n * Generates an ASCII table from the provided data.\n *\n * @param data - The data to be displayed in the table.\n * @returns The generated ASCII table as a string.\n */\nexport function generateAsciiTable(data: string[][]): string {\n if (data.length === 0) return '';\n\n const firstRow = data[0];\n if (!firstRow || firstRow.length === 0) return '';\n\n let table = '';\n const columnWidths: number[] = [];\n\n // Determine the maximum width for each column\n for (let i = 0; i < firstRow.length; i++) {\n let maxWidth = 0;\n for (const row of data) {\n const cell = row[i];\n if (cell !== undefined) maxWidth = Math.max(maxWidth, cell.length);\n }\n columnWidths.push(maxWidth);\n }\n\n // Function to create a horizontal line\n const createLine = (char: string, left: string, intersect: string, right: string): string => {\n let line = left;\n columnWidths.forEach((width, index) => {\n line += char.repeat(width + 2);\n if (index < columnWidths.length - 1) line += intersect;\n else line += right;\n });\n line += '\\n';\n return line;\n };\n\n // Top border\n table += createLine('═', '╔', '╦', '╗');\n\n data.forEach((row, rowIndex) => {\n // Row content\n table += '║';\n row.forEach((cell, columnIndex) => {\n const columnWidth = columnWidths[columnIndex];\n if (columnWidth !== undefined) table += ` ${cell.padEnd(columnWidth)} ║`;\n });\n table += '\\n';\n\n // Separator or bottom border\n if (rowIndex < data.length - 1) table += createLine('─', '╠', '╬', '╣');\n else table += createLine('═', '╚', '╩', '╝');\n });\n\n return table;\n}\n","import { capitalize } from './capitalize';\n\n/**\n * Options for the `prettify` function.\n */\nexport interface PrettifyOptions {\n capitalize?: boolean;\n}\n/**\n * Converts a string from any common naming convention to human-readable format.\n * Accepts camelCase, PascalCase, snake_case, and kebab-case input.\n *\n * @param key - The string to convert\n * @param opts - Optional configuration\n * @returns A space-separated, human-readable string\n *\n * @example\n * prettify(\"camelCaseString\") // \"camel Case String\"\n * prettify(\"PascalCaseString\") // \"Pascal Case String\"\n * prettify(\"snake_case_string\") // \"snake case string\"\n * prettify(\"kebab-case-string\") // \"kebab case string\"\n * prettify(\"mixedCase_string-name\") // \"mixed Case string name\"\n */\n\nexport function prettify(key: string, opts?: PrettifyOptions): string {\n const result = key\n .replace(/([a-z])([A-Z])/g, '$1 $2') // camelCase/PascalCase\n .replace(/[_-]/g, ' ') // snake_case and kebab-case\n .trim();\n\n if (opts?.capitalize) return capitalize(result);\n\n return result;\n}\n","/**\n * Calculates the difference between two numbers and formats it as a string with a '+' prefix for positive differences.\n *\n * @param numBefore - The initial number value\n * @param numAfter - The final number value\n * @returns A string representing the difference, with a '+' sign for positive differences\n *\n * @example\n * // Returns \"+5\"\n * prettyDifference(10, 15);\n *\n * @example\n * // Returns \"-3\"\n * prettyDifference(10, 7);\n */\nexport function prettyDifference(numBefore: number, numAfter: number): string {\n return (numAfter - numBefore > 0 ? `+${numAfter - numBefore}` : numAfter - numBefore).toString();\n}\n","export * from './misc';\nexport * from './numbers';\nexport * from './objects';\nexport * from './strings';\n\n/** Package version */\nexport const version = process.env.PACKAGE_VERSION ?? '0.0.0';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,SAAgB,YAAY,OAAqB;CAC7C,MAAM,IAAI,MAAM,yCAAyC,KAAK,UAAU,KAAK,GAAG;AACpF;;;;;;;;;;ACKA,SAAgB,aAAa,OAA2B;CACpD,OACI,MAAM,OAAO,MACZ,MAAM,KAAK,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS,KAAK,MACxD,CAAC,MAAM,KAAK,SAAS,OAAO,KAC5B,CAAC,MAAM,KAAK,SAAS,MAAM;AAEnC;;;;;;;;AASA,eAAsB,kBAClB,KACA,UACA,QACa;CACb,IAAI;CAEJ,IAAI;EACA,UAAU,oCAAc,KAAK,EAAE,eAAe,KAAK,CAAC;CACxD,SAAS,KAAK;EACV,OAAO,MAAM,4BAA4B,OAAO,GAAG;EACnD,UAAU,CAAC;CACf;CAEA,KAAK,MAAM,SAAS,SAAS;EACzB,MAAM,WAAWA,UAAK,KAAK,KAAK,MAAM,IAAI;EAC1C,MAAM,eAAeA,UAAK,SAAS,QAAQ,IAAI,GAAG,QAAQ;EAE1D,IAAI,MAAM,YAAY,GAClB,MAAM,kBAAkB,UAAU,UAAU,MAAM;OAC/C,IAAI,aAAa,KAAK,GAEzB,MAAM,SAAS,UAAU,cAAc,MADf,OAAO,SACgB;CAEvD;AACJ;;;;;;;AAsBA,SAAgB,eAAe,UAAkB,UAA6B,CAAC,GAAW;CACtF,MAAM,EAAE,UAAU,OAAO,SAAS,SAAS;CAK3C,OAAO,GAAG,SAHO,UACXA,UAAK,SAAS,QAAQ,IAAI,GAAG,SAAS,QAAQ,YAAY,EAAE,CAAC,IAC7DA,UAAK,SAAS,QAAQ,IAAI,GAAG,QAAQ;AAE/C;;;;;;;;;;;;;;;;;;;;;ACjEA,SAAgB,UAAkB,OAA2B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fest';
|
|
4
|
-
import { ILogger } from '@seedcord/types';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Determines if a directory entry is a TypeScript or JavaScript file.
|
|
8
|
-
*
|
|
9
|
-
* @param entry - The directory entry to check.
|
|
10
|
-
* @returns True if the entry is a file ending with .ts or .js.
|
|
11
|
-
*/
|
|
12
|
-
declare function isTsOrJsFile(entry: fs.Dirent): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Recursively traverses through a directory, importing all .ts and .js files and applying a callback to each import.
|
|
15
|
-
*
|
|
16
|
-
* @param dir - The directory path to traverse.
|
|
17
|
-
* @param callback - A function that will be called for each imported module. It receives the full file path, the file's relative path, and the imported module as arguments.
|
|
18
|
-
* @returns A Promise that resolves when the traversal is complete.
|
|
19
|
-
*/
|
|
20
|
-
declare function traverseDirectory(dir: string, callback: (fullPath: string, relativePath: string, imported: Record<string, unknown>) => Promise<void> | void, logger: Logger): Promise<void>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Shuffles an array using the Fisher-Yates algorithm.
|
|
24
|
-
* This function creates a new array with the same elements in a random order,
|
|
25
|
-
* without modifying the original array.
|
|
26
|
-
*
|
|
27
|
-
* @typeParam TArray - The type of elements in the array
|
|
28
|
-
* @param items - The array to shuffle
|
|
29
|
-
* @returns A new array with the same elements in a random order
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* const numbers = [1, 2, 3, 4, 5];
|
|
34
|
-
* const shuffled = fyShuffle(numbers);
|
|
35
|
-
* // shuffled might be [3, 1, 5, 2, 4]
|
|
36
|
-
* // numbers is still [1, 2, 3, 4, 5]
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
declare function fyShuffle<TArray>(items: TArray[]): TArray[];
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Return current time in seconds
|
|
43
|
-
*/
|
|
44
|
-
declare function currentTime(): number;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Generates a random numeric code with the specified number of digits.
|
|
48
|
-
*
|
|
49
|
-
* @param digits - The number of digits for the generated code.
|
|
50
|
-
* @returns A random numeric code with the specified number of digits.
|
|
51
|
-
*/
|
|
52
|
-
declare function generateCode(digits: number): number;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Converts hexcode to number
|
|
56
|
-
*
|
|
57
|
-
* @param hex - The hex code to convert.
|
|
58
|
-
* @returns The converted number.
|
|
59
|
-
*/
|
|
60
|
-
declare function hexToNumber(hex: string): number;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Returns the ordinal suffix for a given number.
|
|
64
|
-
*
|
|
65
|
-
* @param n - The number to get the ordinal for
|
|
66
|
-
* @returns The number with its ordinal suffix
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ordinal(1); // "1st"
|
|
70
|
-
* ordinal(22); // "22nd"
|
|
71
|
-
* ordinal(13); // "13th"
|
|
72
|
-
*/
|
|
73
|
-
declare function ordinal(n: number): string;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Takes two numbers and returns the percentage of the first number in the second number with two decimal places.
|
|
77
|
-
*
|
|
78
|
-
* @param num1 - The first number.
|
|
79
|
-
* @param num2 - The second number.
|
|
80
|
-
*
|
|
81
|
-
* @returns The percentage of the first number in the second number with two decimal places.
|
|
82
|
-
*/
|
|
83
|
-
declare function percentage(num1: number, num2: number): number;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Rounds a number to a specified number of decimal places.
|
|
87
|
-
*
|
|
88
|
-
* @param num - The number to be rounded.
|
|
89
|
-
* @param precision - The number of decimal places to round to.
|
|
90
|
-
* @returns The rounded number.
|
|
91
|
-
*/
|
|
92
|
-
declare function round(num: number, precision: number): number;
|
|
93
|
-
|
|
94
|
-
interface RoundToDenomOptions {
|
|
95
|
-
/**
|
|
96
|
-
* Suffixes to use for each denomination level. Defaults to `['K', 'M', 'B', 'T', 'Q']`.
|
|
97
|
-
*/
|
|
98
|
-
suffixes?: TupleOf<5, string>;
|
|
99
|
-
/** Number of decimal places to include in the rounded result. Defaults to `1`. */
|
|
100
|
-
precision?: number;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Rounds a number to a string representation with a denomination suffix.
|
|
104
|
-
* @param num - The number to round.
|
|
105
|
-
* @example
|
|
106
|
-
* ```ts
|
|
107
|
-
* roundToDenomination(1234); // "1.2K"
|
|
108
|
-
* roundToDenomination(10000, ['k', 'm', 'b', 't', 'q']); // "10k"
|
|
109
|
-
* roundToDenomination(12345678); // "12.3M"
|
|
110
|
-
* ```
|
|
111
|
-
* @returns The rounded number as a string with a denomination suffix.
|
|
112
|
-
*/
|
|
113
|
-
declare function roundToDenomination(num: number, opts?: RoundToDenomOptions): string;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* JSONify an arbitrary type while allowing any object position to be replaced
|
|
117
|
-
* by a circular marker. Optional keys stay optional.
|
|
118
|
-
*/
|
|
119
|
-
type JsonifyWithCirculars<BaseType, Marker extends string = '[Circular]'> = BaseType extends JsonPrimitive ? BaseType : BaseType extends bigint ? string : BaseType extends Date ? string : BaseType extends {
|
|
120
|
-
toJSON(): infer J;
|
|
121
|
-
} ? unknown extends J ? JsonifyObject<BaseType, Marker> : JsonifyWithCirculars<J, Marker> : BaseType extends readonly (infer U)[] ? (JsonifyWithCirculars<U, Marker> | Marker)[] : BaseType extends Map<infer K, infer V> ? [JsonifyWithCirculars<K, Marker> | Marker, JsonifyWithCirculars<V, Marker> | Marker][] : BaseType extends Set<infer U2> ? (JsonifyWithCirculars<U2, Marker> | Marker)[] : BaseType extends (...args: unknown[]) => unknown ? never : BaseType extends object ? JsonifyObject<BaseType, Marker> : never;
|
|
122
|
-
/**
|
|
123
|
-
* Helper to JSONify object types with circular markers.
|
|
124
|
-
*
|
|
125
|
-
* @internal
|
|
126
|
-
*/
|
|
127
|
-
type JsonifyObject<BaseType, Marker extends string> = {
|
|
128
|
-
[K in keyof BaseType as K extends symbol ? never : BaseType[K] extends (...args: unknown[]) => unknown ? never : K]: JsonifyWithCirculars<Exclude<BaseType[K], undefined>, Marker> | Extract<BaseType[K], undefined> | Marker;
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Configuration for {@link filterCirculars}.
|
|
132
|
-
*/
|
|
133
|
-
interface FilterCircularsOptions<Marker extends string = '[Circular]'> {
|
|
134
|
-
/** Optional {@link ILogger} used to log stringify or parse errors. */
|
|
135
|
-
logger?: ILogger;
|
|
136
|
-
/** Override the circular placeholder. Default is `[Circular]`. */
|
|
137
|
-
marker?: Marker;
|
|
138
|
-
/** Processing mode. `json` uses stringify and parse (might end up using a `toJSON()` if found). `decycle` builds a safe clone first. Default is `decycle`. */
|
|
139
|
-
mode?: 'json' | 'decycle';
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Creates a clean, JSON safe copy of a value and replaces circular references with a marker.
|
|
143
|
-
*
|
|
144
|
-
* In `json` mode it behaves like stringify then parse with a replacer that handles cycles and BigInt.
|
|
145
|
-
* In `decycle` mode it first clones without using toJSON, then you can stringify the result later.
|
|
146
|
-
*
|
|
147
|
-
* @typeParam ObjType - Type of the input value.
|
|
148
|
-
* @typeParam Marker - Marker string used for circular references.
|
|
149
|
-
*
|
|
150
|
-
* @param value - The value to clone safely.
|
|
151
|
-
* @param options - Optional configuration.
|
|
152
|
-
*
|
|
153
|
-
* @returns A JSON safe structure with circular references replaced by the marker.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* interface Test {
|
|
158
|
-
* name: string;
|
|
159
|
-
* self?: Test;
|
|
160
|
-
* }
|
|
161
|
-
*
|
|
162
|
-
* const obj: Test = { name: 'seedcord' };
|
|
163
|
-
* obj.self = obj;
|
|
164
|
-
*
|
|
165
|
-
* const clean = filterCirculars(obj);
|
|
166
|
-
* // ^? { name: string; self?: "[Circular]" | { ... } }
|
|
167
|
-
* console.log(clean.self); // "[Circular]"
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
declare function filterCirculars<ObjType, Marker extends string = '[Circular]'>(value: ObjType, options?: FilterCircularsOptions<Marker>): JsonifyWithCirculars<ObjType, Marker>;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Pulls out only the keys from an object that actually have values.
|
|
174
|
-
*
|
|
175
|
-
* @typeParam TObject - the original object type you're pulling from
|
|
176
|
-
* @typeParam TKey - the specific keys you want to copy if they're defined
|
|
177
|
-
* @param source - the object to read values from
|
|
178
|
-
* @param keys - optional list of keys you want to include if they exist. If omitted, all keys are considered
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* ```ts
|
|
182
|
-
* interface Config {
|
|
183
|
-
* host?: string;
|
|
184
|
-
* port?: number;
|
|
185
|
-
* user?: string;
|
|
186
|
-
* password?: string;
|
|
187
|
-
* }
|
|
188
|
-
*
|
|
189
|
-
* const config: Config = {
|
|
190
|
-
* host: 'localhost',
|
|
191
|
-
* port: undefined,
|
|
192
|
-
* user: 'admin',
|
|
193
|
-
* password: undefined
|
|
194
|
-
* };
|
|
195
|
-
*
|
|
196
|
-
* const definedConfig = keepDefined(config, 'host', 'port', 'user', 'password');
|
|
197
|
-
* // Result: { host: 'localhost', user: 'admin' }
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
declare function keepDefined<TObject extends object, TKey extends keyof TObject>(source: TObject, ...keys: readonly TKey[]): Partial<Pick<TObject, TKey extends never ? keyof TObject : TKey>>;
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Returns the word with its first letter capitalized and the rest in lowercase.
|
|
204
|
-
* @param word - The word to be formatted.
|
|
205
|
-
* @returns The formatted word.
|
|
206
|
-
*/
|
|
207
|
-
declare function capitalize(word: string): string;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Function takes an array of strings or numbers and returns the number of characters in the longest string/number
|
|
211
|
-
*
|
|
212
|
-
* @param arr - The array of strings or numbers
|
|
213
|
-
* @returns The length of the longest element when converted to string
|
|
214
|
-
*/
|
|
215
|
-
declare function longestStringLength(arr: (string | number)[]): number;
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Generates an ASCII table from the provided data.
|
|
219
|
-
*
|
|
220
|
-
* @param data - The data to be displayed in the table.
|
|
221
|
-
* @returns The generated ASCII table as a string.
|
|
222
|
-
*/
|
|
223
|
-
declare function generateAsciiTable(data: string[][]): string;
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Options for the `prettify` function.
|
|
227
|
-
*/
|
|
228
|
-
interface PrettifyOptions {
|
|
229
|
-
capitalize?: boolean;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Converts a string from any common naming convention to human-readable format.
|
|
233
|
-
* Handles camelCase, PascalCase, snake_case, and kebab-case.
|
|
234
|
-
*
|
|
235
|
-
* @param key - The string to convert
|
|
236
|
-
* @param opts - Optional configuration
|
|
237
|
-
* @returns A space-separated, human-readable string
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* prettify("camelCaseString") // "camel Case String"
|
|
241
|
-
* prettify("PascalCaseString") // "Pascal Case String"
|
|
242
|
-
* prettify("snake_case_string") // "snake case string"
|
|
243
|
-
* prettify("kebab-case-string") // "kebab case string"
|
|
244
|
-
* prettify("mixedCase_string-name") // "mixed Case string name"
|
|
245
|
-
*/
|
|
246
|
-
declare function prettify(key: string, opts?: PrettifyOptions): string;
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Calculates the difference between two numbers and formats it as a string with a '+' prefix for positive differences.
|
|
250
|
-
*
|
|
251
|
-
* @param numBefore - The initial number value
|
|
252
|
-
* @param numAfter - The final number value
|
|
253
|
-
* @returns A string representing the difference, with a '+' sign for positive differences
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* // Returns "+5"
|
|
257
|
-
* prettyDifference(10, 15);
|
|
258
|
-
*
|
|
259
|
-
* @example
|
|
260
|
-
* // Returns "-3"
|
|
261
|
-
* prettyDifference(10, 7);
|
|
262
|
-
*/
|
|
263
|
-
declare function prettyDifference(numBefore: number, numAfter: number): string;
|
|
264
|
-
|
|
265
|
-
export { type FilterCircularsOptions, type JsonifyObject, type JsonifyWithCirculars, type PrettifyOptions, type RoundToDenomOptions, capitalize, currentTime, filterCirculars, fyShuffle, generateAsciiTable, generateCode, hexToNumber, isTsOrJsFile, keepDefined, longestStringLength, ordinal, percentage, prettify, prettyDifference, round, roundToDenomination, traverseDirectory };
|
|
1
|
+
export type * from './index.d.mts'
|