{"id":26772986,"url":"https://github.com/amirfarzamnia/templon","last_synced_at":"2025-07-14T18:06:17.398Z","repository":{"id":284451262,"uuid":"954994409","full_name":"amirfarzamnia/templon","owner":"amirfarzamnia","description":"Advanced template compiler with deep variable resolution, object processing, and strict validation with circular reference protection.","archived":false,"fork":false,"pushed_at":"2025-07-02T11:04:16.000Z","size":1358,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-04T08:51:35.702Z","etag":null,"topics":["complier","deep","interpolation","nested","object","string","substitution","template","variable"],"latest_commit_sha":null,"homepage":"https://amirfarzamnia.github.io/templon/","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/amirfarzamnia.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":"2025-03-26T00:04:25.000Z","updated_at":"2025-07-01T15:31:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"a5f074de-a7d1-46b2-9394-6ea1807f0d8d","html_url":"https://github.com/amirfarzamnia/templon","commit_stats":null,"previous_names":["amirfarzamnia/templon"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/amirfarzamnia/templon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirfarzamnia%2Ftemplon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirfarzamnia%2Ftemplon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirfarzamnia%2Ftemplon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirfarzamnia%2Ftemplon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amirfarzamnia","download_url":"https://codeload.github.com/amirfarzamnia/templon/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirfarzamnia%2Ftemplon/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265327771,"owners_count":23747768,"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":["complier","deep","interpolation","nested","object","string","substitution","template","variable"],"created_at":"2025-03-29T01:33:59.969Z","updated_at":"2025-07-14T18:06:17.386Z","avatar_url":"https://github.com/amirfarzamnia.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Templon\r\n\r\nAdvanced template compiler with deep variable resolution, object processing, and strict validation with circular reference protection.\r\n\r\n\u003cdiv align=\"center\"\u003e\r\n  \u003cp align=\"center\"\u003e\r\n    \u003cimg src=\"https://raw.githubusercontent.com/amirfarzamnia/templon/refs/heads/main/assets/templon.png\" alt=\"Templon\" width=\"100%\" style=\"border-radius:0.5rem\" /\u003e\r\n  \u003c/p\u003e\r\n\u003c/div\u003e\r\n\r\n[![npm version](https://badge.fury.io/js/templon.svg)](https://www.npmjs.com/package/templon)\r\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\r\n[![GitHub issues](https://img.shields.io/github/issues/amirfarzamnia/templon.svg)](https://github.com/amirfarzamnia/templon/issues)\r\n[![GitHub stars](https://img.shields.io/github/stars/amirfarzamnia/templon.svg)](https://github.com/amirfarzamnia/templon/stargazers)\r\n[![GitHub forks](https://img.shields.io/github/forks/amirfarzamnia/templon.svg)](https://github.com/amirfarzamnia/templon/forks)\r\n\r\n## Features\r\n\r\n- **Deep Variable Resolution**: Access nested properties using dot notation (e.g., `{{user.profile.name}}`)\r\n- **Object/Array Processing**: Automatically handle complex data structures\r\n- **Strict Mode**: Validate template variables and throw errors for missing values\r\n- **Custom Resolvers**: Extend functionality with custom variable resolution logic\r\n- **Circular Reference Protection**: Prevent infinite loops with depth limiting\r\n- **TypeScript Support**: Full type safety and autocompletion\r\n- **Customizable Variable Pattern**: Use your own regex pattern for variable matching\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install templon\r\n# or\r\nyarn add templon\r\n# or\r\npnpm add templon\r\n```\r\n\r\n## Basic Usage\r\n\r\n```typescript\r\nimport { compileTemplate } from \"templon\";\r\n\r\n// Simple string interpolation\r\nconst result = compileTemplate(\"Hello {{name}}\", { name: \"World\" });\r\n// Output: \"Hello World\"\r\n\r\n// Nested object access\r\nconst result = compileTemplate(\"Hello {{user.profile.name}}\", {\r\n  user: {\r\n    profile: {\r\n      name: \"John\",\r\n    },\r\n  },\r\n});\r\n// Output: \"Hello John\"\r\n\r\n// Array access\r\nconst result = compileTemplate(\"First user: {{users.0.name}}\", {\r\n  users: [{ name: \"John\" }, { name: \"Jane\" }],\r\n});\r\n// Output: \"First user: John\"\r\n```\r\n\r\nNote: The template engine uses [radash](https://radash-docs.vercel.app/docs/object/get) under the hood for deep property access, which provides safe and efficient object traversal.\r\n\r\n## Advanced Examples\r\n\r\n### Working with Arrays\r\n\r\n```typescript\r\nconst template = \"Users: {{users}}\";\r\nconst data = {\r\n  users: [\"John\", \"Jane\", \"Bob\"],\r\n};\r\nconst result = compileTemplate(template, data);\r\n// Output: \"Users: John,Jane,Bob\"\r\n```\r\n\r\n### Custom Variable Pattern\r\n\r\n```typescript\r\nconst template = \"Hello \u003cname\u003e\";\r\nconst result = compileTemplate(\r\n  template,\r\n  { name: \"World\" },\r\n  { variablePattern: /\u003c([^{}]+)\u003e/g }\r\n);\r\n// Output: \"Hello World\"\r\n```\r\n\r\n### Strict Mode\r\n\r\n```typescript\r\nconst template = \"Hello {{name}}\";\r\n\r\ntry {\r\n  compileTemplate(template, {}, { strict: true });\r\n} catch (error) {\r\n  // Error: Missing variable: name\r\n}\r\n```\r\n\r\n### Custom Resolver\r\n\r\n```typescript\r\nconst template = \"Hello {{user.name}}\";\r\nconst result = compileTemplate(\r\n  template,\r\n  {},\r\n  {\r\n    resolver: (path) =\u003e {\r\n      if (path === \"user.name\") return \"Custom User\";\r\n\r\n      return undefined;\r\n    },\r\n  }\r\n);\r\n// Output: \"Hello Custom User\"\r\n```\r\n\r\n## Configuration Options\r\n\r\n| Option               | Type                      | Default         | Description                                |\r\n| -------------------- | ------------------------- | --------------- | ------------------------------------------ |\r\n| strict               | boolean                   | false           | Throw errors when variables are missing    |\r\n| preserveUndefined    | boolean                   | false           | Preserve undefined variables in output     |\r\n| autoStringifyObjects | boolean                   | true            | Automatically stringify objects to JSON    |\r\n| parseStrings         | boolean                   | true            | Automatically parse strings in output      |\r\n| parseBinInts         | boolean                   | false           | Automatically parse BigInts in output      |\r\n| resolver             | (path: string) =\u003e any     | undefined       | Custom variable resolver function          |\r\n| stringTransform      | (value: string) =\u003e string | (s) =\u003e s        | Transform function for final string output |\r\n| maxVariableDepth     | number                    | 10              | Maximum depth for variable resolution      |\r\n| variablePattern      | RegExp                    | /{{([^{}]+)}}/g | Custom regex pattern for variable matching |\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a Pull Request.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famirfarzamnia%2Ftemplon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famirfarzamnia%2Ftemplon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famirfarzamnia%2Ftemplon/lists"}