handlebars-lang / handlebars-lang/handlebars.js
Allow length attribute for objects
- Dominant language
- JavaScript
- Stars
- 18.7k
- Forks
- 2.1k
- PR merge metrics
- No merged PRs in 30d
Description
The `.length` property is helpful. It could be very interesting to have the equivalent for dictionaries.
Test code: https://jsfiddle.net/t9njfw5v/1/
This can be achieved with this helper:
```js
Handlebars.registerHelper('len', function(obj) {return Object.keys(obj).length});
```
but `.length` is handy, and consistent with arrays.
Contributor guide
Research direction
Start with the linked JSFiddle reproduction and inspect how Handlebars resolves `.length` for arrays versus dictionary-like objects. Trace the relevant property lookup entry point, then add focused coverage for object length and verify that existing array behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- handlebars, javascript
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100