{"id":19710016,"url":"https://github.com/obadakhalili/sprightly","last_synced_at":"2026-02-26T11:32:36.156Z","repository":{"id":44154510,"uuid":"274053462","full_name":"obadakhalili/sprightly","owner":"obadakhalili","description":"💡 A very light-weight JS template engine","archived":false,"fork":false,"pushed_at":"2024-10-11T06:35:54.000Z","size":126,"stargazers_count":31,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-23T02:44:10.764Z","etag":null,"topics":["expressjs","inject-variables","partials","template-engine"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/obadakhalili.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":"2020-06-22T06:06:03.000Z","updated_at":"2025-08-27T13:19:47.000Z","dependencies_parsed_at":"2024-06-18T22:53:21.876Z","dependency_job_id":"fb596d0e-067e-4e57-8ec4-9af742f702f8","html_url":"https://github.com/obadakhalili/sprightly","commit_stats":{"total_commits":37,"total_committers":3,"mean_commits":"12.333333333333334","dds":0.4054054054054054,"last_synced_commit":"39f57b212902531ac86565a2d39ce2478d464776"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/obadakhalili/sprightly","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obadakhalili%2Fsprightly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obadakhalili%2Fsprightly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obadakhalili%2Fsprightly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obadakhalili%2Fsprightly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/obadakhalili","download_url":"https://codeload.github.com/obadakhalili/sprightly/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obadakhalili%2Fsprightly/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29857522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T08:51:08.701Z","status":"ssl_error","status_checked_at":"2026-02-26T08:50:19.607Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["expressjs","inject-variables","partials","template-engine"],"created_at":"2024-11-11T22:05:55.698Z","updated_at":"2026-02-26T11:32:36.137Z","avatar_url":"https://github.com/obadakhalili.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Template engines like EJS and Handlebars are good. But sometimes, you don't want all the code and the complexity that comes with them. You only want a simple variables injection with components support. Well, that is what Sprightly is for, it is a one-filer that lets you use those tiny features without having to include or think about anything else.\n\n# Guide and APIs\n\nWhen you `import * as APIs from \"sprightly\"` you get access to the following APIs:\n\n- `sprightly`.\n\n  The template engine function.\n  Interface:\n\n  ```tsx\n  function sprightly(entryPoint: string, data: Data, options?: Options): string\n  ```\n\n  Given an `entryPoint`, the function will return the file injected with the variables referenced in `data`. The function also receives an `options` argument containing an object of options to modify the function’s behavior.\n  Example:\n\n  ```html\n  \u003c!-- ./nested/file.html --\u003e\n\n  {{ name }} says {{\u003e ../message.html }}.\n  ```\n\n  ```html\n  \u003c!-- ./message.html --\u003e\n\n  Hi\n  ```\n\n  Notes:\n\n  - `{{ var }}` is the syntax for referencing a variable.\n  - `{{\u003e ./path/to/file }}` is the syntax for referencing a component.\n\n  ```tsx\n  sprightly(\"./nested/file.html\", { cool: \"Osid\" })\n  // =\u003e \"Osid says Hi\".\n  ```\n\n- `sprightlyAsync`.\n\n  A promisifed version of the `sprightly` function described above.\n\n- `Data`.\n\n  The interface for the `data` parameter defind in `sprightly`'s function.\n\n  ```tsx\n  interface Data {\n    [key: string]: string | number | Array\u003cstring | number | Data\u003e | Data\n  }\n  ```\n\n  The `key` is the name of the variable referenced in the template. It can hold a string, a number, a recuresive `Data` object, or an array of all of the mentioned types. This means that the template can use subscripting syntax to reference deeply nested variables. Example:\n\n  ```tsx\n  const data = {\n    property: {\n      nested: [{ anotherProperty: [\"foo\", \"bar\"] }],\n    },\n  }\n\n  sprightly(\"./file.html\", data)\n  // =\u003e \"bar\"\n  ```\n\n  In template:\n\n  ```\n  \u003c!-- ./file.html --\u003e\n\n  {{ property.nested.0.anotherProperty.1 }}\n  ```\n\n  The solution used for the subscribting logic is [get-value](https://www.npmjs.com/package/get-value). Its syntax is simple, but you can visit its page if you want to inspect it more thouroughly.\n\n- `Options`.\n\n  The interface for the `options` parameter defind in `sprightly`'s function.\n\n  ```tsx\n  interface Options {\n    keyFallback?: string\n    throwOnKeyNotfound?: boolean\n    cache?: boolean\n  }\n  ```\n\n  | Option               | Default                                                                                                                                                        | Description                                                                                                                                         |\n  | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |\n  | `throwOnKeyNotFound` | `false`                                                                                                                                                        | Determines whether to throw an error if a referenced variable isn’t found.                                                                          |\n  | `keyFallback`        | empty string                                                                                                                                                   | Contains the value to be used if a referenced variable doesn’t exist. Doesn’t matter if `throwOnKeyNotFound` is set to `true`.                      |\n  | `cache`              | If available, it is set to the `cache` value sent through Express’s options that comes from `app.set(\"view cache\", truthValue)`, if not, it is set to `false`. | Determines whether to cache processed entry points or not. Typically you would want to set this to `true` in production and `false` in development. |\n\n- `SprightlyError`.\n\n  The error class thrown by the `sprightly` function. Occusions that the error is thrown at:\n\n  - If the passed `entryPoint` argument isn’t a string.\n  - If the passed `data` argument isn’t an object.\n  - If the passed `options` argument isn’t an object.\n  - If the passed `entryPoint` doesn’t exist.\n  - If a referenced variable isn’t found. Triggered only if `throwOnKeyNotFound` is set to `true`.\n  - If a referenced component isn’t found.\n\n# Usage with ExpressJS\n\n```tsx\n// to import the Express adapter\nimport sprightlyExpress from \"sprightly/express\"\n\n/* This sets up the template engine.\n * Express by default requires and calls the necessary template engine according to\n * the extension of the file to render (e.g. .hbs). But because sprightly has no specific\n * file extension to allow it to be used with any file, you have to set this up manually.\n */\napp.engine(\n  \"html\",\n  sprightlyExpress({\n    cache: false,\n    keyFallback: \"obada\",\n    throwOnKeyNotfound: false,\n  }),\n)\n\napp.get(\"/\", (_, res) =\u003e {\n  res.render(\"./nested/file.html\", { cool: \"sprightly\" })\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobadakhalili%2Fsprightly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fobadakhalili%2Fsprightly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobadakhalili%2Fsprightly/lists"}