{"id":23878290,"url":"https://github.com/reactgular/object-handlebars","last_synced_at":"2025-02-22T22:28:03.467Z","repository":{"id":57138746,"uuid":"207360106","full_name":"reactgular/object-handlebars","owner":"reactgular","description":"Minimal templating with {{handlebars}} in a JavaScript object.","archived":false,"fork":false,"pushed_at":"2020-07-31T00:38:19.000Z","size":272,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-21T09:41:58.507Z","etag":null,"topics":["handlebars","handlebars-template","javascript","javascript-library","json","mustache","mustache-templates","template-engine","typescript","typescript-library"],"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/reactgular.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":"2019-09-09T16:59:06.000Z","updated_at":"2024-09-15T14:46:17.000Z","dependencies_parsed_at":"2022-09-03T10:40:52.986Z","dependency_job_id":null,"html_url":"https://github.com/reactgular/object-handlebars","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/reactgular%2Fobject-handlebars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactgular%2Fobject-handlebars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactgular%2Fobject-handlebars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactgular%2Fobject-handlebars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reactgular","download_url":"https://codeload.github.com/reactgular/object-handlebars/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240245909,"owners_count":19771028,"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":["handlebars","handlebars-template","javascript","javascript-library","json","mustache","mustache-templates","template-engine","typescript","typescript-library"],"created_at":"2025-01-03T21:18:16.931Z","updated_at":"2025-02-22T22:28:03.442Z","avatar_url":"https://github.com/reactgular.png","language":"TypeScript","readme":"[![Build Status](https://travis-ci.org/reactgular/object-handlebars.svg?branch=master)](https://travis-ci.org/reactgular/object-handlebars)\n[![Coverage Status](https://coveralls.io/repos/github/reactgular/object-handlebars/badge.svg?branch=master)](https://coveralls.io/github/reactgular/object-handlebars?branch=master)\n[![npm version](https://badge.fury.io/js/%40reactgular%2Fobject-handlebars.svg)](https://badge.fury.io/js/%40reactgular%2Fobject-handlebars)\n\n## What is ObjectHandlebars?\n\nObjectHandlebars is a handlebars templating library for use on object properties. It is a *single* function that resolves handlebar\nexpressions relative to the current object.\n\nFor example;\n\n```typescript\nimport {render} from '@reactgular/object-handlebars';\n\nconst data = {\n  first: 'John',\n  last: 'Smith',\n  fullName: '{{first}} {{last}}'\n};\n\nconsole.log(render(data)); // prints {first: \"John\", last: \"Smith\", fullName: \"John Smith\"}\n```\n\n## Installation\n\nTo get started, install the package from npm.\n\n```bash\nnpm install --save @reactgular/object-handlebars\n```\n\n## Usage\n\nObjectHandlerbars is a function that takes the *context object*, *filters* and *recursion depth* as parameters. It does not\ndirectly modify the *context object*, but instead returns a *deep clone*.\n\nYou can install the library with `npm install @reactgular/object-handlebars` and import the main function.\n\n```typescript\n// using TypeScript\nimport {render} from '@reactgular/object-handlebars';\n\n// using NodeJS\nconst objectHandlebars = require('@reactgular/object-handlebars');\nobjectHandlebars.render();\n```\n\n## Function Signature\n\nYou can call the ObjectHandlebars function with a single object parameter, and it returns a deep clone of that object with all string\nproperties rendered with handlebars.\n\n```typescript\n// function definition for ObjectHandlebars\nexport type render = \u003cTType\u003e(obj: TType, filters: Filters = {}, maxDepth: number = 100) =\u003e TType;\n\n// filter functions\nexport type Filter = (s: string) =\u003e string;\nexport interface Filters { [key: string]: Filter;}\n```\n\n### Basic Usage\n\nObject properties that are *strings* will be rendered as basic handlebar templates.\n\n```typescript\nimport {render} from '@reactgular/object-handlebars';\n\nconsole.log(render({a: \"one\", b: \"{{a}}\"})); // prints {a: \"one\", b: \"one\"}\n```\n\n### Filters\n\nYou can pass a map of filter functions. A filter function takes a single argument of a string and returns a string. Filters\ncan be chained together in a handlebars expression like this `{{property|filterA|filterB|filterC}}`.\n\n```typescript\nimport {render} from '@reactgular/object-handlebars';\n\nconst upper = (s) =\u003e s.toUppercase();\nconsole.log(render({a: \"one\", b: \"{{a|upper}}\"}, {upper})); // prints {a: \"one\", b: \"ONE\"}\n```\n\n### Dot notation\n\nHandlebar expressions can use dot notation to reference nested values, but the path is always from the top of the context object.\n\n```typescript\nimport {render} from '@reactgular/object-handlebars';\n\nconst data = {\n    person: {\n        first: \"John\",\n        last: \"Smith\"\n    },\n    fullName: \"{{person.first}} {{person.last}}\"\n};\n\nconsole.log(render(data)); // prints {person: {first: \"John\", last: \"Smith\"}, fullName: \"John Smith\"}\n```\n\n### Array of objects\n\nObjectHandlebars will render any nested objects found in arrays.\n\n```typescript\nimport {render} from '@reactgular/object-handlebars';\n\nconst data = {\n    person: {first: \"John\", last: \"Smith\"},\n    values: [\"{{person.first}}\", \"{{person.last}}\"],\n    objects: [\n        {fullName: \"{{person.first}} {{person.last}}\"}\n    ]\n};\n\nconsole.log(render(data)); \n// prints \n// {\n//    person: {first: \"John\", last: \"Smith\"}\n//    values: [\"John\", \"Smith\"],\n//    objects: [{fullName: \"John Smith\"}]\n// }\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactgular%2Fobject-handlebars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freactgular%2Fobject-handlebars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactgular%2Fobject-handlebars/lists"}