{"id":25356465,"url":"https://github.com/codex-central/get-text-with-replacements","last_synced_at":"2026-04-16T12:40:23.239Z","repository":{"id":213554527,"uuid":"734385536","full_name":"Codex-Central/get-text-with-replacements","owner":"Codex-Central","description":"Function to allow you to get a text with replacements from a text with placeholders","archived":false,"fork":false,"pushed_at":"2023-12-21T22:25:20.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-30T03:01:00.873Z","etag":null,"topics":["javascript","nodejs","npm","replace-text","text","typescript","util"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@codexcentral/get-text-with-replacements","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Codex-Central.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":"2023-12-21T14:50:08.000Z","updated_at":"2023-12-21T18:21:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"8e2723b9-15b4-49b4-890c-f12c4ed9a343","html_url":"https://github.com/Codex-Central/get-text-with-replacements","commit_stats":null,"previous_names":["codex-central/get-text-with-replacements"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fget-text-with-replacements","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fget-text-with-replacements/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fget-text-with-replacements/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fget-text-with-replacements/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Codex-Central","download_url":"https://codeload.github.com/Codex-Central/get-text-with-replacements/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247958720,"owners_count":21024826,"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":["javascript","nodejs","npm","replace-text","text","typescript","util"],"created_at":"2025-02-14T20:47:07.995Z","updated_at":"2026-04-16T12:40:23.196Z","avatar_url":"https://github.com/Codex-Central.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# get-text-with-replacements\nThis library aims to retrieve a specific text message from a data object and replace placeholders within the text with provided values. \n\nIt allows for dynamic text generation by substituting placeholders in the original text with corresponding replacement values, providing flexibility in generating customized messages or content.\n\n\n## Installation\n\n\u003e `npm install @codexcentral/get-text-with-replacements`\n\n## Usage\n### 1. Import the function\n\n```javascript\nimport { getText } from '@codexcentral/get-text-with-replacements';\n```\n\n\n### 2. Create the data object\nDefine between `{ }` the keywords that will be replaced\n\n```javascript\nconst data = {\n  \"hello_world\": \"Hello World {name}!\"\n};\n```\n\n\n### 3. Call the function\n\n```javascript\nconst text = getText({\n  data,\n  key: \"hello_world\",\n  replacements: { name: \"Roberto\" },\n  notFoundText: \"not_found\"\n});\n```\n\n#### Result\n\n```javascript\nconsole.log(text); \n// Hello World Roberto!\n```\n\n\n### Attributes\n\n| Attribute | Type | Mandatory |\n| ------ | ------ | ------ |\n|  data | `object` | true |\n|  key | `string` | true |\n|  replacements | `object` | false |\n|  notFoundText | `string` | false (default: `\u003ckey__not_found\u003e`) |\n\n#### Example of attributes\n```json\n{\n  \"data\": {\n    \"hello_world\": \"Hello World {name}!\"\n  },\n  \"key\": \"hello_world\",\n  \"replacements\": { \"name\": \"Roberto\" },\n  \"notFoundText\": \"not_found\"\n}\n```\n\n## Wrapper function as a Helper (optional)\n### 1. Import the function\n\n```javascript\nimport { getText, TGetText } from '@codexcentral/get-text-with-replacements';\n```\n\n### 2. Create the Helper function\n\n```javascript\nconst getTextReplaced = \u003cT extends Record\u003cstring, any\u003e\u003e({\n  data,\n  key,\n  replacements,\n}: TGetText\u003cT\u003e) =\u003e {\n  return getText({\n    data,\n    key,\n    replacements,\n  });\n};\n```\n\n# Credits\nThese code was written by [Roberto Silva Z.](https://www.linkedin.com/in/robertosilvazuniga/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodex-central%2Fget-text-with-replacements","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodex-central%2Fget-text-with-replacements","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodex-central%2Fget-text-with-replacements/lists"}