{"id":24580429,"url":"https://github.com/ichengbo/string-multiple-replace","last_synced_at":"2025-04-24T01:09:54.755Z","repository":{"id":38819079,"uuid":"152354612","full_name":"iChengbo/string-multiple-replace","owner":"iChengbo","description":"Replace multiple substrings in a string sequentially. 用于批量替换字符串，可以实现不覆盖替换和覆盖替换，具体可以参考readme例子。","archived":false,"fork":false,"pushed_at":"2024-08-09T05:49:36.000Z","size":32,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-24T01:09:47.546Z","etag":null,"topics":["mutiple","replace","string"],"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/iChengbo.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-10T02:59:30.000Z","updated_at":"2024-08-09T05:49:40.000Z","dependencies_parsed_at":"2024-06-21T17:41:46.974Z","dependency_job_id":"b5e12d33-b4b4-4988-ba99-97c9c1a2a140","html_url":"https://github.com/iChengbo/string-multiple-replace","commit_stats":{"total_commits":25,"total_committers":3,"mean_commits":8.333333333333334,"dds":"0.31999999999999995","last_synced_commit":"e0fb56092dbd323646645a701add34843570d3c7"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Fstring-multiple-replace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Fstring-multiple-replace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Fstring-multiple-replace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Fstring-multiple-replace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iChengbo","download_url":"https://codeload.github.com/iChengbo/string-multiple-replace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250540941,"owners_count":21447427,"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":["mutiple","replace","string"],"created_at":"2025-01-24T01:54:10.967Z","updated_at":"2025-04-24T01:09:54.736Z","avatar_url":"https://github.com/iChengbo.png","language":"JavaScript","readme":"# string-multiple-replace\n\n\u003e Replace multiple substrings in a string sequentially.\n\n[![LICENSE](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)\n[![npm-version](https://img.shields.io/npm/v/string-multiple-replace)](https://www.npmjs.com/package/string-multiple-replace)\n[![npm](https://img.shields.io/npm/dm/string-multiple-replace.svg)](https://www.npmjs.com/package/string-multiple-replace)\n\nReplace all substring matches in a string with an mapping object that is table of `replaceThis: withThis`, and you can provide a `sequencer` to decide the order of replacement.\n\n## Install\n\n```sh\nnpm install --save string-multiple-replace\n```\n\nor\n\n```sh\nyarn add string-multiple-replace\n```\n\n\n## Usage\n\n```js\nconst multiReplace = require('string-multiple-replace');\n\nconst input = \"abcde\";\nconst matcherObj = {\n    \"a\": \"b\",\n    \"b\": \"c\",\n    \"c\": \"d\",\n    \"d\": \"e\"\n}\nmultiReplace(input, matcherObj, [\"a\", \"b\", \"c\", \"d\"]); // eeeee\nmultiReplace(input, matcherObj);                       // bcdee\n```\n\n- Example-1\n\n```js\nconst multiReplace = require('string-multiple-replace');\n\nconst input = \"I'm only brave when I have to be. Being brave doesn't mean you go looking for trouble.\";\nconst matcherObj = {\n    \"brave\": \"cowardly\",\n    \"trouble\": \"escape\"\n}\nconst sequencer = [\"brave\", \"trouble\"];\nmultiReplace(input, matcherObj, sequencer);\n//I'm only cowardly when I have to be. Being cowardly doesn't mean you go looking for escape.\n\n```\n\n- Example-2\n\n```js\nconst multiReplace = require('string-multiple-replace');\n\nconst input = \"I'm only brave when I have to be. Being brave doesn't mean you go looking for trouble.\";\nconst matcherObj = {\n    \"brave\": \"cowardly\",\n    \"trouble\": \"escape\"\n}\n\nmultiReplace(input, matcherObj, keys =\u003e keys);\n//I'm only cowardly when I have to be. Being cowardly doesn't mean you go looking for escape.\n\n```\n\n## API\n\n\u003e multiReplace(input, matcherObj [,sequencer])\n\nThe original string is replaced in turn according to the `matcherObj`, where `sequencer` determines the replacement order, and the existence state of `sequencer` determines whether the last operation overwrites the previous operation.\n\n#### input\n\nType: `string`\n\n*Required*\n\n\u003e A string to be processed.\n\n#### matcherObj\n\nType: `object`\n\n*Required*\n\n\u003e An object that represents a string replacement mapping.\n\n#### sequencer\n\nType: `function`, `array`\n\n*Required：false*\n\nA `function` that takes the keys of `matcherObj`, and return an suquence array.\n\n\u003e Upgrade Instruction: the existence state of `sequencer` determines whether the last operation overwrites the previous operation.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichengbo%2Fstring-multiple-replace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fichengbo%2Fstring-multiple-replace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichengbo%2Fstring-multiple-replace/lists"}