"use strict"; 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); // src/index.ts var src_exports = {}; __export(src_exports, { Optional: () => Optional }); module.exports = __toCommonJS(src_exports); // src/optional/Empty.ts var NoSuchElementError = class extends Error { }; var Empty = class { constructor() { this.filter = () => this; this.flatMap = () => this; this.get = () => { throw new NoSuchElementError(); }; this.ifPresent = () => { }; this.ifPresentOrElse = (_, emptyAction) => emptyAction(); this.isEmpty = () => true; this.isPresent = () => false; this.map = () => this; this.or = (supplier) => supplier(); this.orElse = (other) => other; this.orElseGet = (supplier) => supplier(); this.orElseThrow = (supplier) => { const error = supplier ? supplier() : new NoSuchElementError(); throw error; }; } }; // src/optional/Present.ts var Present = class _Present { constructor(value) { this.value = value; this.filter = (predicate) => predicate(this.value) ? this : new Empty(); this.flatMap = (mapper) => mapper(this.value); this.get = () => this.value; this.ifPresent = (action) => action(this.value); this.ifPresentOrElse = (action) => action(this.value); this.isEmpty = () => false; this.isPresent = () => true; this.map = (mapper) => new _Present(mapper(this.value)); this.or = () => this; this.orElse = () => this.value; this.orElseGet = () => this.value; this.orElseThrow = () => this.value; } }; // src/optional/Optional.ts var Optional = class { /** * Returns an empty Optional instance. No value is present for this Optional. * * **API Note:** * Though it may be tempting to do so, avoid testing if an object is empty by comparing with == or != against instances returned by Optional.empty(). There is no guarantee that it is a singleton. Instead, use isEmpty() or isPresent(). * * @returns an empty Optional */ static empty() { return new Empty(); } /** * Returns an Optional describing the given non-null value. * * @param value the value to describe, which must be non-null * @returns an Optional with the value present */ static of(value) { return new Present(value); } /** * Returns an Optional describing the given value, if non-null and defined, otherwise returns an empty Optional. * * @param value the possibly-null or undefined value to describe * @returns an Optional with a present value if the specified value is non-null and defined, otherwise an empty Optional */ static ofNullable(value) { if (value) { return new Present(value); } return new Empty(); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Optional });