Skip to content
프로젝트

jmurphyau/ember-truth-helpers

GitHub에서 보기

소개

{{if}} 및 {{unless}}용 Ember HTMLBars 헬퍼: not, and, or, eq, is-array

기타 프로젝트

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Ember Truth Helpers CI

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

Compatibility

  • Ember.js v4.8 or above
  • Embroider or ember-auto-import >= 2 (this is v2 addon)

Installation

ember install ember-truth-helpers

Usage

Helper JavaScript HTMLBars Import Variable argument count allowed
eq if (a === b) {{if (eq a b)}} import { eq } from 'ember-truth-helpers'; No
not-eq if (a !== b) {{if (not-eq a b)}} import { notEq } from 'ember-truth-helpers'; No
not if (!a) {{if (not a)}} import { not } from 'ember-truth-helpers'; Yes
and if (a && b) {{if (and a b)}} import { and } from 'ember-truth-helpers'; Yes
or if (a || b) {{if (or a b)}} import { or } from 'ember-truth-helpers'; Yes
xor if (a !== b) {{if (xor a b)}} import { xor } from 'ember-truth-helpers'; No
gt if (a > b) {{if (gt a b)}} import { gt } from 'ember-truth-helpers'; No
gte if (a >= b) {{if (gte a b)}} import { gte } from 'ember-truth-helpers'; No
lt if (a < b) {{if (lt a b)}} import { lt } from 'ember-truth-helpers'; No
lte if (a <= b) {{if (lte a b)}} import { eq } from 'ember-truth-helpers'; No
is-array if (Ember.isArray(a)) {{if (is-array a)}} import { isArray } from 'ember-truth-helpers'; Yes
is-empty if (Ember.isEmpty(a)) {{if (is-empty a)}} import { isEmpty } from 'ember-truth-helpers'; No
is-equal if (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.

관련 프로젝트 살펴보기

불러오는 중…