{"id":22961826,"url":"https://github.com/thibaultboursier/tag2content","last_synced_at":"2025-04-02T03:23:16.662Z","repository":{"id":65514039,"uuid":"162000727","full_name":"thibaultboursier/tag2content","owner":"thibaultboursier","description":"Replace a tag with content in a configurable way","archived":false,"fork":false,"pushed_at":"2019-01-08T10:44:04.000Z","size":391,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-26T10:44:58.466Z","etag":null,"topics":["content","regex","replace","tag","template"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thibaultboursier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-16T12:52:50.000Z","updated_at":"2022-11-21T17:22:30.000Z","dependencies_parsed_at":"2023-01-26T20:55:20.300Z","dependency_job_id":null,"html_url":"https://github.com/thibaultboursier/tag2content","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thibaultboursier%2Ftag2content","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thibaultboursier%2Ftag2content/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thibaultboursier%2Ftag2content/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thibaultboursier%2Ftag2content/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thibaultboursier","download_url":"https://codeload.github.com/thibaultboursier/tag2content/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246748197,"owners_count":20827285,"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":["content","regex","replace","tag","template"],"created_at":"2024-12-14T19:14:10.120Z","updated_at":"2025-04-02T03:23:16.621Z","avatar_url":"https://github.com/thibaultboursier.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tag2content\nReplace a tag with content in a configurable way\n\n[![Linux Build Status](https://travis-ci.com/thibaultboursier/tag2content.svg?branch=master)](https://travis-ci.com/thibaultboursier/tag2content)\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save tag2content\n```\n\n## Import\n\n```js\n// ES6\nimport tag2content from 'tag2content';\n\n// CommonJS\nconst tag2content = require('tag2content').default;\n```\n\n## Basic usage\n\nCreate a text, in which you define some tags:\n\n```js\nconst text = 'I would like to go to [country] next year, with my friend [friend-name].';\n```\n\nCreate a configuration for you tags:\n\n```js\nconst tags = {\n  country: () =\u003e 'Japan',\n  'friend-name': () =\u003e 'Joe',\n};\n```\n\nReplace tags with their content:\n\n```js\nconst updatedText = tag2content({\n  tags,\n  text,\n});\n\nconsole.log(updatedText) //=\u003e 'I would like to go to Japan next year, with my friend Joe.';\n```\n\n## Variables\n\nYou can add some variables to your tags:\n\n```js\nconst text = 'I go to [country name=\"England\"] next year, with [friend name=\"Lucy\" to-uppercase=\"true\"].';\n```\n\nWhen you defines a function for each tag, variables are passed as argument. Kebab case variables are transformed to Pascal case (\"to-uppercase\" becomes \"toUppercase\").\n\n```js\nconst tags = {\n  country: variables =\u003e {\n    return variables.name;\n  },\n  friend: ({ name, toUppercase }) =\u003e {\n      return toUppercase ? name.toUpperCase() : name;\n   }\n};\n```\n\n## Custom delimiters\n\nYou can use custom delimiters:\n\n```js\nconst text = 'My first name is {first-name value=\"Robin\"}.';\n\nconst tags = {\n  'first-name': ({ value }) =\u003e value,\n};\n\nconst updatedText = tag2content({\n  delimiters: {\n    end: '}',\n    start: '{',\n  },\n  tags,\n  text,\n});\n\nconsole.log(updatedText) //=\u003e 'My first name is Robin.';\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthibaultboursier%2Ftag2content","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthibaultboursier%2Ftag2content","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthibaultboursier%2Ftag2content/lists"}