@nasriya/cachify
Version:
A lightweight, extensible in-memory caching library for storing anything, with built-in TTL and customizable cache types.
45 lines (44 loc) • 1.83 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.basicValidators = void 0;
const atomix_1 = __importDefault(require("@nasriya/atomix"));
const string = (value, name, context) => {
if (!atomix_1.default.valueIs.string(value)) {
throw new TypeError(`The "${name}" property of the "${context ?? 'options'}" object (when provided) must be a string, but instead got ${typeof value}`);
}
return true;
};
const nonEmptyString = (value, name, context) => {
string(value, name, context);
if (!value) {
throw new RangeError(`The "${name}" property of the "${context ?? 'options'}" object (when provided) must not be empty, but instead got ${value}`);
}
};
const number = (value, name, context) => {
if (!atomix_1.default.valueIs.number(value)) {
throw new TypeError(`The "${name}" property of the "${context ?? 'options'}" object (when provided) must be a number, but instead got ${typeof value}`);
}
return true;
};
const integer = (value, name, context) => {
number(value, name, context);
if (!atomix_1.default.valueIs.integer(value)) {
throw new TypeError(`The "${name}" property of the "${context ?? 'options'}" object (when provided) must be an integer, but instead got ${typeof value}`);
}
};
const positiveInteger = (value, name, context) => {
integer(value, name, context);
if (value < 0) {
throw new RangeError(`The "${name}" property of the "${context ?? 'options'}" object (when provided) must be a positive integer, but instead got ${value}`);
}
};
exports.basicValidators = {
string,
nonEmptyString,
number,
integer,
positiveInteger
};