[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-10369":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":23,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":33,"readmeContent":34,"aiSummary":35,"trendingCount":16,"starSnapshotCount":16,"syncStatus":36,"lastSyncTime":37,"discoverSource":38},10369,"consola","unjs\u002Fconsola","unjs","🐨 Elegant Console Logger for Node.js and Browser ","",null,"TypeScript",7286,213,29,38,0,4,9,33,14,37.99,"Other",false,"main",true,[27,28,29,30,31,32],"cli","console","fancy","log","node","terminal","2026-06-12 02:02:20","# 🐨 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\u003C!-- [![Codecov][codecov-src]][codecov-href] -->\n\n## Why Consola?\n\n👌&nbsp; Easy to use\u003Cbr>\n💅&nbsp; Fancy output with fallback for minimal environments\u003Cbr>\n🔌&nbsp; Pluggable reporters\u003Cbr>\n💻&nbsp; Consistent command line interface (CLI) experience\u003Cbr>\n🏷&nbsp; Tag support\u003Cbr>\n🚏&nbsp; Redirect `console` and `stdout\u002Fstderr` to consola and easily restore redirect.\u003Cbr>\n🌐&nbsp; Browser support\u003Cbr>\n⏯&nbsp; Pause\u002FResume support\u003Cbr>\n👻&nbsp; Mocking support\u003Cbr>\n👮‍♂️&nbsp; Spam prevention by throttling logs\u003Cbr>\n❯&nbsp; Interactive prompt support powered by [`clack`](https:\u002F\u002Fgithub.com\u002Fnatemoo-re\u002Fclack)\u003Cbr>\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\u002F\u002F ESM\nimport { consola, createConsola } from \"consola\";\n\n\u002F\u002F 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:\u002F\u002Fgithub.com\u002Funjs\u002Fconsola\u002Fassets\u002F904724\u002F0e511ee6-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\u002Fbasic\";\nimport { consola, createConsola } from \"consola\u002Fbrowser\";\nimport { createConsola } from \"consola\u002Fcore\";\n```\n\n## Consola Methods\n\n#### `\u003Ctype>(logObject)` `\u003Ctype>(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\u002Fprompt.ts](.\u002Fexamples\u002Fprompt.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\u002Fstderr 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`\u002F`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\u002F\u002F Jest\nconsola.mockTypes((typeName, type) => jest.fn());\n\u002F\u002F 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\u002F\u002F Jest\nconst fn = jest.fn();\n\u002F\u002F 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\u002F\u002F Jest\nconsola.mockTypes((typeName) => typeName === \"fatal\" && jest.fn());\n\u002F\u002F 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\u002Fstd-env](https:\u002F\u002Fgithub.com\u002Funjs\u002Fstd-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\u002F\u002F Prints {\"date\":\"2023-04-18T12:43:38.693Z\",\"args\":[\"foo bar\"],\"type\":\"log\",\"level\":2,\"tag\":\"\"}\nconsola.log(\"foo bar\");\n```\n\n**Example:** Exit on fatal errors\n\n```ts\nimport { consola } from 'consola';\n\nconsola.addReporter({\n  log(logObj) {\n    if(logObj.type === 'fatal') {\n      process.exit(1)\n    }\n  }\n})\n\n\u002F\u002F Will exit on this line.\nconsola.fatal(\"fatal error\");\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](.\u002Fsrc\u002Fconstants.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  \u002F\u002F level: 4,\n  \u002F\u002F fancy: true | false\n  \u002F\u002F formatOptions: {\n  \u002F\u002F     columns: 80,\n  \u002F\u002F     colors: false,\n  \u002F\u002F     compact: false,\n  \u002F\u002F     date: false,\n  \u002F\u002F },\n});\n```\n\n## Integrations\n\n### With jest or vitest\n\n```js\ndescribe(\"your-consola-mock-test\", () => {\n  beforeAll(() => {\n    \u002F\u002F Redirect std and console to consola too\n    \u002F\u002F Calling this once is sufficient\n    consola.wrapAll();\n  });\n\n  beforeEach(() => {\n    \u002F\u002F Re-mock consola before each test call to remove\n    \u002F\u002F calls from before\n    \u002F\u002F Jest\n    consola.mockTypes(() => jest.fn());\n    \u002F\u002F Vitest\n    consola.mockTypes(() => vi.fn());\n  });\n\n  test(\"your test\", async () => {\n    \u002F\u002F Some code here\n\n    \u002F\u002F Let's retrieve all messages of `consola.log`\n    \u002F\u002F 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\u002F\u002F ESM\nimport {\n  stripAnsi,\n  centerAlign,\n  rightAlign,\n  leftAlign,\n  align,\n  box,\n  colors,\n  getColor,\n  colorize,\n} from \"consola\u002Futils\";\n\n\u002F\u002F CommonJS\nconst { stripAnsi } = require(\"consola\u002Futils\");\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\u002F\u002F Prints \"hello\"\nconsola.log({ message: \"hello\" });\n\n\u002F\u002F Prints \"{ message: 'hello' }\"\nconsola.log.raw({ message: \"hello\" });\n```\n\n## License\n\nMIT\n\n\u003C!-- Badges -->\n\n[npm-version-src]: https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fv\u002Fconsola?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-version-href]: https:\u002F\u002Fnpmjs.com\u002Fpackage\u002Fconsola\n[npm-downloads-src]: https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fdm\u002Fconsola?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-downloads-href]: https:\u002F\u002Fnpmjs.com\u002Fpackage\u002Fconsola\n[codecov-src]: https:\u002F\u002Fimg.shields.io\u002Fcodecov\u002Fc\u002Fgh\u002Funjs\u002Fconsola\u002Fmain?style=flat&colorA=18181B&colorB=F0DB4F\n[codecov-href]: https:\u002F\u002Fcodecov.io\u002Fgh\u002Funjs\u002Fconsola\n[bundle-src]: https:\u002F\u002Fimg.shields.io\u002Fbundlephobia\u002Fmin\u002Fconsola?style=flat&colorA=18181B&colorB=F0DB4F\n[bundle-href]: https:\u002F\u002Fbundlephobia.com\u002Fresult?p=consola\n","Consola 是一个适用于 Node.js 和浏览器环境的优雅控制台日志库。它提供了一系列核心功能，包括易于使用的API、支持多种输出格式（即使在资源受限环境中也能正常工作）、可插拔的报告器以及一致的命令行界面体验等。此外，Consola 还具备标签支持、重定向标准输入输出流的能力、暂停\u002F恢复记录功能及防垃圾信息机制等功能特点。此项目非常适合需要跨平台统一日志管理和展示的应用场景，尤其是在开发工具、CLI应用程序或者任何需要增强日志输出美观度与功能性的Web应用中使用。",2,"2026-06-11 03:28:02","top_topic"]