{"id":18429454,"url":"https://github.com/bigpipe/replaces","last_synced_at":"2025-04-13T21:44:40.316Z","repository":{"id":28645556,"uuid":"32164747","full_name":"bigpipe/replaces","owner":"bigpipe","description":"Micro template engine that can automatically escape data.","archived":false,"fork":false,"pushed_at":"2020-10-26T13:10:33.000Z","size":32,"stargazers_count":1,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-19T07:04:39.423Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/bigpipe.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":"2015-03-13T15:45:35.000Z","updated_at":"2020-10-26T13:10:35.000Z","dependencies_parsed_at":"2022-07-21T12:18:11.324Z","dependency_job_id":null,"html_url":"https://github.com/bigpipe/replaces","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Freplaces","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Freplaces/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Freplaces/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Freplaces/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigpipe","download_url":"https://codeload.github.com/bigpipe/replaces/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788869,"owners_count":21161726,"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":[],"created_at":"2024-11-06T05:17:14.773Z","updated_at":"2025-04-13T21:44:40.289Z","avatar_url":"https://github.com/bigpipe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# replaces\n\n[![Version npm][version]](http://browsenpm.org/package/replaces)[![Build Status][build]](https://travis-ci.org/bigpipe/replaces)[![Dependencies][david]](https://david-dm.org/bigpipe/replaces)[![Coverage Status][cover]](https://coveralls.io/r/bigpipe/replaces?branch=master)\n\n[from]: https://img.shields.io/badge/from-bigpipe.io-9d8dff.svg?style=flat-square\n[version]: http://img.shields.io/npm/v/replaces.svg?style=flat-square\n[build]: http://img.shields.io/travis/bigpipe/replaces/master.svg?style=flat-square\n[david]: https://img.shields.io/david/bigpipe/replaces.svg?style=flat-square\n[cover]: http://img.shields.io/coveralls/bigpipe/replaces/master.svg?style=flat-square\n\nReplaces is a micro library that moves the data formatting instructions to the\ntemplate placeholders using special modifier chars.\n\n## Installation\n\nThis module should work server-side and client side using the commonjs module\nsystem. The module it self is released in the public npm registry and can be\ninstalled by running:\n\n```\nnpm install --save replaces\n```\n\n## Usage\n\nThe module only exposes one single interface, which is a function that requires\n3 arguments:\n\n1. The template string that contains the tags that should be replaced.\n2. A Regular Expression that has 2 capturing groups:\n  1. First group should capture the data modifier which can be `\\W+`\n  2. The second group is the name of the key that should be used to extract the\n     data from the supplied data argument.\n3. The data object which contains all the information.\n\n```js\n'use strict';\n\nvar replaces = require('replaces')\n  , template = require('fs').readFileSync(__dirname +'/template.html', 'utf-8');\n\nconsole.log(replaces(template, /{fittings(\\W+)([^}]+?)}/g, {\n  data: 'structure',\n  deeply: {\n    nested: {\n      data: 'structures'\n    }\n  }\n}));\n```\n\nWhere `template.html` would be:\n\n```html\n\u003cdiv\u003e{fittings:deeply.nested.data}\u003c/div\u003e\n\u003cdiv\u003e{fittings@deeply}\u003c/div\u003e\n```\n\nWould produce the following output in the console.\n\n```\n\u003cdiv\u003e\u003c/div\u003e\n\u003cdiv\u003e{\"nested\":{\"data\":\"structures\"}}\u003c/div\u003e\n```\n\n### Modifiers\n\nThe template tags can use various of modifiers. \n\n- **`\u003c\u003e`** Make sure that the data we're trying to add to the template is save\n  to use inside of HTML tags.\n- **`~`** Transform the receiving data in to a JSON.stringify structure.\n- **`@`** Transform the receiving data in to a JSON.stringify structure\n  **without** crashing on circular references like a normal stringify operation\n  would.\n- **`$`** Transform the data using the circular JSON parser and ensure that\n  every value inside the JSON is encoded using the `\u003c\u003e` modifier.\n- **`%`** Escape the data using the `escape` function.\n- Any other non `\\W` is just ignored and will indicated that the data should\n  just be pasted in as normal.\n\nNew modifier can easily be added by adding new properties to the\n`replaces.modifiers` object. The `key` of the object should the be modifier it's\ntriggered by and the value should be a function that transforms the data. The\ntransformer function receives 2 arguments:\n\n1. The key that was used to retrieve the data\n2. Data the key will be replaced with.\n\nThe function should **always** return a string.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigpipe%2Freplaces","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigpipe%2Freplaces","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigpipe%2Freplaces/lists"}