ember-source
Version:
A JavaScript framework for creating ambitious web applications
119 lines (108 loc) • 2.9 kB
JavaScript
import { toBool } from '../@glimmer/global-context/index.js';
import { a as createComputeRef, v as valueForRef } from './reference-BoPB2LfI.js';
import { i as internalHelper } from './hash-BTwOuDGQ.js';
const and = internalHelper(({
positional
}) => {
if (positional.length < 2) {
throw new Error(`\`and\` expects at least two arguments, but received ${positional.length}.`);
}
return createComputeRef(() => {
let last;
for (let i = 0; i < positional.length; i++) {
let arg = positional[i];
last = arg ? valueForRef(arg) : arg;
if (!toBool(last)) return last;
}
return last;
}, null, 'and');
});
/**
* Performs a strict equality comparison.
*
* left === right
*/
function eq(left, right) {
if (arguments.length !== 2) {
throw new Error(`\`eq\` expects exactly two arguments, but received ${arguments.length}.`);
}
return left === right;
}
/**
* Performs a greater than comparison.
*
* left > right
*/
function gt(left, right) {
if (arguments.length !== 2) {
throw new Error(`\`gt\` expects exactly two arguments, but received ${arguments.length}.`);
}
return left > right;
}
/**
* Performs a greater than or equal comparison.
*
* left >= right
*/
function gte(left, right) {
if (arguments.length !== 2) {
throw new Error(`\`gte\` expects exactly two arguments, but received ${arguments.length}.`);
}
return left >= right;
}
/**
* Performs a less than comparison.
*
* left < right
*/
function lt(left, right) {
if (arguments.length !== 2) {
throw new Error(`\`lt\` expects exactly two arguments, but received ${arguments.length}.`);
}
return left < right;
}
/**
* Performs a less than or equal comparison.
*
* left <= right
*/
function lte(left, right) {
if (arguments.length !== 2) {
throw new Error(`\`lte\` expects exactly two arguments, but received ${arguments.length}.`);
}
return left <= right;
}
/**
* Performs a strict inequality comparison.
*
* left !== right
*/
function neq(left, right) {
if (arguments.length !== 2) {
throw new Error(`\`neq\` expects exactly two arguments, but received ${arguments.length}.`);
}
return left !== right;
}
const not = (...args) => {
if (args.length !== 1) {
throw new Error(`\`not\` expects exactly one argument, but received ${args.length}.`);
}
return !toBool(args[0]);
};
const or = internalHelper(({
positional
}) => {
if (positional.length < 2) {
throw new Error(`\`or\` expects at least two arguments, but received ${positional.length}.`);
}
return createComputeRef(() => {
let last;
for (let i = 0; i < positional.length; i++) {
let arg = positional[i];
last = arg ? valueForRef(arg) : arg;
if (toBool(last)) return last;
}
return last;
}, null, 'or');
});
export { and as a, gte as b, lte as c, not as d, eq as e, gt as g, lt as l, neq as n, or as o };