{"id":14982062,"url":"https://github.com/gulpjs/theming-log","last_synced_at":"2025-10-19T11:31:17.804Z","repository":{"id":41519069,"uuid":"116025713","full_name":"gulpjs/theming-log","owner":"gulpjs","description":"Creates a logger with theme for text decoration.","archived":false,"fork":false,"pushed_at":"2022-10-01T05:25:13.000Z","size":88,"stargazers_count":4,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-29T15:14:39.572Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gulpjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-02T14:50:24.000Z","updated_at":"2023-12-10T14:38:51.000Z","dependencies_parsed_at":"2023-01-19T04:02:16.115Z","dependency_job_id":null,"html_url":"https://github.com/gulpjs/theming-log","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Ftheming-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Ftheming-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Ftheming-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Ftheming-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gulpjs","download_url":"https://codeload.github.com/gulpjs/theming-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237116948,"owners_count":19258331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T14:04:43.360Z","updated_at":"2025-10-19T11:31:17.452Z","avatar_url":"https://github.com/gulpjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://gulpjs.com\"\u003e\n    \u003cimg height=\"257\" width=\"114\" src=\"https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n# theming-log\n\n[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]\n\nCreates a logger with theme for text decorations.\n\n## Usage\n\n```js\nconst themingLog = require('theming-log');\nconst ansiColors = require('ansi-colors'); // Use ansi-colors for coloring in this example.\n\nconst emojiCry = String.fromCodePoint(0x1f622);\n\nconst theme = {\n  ERROR: '{red: {1}}',\n  red: ansiColors.red,\n  emoji: {\n    Cry: () =\u003e emojiCry,\n  },\n};\n\nconst log = themingLog(theme);\n\nlog('{emoji.Cry} This is {ERROR: an error message: {1: error code} }.', 'E001');\n// =\u003e '😢 This is \\u001b[31man error message: E001\\u001b[39m.'\n\nvar str = themingLog.format(\n  '{emoji.Cry} This is {ERROR: an error message: {1: error code} }.',\n  'E001'\n);\n// str === '😢 This is \\u001b[31man error message: E001\\u001b[39m.'\n```\n\n## API\n\n### themingLog(theme [, logger] [, lineSep]) : function\n\nCreates a logging function based on `console.log` or a specified logging function. This created logging function converts a template text which contains style blocks (for example, `'{MSG: a message.}'`) to a decorated text.\n\nThe _theme_ is an plain object which maps pairs of a style name (`'MSG'` in the above example) and either a style function or a template text.\nA style function receives a block content (`'a message'` in the above example) and returns a converted text.\nIf a block content is a template text, it is parsed and converted with theme equally.\n\nIf the 2nd or 3rd argument is boolean, it is set to _lineSep_.\nIf _lineSep_ is true, the created logging function split a converted text into multiple lines with newline codes and output them line by line.\n\n**Parameters:**\n\n| Parameter |   Type   | Description                                                                                                             |\n| :-------- | :------: | :---------------------------------------------------------------------------------------------------------------------- |\n| _theme_   |  object  | An object which is a map of style names and either style functions or template texts.                                   |\n| _logger_  | function | A logging function which is based on by a created logging function. (Optional, and `console.log` in default.)           |\n| _lineSep_ | boolean  | If true, A logging function split a converted text into multiple lines with newline codes and output them line by line. |\n\n**Returns:**\n\nA logging function with theme for text decorations.\n\nThe API of a returned function is as follows:\n\n- **_log_** **(template [, ...args]) : Void**\n\n  | Parameters |  Type  | Description                                               |\n  | :--------- | :----: | :-------------------------------------------------------- |\n  | _template_ | string | A template text (explained [above][template])             |\n  | _args_     | _any_  | Style blocks for arguments (explained [above][arguments]) |\n\n#### Format of a template text\n\nA template text can contain style blocks in itself.\nA style block is rounded by `{` and `}`, and this can has a pair of a style name and a block content which are separated by a colon `:`.\nIf there is no colon in a style block, the whole text in the block is operated as a style name.\n\n- `'{ xxxx: yyyy }'` → the style name is `'xxxx'` and the block content is `'yyyy'`.\n- `'{ xxxx }'` → the style name is `'xxxx'` and the block content is `''`.\n- `'{ xxxx : }'` → the style name is `'xxxx'` and the block content is `''`.\n- `'{ : yyyy }'` → `'yyyy'` is operated as a text, not a block content.\n\nTexts in a style block, both a style name and a block content, are trimmed white spaces on both sides.\nRegarding a block content, the escape mark `\\` can prevent trimming.\nAlso, this mark can escape `{` and `}`.\n\n- `'{ xxx: \\\\ yyy\\\\ }'` → theme name is `'xxx'` and block content is `' yyy '`.\n- `'\\\\{ xxx: yyy \\\\}'` → a text `'{ xxx: yyy }'`, not a style block.\n\n**_NOTICE:_** _Both a function created by **themingLog** and **themingLog.format** use `\\` as an escape mark, therefore `\\` in a template text are erased.\nSo you need to take care of `\\` marks, especially path separators on Windows._\n\n```js\nvar log = themingLog({}, console.log);\nvar format = themingLog.format;\n\n// Erases '\\\\' as a escape mark.\nlog('C:\\\\\\\\abc\\\\\\\\def\\\\\\\\ghi');\n// =\u003e console.log('C:\\\\abc\\\\def\\\\ghi') =\u003e C:\\abc\\def\\ghi\n\n// Not erases '\\\\' in arguments.\nlog('{1}', 'C:\\\\abc\\\\def\\\\ghi');\n// =\u003e console.log('C:\\\\abc\\\\def\\\\ghi') =\u003e C:\\abc\\def\\ghi\n\n// Erases '\\\\' as a escape mark.\nconsole.log(format({}, 'C:\\\\\\\\abc\\\\\\\\def\\\\\\\\ghi'));\n// =\u003e console.log('C:\\\\abc\\\\def\\\\ghi') =\u003e C:\\abc\\def\\ghi\n\n// Not erases '\\\\' in arguments.\nconsole.log(format({}, '{1}', 'C:\\\\abc\\\\def\\\\ghi'));\n// =\u003e console.log('C:\\\\abc\\\\def\\\\ghi') =\u003e C:\\abc\\def\\ghi\n\n// format() and next log() erase double '\\\\' as escape marks\nlog(format({}, 'C:\\\\\\\\\\\\\\\\abc\\\\\\\\\\\\\\\\def\\\\\\\\\\\\\\\\ghi'));\n// =\u003e log('C:\\\\\\\\abc\\\\\\\\def\\\\\\\\ghi') =\u003e C:\\abc\\def\\ghi\n\n// Only log() erases '\\\\' as a escape mark.\nlog(format({}, '{1}', 'C:\\\\\\\\abc\\\\\\\\def\\\\\\\\ghi'));\n// =\u003e log('C:\\\\\\\\abc\\\\\\\\def\\\\\\\\ghi') =\u003e C:\\abc\\def\\ghi\n\n// Neither log() nor format() erase '\\\\'\nlog('{1}', format({}, '{1}', 'C:\\\\abc\\\\def\\\\ghi'));\n// =\u003e log('{1]\", 'C:\\\\abc\\\\def\\\\ghi') =\u003e C:\\abc\\def\\ghi\n```\n\n##### Style block for argument\n\nA logging function can take multiple arguments.\nA style block to be converted to an argument is same format with a normal style block but its style name is a number starting from 1, which indicates the index of the argument, like `{2}` or `{2: Explanatory text }`. A block content in a style block for an argument is never used, so it can be used as an explanatory text.\n\n- `{ 1 }` → replaced with the second argument (the first argument except the template text) of logging function, or an empty string if the second argument is not given.\n- `{ 3 : yyyy }` → replaced with the fourth argument (the third argument except the template text) of logging function, or an empty string if the fourth argument is not given. (`'yyyy'` is never used.)\n\n### themingLog.format(theme, template [, ...args]) : string\n\nParses _template_ text and converts it to a decorated string with _theme_ and _args_.\n\n**Parameters:**\n\n| Parameter  |  Type  | Description                                                                           |\n| :--------- | :----: | :------------------------------------------------------------------------------------ |\n| _theme_    | object | An object which is a map of style names and either style functions or template texts. |\n| _template_ | string | A template text (explained [above][template])                                         |\n| _args_     | _any_  | Style blocks for arguments (explained [above][arguments])                             |\n\n**Returns:**\n\nA converted string.\n\n### themingLog.formatLines(theme, template [, ...args]) : Array\n\nParses _template_ text, converts it to a decorated string with _theme_ and _args_, and splits the decorated string to multiple lines with newline codes.\n\n**Parameters:**\n\n| Parameter  |  Type  | Description                                                                           |\n| :--------- | :----: | :------------------------------------------------------------------------------------ |\n| _theme_    | object | An object which is a map of style names and either style functions or template texts. |\n| _template_ | string | A template text (explained [above][template])                                         |\n| _args_     | _any_  | Style blocks for arguments (explained [above][arguments])                             |\n\n**Returns:**\n\nAn array of converted string splitted by newline codes.\n\n## License\n\nMIT\n\n\u003c!-- prettier-ignore-start --\u003e\n[downloads-image]: https://img.shields.io/npm/dm/theming-log.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/theming-log\n[npm-image]: https://img.shields.io/npm/v/theming-log.svg?style=flat-square\n\n[ci-url]: https://github.com/gulpjs/theming-log/actions?query=workflow:dev\n[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/theming-log/dev?style=flat-square\n\n[coveralls-url]: https://coveralls.io/r/gulpjs/theming-log\n[coveralls-image]: https://img.shields.io/coveralls/gulpjs/theming-log/master.svg?style=flat-square\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- prettier-ignore-start --\u003e\n[template]: #format-of-a-template-text\n[arguments]: #style-block-for-argument\n\u003c!-- prettier-ignore-end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgulpjs%2Ftheming-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgulpjs%2Ftheming-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgulpjs%2Ftheming-log/lists"}