{"version":3,"file":"index.cjs","names":["identity"],"sources":["../src/create-colors.ts","../src/index.ts"],"sourcesContent":["import { entries, identity } from '@neodx/std';\n\n// TODO(#165): rework positional options\nexport function createColors(isTTY = false, disabled = false, force = false) {\n  const enabled =\n    force ||\n    (!disabled &&\n      typeof process !== 'undefined' &&\n      !('NO_COLOR' in process.env || process.argv.includes('--no-color')) &&\n      !('GITHUB_ACTIONS' in process.env) &&\n      ('FORCE_COLOR' in process.env ||\n        process.argv.includes('--color') ||\n        process.platform === 'win32' ||\n        (isTTY && process.env.TERM !== 'dumb') ||\n        'CI' in process.env));\n\n  return Object.fromEntries(\n    colorsEntries.map(([color]) => [color, enabled ? formatters[color] : identity])\n  ) as Colors;\n}\n\nexport type Colors = Record<ColorName, ColorFormatter>;\nexport type ColorName = keyof typeof colorsMap;\nexport type ColorFormatter = (message: string) => string;\n\nconst colorsMap = {\n  // modifiers\n  reset: [0, 0],\n  bold: [1, 22],\n  dim: [2, 22],\n  italic: [3, 23],\n  overline: [53, 55],\n  underline: [4, 24],\n  inverse: [7, 27],\n  hidden: [8, 28],\n  strikethrough: [9, 29],\n\n  // colors\n  black: [30, 39],\n  red: [31, 39],\n  green: [32, 39],\n  yellow: [33, 39],\n  blue: [34, 39],\n  magenta: [35, 39],\n  cyan: [36, 39],\n  white: [37, 39],\n  gray: [90, 39],\n\n  // bright colors\n\n  redBright: [91, 39],\n  greenBright: [92, 39],\n  yellowBright: [93, 39],\n  blueBright: [94, 39],\n  magentaBright: [95, 39],\n  cyanBright: [96, 39],\n  whiteBright: [97, 39],\n\n  // background colors\n  bgBlack: [40, 49],\n  bgRed: [41, 49],\n  bgGreen: [42, 49],\n  bgYellow: [43, 49],\n  bgBlue: [44, 49],\n  bgMagenta: [45, 49],\n  bgCyan: [46, 49],\n  bgWhite: [47, 49]\n} satisfies Record<string, [open: number, close: number]>;\nconst colorsEntries = entries(colorsMap);\nconst formatters = Object.fromEntries(\n  colorsEntries.map(([key, [openCode, closeCode]]) => {\n    const rgx = new RegExp(`\\\\x1b\\\\[${closeCode}m`, 'g');\n    const open = `\\u001B[${openCode}m`;\n    const close = `\\u001B[${closeCode}m`;\n\n    return [\n      key,\n      (message: string) =>\n        open + (!message.includes(close) ? message.replace(rgx, close + open) : message) + close\n    ];\n  })\n);\n","import { createColors } from './create-colors';\n\nexport type { ColorFormatter, ColorName, Colors } from './create-colors';\n\nexport const colors = createColors(true);\nexport { createColors };\n"],"mappings":";;;AAGA,SAAgB,aAAa,QAAQ,OAAO,WAAW,OAAO,QAAQ,OAAO;CAC3E,MAAM,UACJ,SACC,CAAC,YACA,OAAO,YAAY,eACnB,EAAE,cAAc,QAAQ,OAAO,QAAQ,KAAK,SAAS,YAAY,MACjE,EAAE,oBAAoB,QAAQ,SAC7B,iBAAiB,QAAQ,OACxB,QAAQ,KAAK,SAAS,SAAS,KAC/B,QAAQ,aAAa,WACpB,SAAS,QAAQ,IAAI,SAAS,UAC/B,QAAQ,QAAQ;CAEtB,OAAO,OAAO,YACZ,cAAc,KAAK,CAAC,WAAW,CAAC,OAAO,UAAU,WAAW,SAASA,WAAAA,QAAQ,CAAC,CAChF;AACF;AAiDA,MAAM,iBAAA,GAAA,WAAA,QAAA,CAAwB;CAzC5B,OAAO,CAAC,GAAG,CAAC;CACZ,MAAM,CAAC,GAAG,EAAE;CACZ,KAAK,CAAC,GAAG,EAAE;CACX,QAAQ,CAAC,GAAG,EAAE;CACd,UAAU,CAAC,IAAI,EAAE;CACjB,WAAW,CAAC,GAAG,EAAE;CACjB,SAAS,CAAC,GAAG,EAAE;CACf,QAAQ,CAAC,GAAG,EAAE;CACd,eAAe,CAAC,GAAG,EAAE;CAGrB,OAAO,CAAC,IAAI,EAAE;CACd,KAAK,CAAC,IAAI,EAAE;CACZ,OAAO,CAAC,IAAI,EAAE;CACd,QAAQ,CAAC,IAAI,EAAE;CACf,MAAM,CAAC,IAAI,EAAE;CACb,SAAS,CAAC,IAAI,EAAE;CAChB,MAAM,CAAC,IAAI,EAAE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