123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- 'use strict';
-
- var SafeString = require('./runtime').SafeString;
- /**
- * Returns `true` if the object is a function, otherwise `false`.
- * @param { any } value
- * @returns { boolean }
- */
-
-
- function callable(value) {
- return typeof value === 'function';
- }
-
- exports.callable = callable;
- /**
- * Returns `true` if the object is strictly not `undefined`.
- * @param { any } value
- * @returns { boolean }
- */
-
- function defined(value) {
- return value !== undefined;
- }
-
- exports.defined = defined;
- /**
- * Returns `true` if the operand (one) is divisble by the test's argument
- * (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
-
- function divisibleby(one, two) {
- return one % two === 0;
- }
-
- exports.divisibleby = divisibleby;
- /**
- * Returns true if the string has been escaped (i.e., is a SafeString).
- * @param { any } value
- * @returns { boolean }
- */
-
- function escaped(value) {
- return value instanceof SafeString;
- }
-
- exports.escaped = escaped;
- /**
- * Returns `true` if the arguments are strictly equal.
- * @param { any } one
- * @param { any } two
- */
-
- function equalto(one, two) {
- return one === two;
- }
-
- exports.equalto = equalto; // Aliases
-
- exports.eq = exports.equalto;
- exports.sameas = exports.equalto;
- /**
- * Returns `true` if the value is evenly divisible by 2.
- * @param { number } value
- * @returns { boolean }
- */
-
- function even(value) {
- return value % 2 === 0;
- }
-
- exports.even = even;
- /**
- * Returns `true` if the value is falsy - if I recall correctly, '', 0, false,
- * undefined, NaN or null. I don't know if we should stick to the default JS
- * behavior or attempt to replicate what Python believes should be falsy (i.e.,
- * empty arrays, empty dicts, not 0...).
- * @param { any } value
- * @returns { boolean }
- */
-
- function falsy(value) {
- return !value;
- }
-
- exports.falsy = falsy;
- /**
- * Returns `true` if the operand (one) is greater or equal to the test's
- * argument (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
-
- function ge(one, two) {
- return one >= two;
- }
-
- exports.ge = ge;
- /**
- * Returns `true` if the operand (one) is greater than the test's argument
- * (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
-
- function greaterthan(one, two) {
- return one > two;
- }
-
- exports.greaterthan = greaterthan; // alias
-
- exports.gt = exports.greaterthan;
- /**
- * Returns `true` if the operand (one) is less than or equal to the test's
- * argument (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
-
- function le(one, two) {
- return one <= two;
- }
-
- exports.le = le;
- /**
- * Returns `true` if the operand (one) is less than the test's passed argument
- * (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
-
- function lessthan(one, two) {
- return one < two;
- }
-
- exports.lessthan = lessthan; // alias
-
- exports.lt = exports.lessthan;
- /**
- * Returns `true` if the string is lowercased.
- * @param { string } value
- * @returns { boolean }
- */
-
- function lower(value) {
- return value.toLowerCase() === value;
- }
-
- exports.lower = lower;
- /**
- * Returns `true` if the operand (one) is less than or equal to the test's
- * argument (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
-
- function ne(one, two) {
- return one !== two;
- }
-
- exports.ne = ne;
- /**
- * Returns true if the value is strictly equal to `null`.
- * @param { any }
- * @returns { boolean }
- */
-
- function nullTest(value) {
- return value === null;
- }
-
- exports.null = nullTest;
- /**
- * Returns true if value is a number.
- * @param { any }
- * @returns { boolean }
- */
-
- function number(value) {
- return typeof value === 'number';
- }
-
- exports.number = number;
- /**
- * Returns `true` if the value is *not* evenly divisible by 2.
- * @param { number } value
- * @returns { boolean }
- */
-
- function odd(value) {
- return value % 2 === 1;
- }
-
- exports.odd = odd;
- /**
- * Returns `true` if the value is a string, `false` if not.
- * @param { any } value
- * @returns { boolean }
- */
-
- function string(value) {
- return typeof value === 'string';
- }
-
- exports.string = string;
- /**
- * Returns `true` if the value is not in the list of things considered falsy:
- * '', null, undefined, 0, NaN and false.
- * @param { any } value
- * @returns { boolean }
- */
-
- function truthy(value) {
- return !!value;
- }
-
- exports.truthy = truthy;
- /**
- * Returns `true` if the value is undefined.
- * @param { any } value
- * @returns { boolean }
- */
-
- function undefinedTest(value) {
- return value === undefined;
- }
-
- exports.undefined = undefinedTest;
- /**
- * Returns `true` if the string is uppercased.
- * @param { string } value
- * @returns { boolean }
- */
-
- function upper(value) {
- return value.toUpperCase() === value;
- }
-
- exports.upper = upper;
- /**
- * If ES6 features are available, returns `true` if the value implements the
- * `Symbol.iterator` method. If not, it's a string or Array.
- *
- * Could potentially cause issues if a browser exists that has Set and Map but
- * not Symbol.
- *
- * @param { any } value
- * @returns { boolean }
- */
-
- function iterable(value) {
- if (typeof Symbol !== 'undefined') {
- return !!value[Symbol.iterator];
- } else {
- return Array.isArray(value) || typeof value === 'string';
- }
- }
-
- exports.iterable = iterable;
- /**
- * If ES6 features are available, returns `true` if the value is an object hash
- * or an ES6 Map. Otherwise just return if it's an object hash.
- * @param { any } value
- * @returns { boolean }
- */
-
- function mapping(value) {
- // only maps and object hashes
- var bool = value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value);
-
- if (Set) {
- return bool && !(value instanceof Set);
- } else {
- return bool;
- }
- }
-
- exports.mapping = mapping;
|