{"version":3,"sources":["../src/logs/createLogger.ts","../src/core/id.ts","../src/core/formatNumber.ts","../src/core/array.ts","../src/core/string.ts","../src/core/date.ts","../src/core/async.ts"],"sourcesContent":["import type { LogLevel, LoggerOptions } from \"../types\";\r\n\r\nconst LEVEL_WEIGHT: Record<LogLevel, number> = {\r\n  debug: 0,\r\n  info: 1,\r\n  warn: 2,\r\n  error: 3,\r\n};\r\n\r\n/**\r\n * Creates a logger instance with configurable logging levels, formatting, and output options.\r\n *\r\n * @param options - Logger configuration options object\r\n * @param options.level - Minimum log level to output: 'debug', 'info', 'warn', or 'error' (default: \"info\")\r\n * @param options.enabled - Whether logging is enabled (default: true)\r\n * @param options.prefix - Optional prefix/scope to include in log messages\r\n * @param options.json - Whether to output logs as JSON format (default: false)\r\n * @returns A logger object with debug, info, warn, error, and json methods\r\n */\r\nexport function createLogger(options: LoggerOptions = {}) {\r\n  const { level = \"info\", enabled = true, prefix, json = false } = options;\r\n\r\n  function log(type: LogLevel, message: string, data?: unknown) {\r\n    if (!enabled) return;\r\n    if (LEVEL_WEIGHT[type] < LEVEL_WEIGHT[level]) return;\r\n\r\n    const payload = {\r\n      time: new Date().toISOString(),\r\n      level: type,\r\n      scope: prefix,\r\n      message,\r\n      data,\r\n    };\r\n\r\n    if (json) {\r\n      console[type](JSON.stringify(payload));\r\n    } else {\r\n      const tag = prefix ? `[${prefix}]` : \"\";\r\n      console[type](\r\n        `[${payload.time}] ${type.toUpperCase()} ${tag}`,\r\n        message,\r\n        data ?? \"\"\r\n      );\r\n    }\r\n  }\r\n\r\n  return {\r\n    debug: (message: string, data?: unknown) => log(\"debug\", message, data),\r\n    info: (message: string, data?: unknown) => log(\"info\", message, data),\r\n    warn: (message: string, data?: unknown) => log(\"warn\", message, data),\r\n    error: (message: string, data?: unknown) => log(\"error\", message, data),\r\n    json: (message: string, data?: unknown) => log(\"debug\", JSON.stringify({ message, data }), data),\r\n  };\r\n}\r\n","import type { GenerateIdOptions } from \"../types\";\r\n\r\nconst DEFAULT_ALPHABET =\r\n    \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\r\n\r\nconst cryptoObj =\r\n    typeof globalThis !== \"undefined\" && \"crypto\" in globalThis\r\n        ? (globalThis.crypto as Crypto)\r\n        : undefined;\r\n\r\nfunction getRandomBytes(length: number, secure: boolean): number[] {\r\n    if (secure && cryptoObj?.getRandomValues) {\r\n        const bytes = new Uint8Array(length);\r\n        cryptoObj.getRandomValues(bytes);\r\n        return Array.from(bytes);\r\n    }\r\n\r\n    return Array.from({ length }, () => Math.floor(Math.random() * 256));\r\n}\r\n\r\nfunction formatAsUUID(hex: string): string {\r\n    return (\r\n      hex.slice(0, 8) + \"-\" +\r\n      hex.slice(8, 12) + \"-\" +\r\n      hex.slice(12, 16) + \"-\" +\r\n      hex.slice(16, 20) + \"-\" +\r\n      hex.slice(20, 32)\r\n    );\r\n  }\r\n  \r\n\r\nfunction createSeededRandom(seed: number) {\r\n    let value = seed;\r\n    return () => {\r\n        value = (value * 9301 + 49297) % 233280;\r\n        return value / 233280;\r\n    };\r\n}\r\n\r\n/**\r\n * Generates a unique ID with customizable options for prefix, length, alphabet, and format.\r\n *\r\n * @param options - ID generation options object\r\n * @param options.prefix - Optional prefix to prepend to the generated ID (default: \"\")\r\n * @param options.length - Length of the ID when format is \"plain\" (default: 8)\r\n * @param options.alphabet - Characters to use for ID generation (default: alphanumeric)\r\n * @param options.uppercase - Whether to convert the ID to uppercase (default: false)\r\n * @param options.secure - Whether to use cryptographically secure random generation (default: true)\r\n * @param options.seed - Optional seed for deterministic ID generation\r\n * @param options.format - Output format: \"plain\" or \"uuid\" (default: \"uuid\")\r\n * @returns A generated unique ID string\r\n */\r\nexport function generateId(options: GenerateIdOptions = {}): string {\r\n    const {\r\n      prefix = \"\",\r\n      length = 8,\r\n      alphabet = DEFAULT_ALPHABET,\r\n      uppercase = false,\r\n      secure = true,\r\n      seed,\r\n      format = \"uuid\",\r\n    } = options;\r\n  \r\n    const finalLength = format === \"uuid\" ? 32 : length;\r\n    const random = seed !== undefined ? createSeededRandom(seed) : null;\r\n    const bytes = getRandomBytes(finalLength, secure);\r\n  \r\n    let id = \"\";\r\n    for (let i = 0; i < finalLength; i++) {\r\n      const index = random\r\n        ? Math.floor(random() * alphabet.length)\r\n        : bytes[i]! % alphabet.length;\r\n  \r\n      id += alphabet[index];\r\n    }\r\n  \r\n    if (uppercase) id = id.toUpperCase();\r\n  \r\n    if (format === \"uuid\") {\r\n      id = formatAsUUID(id);\r\n    }\r\n  \r\n    return prefix + id;\r\n  }","import type { FormatNumberOptions, ThousandsGroupStyle } from \"../types\";\r\n\r\nfunction applyGrouping(\r\n  value: string,\r\n  separator: string,\r\n  style: ThousandsGroupStyle\r\n): string {\r\n  switch (style) {\r\n    case \"lakh\":\r\n      return value.replace(/(\\d)(?=(\\d\\d)+\\d$)/g, `$1${separator}`);\r\n\r\n    case \"wan\":\r\n      return value.replace(/(\\d)(?=(\\d{4})+$)/g, `$1${separator}`);\r\n\r\n    case \"thousand\":\r\n    default:\r\n      return value.replace(/\\B(?=(\\d{3})+(?!\\d))/g, separator);\r\n  }\r\n}\r\n\r\n/**\r\n * Formats a number with customizable decimal places, separators, and grouping styles.\r\n *\r\n * @param options - Formatting options object\r\n * @param options.value - The number or string to format\r\n * @param options.allowNegative - Whether to allow negative numbers (default: true)\r\n * @param options.decimalScale - Maximum number of decimal places (default: Infinity)\r\n * @param options.decimalSeparator - Character to use as decimal separator (default: \".\")\r\n * @param options.fixedDecimalScale - Whether to always show the specified decimal places (default: false)\r\n * @param options.thousandSeparator - Character(s) to use as thousand separator, or false to disable (default: \",\")\r\n * @param options.thousandsGroupStyle - Grouping style: 'none', 'thousand', 'lakh', or 'wan' (default: \"thousand\")\r\n * @returns The formatted number as a string\r\n */\r\nexport function formatNumber({\r\n  value,\r\n  allowNegative = true,\r\n  decimalScale = Infinity,\r\n  decimalSeparator = \".\",\r\n  fixedDecimalScale = false,\r\n  thousandSeparator = \",\",\r\n  thousandsGroupStyle = \"thousand\",\r\n}: FormatNumberOptions): string {\r\n  if (value === null || value === undefined) return \"\";\r\n\r\n  let numStr = String(value).replace(/,/g, \"\");\r\n\r\n  const isNegative = numStr.startsWith(\"-\");\r\n  if (isNegative) {\r\n    if (!allowNegative) numStr = numStr.slice(1);\r\n    else numStr = numStr.slice(1);\r\n  }\r\n\r\n  if (!/^\\d*(\\.\\d*)?$/.test(numStr)) return \"\";\r\n\r\n  let [integerPart, decimalPart = \"\"] = numStr.split(\".\");\r\n\r\n  if (decimalScale !== Infinity) {\r\n    decimalPart = decimalPart.slice(0, decimalScale);\r\n    if (fixedDecimalScale) {\r\n      decimalPart = decimalPart.padEnd(decimalScale, \"0\");\r\n    }\r\n  }\r\n\r\n  if (thousandSeparator && thousandsGroupStyle !== \"none\") {\r\n    const sep = typeof thousandSeparator === \"string\" ? thousandSeparator : \",\";\r\n\r\n    integerPart = applyGrouping(integerPart ?? \"\", sep, thousandsGroupStyle);\r\n  }\r\n\r\n  let result = integerPart;\r\n\r\n  if (decimalPart.length > 0) {\r\n    result += decimalSeparator + decimalPart;\r\n  }\r\n\r\n  return isNegative && allowNegative ? `-${result}` : result ?? \"\";\r\n}","import type { WhereOptions } from \"../types\";\r\n\r\n/**\r\n * Filters an array of objects by a given key, with optional value matching.\r\n *\r\n * @param options - Filter options object\r\n * @param options.data - The array to filter\r\n * @param options.key - The object property to filter by\r\n * @param options.value - Optional value to match against the key\r\n *\r\n * @returns A filtered array of matching items\r\n */\r\nexport function where<T>(options: WhereOptions<T>): T[] {\r\n    if (!Array.isArray(options.data)) {\r\n        return [];\r\n    }\r\n\r\n    return options.data.filter((item) => {\r\n        if (options.value === undefined) {\r\n            return Object.prototype.hasOwnProperty.call(item, options.key);\r\n        }\r\n        return item[options.key] === options.value;\r\n    });\r\n}\r\n\r\n/**\r\n * Get a unique array of items.\r\n *\r\n * @param array - The array to get a unique items from\r\n * @returns A unique array of items\r\n */\r\nexport function unique<T>(array: T[]): T[] {\r\n    return [...new Set(array)]\r\n}\r\n\r\n/**\r\n * Get a random item from an array.\r\n *\r\n * @param array - The array to get a random item from\r\n * @returns A random item from the array\r\n */\r\nexport function randomFromArray<T>(array: T[]): T | undefined {\r\n    if (!Array.isArray(array)) {\r\n        return undefined;\r\n    }\r\n\r\n    return array[Math.floor(Math.random() * array.length)];\r\n}","/**\r\n * Truncate a string and append \"...\" if it exceeds the given length.\r\n *\r\n * @param text - The text to truncate\r\n * @param maxLength - Maximum allowed length\r\n * @param append - The text to append if the string exceeds the maximum length\r\n * @returns The truncated text\r\n */\r\nexport function truncate(text: string, maxLength: number, append: string = '...'): string {\r\n    if (typeof text !== 'string') return '';\r\n    if (text.length <= maxLength) return text;\r\n\r\n    return text.slice(0, maxLength) + append;\r\n}\r\n\r\n/**\r\n * Capitalize the first letter of a string.\r\n *\r\n * @param str - The string to capitalize\r\n * @returns The capitalized string\r\n */\r\nexport function capitalize(str: string): string {\r\n    if (!str) return ''\r\n    return str.charAt(0).toUpperCase() + str.slice(1)\r\n}\r\n\r\n/**\r\n * Convert a string to uppercase.\r\n *\r\n * @param str - The string to convert to uppercase\r\n * @returns The uppercase string\r\n */\r\nexport function uppercase(str: string): string {\r\n    if (!str) return ''\r\n    return str.toUpperCase()\r\n}\r\n\r\n\r\n/**\r\n * Convert a string to a slug.\r\n *\r\n * @param text - The text to convert to a slug\r\n * @returns The slugified string\r\n */\r\nexport function slugify(text: string): string {\r\n    return text\r\n        .toLowerCase()\r\n        .trim()\r\n        .replace(/[^a-z0-9]+/g, '-')\r\n}\r\n","/**\r\n * Format a duration in seconds to a human-readable string.\r\n *\r\n * @param seconds - The duration in seconds\r\n * @returns The formatted duration (e.g. \"1h 30m 0s\")\r\n */\r\nexport function formatDuration(seconds: number): string {\r\n    const h = Math.floor(seconds / 3600)\r\n    const m = Math.floor((seconds % 3600) / 60)\r\n    const s = seconds % 60\r\n    return `${h}h ${m}m ${s}s`\r\n}\r\n\r\n/**\r\n * Format a date to a human-readable string.\r\n *\r\n * @param date - The date to format\r\n * @returns The formatted date (e.g. \"1h 30m 0s ago\")\r\n */\r\nexport function timeAgo(date: string | Date): string {\r\n    const diff = Math.floor((Date.now() - new Date(date).getTime()) / 1000)\r\n\r\n    if (diff < 60) return `${diff}s ago`\r\n    if (diff < 3600) return `${Math.floor(diff / 60)}m ago`\r\n    if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`\r\n    return `${Math.floor(diff / 86400)}d ago`\r\n}\r\n","/**\r\n * Sleep for a given number of milliseconds.\r\n *\r\n * @param ms - The number of milliseconds to sleep\r\n * @returns A promise that resolves after the given number of milliseconds\r\n */\r\nexport const sleep = (ms: number): Promise<void> => new Promise(resolve => setTimeout(resolve, ms))\r\n\r\n\r\n/**\r\n * Try to execute a function and catch any errors.\r\n *\r\n * @param fn - The function to execute\r\n * @returns A promise that resolves to an array with the error (if any) and the result (if any) \r\n */\r\nexport async function tryCatch<T>(\r\n    fn: () => Promise<T>\r\n  ): Promise<[Error | null, T | null]> {\r\n    try {\r\n      return [null, await fn()]\r\n    } catch (err) {\r\n      return [err as Error, null]\r\n    }\r\n  }\r\n  "],"mappings":"6BAEA,IAAMA,EAAyC,CAC7C,MAAO,EACP,KAAM,EACN,KAAM,EACN,MAAO,CACT,EAYO,SAASC,EAAaC,EAAyB,CAAC,EAAG,CACxD,GAAM,CAAE,MAAAC,EAAQ,OAAQ,QAAAC,EAAU,GAAM,OAAAC,EAAQ,KAAAC,EAAO,EAAM,EAAIJ,EAEjE,SAASK,EAAIC,EAAgBC,EAAiBC,EAAgB,CAE5D,GADI,CAACN,GACDJ,EAAaQ,CAAI,EAAIR,EAAaG,CAAK,EAAG,OAE9C,IAAMQ,EAAU,CACd,KAAM,IAAI,KAAK,EAAE,YAAY,EAC7B,MAAOH,EACP,MAAOH,EACP,QAAAI,EACA,KAAAC,CACF,EAEA,GAAIJ,EACF,QAAQE,CAAI,EAAE,KAAK,UAAUG,CAAO,CAAC,MAChC,CACL,I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Q,cAAe,GAAG,CACnC,CC3CO,SAASO,EAAeC,EAAyB,CACpD,IAAMC,EAAI,KAAK,MAAMD,EAAU,IAAI,EAC7BE,EAAI,KAAK,MAAOF,EAAU,KAAQ,EAAE,EACpCG,EAAIH,EAAU,GACpB,MAAO,GAAGC,CAAC,KAAKC,CAAC,KAAKC,CAAC,GAC3B,CAQO,SAASC,EAAQC,EAA6B,CACjD,IAAMC,EAAO,KAAK,OAAO,KAAK,IAAI,EAAI,IAAI,KAAKD,CAAI,EAAE,QAAQ,GAAK,GAAI,EAEtE,OAAIC,EAAO,GAAW,GAAGA,CAAI,QACzBA,EAAO,KAAa,GAAG,KAAK,MAAMA,EAAO,EAAE,CAAC,QAC5CA,EAAO,MAAc,GAAG,KAAK,MAAMA,EAAO,IAAI,CAAC,QAC5C,GAAG,KAAK,MAAMA,EAAO,KAAK,CAAC,OACtC,CCpBO,IAAMC,EAASC,GAA8B,IAAI,QAAQC,GAAW,WAAWA,EAASD,CAAE,CAAC,EASlG,eAAsBE,EAClBC,EACmC,CACnC,GAAI,CACF,MAAO,CAAC,KAAM,MAAMA,EAAG,CAAC,CAC1B,OAASC,EAAK,CACZ,MAAO,CAACA,EAAc,IAAI,CAC5B,CACF","names":["LEVEL_WEIGHT","createLogger","options","level","enabled","prefix","json","log","type","message","data","payload","tag","DEFAULT_ALPHABET","cryptoObj","getRandomBytes","length","secure","bytes","formatAsUUID","hex","createSeededRandom","seed","value","generateId","options","prefix","alphabet","uppercase","format","finalLength","random","id","i","index","applyGrouping","value","separator","style","formatNumber","allowNegative","decimalScale","decimalSeparator","fixedDecimalScale","thousandSeparator","thousandsGroupStyle","numStr","isNegative","integerPart","decimalPart","result","where","options","item","unique","array","randomFromArray","truncate","text","maxLength","append","capitalize","str","uppercase","slugify","formatDuration","seconds","h","m","s","timeAgo","date","diff","sleep","ms","resolve","tryCatch","fn","err"]}