perlica
Version:
<h1 align="center">Perlica</h1>
145 lines (143 loc) • 4.46 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all2) => {
for (var name in all2)
__defProp(target, name, { get: all2[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);
// src/Predicate/index.ts
var Predicate_exports = {};
__export(Predicate_exports, {
all: () => all,
and: () => and,
any: () => any,
eq: () => eq,
hasProperty: () => hasProperty,
isArray: () => isArray,
isAsyncIterable: () => isAsyncIterable,
isBigInt: () => isBigInt,
isBoolean: () => isBoolean,
isDate: () => isDate,
isError: () => isError,
isFunction: () => isFunction,
isInteger: () => isInteger,
isIterable: () => isIterable,
isMap: () => isMap,
isNotNull: () => isNotNull,
isNotNullable: () => isNotNullable,
isNotUndefined: () => isNotUndefined,
isNull: () => isNull,
isNullable: () => isNullable,
isNumber: () => isNumber,
isObject: () => isObject,
isPromise: () => isPromise,
isRecordOrArray: () => isRecordOrArray,
isRegExp: () => isRegExp,
isSet: () => isSet,
isString: () => isString,
isSymbol: () => isSymbol,
isTruthy: () => isTruthy,
isUndefined: () => isUndefined,
ne: () => ne,
not: () => not,
or: () => or
});
module.exports = __toCommonJS(Predicate_exports);
var not = (self) => (value) => !self(value);
var and = (self, that) => (value) => self(value) && that(value);
var or = (self, that) => (value) => self(value) || that(value);
var all = (predicates) => {
return (value) => {
for (const p of predicates) {
if (p(value) === false) {
return false;
}
}
return true;
};
};
var any = (predicates) => {
return (value) => {
for (const p of predicates) {
if (p(value) === true) {
return true;
}
}
return false;
};
};
var eq = (that) => (value) => value === that;
var ne = (that) => (value) => value !== that;
var isTruthy = (value) => !!value;
var isNull = (value) => value === null;
var isNotNull = (value) => value !== null;
var isUndefined = (value) => value === void 0;
var isNotUndefined = (value) => value !== void 0;
var isBoolean = (value) => typeof value === "boolean";
var isNumber = (value) => typeof value === "number";
var isInteger = (value) => Number.isInteger(value);
var isBigInt = (value) => typeof value === "bigint";
var isString = (value) => typeof value === "string";
var isArray = (value) => Array.isArray(value);
var isFunction = (value) => typeof value === "function";
var isSymbol = (value) => typeof value === "symbol";
var isSet = (value) => value instanceof Set;
var isMap = (value) => value instanceof Map;
var isRegExp = (value) => value instanceof RegExp;
var isError = (value) => value instanceof Error;
var isNullable = (value) => isNull(value) || isUndefined(value);
var isNotNullable = (value) => isNotNull(value) && isNotUndefined(value);
var isPromise = (value) => hasProperty(value, "then") && hasProperty(value, "catch") && isFunction(value.then) && isFunction(value.catch);
var isDate = (value) => value instanceof Date;
var isRecordOrArray = (value) => typeof value === "object" && isNotNull(value);
var isObject = (value) => isRecordOrArray(value) || isFunction(value);
var hasProperty = (value, property) => isObject(value) && property in value;
var isIterable = (value) => hasProperty(value, Symbol.iterator);
var isAsyncIterable = (value) => hasProperty(value, Symbol.asyncIterator);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
all,
and,
any,
eq,
hasProperty,
isArray,
isAsyncIterable,
isBigInt,
isBoolean,
isDate,
isError,
isFunction,
isInteger,
isIterable,
isMap,
isNotNull,
isNotNullable,
isNotUndefined,
isNull,
isNullable,
isNumber,
isObject,
isPromise,
isRecordOrArray,
isRegExp,
isSet,
isString,
isSymbol,
isTruthy,
isUndefined,
ne,
not,
or
});