Home

Awesome

Ember Truth Helpers CI

HTMLBars template helpers for additional truth logic in if and unless statements.

Compatibility

Installation

ember install ember-truth-helpers

Usage

HelperJavaScriptHTMLBarsImportVariable argument count allowed
eqif (a === b){{if (eq a b)}}import { eq } from 'ember-truth-helpers';No
not-eqif (a !== b){{if (not-eq a b)}}import { notEq } from 'ember-truth-helpers';No
notif (!a){{if (not a)}}import { not } from 'ember-truth-helpers';Yes
andif (a && b){{if (and a b)}}import { and } from 'ember-truth-helpers';Yes
or<code>if (a || b)</code>{{if (or a b)}}    import { or } from 'ember-truth-helpers';Yes
xor<code>if (a !== b)</code>{{if (xor a b)}}import { xor } from 'ember-truth-helpers';No
gtif (a > b){{if (gt a b)}}import { gt } from 'ember-truth-helpers';No
gteif (a >= b){{if (gte a b)}}import { gte } from 'ember-truth-helpers';No
ltif (a < b){{if (lt a b)}}import { lt } from 'ember-truth-helpers';No
lteif (a <= b){{if (lte a b)}}import { eq } from 'ember-truth-helpers';No
is-arrayif (Ember.isArray(a)){{if (is-array a)}}import { isArray } from 'ember-truth-helpers';Yes
is-emptyif (Ember.isEmpty(a)){{if (is-empty a)}}import { isEmpty } from 'ember-truth-helpers';No
is-equalif (Ember.isEqual(a, b)){{if (is-equal a b)}}import { isEqual } from 'ember-truth-helpers';No

API

is-equal

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.

Other Helpers

Usage with Glint

ember-truth-helpers is a glint enabled addon. Add this to your types/global.d.ts file:

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 TS to recognize this (beginning from TS 4.7), you must set moduleResolution to node16 or nodenext.

Usage in Single File Components

For usage in gts or gjs files, all helpers are exported from the index:

import { or } from 'ember-truth-helpers';

<template>
  {{#if (or @admin @user)}}
    Admin Controls are going here
  {{/if}}
</template>

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.