UNPKG

compare-functions

Version:

Functions to check equality for variouse criterea

12 lines (11 loc) 761 B
const curry = require('curry'); const rb = require("rainboom"); const funcs = { strict: (a, b) => a === b, asString: (a, b) => a.toString() === b.toString(), setContent: (a, b) => (a instanceof Set) && (b instanceof Set) && a.size === b.size && rb(a).every(v => b.has(v)), functionSource: (a, b) => (typeof a === "function") && (typeof a === "function") && (a.toString() === b.toString()), mapContent: (a, b) => (a instanceof Map) && (b instanceof Map) && a.size === b.size && rb(a).every(([k, v]) => b.has(k) && b.get(k) === v), near: (distance, a, b) => (typeof a === "number") && (typeof b === "number") && Math.abs(a - b) <= distance, }; module.exports = Object.freeze(rb().entries(funcs).map(([k, v]) => [k, curry(v)]).toObject());