{"version":3,"file":"logger.cjs","names":["RESET","GREEN","BEIGE","GREY","BLUE","GREY_DARK","WHITE","GREY_LIGHT","RED"],"sources":["../../src/logger.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type {\n  CustomIntlayerConfig,\n  IntlayerConfig,\n} from '@intlayer/types/config';\nimport type * as ANSIColorsTypes from './colors';\nimport {\n  BEIGE,\n  BLUE,\n  GREEN,\n  GREY,\n  GREY_DARK,\n  GREY_LIGHT,\n  RED,\n  RESET,\n  WHITE,\n} from './colors';\n\nexport type ANSIColorsType =\n  (typeof ANSIColorsTypes)[keyof typeof ANSIColorsTypes];\n\nexport type Details = {\n  isVerbose?: boolean;\n  level?: 'info' | 'warn' | 'error' | 'debug';\n  config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n  loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n  if (typeof loggerPrefix !== 'undefined') {\n    return loggerPrefix;\n  }\n\n  return configPrefix;\n};\n\nexport const logger: Logger = (content, details) => {\n  const config = details?.config ?? {};\n  const mode = config.mode ?? 'default';\n\n  if (mode === 'disabled' || (details?.isVerbose && mode !== 'verbose')) return;\n\n  const prefix = getPrefix(config.prefix);\n  const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n  const level = details?.level ?? 'info';\n\n  const logMethod =\n    config[level] ?? console[level] ?? config.log ?? console.log;\n\n  logMethod(...flatContent);\n};\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n  (configuration?: Pick<IntlayerConfig, 'log'>, globalDetails?: Details) =>\n  (content: any, details?: Details) =>\n    logger(content, {\n      ...(details ?? {}),\n      config: {\n        ...configuration?.log,\n        ...globalDetails?.config,\n        ...(details?.config ?? {}),\n      },\n    });\n\nexport const colorize = (\n  string: string,\n  color?: ANSIColorsType,\n  reset?: boolean | ANSIColorsType\n): string =>\n  color\n    ? `${color}${string}${reset ? (typeof reset === 'boolean' ? RESET : reset) : RESET}`\n    : string;\n\nexport const colorizeLocales = (\n  locales: Locale | Locale[],\n  color: ANSIColorsType = GREEN,\n  reset: boolean | ANSIColorsType = RESET\n) =>\n  [locales]\n    .flat()\n    .map((locale) => colorize(locale, color, reset))\n    .join(`, `);\n\nexport const colorizeKey = (\n  keyPath: string | string[],\n  color: ANSIColorsType = BEIGE,\n  reset: boolean | ANSIColorsType = RESET\n) =>\n  [keyPath]\n    .flat()\n    .map((key) => colorize(key, color, reset))\n    .join(`, `);\n\nexport const colorizePath = (\n  path: string | string[],\n  color: ANSIColorsType = GREY,\n  reset: boolean | ANSIColorsType = RESET\n) =>\n  [path]\n    .flat()\n    .map((path) => colorize(path, color, reset))\n    .join(`, `);\n\nexport const colorizeNumber = (\n  number: number | string,\n  options: Partial<Record<Intl.LDMLPluralRule, ANSIColorsType>> = {\n    zero: BLUE,\n    one: BLUE,\n    two: BLUE,\n    few: BLUE,\n    many: BLUE,\n    other: BLUE,\n  }\n): string => {\n  if (number === 0 || number === '0') {\n    const color = options.zero ?? GREEN;\n    return colorize(number.toString(), color);\n  }\n\n  // Kept inside the function. Top-level instantiation of classes/APIs\n  // is treated as a side-effect and prevents tree-shaking if the function is unused.\n  const rule = new Intl.PluralRules('en').select(Number(number));\n  const color = options[rule];\n  return colorize(number.toString(), color);\n};\n\nexport const colorizeObject = (\n  obj: any,\n  indentLevel = 0,\n  indentSize = 2,\n  key?: string\n): string => {\n  const indent = ' '.repeat(indentLevel * indentSize);\n  const nextIndent = ' '.repeat((indentLevel + 1) * indentSize);\n\n  if (obj === null) {\n    return colorize('null', BLUE);\n  }\n\n  if (typeof obj === 'boolean') {\n    return colorize(obj.toString(), BLUE);\n  }\n\n  if (typeof obj === 'number') {\n    return colorize(obj.toString(), BLUE);\n  }\n\n  if (typeof obj === 'string') {\n    const isDateString = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/.test(obj);\n    const isUrl = obj.startsWith('http://') || obj.startsWith('https://');\n    const isGlob = obj.includes('*') || obj.includes('?') || obj.includes('{');\n    const isPath =\n      obj.startsWith('/') ||\n      obj.startsWith('./') ||\n      obj.startsWith('../') ||\n      /\\.[a-zA-Z0-9]{2,5}$/.test(obj);\n    const isSecret =\n      /^[0-9a-fA-F]{24,}$/.test(obj) || (obj.length >= 40 && !/\\s/.test(obj));\n    const hasSpaces = /\\s/.test(obj);\n\n    if (isDateString) return colorize(`\"${obj}\"`, BEIGE);\n    if (isUrl) return colorize(`\"${obj}\"`, GREY_DARK);\n    if (isGlob) return colorize(`\"${obj}\"`, GREY);\n    if (isPath) return colorize(`\"${obj}\"`, GREY_DARK);\n    if (isSecret) return colorize(`\"${obj}\"`, GREY);\n    if (hasSpaces) return colorize(`\"${obj}\"`, WHITE);\n    return colorize(`\"${obj}\"`, BLUE);\n  }\n\n  if (Array.isArray(obj)) {\n    if (obj.length === 0) {\n      return '[]';\n    }\n    const items = obj\n      .map(\n        (item) =>\n          `${nextIndent}${colorizeObject(item, indentLevel + 1, indentSize, key)}`\n      )\n      .join(',\\n');\n    return `[\\n${items}\\n${indent}]`;\n  }\n\n  if (typeof obj === 'object') {\n    const keys = Object.keys(obj);\n\n    if (keys.length === 0) {\n      return '{}';\n    }\n\n    const fields = keys\n      .map((key) => {\n        const coloredKey = colorize(`\"${key}\"`, GREY_LIGHT);\n        const value = obj[key];\n        const coloredValue = colorizeObject(\n          value,\n          indentLevel + 1,\n          indentSize,\n          key\n        );\n        return `${nextIndent}${coloredKey}: ${coloredValue}`;\n      })\n      .join(',\\n');\n    return `{\\n${fields}\\n${indent}}`;\n  }\n\n  return colorize(String(obj), GREY);\n};\n\nexport const removeColor = (text: string) =>\n  // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n  text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n  let value: number = 0;\n  if (typeof length === 'number') {\n    value = length;\n  }\n  if (typeof length === 'string') {\n    value = length.length;\n  }\n  if (\n    Array.isArray(length) &&\n    length.every((locale) => typeof locale === 'string')\n  ) {\n    value = Math.max(...length.map((str) => str.length));\n  }\n  if (\n    Array.isArray(length) &&\n    length.every((locale) => typeof locale === 'number')\n  ) {\n    value = Math.max(...length);\n  }\n  return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n  colSize: 0,\n  minSize: 0,\n  maxSize: Infinity,\n  pad: 'right',\n  padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n  text: string | string[],\n  options?: {\n    colSize?: number | number[] | string | string[];\n    minSize?: number;\n    maxSize?: number;\n    pad?: 'left' | 'right';\n    padChar?: string;\n  }\n): string =>\n  [text]\n    .flat()\n    .map((text) => {\n      const { colSize, minSize, maxSize, pad } = {\n        ...defaultColonOptions,\n        ...(options ?? {}),\n      };\n\n      const length = getLength(colSize);\n      const spacesLength = Math.max(\n        minSize!,\n        Math.min(maxSize!, length - removeColor(text).length)\n      );\n\n      if (pad === 'left') {\n        return `${' '.repeat(spacesLength)}${text}`;\n      }\n\n      return `${text}${' '.repeat(spacesLength)}`;\n    })\n    .join('');\n\nexport const x = colorize('✗', RED);\nexport const v = colorize('✓', GREEN);\nexport const clock = colorize('⏲', BLUE);\n"],"mappings":";;;;AA6BA,IAAI;AAEJ,MAAa,aAAa,WAA+B;AACvD,gBAAe;;AAGjB,MAAa,aAAa,iBAA8C;AACtE,KAAI,OAAO,iBAAiB,YAC1B,QAAO;AAGT,QAAO;;AAGT,MAAa,UAAkB,SAAS,YAAY;CAClD,MAAM,SAAS,SAAS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