HTMLBars template helpers for additional truth logic in if and unless statements.
ember install ember-truth-helpers
| Helper | JavaScript | HTMLBars | Variable argument count allowed |
|---|---|---|---|
| eq | if (a === b) |
{{if (eq a b)}} |
No |
| not-eq | if (a !== b) |
{{if (not-eq a b)}} |
No |
| not | if (!a) |
{{if (not a)}} |
Yes |
| and | if (a && b)* |
{{if (and a b)}} |
Yes |
| or | if (a || b) * |
{{if (or a b)}} |
Yes |
| xor | if (a && !b || !a && b)* |
{{if (xor a b)}} |
No |
| gt | if (a > b) |
{{if (gt a b)}} |
No |
| gte | if (a >= b) |
{{if (gte a b)}} |
No |
| lt | if (a < b) |
{{if (lt a b)}} |
No |
| lte | if (a <= b) |
{{if (lte a b)}} |
No |
| is-array | if (Ember.isArray(a)) |
{{if (is-array a)}} |
Yes |
| is-empty | if (Ember.isEmpty(a)) |
{{if (is-empty a)}} |
No |
| is-equal | if (Ember.isEqual(a, b)) |
{{if (is-equal a b)}} |
No |
(or a b), even if a is truthy, b will still be evaluated.
See this explanation.
is-equal uses Ember.isEqual helper to evaluate equality of two values.
eq should be sufficient for most applications. is-equal is necessary when trying to compare a complex object to
a primitive value.
git clone https://github.com/jmurphyau/ember-truth-helpers.gitcd ember-truth-helpersyarn
yarn lint:hbsyarn lint:jsyarn lint:js -- --fix
ember test– Runs the test suite on the current Ember versionember test --server– Runs the test suite in "watch mode"ember try:each– Runs the test suite against multiple Ember versions
ember serve- Visit the dummy application at http://localhost:4200.
For more information on using ember-cli, visit https://ember-cli.com/.
This project is licensed under the MIT License.