{"id":22355520,"url":"https://github.com/zbo14/reworder","last_synced_at":"2025-06-15T21:37:09.129Z","repository":{"id":65489883,"uuid":"452928610","full_name":"zbo14/reworder","owner":"zbo14","description":"✏️ Replace words and phrases via custom mappings","archived":false,"fork":false,"pushed_at":"2022-02-12T17:47:11.000Z","size":622,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-02T17:36:45.320Z","etag":null,"topics":["matching","phrases","regex","subgroups","text","text-matching","text-processing","words"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/reworder","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/zbo14.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2022-01-28T03:38:33.000Z","updated_at":"2022-02-12T22:05:53.000Z","dependencies_parsed_at":"2023-01-25T17:35:14.190Z","dependency_job_id":null,"html_url":"https://github.com/zbo14/reworder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zbo14/reworder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Freworder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Freworder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Freworder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Freworder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbo14","download_url":"https://codeload.github.com/zbo14/reworder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Freworder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260053760,"owners_count":22951962,"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":["matching","phrases","regex","subgroups","text","text-matching","text-processing","words"],"created_at":"2024-12-04T14:07:03.462Z","updated_at":"2025-06-15T21:37:09.104Z","avatar_url":"https://github.com/zbo14.png","language":"JavaScript","readme":"# reworder\n\n[![npm](https://img.shields.io/npm/v/reworder.svg?color=brightgreen)](https://www.npmjs.com/package/reworder)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n\nReplace words and phrases via custom mappings!\n\n## Install\n\n`npm i reworder`\n\n## Usage\n\n**Replace by strings:**\n\n```js\n'use strict'\n\nconst reworder = require('reword')\n\nconst reword = reworder([\n  { key: 'foo', value: 'bar' },\n  { key: 'bar', value: 'baz' }\n])\n\nconst input = 'abc foo hello world bar baz'\nconst result = reword(input)\n\nconsole.log(result)\n\n// {\n//   input: 'abc foo hello world bar baz',\n//\n//   matches: [\n//     { key: 'foo', index: 4, value: 'bar' },\n//     { key: 'bar', index: 20, value: 'baz' }\n//   ],\n//\n//   output: 'abc bar hello world baz baz'\n// }\n```\n\n**Replace by regex:**\n\n```js\nconst reword = reworder({ key: /ba\\w/, value: 'foo' })\nconst input = 'abc foo hello world bar baz'\nconst result = reword(input)\n\nconsole.log(result)\n\n// {\n//   input: 'abc foo hello world bar baz',\n//\n//   matches: [\n//     { key: 'bar', index: 20, value: 'foo' },\n//     { key: 'baz', index: 24, value: 'foo' }\n//   ],\n//\n//   output: 'abc foo hello world foo foo'\n// }\n```\n\n**Replace by transform function:**\n\n```js\nconst reword = reworder({\n  key: /ba\\w/,\n  transform: key =\u003e key.slice(-1)\n})\n\nconst input = 'abc foo hello world bar baz'\nconst result = reword(input)\n\nconsole.log(result)\n\n// {\n//   input: 'abc foo hello world bar baz',\n//\n//   matches: [\n//     { key: 'bar', index: 20, value: 'r' },\n//     { key: 'baz', index: 24, value: 'z' }\n//   ],\n//\n//   output: 'abc foo hello world r z'\n// }\n```\n\n`transform` can be `async`, in which case the `reword` function returns a promise:\n\n```js\nconst result = await reword(input)\n```\n\n**Replace with options:**\n\n```js\nconst config = [\n  { key: 'foo', value: 'bar' },\n  { key: 'hello world', value: 'helloworld' }\n]\n\nconst options = {\n  caseInsensitive: true,\n  includePunctuation: ',',\n  variableSpacing: true\n}\n\nconst reword = reworder(config, options)\nconst input = 'abc FoO hello,   world bar baz'\nconst result = reword(input)\n\nconsole.log(result)\n\n// {\n//   input: 'abc FoO hello,   world bar baz',\n//\n//   matches: [\n//     { key: 'FoO', index: 4, value: 'bar' },\n//     { key: 'hello,   world', index: 8, value: 'helloworld' }\n//   ],\n//\n//   output: 'abc bar helloworld bar baz'\n// }\n```\n\n## Reference\n\n* `config` is an object literal or array of object literals. Each object literal must contain a `key` (string or RegExp) and either `value` (string) or `transform` (function). The `transform` function should accept a single argument- a string matching the `key`, and return a string or a promise that resolves to a string.\n* `options` is an object literal with the following properties:\n    * `caseInsensitive` is a boolean indicating whether regex permits case insensitive matching.\n    * `includePunctuation` is a boolean or string indicating whether/what punctuation can be included in matches.\n    * `variableSpacing` is a boolean indicating whether the regex matches variable number of spaces.\n\n## Test\n\n`npm test`\n\n## Lint\n\n`npm run lint` or `npm run lint:fix`\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbo14%2Freworder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbo14%2Freworder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbo14%2Freworder/lists"}