Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function isNearlyEqual(a, b, config = {} ) {
const {
numDigits = 6,
nSamples = 5,
range = [1, 3]
} = config
if (getType(a) !== getType(b)) {
return false
}
switch (getType(a)) {
case 'number': {
return Math.abs(a - b) <= 10 ** -numDigits
}
case 'array': {
return a.length === b.length &&
a.every((item, index) => isNearlyEqual(item, b[index], config))
}
case 'function': {
// by using max arity, we allow that functions of different arity might be
// nearly equal. For example, x => 5 and (x, y) => 5
const arity = Math.max(a.length, b.length)
const [min, max] = range
const samples = genSamples(min, max, nSamples, arity)
export function isNearlyEqual(a, b, config = {} ) {
const {
numDigits = 6,
nSamples = 5,
range = [1, 3]
} = config
if (getType(a) !== getType(b)) {
return false
}
switch (getType(a)) {
case 'number': {
return Math.abs(a - b) <= 10 ** -numDigits
}
case 'array': {
return a.length === b.length &&
a.every((item, index) => isNearlyEqual(item, b[index], config))
}
case 'function': {
// by using max arity, we allow that functions of different arity might be
constructor(value: unknown) {
if (isPrimitive(value)) {
throw new TypeError(
[
'Primitives cannot leak memory.',
'You passed a ' + typeof value + ': <' + prettyFormat(value) + '>',
].join(' '),
);
}
let weak: typeof import('weak-napi');
try {
// eslint-disable-next-line import/no-extraneous-dependencies
weak = require('weak-napi');
} catch (err) {
if (!err || err.code !== 'MODULE_NOT_FOUND') {
throw err;
const isDate = value => getType(value) === 'date' && !isNaN(value);
function throwOnBadArgs(givenStyle, windowHeight) {
if (getType(givenStyle) !== 'object' && givenStyle !== undefined)
throw Error(`style (the first argument) must be an object or undefined`);
if (typeof windowHeight !== 'number' || windowHeight < 0)
throw Error('Second argument (windowHeight) must be a non-negative number');
}