{"name":"consola","version":"3.3.0","keywords":["console","logger","reporter","elegant","cli","universal","unified","prompt","clack","format","error","stacktrace"],"license":"MIT","_id":"consola@3.3.0","homepage":"https://github.com/unjs/consola#readme","bugs":{"url":"https://github.com/unjs/consola/issues"},"dist":{"shasum":"b89affdff331a40eac2f11ecc571eb230b7b560b","tarball":"http://registry-npm.ywwl.com/consola/download/consola-3.3.0.tgz","fileCount":41,"integrity":"sha512-kxltocVQCwQNFvw40dlVRYeAkAvtYjMFZYNlOcsF5wExPpGwPxMwgx4IfDJvBRPtBpnQwItd5WkTaR0ZwT/TmQ==","signatures":[{"sig":"MEUCIEqij0Yuje8qpmuPMdylFnxAc3zEveylgx0dlH4htlIAAiEAu2vY3H21SYmnrGBOVYmWi3zKEA2AZpraXyr8rcewqnk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":319982,"size":81312,"noattachment":false,"key":"/consola/-/consola-3.3.0.tgz"},"main":"./lib/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.mjs","browser":"./dist/browser.mjs","engines":{"node":"^14.18.0 || >=16.10.0"},"exports":{".":{"node":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./lib/index.cjs"},"default":{"types":"./dist/browser.d.ts","import":"./dist/browser.mjs","require":"./dist/browser.cjs"}},"./core":{"types":"./dist/core.d.ts","import":"./dist/core.mjs","require":"./dist/core.cjs"},"./basic":{"node":{"types":"./dist/basic.d.ts","import":"./dist/basic.mjs","require":"./dist/basic.cjs"},"default":{"types":"./dist/browser.d.ts","import":"./dist/browser.mjs","require":"./dist/browser.cjs"}},"./utils":{"types":"./dist/utils.d.ts","import":"./dist/utils.mjs","require":"./dist/utils.cjs"},"./browser":{"types":"./dist/browser.d.ts","import":"./dist/browser.mjs","require":"./dist/browser.cjs"}},"gitHead":"0502452d9ed2aab412dffe779784d6a2be0b099a","scripts":{"dev":"vitest","lint":"eslint . && prettier -c src examples test","test":"pnpm lint && pnpm vitest run --coverage","build":"unbuild","release":"pnpm test && pnpm build && changelogen --release --push && npm publish","lint:fix":"eslint . --fix && prettier -w src examples test"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"repository":{"url":"git+https://github.com/unjs/consola.git","type":"git"},"_npmVersion":"10.9.0","description":"Elegant Console Wrapper","directories":{},"_nodeVersion":"22.12.0","_hasShrinkwrap":false,"packageManager":"pnpm@9.12.3","devDependencies":{"defu":"^6.1.4","jiti":"^2.4.2","eslint":"^9.17.0","lodash":"^4.17.21","vitest":"^2.1.8","std-env":"^3.8.0","unbuild":"^3.0.1","prettier":"^3.4.2","sentencer":"^0.2.1","sisteransi":"^1.0.5","typescript":"^5.7.2","@clack/core":"^0.4.0","@types/node":"^22.10.2","changelogen":"^0.5.7","string-width":"^7.2.0","eslint-config-unjs":"^0.4.2","@vitest/coverage-v8":"^2.1.8","is-unicode-supported":"^2.1.0"},"_npmOperationalInternal":{"tmp":"tmp/consola_3.3.0_1734652262804_0.19983006160615324","host":"s3://npm-registry-packages-npm-production"},"readme":"# 🐨 Consola\n\n> Elegant Console Wrapper\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n\n<!-- [![Codecov][codecov-src]][codecov-href] -->\n\n## Why Consola?\n\n👌&nbsp; Easy to use<br>\n💅&nbsp; Fancy output with fallback for minimal environments<br>\n🔌&nbsp; Pluggable reporters<br>\n💻&nbsp; Consistent command line interface (CLI) experience<br>\n🏷&nbsp; Tag support<br>\n🚏&nbsp; Redirect `console` and `stdout/stderr` to consola and easily restore redirect.<br>\n🌐&nbsp; Browser support<br>\n⏯&nbsp; Pause/Resume support<br>\n👻&nbsp; Mocking support<br>\n👮‍♂️&nbsp; Spam prevention by throttling logs<br>\n❯&nbsp; Interactive prompt support powered by [`clack`](https://github.com/natemoo-re/clack)<br>\n\n## Installation\n\nUsing npm:\n\n```bash\nnpm i consola\n```\n\nUsing yarn:\n\n```bash\nyarn add consola\n```\n\nUsing pnpm:\n\n```bash\npnpm i consola\n```\n\n## Getting Started\n\n```js\n// ESM\nimport { consola, createConsola } from \"consola\";\n\n// CommonJS\nconst { consola, createConsola } = require(\"consola\");\n\nconsola.info(\"Using consola 3.0.0\");\nconsola.start(\"Building project...\");\nconsola.warn(\"A new version of consola is available: 3.0.1\");\nconsola.success(\"Project built!\");\nconsola.error(new Error(\"This is an example error. Everything is fine!\"));\nconsola.box(\"I am a simple box\");\nawait consola.prompt(\"Deploy to the production?\", {\n  type: \"confirm\",\n});\n```\n\nWill display in the terminal:\n\n![consola-screenshot](https://github.com/unjs/consola/assets/904724/0e511ee6-2543-43ab-9eda-152f07134d94)\n\nYou can use smaller core builds without fancy reporter to save 80% of the bundle size:\n\n```ts\nimport { consola, createConsola } from \"consola/basic\";\nimport { consola, createConsola } from \"consola/browser\";\nimport { createConsola } from \"consola/core\";\n```\n\n## Consola Methods\n\n#### `<type>(logObject)` `<type>(args...)`\n\nLog to all reporters.\n\nExample: `consola.info('Message')`\n\n#### `await prompt(message, { type, cancel })`\n\nShow an input prompt. Type can either of `text`, `confirm`, `select` or `multiselect`.\n\nIf prompt is canceled by user (with Ctrol+C), default value will be resolved by default. This strategy can be configured by setting `{ cancel: \"...\" }` option:\n\n- `\"default\"` - Resolve the promise with the `default` value or `initial` value.\n- `\"undefined`\" - Resolve the promise with `undefined`.\n- `\"null\"` - Resolve the promise with `null`.\n- `\"symbol\"` - Resolve the promise with a symbol `Symbol.for(\"cancel\")`.\n- `\"reject\"` - Reject the promise with an error.\n\nSee [examples/prompt.ts](./examples/prompt.ts) for usage examples.\n\n#### `addReporter(reporter)`\n\n- Aliases: `add`\n\nRegister a custom reporter instance.\n\n#### `removeReporter(reporter?)`\n\n- Aliases: `remove`, `clear`\n\nRemove a registered reporter.\n\nIf no arguments are passed all reporters will be removed.\n\n#### `setReporters(reporter|reporter[])`\n\nReplace all reporters.\n\n#### `create(options)`\n\nCreate a new `Consola` instance and inherit all parent options for defaults.\n\n#### `withDefaults(defaults)`\n\nCreate a new `Consola` instance with provided defaults\n\n#### `withTag(tag)`\n\n- Aliases: `withScope`\n\nCreate a new `Consola` instance with that tag.\n\n#### `wrapConsole()` `restoreConsole()`\n\nGlobally redirect all `console.log`, etc calls to consola handlers.\n\n#### `wrapStd()` `restoreStd()`\n\nGlobally redirect all stdout/stderr outputs to consola.\n\n#### `wrapAll()` `restoreAll()`\n\nWrap both, std and console.\n\nconsole uses std in the underlying so calling `wrapStd` redirects console too.\nBenefit of this function is that things like `console.info` will be correctly redirected to the corresponding type.\n\n#### `pauseLogs()` `resumeLogs()`\n\n- Aliases: `pause`/`resume`\n\n**Globally** pause and resume logs.\n\nConsola will enqueue all logs when paused and then sends them to the reported when resumed.\n\n#### `mockTypes`\n\n- Aliases: `mock`\n\nMock all types. Useful for using with tests.\n\nThe first argument passed to `mockTypes` should be a callback function accepting `(typeName, type)` and returning the mocked value:\n\n```js\n// Jest\nconsola.mockTypes((typeName, type) => jest.fn());\n// Vitest\nconsola.mockTypes((typeName, type) => vi.fn());\n```\n\nPlease note that with the example above, everything is mocked independently for each type. If you need one mocked fn create it outside:\n\n```js\n// Jest\nconst fn = jest.fn();\n// Vitest\nconst fn = vi.fn();\nconsola.mockTypes(() => fn);\n```\n\nIf callback function returns a _falsy_ value, that type won't be mocked.\n\nFor example if you just need to mock `consola.fatal`:\n\n```js\n// Jest\nconsola.mockTypes((typeName) => typeName === \"fatal\" && jest.fn());\n// Vitest\nconsola.mockTypes((typeName) => typeName === \"fatal\" && vi.fn());\n```\n\n**NOTE:** Any instance of consola that inherits the mocked instance, will apply provided callback again.\nThis way, mocking works for `withTag` scoped loggers without need to extra efforts.\n\n## Custom Reporters\n\nConsola ships with 3 built-in reporters out of the box. A fancy colored reporter by default and fallsback to a basic reporter if running in a testing or CI environment detected using [unjs/std-env](https://github.com/unjs/std-env) and a basic browser reporter.\n\nYou can create a new reporter object that implements `{ log(logObject): () => { } }` interface.\n\n**Example:** Simple JSON reporter\n\n```ts\nimport { createConsola } from \"consola\";\n\nconst consola = createConsola({\n  reporters: [\n    {\n      log: (logObj) => {\n        console.log(JSON.stringify(logObj));\n      },\n    },\n  ],\n});\n\n// Prints {\"date\":\"2023-04-18T12:43:38.693Z\",\"args\":[\"foo bar\"],\"type\":\"log\",\"level\":2,\"tag\":\"\"}\nconsola.log(\"foo bar\");\n```\n\n## Log Level\n\nConsola only shows logs with configured log level or below. (Default is `3`)\n\nAvailable log levels:\n\n- `0`: Fatal and Error\n- `1`: Warnings\n- `2`: Normal logs\n- `3`: Informational logs, success, fail, ready, start, ...\n- `4`: Debug logs\n- `5`: Trace logs\n- `-999`: Silent\n- `+999`: Verbose logs\n\nYou can set the log level by either:\n\n- Passing `level` option to `createConsola`\n- Setting `consola.level` on instance\n- Using the `CONSOLA_LEVEL` environment variable (not supported for browser and core builds).\n\n## Log Types\n\nLog types are exposed as `consola.[type](...)` and each is a preset of styles and log level.\n\nA list of all available built-in types is [available here](./src/constants.ts).\n\n## Creating a new instance\n\nConsola has a global instance and is recommended to use everywhere.\nIn case more control is needed, create a new instance.\n\n```js\nimport { createConsola } from \"consola\";\n\nconst logger = createConsola({\n  // level: 4,\n  // fancy: true | false\n  // formatOptions: {\n  //     columns: 80,\n  //     colors: false,\n  //     compact: false,\n  //     date: false,\n  // },\n});\n```\n\n## Integrations\n\n### With jest or vitest\n\n```js\ndescribe(\"your-consola-mock-test\", () => {\n  beforeAll(() => {\n    // Redirect std and console to consola too\n    // Calling this once is sufficient\n    consola.wrapAll();\n  });\n\n  beforeEach(() => {\n    // Re-mock consola before each test call to remove\n    // calls from before\n    // Jest\n    consola.mockTypes(() => jest.fn());\n    // Vitest\n    consola.mockTypes(() => vi.fn());\n  });\n\n  test(\"your test\", async () => {\n    // Some code here\n\n    // Let's retrieve all messages of `consola.log`\n    // Get the mock and map all calls to their first argument\n    const consolaMessages = consola.log.mock.calls.map((c) => c[0]);\n    expect(consolaMessages).toContain(\"your message\");\n  });\n});\n```\n\n### With jsdom\n\n```js\n{\n  new jsdom.VirtualConsole().sendTo(consola);\n}\n```\n\n## Console Utils\n\n```ts\n// ESM\nimport {\n  stripAnsi,\n  centerAlign,\n  rightAlign,\n  leftAlign,\n  align,\n  box,\n  colors,\n  getColor,\n  colorize,\n} from \"consola/utils\";\n\n// CommonJS\nconst { stripAnsi } = require(\"consola/utils\");\n```\n\n## Raw logging methods\n\nObjects sent to the reporter could lead to unexpected output when object is close to internal object structure containing either `message` or `args` props. To enforce the object to be interpreted as pure object, you can use the `raw` method chained to any log type.\n\n**Example:**\n\n```js\n// Prints \"hello\"\nconsola.log({ message: \"hello\" });\n\n// Prints \"{ message: 'hello' }\"\nconsola.log.raw({ message: \"hello\" });\n```\n\n## License\n\nMIT\n\n<!-- Badges -->\n\n[npm-version-src]: https://img.shields.io/npm/v/consola?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-version-href]: https://npmjs.com/package/consola\n[npm-downloads-src]: https://img.shields.io/npm/dm/consola?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-downloads-href]: https://npmjs.com/package/consola\n[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/consola/main?style=flat&colorA=18181B&colorB=F0DB4F\n[codecov-href]: https://codecov.io/gh/unjs/consola\n[bundle-src]: https://img.shields.io/bundlephobia/min/consola?style=flat&colorA=18181B&colorB=F0DB4F\n[bundle-href]: https://bundlephobia.com/result?p=consola\n","publish_time":1734652263001,"maintainers":[{"name":"atinux","email":"atinux@gmail.com"},{"name":"pi0","email":"pyapar@gmail.com"}],"_cnpm_publish_time":1734652263001,"dist-tags":{"1x":"1.4.5","3x":"3.0.0-5","latest":"3.4.2"}}