{"id":19559997,"url":"https://github.com/plotdb/template-text","last_synced_at":"2026-05-13T22:32:02.091Z","repository":{"id":71939839,"uuid":"310489633","full_name":"plotdb/template-text","owner":"plotdb","description":"text from template for all purposes","archived":false,"fork":false,"pushed_at":"2023-05-05T00:52:24.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-14T23:33:02.947Z","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/plotdb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2020-11-06T04:16:35.000Z","updated_at":"2023-05-05T00:52:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"3602025c-2772-4e38-b180-c0381a99b199","html_url":"https://github.com/plotdb/template-text","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"f252137f156ef28ef3e0751ebe8ece0b475f5436"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Ftemplate-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Ftemplate-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Ftemplate-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Ftemplate-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plotdb","download_url":"https://codeload.github.com/plotdb/template-text/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240713300,"owners_count":19845626,"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-11T05:05:28.599Z","updated_at":"2026-05-13T22:32:02.086Z","avatar_url":"https://github.com/plotdb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# template-text\n\ngenerate text from template for all purposes with LiveScript syntax. Use `eval` so one should always use this with owned/reviewed `template.file`.\n\nNote: this is equivalent to run code in template. Always use it with trusted data source only.\n\n\n## Usage\n\ninstall with npm:\n\n    npm install --save template-text\n\n\ncommand name and parameters:\n\n    tt -c config.file -o output.file template.file\n\n\nYou can also require a module as config to use functions in the template from the module:\n\n    tt -r some-module -o output.file template.file\n\n\n## API\n\nProgrammatically interpolate your template with `template-text` api:\n\n    tt = require(\"template-text\")\n    cfg = function() { return { ... }; } || { ... };\n    ret = tt(\"\u003ctemplate-file-content\u003e\", cfg, \u003croot-path\u003e);\n\nwhere:\n\n - cfg: a hash of all available variable\n - root-path: reference root when look up files for include api.\n\n\n## Template File Format\n\nFor every string you want to replace, use `!{ ... }` with variable / expression inside. For example, \n\n    Hello !{user.name}!\n\n    You have visited our website for !{user.count} time.\n\n\nIt also supports conditional block:\n\n    !{if user.count \u003e 10 =\u003e '''\n\n    it seems that you have been here for many times.\n\n    ''' else '''\n\n    Newcomer here? You probably will want to take a look at our tutorial.\n\n    '''}\n\n\nIf you need interpolation inside expressions, please note that `\"\"\"` is escaped so you need to use `!\"\" ... \"\"!`:\n\n\n    !{if user.count \u003e 10 =\u003e !\"\"\n\n    it seems that you have been here for !{count} times.\n\n    \"\"! else !\"\"\n\n    Hi !{name}, newcomer here? You probably will want to take a look at our tutorial.\n\n    \"\"!}\n\n\nWhen calling with API, you can even use builtin functions for expressions, or custom function if you pass it into the config object:\n\n    A random number: !{Math.random()}\n    A random UUID: !{uuid()}\n\n\nProgram counterpart for above text:\n\n    uuid = require(\"uuid\");\n    tt = require(\"template-text\");\n\n    ret = tt(\u003cthe above text\u003e, {uuid: uuid});\n\n\nAgain, we use LiveScript to parse the expression when interpolating, so it's quite dangerous to load template from untrusted source. Be sure to only use template-text with templates from trusted source.\n\n\n## Builtin Functions\n\nExcept common JS APIs, you can also use following API in template:\n\n - include(filename) - recursively include file in place.\n\n\n## TODO\n\n - Token Customizing - It's possible that the token `!{ ... }` is used by the target language / syntax of the text we want to interpolate. So it will be nice if we can make it customizable.\n - Defaul Language - make it customizable about the language users want to use, at least for following languages:\n   - ES6 ( ES2015 or later )\n   - TypeScript\n   \n\n\n## License \n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotdb%2Ftemplate-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplotdb%2Ftemplate-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotdb%2Ftemplate-text/lists"}