{"id":16296502,"url":"https://github.com/f1lt3r/implant","last_synced_at":"2025-03-20T04:31:22.548Z","repository":{"id":57141230,"uuid":"126243320","full_name":"F1LT3R/implant","owner":"F1LT3R","description":"🌱 asynchronous inline content replacement","archived":false,"fork":false,"pushed_at":"2018-04-25T21:22:26.000Z","size":87,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-12T14:05:53.937Z","etag":null,"topics":["async","content","dynamic","handler","implant","insert","module","node","object","promise","replace","string"],"latest_commit_sha":null,"homepage":"http://f1lt3r.io","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/F1LT3R.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":"2018-03-21T21:33:39.000Z","updated_at":"2025-02-11T15:50:20.000Z","dependencies_parsed_at":"2022-09-05T01:21:21.602Z","dependency_job_id":null,"html_url":"https://github.com/F1LT3R/implant","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/F1LT3R%2Fimplant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/F1LT3R%2Fimplant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/F1LT3R%2Fimplant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/F1LT3R%2Fimplant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/F1LT3R","download_url":"https://codeload.github.com/F1LT3R/implant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814893,"owners_count":20352038,"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":["async","content","dynamic","handler","implant","insert","module","node","object","promise","replace","string"],"created_at":"2024-10-10T20:22:59.234Z","updated_at":"2025-03-20T04:31:22.262Z","avatar_url":"https://github.com/F1LT3R.png","language":"JavaScript","funding_links":["https://patreon.com/bePatron?u=9720216"],"categories":[],"sub_categories":[],"readme":"# Implant\n\n\u003cimg align=\"right\" height=\"260\" src=\"implant-logo.png\"\u003e\n\n\u003e 🌱  asynchronous inline content replacement\n\n[![Build Status](https://travis-ci.org/F1LT3R/implant.svg?branch=master)](https://travis-ci.org/F1LT3R/implant)\n[![Coverage Status](https://coveralls.io/repos/github/F1LT3R/implant/badge.svg?branch=master)](https://coveralls.io/github/F1LT3R/implant?branch=master)\n[![NPM Version](https://img.shields.io/npm/v/implant.svg)](https://www.npmjs.com/package/implant)\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n\nSupport the development of Implant.\n\n\u003ca href=\"https://patreon.com/bePatron?u=9720216\"\u003e\u003cimg width=\"160\" src=\"https://f1lt3r.io/content/images/2018/04/become_a_patron_button@2x.png\"\u003e\u003c/a\u003e\n\n## Install\n\n```\n$ yarn add implant\n```\n\n## Fetching Network Resources\n\nReference an Implant handler from your HTML:\n\n```html\n\u003cp\u003e{get: \"https://f1lt3r.github.io/foobar/bazqux.html\"}\u003c/p\u003e\n```\n\nWrite the Implant handler:\n\n```js\nconst request = require('request')\n\nconst handlers = {\n    get: url =\u003e new Promise((resolve, reject) =\u003e {\n        request(url, (err, res, body) =\u003e {\n            if (err) {\n                return reject(err)\n            }\n\n            resolve(body)\n        })\n    })\n}\n\nconst result = implant(html, handlers)'\n```\n\nThe content of [bazqux.html](https://f1lt3r.github.io/foobar/bazqux.html) is fetched from the web when implant handler is executed.\n\nCheckout the result:\n\n```html\n\u003cp\u003e\u003ch1\u003eHello, wombat!\u003c/h1\u003e\u003c/p\u003e\n```\n\n## Using JavaScript Objects\n\nYou can use plain JavaScript object within your HTML:\n\n```html\n\u003cdiv\u003e\n    \u003c!-- Implant reference object --\u003e\n    {article: {\n        id: 8421,\n        section: 3\n    }}\n\u003c/div\u003e\n```\n\nYour Implant handler can reference data using the properties you pass: \n\n```js\n// Some store of data\nconst articles = {\n    8421: {\n        sections: {\n            3: 'Foo. Or foo not. There is no bar.'\n        }\n    }\n}\n\n// Implant handler returns data from store\nconst handlers = {\n    article: ref =\u003e {\n        const {id, section} = ref\n        return articles[id].sections[section]\n    }\n}\n\nconst result = implant(html, handlers)\n```\n\nResult:\n\n```html\n\u003cdiv\u003eFoo. Or foo not. There is no bar.\u003c/div\u003e\n```\n\n## Using Illegal JavaScript Values\n\nIt is also possible to use illegal JavaScript values, such as references to objects that do not exist. For example:\n\n```html\n\u003cdiv\u003e{foo: i.find.your.lack.of.qux.disturbing}\u003c/div\u003e\n```\n\nWhen an illegal value is encountered, Implant pass back a stringified version of the handler.\n\n```js\nconst handlers = {\n    foo: uri =\u003e console.log\n    // 'i.find.your.lack.of.qux.disturbing'\n}\n```\n\nHandling values this way allows you to write cleaner syntax in your content templates by excluding quotes; or designing your own custom syntax.\n\nYou might use this feature to reference filenames without quotes:\n\n```html\n\u003cdiv\u003e{article: programming-101.md}\u003c/div\u003e\n```\n\nThen you could fetch and render the article like this.\n\n```js\nconst handlers = {\n    foo: uri =\u003e fetchPost(uri)\n}\n```\n\n## Recusion\n\nYou can recurse through the result of you implant like this:\n\n```js\nconst html = {\n    level1: '\u003cdiv\u003e1 {include: level2}\u003c/div\u003e',\n    level2: '\u003cdiv\u003e2 {include: level3}\u003c/div\u003e',\n    level3: '\u003cdiv\u003e3 {include: level4}\u003c/div\u003e'\n}\n\nconst handlers = {\n    include: ref =\u003e {\n        return html[ref]\n    }\n}\n\nconst opts = {\n    maxRecursion: 3\n}\n\n;(async () =\u003e {\n    const result = await implant(html.level1, handlers, opts)\n\n})()\n```\n\nResult:\n\n```html\n\u003cdiv\u003e1 \u003cdiv\u003e2 \u003cdiv\u003e3 {include: level4}\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\n```\n\n### Why Recusion?\n\nYou may want to use recursion if you are building a just-in-time dependancy tree. For example: if your implant fetched a dependency that contained a reference to another depdendancy.\n\nNote: if you do not specify the `maxRecusion` option, implant will only run once.\n\n## Credits\n\nThanks to the following designers from the Noun Project for the vectors used in the lead graphic.\n\n- [Sarah Rudkin](https://thenounproject.com/sarahdrudkin/)\n- [Alex Tai](https://thenounproject.com/sandorsz/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff1lt3r%2Fimplant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff1lt3r%2Fimplant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff1lt3r%2Fimplant/lists"}