"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { IflessNumber: () => ifless_number_default, IflessObject: () => ifless_object_default, IflessString: () => ifless_string_default, buildIfless: () => buildIfless, default: () => src_default, ifless: () => ifless, isEnglishChar: () => isEnglishChar, isNumeric: () => isNumeric }); module.exports = __toCommonJS(src_exports); // src/ifless.ts var import_lodash = __toESM(require("lodash.result"), 1); var Ifless = class { constructor() { this._registeredFunctions = {}; this._appliedStuffSucceeded = false; } when(fn, thenResult) { if (!this.resultIsDefined() && fn()) { this._result = thenResult; } return this; } whenFn(fn, thenResult) { return this.when(fn, thenResult); } registerFn(name, fn) { this._registeredFunctions[name] = fn; return this; } execute() { let allPassed = false; for (const key in this._registeredFunctions) { if (this._registeredFunctions[key]()) { allPassed = true; } else { allPassed = false; break; } } this._appliedStuffSucceeded = allPassed; return this; } executeRegisteredFunctions() { return this.execute(); } executeRegisteredFn(name) { if ((0, import_lodash.default)(this._registeredFunctions, name)) { this._appliedStuffSucceeded = true; } return this; } clearRegisteredFn(name) { delete this._registeredFunctions[name]; return this; } whenAllPassed(thenResult) { if (!this.resultIsDefined() && this._appliedStuffSucceeded) { this._result = thenResult; } return this; } whenOverResult(fn, thenResult) { if (this._result) { if (fn(this._result)) { this._result = thenResult; } } return this; } reset() { this._result = void 0; return this; } otherwise(otherwiseResult) { this._result = otherwiseResult; } get result() { return this._result; } resultIsDefined() { return this._result !== void 0; } }; var ifless_default = Ifless; // src/ifless-subject.ts var import_lodash2 = __toESM(require("lodash.invoke"), 1); var IflessSubject = class { constructor(subject) { this._registeredFunctions = {}; this._appliedStuffSucceeded = false; this._subject = subject; } when(fn, thenResult) { if (!this.resultIsDefined() && fn(this._subject)) { this._result = thenResult; } return this; } whenFn(fn, thenResult) { return this.when(fn, thenResult); } andWhen(fn, thenResult) { if (this._result && fn(this._subject)) { this._result = thenResult; } return this; } whenOverResult(fn, thenResult) { if (this._result) { if (fn(this._result)) { this._result = thenResult; } } return this; } whenOverResultFn(fn, overResultFn) { if (this._result) { if (fn(this._result)) { this._result = overResultFn(this._result); } } return this; } changeSubject(newSubject) { this._subject = newSubject; this._result = void 0; return this; } executeWithAnyPass() { let anyPassed = false; for (const key in this._registeredFunctions) { if (this._registeredFunctions[key](this._subject)) { anyPassed = true; break; } else { anyPassed = false; } } this._appliedStuffSucceeded = anyPassed; return this; } registerFn(name, fn) { this._registeredFunctions[name] = fn; return this; } execute() { let allPassed = false; for (const key in this._registeredFunctions) { if (this._registeredFunctions[key](this._subject)) { allPassed = true; } else { allPassed = false; break; } } this._appliedStuffSucceeded = allPassed; return this; } executeRegisteredFunctions() { return this.execute(); } executeRegisteredFn(name) { if ((0, import_lodash2.default)(this._registeredFunctions, name, this._subject)) { this._appliedStuffSucceeded = true; } return this; } clearRegisteredFn(name) { delete this._registeredFunctions[name]; return this; } whenPassed(thenResult) { return this.whenAllPassed(thenResult); } whenAllPassed(thenResult) { if (!this.resultIsDefined() && this._appliedStuffSucceeded) { this._result = thenResult; } return this; } reset() { this._result = void 0; return this; } otherwise(otherwiseResult) { this._result || (this._result = otherwiseResult); return this; } get result() { return this._result; } resultIsDefined() { return this._result !== void 0; } }; var ifless_subject_default = IflessSubject; // src/ifless-number.ts var IflessNumber = class extends ifless_subject_default { constructor(subject) { super(subject); this._subject = subject; } when(fn, thenResult) { if (!this.resultIsDefined() && fn(this._subject)) { this._result = thenResult; } return this; } whenFn(fn, thenResult) { return this.when(fn, thenResult); } whenGt(comparableNumber, thenResult) { if (!this.resultIsDefined() && this._subject > comparableNumber) { this._result = thenResult; } return this; } whenGte(comparableNumber, thenResult) { if (!this.resultIsDefined() && this._subject >= comparableNumber) { this._result = thenResult; } return this; } whenLt(comparableNumber, thenResult) { if (!this.resultIsDefined() && this._subject < comparableNumber) { this._result = thenResult; } return this; } whenLte(comparableNumber, thenResult) { if (!this.resultIsDefined() && this._subject <= comparableNumber) { this._result = thenResult; } return this; } whenEq(comparableNumber, thenResult) { if (!this.resultIsDefined() && this._subject === comparableNumber) { this._result = thenResult; } return this; } whenEqual(comparableNumber, thenResult) { if (!this.resultIsDefined() && this._subject === comparableNumber) { this._result = thenResult; } return this; } whenBetween(min, max, thenResult) { if (!this.resultIsDefined() && this._subject >= min && this._subject <= max) { this._result = thenResult; } return this; } whenNegative(thenResult) { if (!this.resultIsDefined() && this._subject < 0) { this._result = thenResult; } return this; } whenPositive(thenResult) { if (!this.resultIsDefined() && this._subject > 0) { this._result = thenResult; } return this; } whenZero(thenResult) { if (!this.resultIsDefined() && this._subject === 0) { this._result = thenResult; } return this; } whenOverResult(fn, thenResult) { if (this._result) { if (fn(this._result)) { this._result = thenResult; } } return this; } whenOverResultFn(fn, overResultFn) { if (this._result) { if (fn(this._result)) { this._result = overResultFn(this._result); } } return this; } otherwise(otherwiseResult) { this._result || (this._result = otherwiseResult); return this; } }; var ifless_number_default = IflessNumber; // src/ifless-string.ts var isEnglishChar = (char) => char >= "a" && char <= "z" || char >= "A" && char <= "Z"; var isNumeric = (value) => !Number.isNaN(value) && !Number.isNaN(Number.parseFloat(value)); var charIsVowel = (char) => ["a", "e", "i", "o", "u", "y"].includes(char.toLowerCase()); var IflessString = class extends ifless_subject_default { constructor(subject) { super(subject); this._subject = subject; } when(fn, thenResult) { if (!this.resultIsDefined() && fn(this._subject)) { this._result = thenResult; } return this; } whenFn(fn, thenResult) { return this.when(fn, thenResult); } whenEq(comparableString, thenResult) { if (!this.resultIsDefined() && this._subject === comparableString) { this._result = thenResult; } return this; } whenStartsWith(searchString, thenResult) { if (!this.resultIsDefined() && this._subject.startsWith(searchString)) { this._result = thenResult; } return this; } whenEndsWith(searchString, thenResult) { if (!this.resultIsDefined() && this._subject.endsWith(searchString)) { this._result = thenResult; } return this; } whenIncludes(searchString, thenResult) { if (!this.resultIsDefined() && this._subject.includes(searchString)) { this._result = thenResult; } return this; } whenEqual(comparableString, thenResult) { if (!this.resultIsDefined() && this._subject === comparableString) { this._result = thenResult; } return this; } whenOneOf(searchStrings, thenResult) { if (!this.resultIsDefined() && searchStrings.includes(this._subject)) { this._result = thenResult; } return this; } whenOverResult(fn, thenResult) { if (this._result) { if (fn(this._result)) { this._result = thenResult; } } return this; } whenOverResultFn(fn, overResultFn) { if (this._result) { if (fn(this._result)) { this._result = overResultFn(this._result); } } return this; } otherwise(otherwiseResult) { this._result || (this._result = otherwiseResult); return this; } isNumeric() { return isNumeric(this._subject); } isEnglishChar() { if (isEnglishChar(this._subject)) { return true; } return false; } isEnglishVowelChar() { if (isEnglishChar(this._subject) && charIsVowel(this._subject.toLowerCase())) { return true; } return false; } isEnglishConsonantChar() { if (isEnglishChar(this._subject) && !charIsVowel(this._subject.toLowerCase())) { return true; } return false; } includesEnglishChar() { for (const char of this._subject) { if (isEnglishChar(char)) { return true; } } return false; } }; var ifless_string_default = IflessString; // src/ifless-object.ts var import_lodash3 = __toESM(require("lodash.isequal"), 1); var import_lodash4 = __toESM(require("lodash.result"), 1); var IflessObject = class extends ifless_subject_default { constructor(subject) { super(subject); this._subject = subject; } when(fn, thenResult) { if (!this.resultIsDefined() && fn(this._subject)) { this._result = thenResult; } return this; } whenFn(fn, thenResult) { return this.when(fn, thenResult); } andWhen(fn, thenResult) { if (this._result && fn(this._subject)) { this._result = thenResult; } return this; } andWhenPathSatisfies(path, fn, thenResult) { if (this._result && fn((0, import_lodash4.default)(this._subject, path))) { this._result = thenResult; } return this; } whenEq(comparable, thenResult) { if (!this.resultIsDefined() && (0, import_lodash3.default)(this._subject, comparable)) { this._result = thenResult; } return this; } whenPathEq(path, comparable, thenResult) { if (!this.resultIsDefined() && (0, import_lodash3.default)((0, import_lodash4.default)(this._subject, path), comparable)) { this._result = thenResult; } return this; } whenPathSatisfies(path, satisfiesFn, thenResult) { if (!this.resultIsDefined() && satisfiesFn((0, import_lodash4.default)(this._subject, path))) { this._result = thenResult; } return this; } whenHasKey(key, thenResult) { if (!this.resultIsDefined() && key in this._subject) { this._result = thenResult; } return this; } whenOverResult(fn, thenResult) { if (this._result) { if (fn(this._result)) { this._result = thenResult; } } return this; } whenOverResultFn(fn, overResultFn) { if (this._result) { if (fn(this._result)) { this._result = overResultFn(this._result); } } return this; } andWhenPathEq(path, comparable, thenResult) { if (this.resultIsDefined() && (0, import_lodash3.default)((0, import_lodash4.default)(this._subject, path), comparable)) { this._result = thenResult; } return this; } otherwise(otherwiseResult) { if (this._result === void 0) { this._result = otherwiseResult; } return this; } }; var ifless_object_default = IflessObject; // src/index.ts var src_default = ifless_default; var ifless = new ifless_default(); var buildIfless = (value) => { if (typeof value === "string") { return new ifless_string_default(value); } if (typeof value === "number") { return new ifless_number_default(value); } if (typeof value === "object") { return new ifless_object_default(value); } throw new Error(`type ${typeof value} is not supported as a subject`); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { IflessNumber, IflessObject, IflessString, buildIfless, ifless, isEnglishChar, isNumeric });