{"version":3,"file":"logger.cjs","names":["RESET","GREEN","BEIGE","GREY","BLUE","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 { BEIGE, BLUE, GREEN, GREY, RED, RESET } 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 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":";;;;AAmBA,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,UAAU,EAAE;CACpC,MAAM,OAAO,OAAO,QAAQ;AAE5B,KAAI,SAAS,cAAe,SAAS,aAAa,SAAS,UAAY;CAEvE,MAAM,SAAS,UAAU,OAAO,OAAO;CACvC,MAAM,cAAc,SAAS,CAAC,QAAQ,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM;CAC7E,MAAM,QAAQ,SAAS,SAAS;AAKhC,EAFE,OAAO,U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