@typescript-package/affix
Version:
A lightweight TypeScript library for different kind of affixes.
92 lines (91 loc) • 4.57 kB
TypeScript
import { AffixCore } from "./affix-core.abstract";
import { BasicAffixKind } from "@typedly/affix";
/**
* @description A concrete class to manage affixes that can be applied to strings with additional sanitization.
* @export
* @class Affix
* @template {string | [string, string]} [Value=string | [string, string]] The type of affix constrained by the `string`. Defaults to `string`.
* @template {BasicAffixKind | undefined} [Kind=BasicAffixKind | undefined]
* @template {RegExp | string | undefined} [Pattern=RegExp | string | undefined]
*/
export declare class Affix<Value extends string | [string, string] = string | [string, string], Kind extends BasicAffixKind | undefined = BasicAffixKind | undefined, Pattern extends RegExp | string | undefined = RegExp | string | undefined> extends AffixCore<Value, Kind> {
#private;
/**
* @description Defines the affix sanitized by specified pattern.
* @public
* @static
* @template {string | [string, string]} [Value=string | [string, string]] The type of affix constrained by the `string` type. Defaults to `string`.
* @param {Value} value A value of generic type variable `Value` constrained by the `string` type to be sanitized with the `pattern`.
* @param {RegExp | string} [pattern=Affix.pattern] The pattern of `RegExp` to sanitize the `affix`. Defaults to static `Affix.pattern`.
* @returns {Value} The returned value is an affix of a generic type variable `Value`, optionally sanitized by the `pattern`.
*/
static sanitize<Start extends string = string, End extends string = Start, Value extends string | [Start, End] = string | [Start, End]>(value: Value, pattern?: RegExp | string): Value;
/**
* @description The default pattern used to sanitize the affix, which removes characters that are not part of the valid characters for the affix.
* @public
* @static
* @type {RegExp | string}
*/
static pattern: RegExp | string;
/**
* @description Tag name for the `toStringTag`.
* @public
* @static
* @type {string}
*/
static tagName: string;
/**
* @description Returns the `string` tag representation of the `Affix` class when used in `Object.prototype.toString.call(instance)`.
* @public
* @readonly
* @type {string}
*/
get [Symbol.toStringTag](): string;
/**
* @description Returns the privately stored pattern of `PatternValue` type to sanitize the affix.
* @public
* @readonly
* @type {(Pattern)}
*/
get pattern(): Pattern;
/**
* Creates an instance of `Affix`.
* @constructor
* @param {Value} value An optional initial affix of generic type variable `Value` constrained by `string` type. Defaults to `Affix.pattern`.
* @param {{ kind?: Kind, pattern?: Pattern }} [param0={}] The options object to set the kind and pattern of the affix.
* @param {Kind} param0.kind The kind of affix constrained by `BasicAffixKind` type.
* @param {Pattern} param0.pattern The pattern of `PatternValue` to sanitize the affix.
*/
constructor(value: Value, { kind, pattern }?: {
kind?: Kind;
pattern?: Pattern;
});
/**
* @description Returns the affix, optionally sanitized by the `pattern`.
* @public
* @param {(Pattern)} [pattern=this.#pattern] The pattern of `RegExp` to sanitize privately stored affix.
* @returns {Value} Returns privately stored `#affix` of `Value` type optionally sanitized by the `pattern`.
*/
get(pattern?: Pattern): Value;
/**
* @description Sets and stores privately sanitized affix of generic type variable `Value` constrained by `string` type.
* @public
* @param {({ kind?: Kind, pattern?: Pattern, value?: Value})} [param0={}]
* @param {Kind} param0.kind The kind of affix constrained by `BasicAffixKind` type.
* @param {Pattern} param0.pattern The pattern of `Pattern` to sanitize the affix.
* @param {Value} param0.value The value of the affix constrained by `string` type.
* @returns {this} The returned value is current instance for method chaining.
*/
set({ kind, pattern, value }?: {
kind?: Kind;
pattern?: Pattern;
value?: Value;
}): this;
/**
* @description Sets the pattern to sanitize the affix.
* @public
* @param {Pattern} pattern The pattern of `Pattern` to sanitize the affix.
* @returns {this} The returned value is current instance for method chaining.
*/
setPattern(pattern: Pattern): this;
}