import { Nullable } from './types.js'; type NameSource = Nullable; interface ErrorMessage { source: NameSource; message?: string; } /** The error types supported by `Namefully`. */ export declare enum NameErrorType { /** * Thrown when a name entry/argument is incorrect. * * For example, a name should have a minimum of 2 characters, so an empty * string or a string of one character would cause this kind of error. */ INPUT = 0, /** * Thrown when the name components do not match the validation rules if the * `Config.bypass` is not flagged up. This bypass option skips the validation * rules. * * See also: `ValidationError` */ VALIDATION = 1, /** * Thrown by not allowed operations such as in NameBuilder or name formatting. * * See also: `NotAllowedError`, `Namefully.format`. */ NOT_ALLOWED = 2, /** Thrown by any other unknown sources or unexpected situation. */ UNKNOWN = 3 } /** * Base class for all name-related errors. * * A custom error is intended to convey information to the user about a failure, * so that it can be addressed programmatically. * * A name handling failure is not considered a native error that should cause a * program failure. Au contraire, it is expected that a programmer using this utility * would consider validating a name using its own business rules. That is not * this utility's job to guess those rules. So, the predefined `ValidationRules` * obey some common validation techniques when it comes to sanitizing a personal * name. For this reason, the `Config.bypass` is set to `true` by default, * indicating that those predefined rules should be skipped for the sake of the * program. * * A programmer may leverage `Parser` to indicate business-tailored rules if he * or she wants this utility to perform those safety checks behind the scenes. * * A name error intends to provide useful information about what causes the error * and let the user take initiative on what happens next to the given name: * reconstructing it or discarding it. */ export declare class NameError extends Error { readonly source: NameSource; readonly type: NameErrorType; /** * Creates an error with a message describing the issue for a name source. * @param source name input that caused the error * @param message describing the failure. * @param type of error via `NameErrorType` */ constructor(source: NameSource, message?: string, type?: NameErrorType); /** The actual source input which caused the error. */ get sourceAsString(): string; /** Whether a message describing the failure exists. */ get hasMessage(): boolean; /** Returns a string representation of the error. */ toString(): string; } /** * An error thrown when a name source input is incorrect. * * A `Name` is a name for this utility under certain criteria (i.e., 1+ chars), * hence, a wrong input will cause this kind of error. Another common reason * may be a wrong key in a JSON name parsing mechanism. * * Keep in mind that this error is different from a `ValidationError`. */ export declare class InputError extends NameError { /** * Creates a new `InputError` with an optional error `message`. * * The name source is by nature a string content, maybe wrapped up in a different * type. This string value may be extracted to form the following output: * "InputError (stringName)", * "InputError (stringName): message". */ constructor(error: ErrorMessage); } /** An error thrown to indicate that a name fails the validation rules. */ export declare class ValidationError extends NameError { /** Name of the invalid `nameType` if available. */ readonly nameType: string; /** * Creates error containing the invalid `nameType` and a `message` that * briefly describes the problem if provided. * * For example, a validation error can be interpreted as: * "ValidationError (nameType='stringName')", * "ValidationError (nameType='stringName'): message" */ constructor(error: ErrorMessage & { nameType: string; }); toString(): string; } /** * Thrown by not allowed operations such as in name formatting. * * For example, this will occur when trying to format a name accordingly using * a non-supported key. */ export declare class NotAllowedError extends NameError { /** The revoked operation name. */ readonly operation: string; /** * Creates a new `NotAllowedError` with an optional error `message` and the * `operation` name. * * For example, an error of this kind can be interpreted as: * "NotAllowedError (stringName)", * "NotAllowedError (stringName) - operationName", * "NotAllowedError (stringName) - operationName: message" */ constructor(error: ErrorMessage & { operation: string; }); toString(): string; } /** * A fallback error thrown by any unknown sources or unexpected failure that are * not of `NameError`. * * In this particular case, an `origin` remains useful as it provides details * on the sources and the true nature of the unexpected error. * At this point, deciding whether to exit the program or not depends on the * programmer. */ export declare class UnknownError extends NameError { /** The possible unknown error, with trace revealing its source and reason. */ readonly origin?: Error; /** * Creates a new `UnknownError` with an optional error `message`. * Optionally, the original error revealing the true nature of the failure. */ constructor(error: ErrorMessage & { origin?: Error; }); toString(): string; } export {};