src/util/Util.js
/**
 * Create a boolean function that compares an input element to the given value.
 *
 * @name module:util._match
 * @function
 * @private
 * @param {Number|string|object|null} value the matching value
 * @return {} a function that compares an input element to the given value
 */
Create a boolean function that compares an input element to the given value.
Create a boolean function that compares an input element to the given value .
function _match(value)
{
	const response = {
		origin: "util._match",
		context: "when creating a function that compares an input element to the given value",
	};
	try
	{
		if (typeof value === "function")
		{
			throw "the value cannot be a function";
		}
		if (Number.isNaN(value))
		{
			return (element) => Number.isNaN(element);
		}
		if (value === null)
		{
			return (element) => element === null;
		}
		if (typeof value === "object")
		{
			const jsonValue = JSON.stringify(value);
			if (typeof jsonValue === "undefined")
			{
				throw "value could not be converted to a JSON string";
			}
			return (element) =>
			{
				const jsonElement = JSON.stringify(element);
				return (jsonElement === jsonValue);
			};
		}
		return (element) => element === value;
	}
	catch (error)
	{
		throw { ...response, error };
	}
}
function _match ( value ) { const response = { origin : "util._match" , context : "when creating a function that compares an input element to the given value" , } ; try { if ( typeof value === "function" ) { throw "the value cannot be a function" ; } if ( Number . isNaN ( value ) ) { return ( element ) => Number . isNaN ( element ) ; } if ( value === null ) { return ( element ) => element === null ; } if ( typeof value === "object" ) { const jsonValue = JSON . stringify ( value ) ; if ( typeof jsonValue === "undefined" ) { throw "value could not be converted to a JSON string" ; } return ( element ) => { const jsonElement = JSON . stringify ( element ) ; return ( jsonElement === jsonValue ) ; } ; } return ( element ) => element === value ; } catch ( error ) { throw { ... response , error } ; } }
Create a boolean function that compares an input element to the given value.
Create a boolean function that compares an input element to the given value .
// function: // NaN: // null: // object: we compare using JSON.stringify // everything else: