@barchart/common-js
Version:
Library of common JavaScript utilities
95 lines (93 loc) • 2.88 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var is_exports = {};
__export(is_exports, {
array: () => array,
boolean: () => boolean,
date: () => date,
extension: () => extension,
fn: () => fn,
integer: () => integer,
iterable: () => iterable,
large: () => large,
nan: () => nan,
negative: () => negative,
nil: () => nil,
number: () => number,
object: () => object,
positive: () => positive,
regexp: () => regexp,
string: () => string,
undef: () => undef,
zeroLengthString: () => zeroLengthString
});
module.exports = __toCommonJS(is_exports);
function number(candidate) {
return typeof candidate === "number" && !isNaN(candidate);
}
function nan(candidate) {
return typeof candidate === "number" && isNaN(candidate);
}
function integer(candidate) {
return typeof candidate === "number" && !isNaN(candidate) && (candidate | 0) === candidate;
}
function large(candidate) {
return typeof candidate === "number" && !isNaN(candidate) && isFinite(candidate) && Math.floor(candidate) === candidate;
}
function positive(candidate) {
return number(candidate) && candidate > 0;
}
function negative(candidate) {
return number(candidate) && candidate < 0;
}
function iterable(candidate) {
return !nil(candidate) && !undef(candidate) && fn(candidate[Symbol.iterator]);
}
function string(candidate) {
return typeof candidate === "string";
}
function date(candidate) {
return candidate instanceof Date;
}
function regexp(candidate) {
return candidate instanceof RegExp;
}
function fn(candidate) {
return typeof candidate === "function";
}
function array(candidate) {
return Array.isArray(candidate);
}
function boolean(candidate) {
return typeof candidate === "boolean";
}
function object(candidate) {
return typeof candidate === "object" && candidate !== null;
}
function nil(candidate) {
return candidate === null;
}
function undef(candidate) {
return candidate === void 0;
}
function zeroLengthString(candidate) {
return string(candidate) && candidate.length === 0;
}
function extension(parent, child) {
return fn(parent) && fn(child) && child.prototype instanceof parent;
}