<commit_before>'use strict';

var utils = require('./utils');
var predicate = module.exports;

var curry = utils.curry;

if (Object.is) {
  predicate.is = curry(Object.is);
} else {
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  predicate.is = curry(function(v1, v2) {
    if (v1 === 0 && v2 === 0) {
      return 1 / v1 === 1 / v2;
    }
    if (v1 !== v1) {
      return v2 !== v2;
    }
    return v1 === v2;
  });
}

predicate.exists = function (val) {
  return val != null;
};

predicate.truthy = function (val) {
  // coerce for null != null
  return !!(val && predicate.exists(val));
};

predicate.falsey = utils.complement(predicate.truthy);

//---- value comparision methods

predicate.equal = curry(function (a, b) {
  return a === b;
});

predicate.eq = curry(function (a, b) {
  return a == b;
});

predicate.null = predicate.equal(null);
predicate.undef = predicate.equal(undefined);

predicate.lt = predicate.less = curry(function (a, b) {
  return a < b;
});

predicate.le = predicate.lessEq = curry(function (a, b) {
  return predicate.equal(a, b) || predicate.less(a, b);
});

predicate.gt = predicate.greater = curry(function (a, b) {
  return a > b;
});

predicate.ge = predicate.greaterEq = curry(function (a, b) {
  return predicate.equal(a, b) || predicate.greater(a, b);
});

// --- Type checking predicates

// Forces objects toString called returned as [object Object] for instance
var __toString = Object.prototype.toString;
var eqToStr = curry(function(str, val) {
  return predicate.equal(str, __toString.call(val));
});

//---- Object type checks

predicate.object = predicate.obj = function (val) {
  return val === Object(val);
};

predicate.array = predicate.arr = Array.isArray || eqToStr('[object Array]');
predicate.date = eqToStr('[object Date]');
predicate.rgx = predicate.RegExp = eqToStr('[object RegExp]');

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite
predicate.finite = Number.isFinite || function (val) {
  return predicate.number(val) && isFinite(val);
};

predicate.NaN = predicate.is(NaN);

predicate.instance = curry(function (Cls, inst) {
  return inst instanceof Cls;
});

predicate.arguments = eqToStr('[object Arguments]');
predicate.error = predicate.instance(Error);

// creates fns for predicate.string, etc
var typeofBuilder = curry(function(type, val) {
  return predicate.equal(type, typeof val);
});

//--- Create typeof methods

// type of string and alias name
// predicate.fn, predicate.num, etc
[
  ['function', 'fn'],<commit_msg>add nan alias<commit_after>'use strict';

var utils = require('./utils');
var predicate = module.exports;

var curry = utils.curry;

if (Object.is) {
  predicate.is = curry(Object.is);
} else {
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  predicate.is = curry(function(v1, v2) {
    if (v1 === 0 && v2 === 0) {
      return 1 / v1 === 1 / v2;
    }
    if (v1 !== v1) {
      return v2 !== v2;
    }
    return v1 === v2;
  });
}

predicate.exists = function (val) {
  return val != null;
};

predicate.truthy = function (val) {
  // coerce for null != null
  return !!(val && predicate.exists(val));
};

predicate.falsey = utils.complement(predicate.truthy);

//---- value comparision methods

predicate.equal = curry(function (a, b) {
  return a === b;
});

predicate.eq = curry(function (a, b) {
  return a == b;
});

predicate.null = predicate.equal(null);
predicate.undef = predicate.equal(undefined);

predicate.lt = predicate.less = curry(function (a, b) {
  return a < b;
});

predicate.le = predicate.lessEq = curry(function (a, b) {
  return predicate.equal(a, b) || predicate.less(a, b);
});

predicate.gt = predicate.greater = curry(function (a, b) {
  return a > b;
});

predicate.ge = predicate.greaterEq = curry(function (a, b) {
  return predicate.equal(a, b) || predicate.greater(a, b);
});

// --- Type checking predicates

// Forces objects toString called returned as [object Object] for instance
var __toString = Object.prototype.toString;
var eqToStr = curry(function(str, val) {
  return predicate.equal(str, __toString.call(val));
});

//---- Object type checks

predicate.object = predicate.obj = function (val) {
  return val === Object(val);
};

predicate.array = predicate.arr = Array.isArray || eqToStr('[object Array]');
predicate.date = eqToStr('[object Date]');
predicate.rgx = predicate.RegExp = eqToStr('[object RegExp]');

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite
predicate.finite = Number.isFinite || function (val) {
  return predicate.number(val) && isFinite(val);
};

predicate.nan = predicate.NaN = predicate.is(NaN);

predicate.instance = curry(function (Cls, inst) {
  return inst instanceof Cls;
});

predicate.arguments = eqToStr('[object Arguments]');
predicate.error = predicate.instance(Error);

// creates fns for predicate.string, etc
var typeofBuilder = curry(function(type, val) {
  return predicate.equal(type, typeof val);
});

//--- Create typeof methods

// type of string and alias name
// predicate.fn, predicate.num, etc
[
  ['function', 'fn'],
{'fraction_non_alphanumeric': 0.16922486569455103, 'fraction_numerical': 0.0061396776669224865, 'mean_word_length': 3.8810861423220975, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1021711', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1738, 'n_words': 420}