UNPKG

@typescript-package/affix

Version:

A lightweight TypeScript library for the affix - prefix and suffix.

73 lines (72 loc) 3.19 kB
import { Value } from '@typescript-package/core'; /** * @description A class to manage affixes (prefixes or suffixes) that can be applied to strings. * @export * @abstract * @class Affix * @template {string} [Value=string] The type of affix constrained by the `string`. Defaults to, `string`. * @extends {Value<Value>} */ export declare abstract class Affix<Value extends string = string> extends Value<Value> { #private; /** * @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 Defines the affix sanitized by specified pattern. * @public * @static * @template {string} [Value=string] * @param {Value} value A value of generic type variable `Value` constrained by the `string` type to be sanitized with the `pattern`. * @param {RegExp} [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<Value extends string = string>(value: Value, pattern?: RegExp): Value; /** * @description The default pattern pattern used to sanitize the affix, which removes characters that are not part of the valid characters for the affix. * @public * @static * @type {RegExp} */ static pattern: RegExp; /** * @description Returns the privately stored pattern of `RegExp` type to sanitize the affix. * @public * @readonly * @type {RegExp} */ get pattern(): RegExp; /** * Creates an instance of child class. * @constructor * @param {?Value} [value] An optional initial affix of generic type variable `Value` constrained by `string` type. * @param {?RegExp} [pattern] The pattern of `RegExp` to sanitize the affix. */ constructor(value?: Value, pattern?: RegExp); /** * @description Returns the affix, optionally sanitized by the `pattern`. * @public * @param {?RegExp} [pattern] The pattern of `RegExp` to sanitize privately stored affix. * @returns {string} Returns privately stored `#affix` of `string` type optionally sanitized by the `pattern`. */ get(pattern?: RegExp): Value; /** * @description Sets and stores privately sanitized affix of generic type variable `Value` constrained by `string` type. * @private * @param {Value} value The `affix` of generic type variable `Value`. * @param {RegExp} [pattern=this.#pattern] The pattern of `RegExp` to sanitize the `affix`. Defaults to privately stored `#pattern`. * @returns {this} The returned value is current instance for method chaining. */ set(value: Value, pattern?: RegExp): this; /** * @description Sets the pattern to sanitize the affix. * @public * @param {RegExp} pattern The pattern of `RegExp` to sanitize the affix. * @returns {this} */ setPattern(pattern: RegExp): this; }