Ember Truth Helpers
HTMLBars template helpers for additional truth logic in if and unless statements.
- Ember.js v4.8 or above
- Embroider or ember-auto-import >= 2 (this is v2 addon)
```
ember install ember-truth-helpers
Helper | JavaScript | HTMLBars | Import | Variable argument count allowed|
---------|-------------------------------------------------|-------------------------|-------------------------------------------------- |--------------------------------|
eq | if (a === b) | {{if (eq a b)}} | import { eq } from 'ember-truth-helpers'; |No |if (a !== b)
not-eq | | {{if (not-eq a b)}} | import { notEq } from 'ember-truth-helpers'; |No |if (!a)
not | | {{if (not a)}} | import { not } from 'ember-truth-helpers'; |Yes |if (a && b)
and | | {{if (and a b)}} | import { and } from 'ember-truth-helpers'; |Yes |{{if (or a b)}}
or | if (a || b) | | import { or } from 'ember-truth-helpers'; |Yes |{{if (xor a b)}}
xor | if (a !== b) | | import { xor } from 'ember-truth-helpers'; |No |if (a > b)
gt | | {{if (gt a b)}} | import { gt } from 'ember-truth-helpers'; |No |if (a >= b)
gte | | {{if (gte a b)}} | import { gte } from 'ember-truth-helpers'; |No |if (a < b)
lt | | {{if (lt a b)}} | import { lt } from 'ember-truth-helpers'; |No |if (a <= b)
lte | | {{if (lte a b)}} | import { eq } from 'ember-truth-helpers'; |No |if (Ember.isArray(a))
is-array | | {{if (is-array a)}} | import { isArray } from 'ember-truth-helpers'; |Yes |if (Ember.isEmpty(a))
is-empty | | {{if (is-empty a)}} | import { isEmpty } from 'ember-truth-helpers'; |No |if (Ember.isEqual(a, b))
is-equal | | {{if (is-equal a b)}} | import { isEqual } from 'ember-truth-helpers'; |No |
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.
* ember-get-helper
* ember-composable-helpers
ember-truth-helpers is a glint enabled addon. Add this to yourtypes/global.d.ts file:
`ts
import '@glint/environment-ember-loose';
import type EmberTruthRegistry from 'ember-truth-helpers/template-registry';
declare module '@glint/environment-ember-loose/registry' {
export default interface Registry extends EmberTruthRegistry, / other addon registries / {
// local entries
}
}
`
For the entire guide, please refer to Using
Addons
section on the glint handbook.
Types are made available through package.json exports field. In order for TSmoduleResolution
to recognize this (beginning from TS 4.7), you must setnode16
to or nodenext.
For usage in gts or gjs files, all helpers are exported from the index:
`gts
import { or } from 'ember-truth-helpers';
{{#if (or @admin @user)}}
Admin Controls are going here
{{/if}}
``
See the Contributing guide for details.
This project is licensed under the MIT License.