{"id":15478391,"url":"https://github.com/hellocomet/handlespy","last_synced_at":"2025-07-12T13:04:24.622Z","repository":{"id":57260597,"uuid":"185977742","full_name":"hellocomet/handlespy","owner":"hellocomet","description":"A Node.js library to inspect the required variables in a handlebars template","archived":false,"fork":false,"pushed_at":"2019-06-05T09:34:39.000Z","size":53,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-27T05:40:22.362Z","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/hellocomet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-10T11:36:14.000Z","updated_at":"2020-04-30T10:32:43.000Z","dependencies_parsed_at":"2022-08-25T03:52:51.810Z","dependency_job_id":null,"html_url":"https://github.com/hellocomet/handlespy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hellocomet/handlespy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellocomet%2Fhandlespy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellocomet%2Fhandlespy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellocomet%2Fhandlespy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellocomet%2Fhandlespy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hellocomet","download_url":"https://codeload.github.com/hellocomet/handlespy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellocomet%2Fhandlespy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264995105,"owners_count":23694883,"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-10-02T04:03:55.689Z","updated_at":"2025-07-12T13:04:24.585Z","avatar_url":"https://github.com/hellocomet.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Handlespy\n\nHandlespy is a simple Node.js library to inspect Handlebars templates for required variables. This is accomplished by iterating over the AST produced by the `handlebars` parser.\n\nIt also provides a helper to verify that a payload contains all required variables.\n\n## Installation\n\n```sh\nnpm install handlespy\n# or\nyarn add handlespy\n```\n\n## Usage\n\n```javascript\nconst { getRequiredVariables, getMissingVariables } = require('handlespy')\n\nconst template = `\nA simple handlebar template containing a variable ({{someVariable}}) and a loop :\n\n{{#each someLoop}}\n- {{someProperty}}\n{{/each}}\n`\n\nconst requiredVariables = getRequiredVariables(template)\n/*\n[\n  'someVariable',\n  { loopVariable: 'someLoop', properties: [ 'someProperty' ] }\n]\n*/\n\nconst completePayload = {\n  someVariable: 'Test',\n  someLoop: [{ someProperty: 'Another test' }]\n}\n\nconst incompletePayload = {\n  // missing someVariable,\n  someLoop: [\n    { someProperty: 'Another test' },\n    { unsupportedProperty: 'Final test' }, // someLoop[1] is missing the required someProperty\n  ]\n}\n\nconst test1 = getMissingVariables(completePayload, requiredVariables)\n// []\nconst test2 = getMissingVariables(incompletePayload, requiredVariables)\n/*\n[ 'someVariable', 'someLoop[1].someProperty' ]\n*/\n```\n\n## API\n\n### getRequiredVariables\n\n- expects : (String) A handlebars template\n- returns : (Array) The required variables\n\nEach item in the returned array can either be a string (denoting a simple variable), or an object (denoting an `each` loop) containing the following :\n\n- loopVariable (String) : the name of the variable\n- properties (Array) : the required properties on the looped variable\n  - *loops can be nested, so `properties` can contain another object with `loopVariable` and `properties`*\n  - *if only `this` is used in the loop, `properties` is an empty array*\n\n### getMissingVariables\n\n- expects :\n  - (Object) The payload to check\n  - One of the following :\n    - (String) A handlebars template\n    - (Array) or a required variables specification as returned by `getRequiredVariables`\n- returns : (Array) The missing variables\n\nEach item in the returned array is a string, which can be of either of the following formats :\n\n- `missingVariable` : variable is missing in the payload\n- `missingArray[]` : a variable, which is used in an `each` loop, is present in the payload but isn't an array\n- `item[2].missingProperty` : an item in an array is missing a required properties\n\n## Contributing\n\nIf you find any bug or missing functionality in handlespy, don't hesitate to create an issue ! If you can provide a PR with a failing test, this would help greatly in solving the issue :)\n\n***\n\n_Made with 💖 @ [comet](https://comet.co)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellocomet%2Fhandlespy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhellocomet%2Fhandlespy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellocomet%2Fhandlespy/lists"}