{"versions":{"0.2.1":{"name":"ansi-fragments","version":"0.2.1","main":"build/index.js","license":"MIT","description":"A tiny library with builders to help making logs/CLI pretty with a nice DX.","repository":{"type":"git","url":"https://github.com/zamotany/ansi-fragments.git"},"keywords":["cli","ansi"],"author":{"name":"Paweł Trysła","email":"zamotany.oss@gmail.com"},"bugs":{"url":"https://github.com/zamotany/ansi-fragments/issues"},"homepage":"https://github.com/zamotany/ansi-fragments","scripts":{"lint":"tslint -t stylish --project tsconfig.json","test":"jest","build":"tsc --build tsconfig.json","clean":"del build","prepare":"yarn clean && yarn build"},"dependencies":{"colorette":"^1.0.7","slice-ansi":"^2.0.0","strip-ansi":"^5.0.0"},"devDependencies":{"@callstack/tslint-config":"^0.1.0","@types/jest":"^23.3.13","@types/slice-ansi":"^2.0.0","@types/strip-ansi":"^3.0.0","del-cli":"^1.1.0","jest":"^24.0.0","ts-jest":"^23.10.5","tslint":"^5.12.0","typescript":"^3.2.2"},"jest":{"preset":"ts-jest","rootDir":"./src"},"_id":"ansi-fragments@0.2.1","dist":{"shasum":"24409c56c4cc37817c3d7caa99d8969e2de5a05e","size":8528,"noattachment":false,"tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/ansi-fragments/-/ansi-fragments-0.2.1.tgz"},"maintainers":[{"name":"anonymous","email":"zamotany.oss@gmail.com"}],"_npmUser":{"name":"anonymous","email":"zamotany.oss@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ansi-fragments_0.2.1_1554630505743_0.31298859893584074"},"_hasShrinkwrap":false,"publish_time":1554630505937,"_cnpm_publish_time":1554630505937,"contributors":[]},"0.1.1":{"name":"ansi-fragments","version":"0.1.1","main":"build/index.js","license":"MIT","description":"A tiny library with builders to help making logs/CLI pretty with a nice DX.","repository":{"type":"git","url":"https://github.com/zamotany/ansi-fragments.git"},"keywords":["cli","ansi"],"author":{"name":"Paweł Trysła","email":"zamotany.oss@gmail.com"},"bugs":{"url":"https://github.com/zamotany/ansi-fragments/issues"},"homepage":"https://github.com/zamotany/ansi-fragments","scripts":{"lint":"tslint -t stylish --project tsconfig.json","test":"jest","build":"tsc --build tsconfig.json","clean":"del build","prepare":"yarn clean && yarn build"},"dependencies":{"colorette":"^1.0.7","slice-ansi":"^2.0.0","strip-ansi":"^5.0.0"},"devDependencies":{"@callstack/tslint-config":"^0.1.0","@types/jest":"^23.3.13","@types/slice-ansi":"^2.0.0","@types/strip-ansi":"^3.0.0","del-cli":"^1.1.0","jest":"^24.0.0","ts-jest":"^23.10.5","tslint":"^5.12.0","typescript":"^3.2.2"},"jest":{"preset":"ts-jest","rootDir":"./src"},"_id":"ansi-fragments@0.1.1","dist":{"shasum":"9e6c1b81c36219bf45317132d66857342bb05f73","size":7357,"noattachment":false,"tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/ansi-fragments/-/ansi-fragments-0.1.1.tgz"},"maintainers":[{"name":"anonymous","email":"zamotany.oss@gmail.com"}],"_npmUser":{"name":"anonymous","email":"zamotany.oss@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ansi-fragments_0.1.1_1554629509433_0.9380774602620081"},"_hasShrinkwrap":false,"publish_time":1554629509587,"_cnpm_publish_time":1554629509587,"contributors":[]},"0.2.0":{"name":"ansi-fragments","version":"0.2.0","main":"build/index.js","license":"MIT","description":"A tiny library with builders to help making logs/CLI pretty with a nice DX.","repository":{"type":"git","url":"https://github.com/zamotany/ansi-fragments.git"},"keywords":["cli","ansi"],"author":{"name":"Paweł Trysła","email":"zamotany.oss@gmail.com"},"bugs":{"url":"https://github.com/zamotany/ansi-fragments/issues"},"homepage":"https://github.com/zamotany/ansi-fragments","scripts":{"lint":"tslint -t stylish --project tsconfig.json","test":"jest","build":"tsc --build tsconfig.json","clean":"del build","prepare":"yarn clean && yarn build"},"dependencies":{"colorette":"^1.0.7","del-cli":"^1.1.0","slice-ansi":"^2.0.0","strip-ansi":"^5.0.0"},"devDependencies":{"@callstack/tslint-config":"^0.1.0","@types/jest":"^23.3.13","@types/slice-ansi":"^2.0.0","@types/strip-ansi":"^3.0.0","jest":"^24.0.0","ts-jest":"^23.10.5","tslint":"^5.12.0","typescript":"^3.2.2"},"jest":{"preset":"ts-jest","rootDir":"./src"},"_id":"ansi-fragments@0.2.0","dist":{"shasum":"6d6d9ddf374b2df31d1f26837b08b9a627bb59da","size":9390,"noattachment":false,"tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/ansi-fragments/-/ansi-fragments-0.2.0.tgz"},"maintainers":[{"name":"anonymous","email":"zamotany.oss@gmail.com"}],"_npmUser":{"name":"anonymous","email":"zamotany.oss@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ansi-fragments_0.2.0_1548445335641_0.657194310900675"},"_hasShrinkwrap":false,"publish_time":1548445335784,"_cnpm_publish_time":1548445335784,"contributors":[]},"0.1.0":{"name":"ansi-fragments","version":"0.1.0","main":"build/index.js","license":"MIT","description":"A tiny library with builders to help making logs/CLI pretty with a nice DX.","repository":{"type":"git","url":"git+https://github.com/zamotany/ansi-fragments.git"},"keywords":["cli","ansi"],"author":{"name":"Paweł Trysła","email":"zamotany.oss@gmail.com"},"bugs":{"url":"https://github.com/zamotany/ansi-fragments/issues"},"homepage":"https://github.com/zamotany/ansi-fragments","scripts":{"lint":"tslint -t stylish --project tsconfig.json","build":"tsc --build tsconfig.json","clean":"del build","prepare":"yarn clean && yarn build"},"dependencies":{"colorette":"^1.0.7","del-cli":"^1.1.0","slice-ansi":"^2.0.0","strip-ansi":"^5.0.0"},"devDependencies":{"@callstack/tslint-config":"^0.1.0","@types/slice-ansi":"^2.0.0","@types/strip-ansi":"^3.0.0","tslint":"^5.12.0","typescript":"^3.2.2"},"gitHead":"d1aee29a868a37f5c4f2bafe2d3a49d24a5b21cb","_id":"ansi-fragments@0.1.0","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"anonymous","email":"zamotany.oss@gmail.com"},"dist":{"shasum":"147d805a6512bd5aa4bc84df5d6c067b225ce477","size":5935,"noattachment":false,"tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/ansi-fragments/-/ansi-fragments-0.1.0.tgz"},"maintainers":[{"name":"anonymous","email":"zamotany.oss@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ansi-fragments_0.1.0_1546908043323_0.3462458557019117"},"_hasShrinkwrap":false,"publish_time":1546908043406,"_cnpm_publish_time":1546908043406,"contributors":[]}},"dist-tags":{"latest":"0.2.1"},"name":"ansi-fragments","time":{"modified":"2023-07-28T03:42:41.887Z","created":"2022-01-26T23:20:47.581Z","0.2.1":"2019-04-07T09:48:25.937Z","0.1.1":"2019-04-07T09:31:49.587Z","0.2.0":"2019-01-25T19:42:15.784Z","0.1.0":"2019-01-08T00:40:43.406Z"},"readme":"# ansi-fragments\n\n[![Version][version]][package]   \n\n[![PRs Welcome][prs-welcome-badge]][prs-welcome]\n[![MIT License][license-badge]][license]\n[![Chat][chat-badge]][chat]\n[![Code of Conduct][coc-badge]][coc]\n\nA tiny library with builders to help making logs/CLI pretty with a nice DX.\n\n- [ansi-fragments](#ansi-fragments)\n  - [Installation](#installation)\n  - [Usage](#usage)\n  - [API](#api)\n      - [`color`](#color)\n      - [`modifier`](#modifier)\n      - [`container`](#container)\n      - [`pad`](#pad)\n      - [`fixed`](#fixed)\n      - [`ifElse`](#ifElse)\n      - [`provide`](#provide)\n\n## Installation\n\n```bash\nyarn add ansi-fragments\n```\n\n## Usage\n\n```js\nimport { color, modifier, pad, container } from 'ansi-fragments';\n\nconst prettyLog = (level, message) => container(\n  color('green', modifier('italic', level)),\n  pad(1),\n  message\n).build();\n\nconsole.log(prettyLog('success', 'Yay!'));\n```\n\n## API\n\nEach fragment implements `IFragment` interface:\n\n```ts\ninterface IFragment {\n  build(): string;\n}\n```\n\nThe `build` method is responsible for traversing the tree of fragments and create a string representation with ANSI escape codes.\n\n\n#### `color`\n\n```ts\ncolor(\n  ansiColor: AnsiColor,\n  ...children: Array<string | IFragment>\n): IFragment\n```\n\nCreates fragment for standard ANSI [colors](./src/fragments/Color.ts).\n\n```js\ncolor('red', 'Oh no');\ncolor('bgBlue', color('brightBlue', 'Hey'));\ncolor('green', modifier('bold', 'Sup!'));\n```\n\n#### `modifier`\n\n```ts\nmodifier(\n  ansiModifier: AnsiModifier,\n  ...children: Array<string | IFragment>\n): IFragment\n```\n\nCreates fragment for standard ANSI [modifiers](./src/fragments/Modifier.ts): `dim`, `bold`, `hidden`, `italic`, `underline`, `strikethrough`.\n\n```js\nmodifier('underline', 'Hello', 'World');\nmodifier('italic', modifier('bold', 'Hey'));\nmodifier('bold', color('green', 'Sup!'));\n```\n\n#### `container`\n\n```ts\ncontainer(...children: Array<string | IFragment>): IFragment\n```\n\nCreates fragment, which sole purpose is to hold and build nested fragments.\n\n```js\ncontainer(\n  color('gray', '[08/01/18 12:00]'),\n  pad(1),\n  color('green', 'success'),\n  pad(1),\n  'Some message'\n)\n```\n\n#### `pad`\n\n```ts\npad(count: number, separator?: string): IFragment\n```\n\nCreates fragment, which repeats given separator (default: ` `) given number of times.\n\n```js\npad(1);\npad(2, '#')\npad(1, '\\n')\n```\n\n#### `fixed`\n\n```ts\nfixed(\n  value: number,\n  bias: 'start' | 'end',\n  ...children: Array<string | IFragment>\n): IFragment\n```\n\nCreates fragment, which makes sure the children will always build to given number of non-ANSI characters. It will either trim the results or add necessary amount of spaces. The `bias` control if trimming/padding should be done at the start of the string representing built children or at the end.\n\n```js\nfixed(5, 'start', 'ERR'); // => '  ERR'\nfixed(8, 'end', color('green', 'success')); // equals to color('green', 'success') + ' '\nfixed(10, 'end', 'Hello', pad(2), 'World') // => 'Hello  Wor'\n```\n\n#### `ifElse`\n\n```ts\nifElse(\n  condition: Condition,\n  ifTrueFragment: string | IFragment,\n  elseFragment: string | IFragment\n): IFragment\n\ntype ConditionValue = boolean | string | number | null | undefined;\ntype Condition = ConditionValue | (() => ConditionValue);\n```\n\nChange the output based on condition. Condition can ba a primitive value, which can be casted to boolean or a function. If conation or return value of condition is evaluated to `true`, the first argument - `ifTrueFragment` will be used, otherwise `elseFragment`.\n\n```js\nlet condition = getConditionValue()\nifElse(\n  () => condition,\n  color('red', 'ERROR'),\n  color('yellow', 'WARNING')\n)\n```\n\n#### `provide`\n\n```ts\nprovide<T>(\n  value: T,\n  builder: (value: T) => string | IFragment\n): IFragment\n```\n\nProvides given value to a builder function, which should return `string` or fragment. Useful in situations when the output is connected with some calculated value - using `provide` you only need to calculate final value once and forward it to custom styling logic.\n\n```js\nprovide(getMessageFromSomewhere(), value => {\n  switch (value.level) {\n    case 'error':\n      return container(\n        color('red', modifier('bold', value.level.toUpperCase())),\n        pad(2),\n        value.log\n      );\n    case 'info':\n      return container(\n        color('blue', value.level.toUpperCase()),\n        pad(2),\n        value.log\n      );\n    default:\n      return container(value.level.toUpperCase(), pad(2), value.log);\n  }\n})\n```\n\n\n<!-- badges (common) -->\n\n[license-badge]: https://img.shields.io/npm/l/ansi-fragments.svg?style=flat-square\n[license]: https://opensource.org/licenses/MIT\n[prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square\n[prs-welcome]: http://makeapullrequest.com\n[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square\n[coc]: https://github.com/zamotany/ansi-fragments/blob/master/CODE_OF_CONDUCT.md\n[chat-badge]: https://img.shields.io/badge/chat-discord-brightgreen.svg?style=flat-square&colorB=7289DA&logo=discord\n[chat]: https://discord.gg/zwR2Cdh\n\n[version]: https://img.shields.io/npm/v/ansi-fragments.svg?style=flat-square\n[package]: https://www.npmjs.com/package/ansi-fragments","users":{}}