{"_id":"@duongtdn/style-factory","name":"@duongtdn/style-factory","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@duongtdn/style-factory","version":"1.0.0","description":"## Overview","main":"dist/index.js","scripts":{"clean":"rm -rf dist","build":"babel src --out-dir dist --source-maps","test":"jest"},"keywords":[],"repository":{"type":"git","url":"git+https://github.com/duongtdn/style-factory.git"},"author":{"name":"duongtdn"},"license":"MIT","bugs":{"url":"https://github.com/duongtdn/style-factory/issues"},"homepage":"https://github.com/duongtdn/style-factory#readme","devDependencies":{"@babel/cli":"^7.19.3","@babel/core":"^7.19.1","@babel/plugin-proposal-object-rest-spread":"^7.18.9","@babel/preset-env":"^7.19.1","core-js":"^3.25.3","jest":"^29.0.3","regenerator-runtime":"^0.13.9"},"gitHead":"64355c30b6370cfb5b55523a542132f794111f33","_id":"@duongtdn/style-factory@1.0.0","_nodeVersion":"16.19.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-hFVOKKbLeFrGIGDqcGrDSgDe1XX9v6gjkNyB8MHpcXvz6L7rEjLR0l/095fsBOKrqAhU9zfm5NepDAYdpcb8Hw==","shasum":"8ebf87fc4e4872021c7179ef084c27e176ad15a5","tarball":"https://registry.npmjs.org/@duongtdn/style-factory/-/style-factory-1.0.0.tgz","fileCount":7,"unpackedSize":19348,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFoBujyB/AHrVy6yacMIn7NBoHh4uFA7QLO43KckzPYcAiEA9KG3z4s0k4FcnvuQ/gsWUWXWFgpuiltlQmg31RA9QkM="}]},"_npmUser":{"name":"duongtdn","email":"duongtdn@gmail.com"},"directories":{},"maintainers":[{"name":"duongtdn","email":"duongtdn@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/style-factory_1.0.0_1694152398813_0.4561024357481016"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-08T05:53:18.704Z","1.0.0":"2023-09-08T05:53:18.974Z","modified":"2023-09-08T05:53:19.285Z"},"maintainers":[{"name":"duongtdn","email":"duongtdn@gmail.com"}],"description":"## Overview","homepage":"https://github.com/duongtdn/style-factory#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/duongtdn/style-factory.git"},"author":{"name":"duongtdn"},"bugs":{"url":"https://github.com/duongtdn/style-factory/issues"},"license":"MIT","readme":"# Style Factory\n\n## Overview\n\nThe **Style Factory** is a JavaScript class designed to help you apply inline styles to specific patterns within a text string. It provides a clean and efficient way to format text with different styles based on user-defined patterns.\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Creating a Style Factory Instance](#creating-a-style-factory-instance)\n  - [Defining Style Rules](#defining-style-rules)\n  - [Defining Clean Rules](#defining-clean-rules)\n  - [Creating Styled Text](#creating-styled-text)\n- [API Reference](#api-reference)\n  - [useStyle(pattern, style)](#usestylepattern-style)\n  - [useCleaner(pattern)](#usecleanerpattern)\n  - [create(text)](#createtext)\n- [Examples](#examples)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\n```bash\nnpm install @duongtdn/style-factory\n```\n\n## Usage\n\n### Creating a Style Factory Instance\n\nTo start using the Style Factory, you need to create an instance of the `StyleFactory` class:\n\n```javascript\nimport StyleFactory from '@duongtdn/style-factory';\n\nconst styleFactory = new StyleFactory();\n```\n\n### Defining Style Rules\n\nThe Style Factory allows you to define patterns and associate them with inline styles. You can use the `useStyle(pattern, style)` method to add style rules. The `pattern` parameter can be a string or a regular expression, and `style` is an object that defines the inline style for matching words or patterns.\n\n```javascript\nstyleFactory.useStyle('error', { color: 'red' })\n            .useStyle(/\\serror\\s/, { backgroundColor: 'yellow' });\n```\n\n### Defining Clean Rules\n\nIn some cases, you may want to remove specific patterns from the text. The `useCleaner(pattern)` method allows you to add clean rules. Just like with style rules, `pattern` can be a string or a regular expression.\n\n```javascript\nstyleFactory.useCleaner(/\\d+/); // Remove all digits from the text\n```\n\n### Creating Styled Text\n\nOnce you've defined your style and clean rules, you can use the `create(text)` method to apply those rules to a text string. This method returns an array of objects, where each object represents a piece of text with its associated style.\n\n```javascript\nconst styledText = styleFactory.create('This is an error message: error 404.');\nconsole.log(styledText);\n```\n\n## API Reference\n\n### `useStyle(pattern, style)`\n\n- `pattern`: Can be a string or a regular expression. It defines the pattern to match in the text.\n- `style`: An object that defines the inline style for the matched pattern.\n- Returns: `this` (allows method chaining)\n\n### `useCleaner(pattern)`\n\n- `pattern`: Can be a string or a regular expression. It defines the pattern to remove from the text.\n- Returns: `this` (allows method chaining)\n\n### `create(text)`\n\n- `text`: The input text string to be formatted.\n- Returns: An array of objects containing text and their associated styles.\n\n## Examples\n\nHere's a simple example of using the Style Factory:\n\n```javascript\nimport StyleFactory from '@duongtdn/style-factory';\n\nconst styleFactory = new StyleFactory();\n\nstyleFactory.useStyle('error', { color: 'red' })\n            .useStyle(/\\serror\\s/, { backgroundColor: 'yellow' })\n            .useCleaner(/\\d+/);\n\nconst text = 'This is an error message: error 404.';\nconst styledText = styleFactory.create(text);\nconsole.log(styledText);\n```\n\nThe above example will format the text and produce an array with styled text segments.\n\n## Contributing\n\nContributions to the Style Factory are welcome! If you have ideas, suggestions, or bug reports, please open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).","readmeFilename":"README.md"}