@typescript-package/affix
Version:
A lightweight TypeScript library for different kind of affixes.
84 lines (83 loc) • 3.85 kB
TypeScript
import { Affix } from "./affix.class";
import { PrefixTemplate } from '@typedly/affix';
/**
* @description A class to manage prefixes that can be applied to strings.
* @export
* @class Prefix
* @template {string} [Value=string] The type of prefix constrained by the `string`.
* @template {RegExp | string | undefined} [Pattern=RegExp | string | undefined] The type of pattern constrained by the `RegExp` or `string`.
* @extends {Affix<Value, 'prefix', Pattern>}
*/
export declare class Prefix<Value extends string = string, Pattern extends RegExp | string | undefined = RegExp | string | undefined> extends Affix<Value, 'prefix', Pattern> {
/**
* @description Prepends the prefix to stem string.
* @public
* @static
* @template {string} [Stem=string] The type of stem string constrained by the `string`.
* @template {string} [Prefix=string] The type of prefix constrained by the `string`.
* @param {Stem} stem The stem string to append the prefix.
* @param {Prefix} [prefix=Prefix.default as Prefix] Prefix to append to stem.
* @param {Delimiter} [delimiter='' as Delimiter] The delimiter to use between the prefix and the stem.
* @param {boolean} [sanitize=true] Whether to sanitize the prefix using the static `Prefix.pattern`.
* @returns {PrefixTemplate<Prefix, Stem, Delimiter>}
*/
static prepend<Stem extends string = string, Prefix extends string = string, Delimiter extends string = ''>(stem: Stem, prefix?: Prefix, delimiter?: Delimiter, sanitize?: boolean): PrefixTemplate<Prefix, Stem, Delimiter>;
/**
* @description Tag name for the `toStringTag`.
* @public
* @static
* @type {string}
*/
static tagName: string;
/**
* @description The default prefix to use.
* @public
* @static
* @type {string}
*/
static default: string;
/**
* @description Returns the `string` tag representation of the `Prefix` class when used in `Object.prototype.toString.call(instance)`.
* @public
* @readonly
* @type {string}
*/
get [Symbol.toStringTag](): string;
/**
* @description The prefix value of the generic type variable `Value` constrained by the `string` type.
* @public
* @readonly
* @type {Value}
*/
get prefix(): Value;
/**
* Creates an instance of `Prefix`.
* @constructor
* @param {Value} [value='' as Value] The value of the prefix, constrained by the `string` type. Defaults to an empty string.
* @param {Pattern} [pattern=Prefix.pattern] The pattern to sanitize the prefix. Defaults to the static `Prefix.pattern`.
*/
constructor(value?: Value, pattern?: Pattern);
/**
* @description Prepends the prefix to stem string.
* @public
* @template {string} [Stem=string] The type of the stem string.
* @template {string} [Delimiter=''] The type of delimiter string.
* @param {Stem} stem The stem to prepend the prefix.
* @param {Delimiter} [delimiter='' as Delimiter] The delimiter to use between the prefix and the stem.
* @returns {PrefixTemplate<Value, Stem, Delimiter>} The resulting string with the prefix prepended.
*/
prependTo<Stem extends string = string, Delimiter extends string = ''>(stem: Stem, delimiter?: Delimiter): PrefixTemplate<Value, Stem, Delimiter>;
/**
* Sets the pattern and value for the prefix affix.
* @inheritdoc
* @public
* @param {{ pattern?: Pattern, value?: Value }} [param0={}]
* @param {Pattern} param0.pattern The pattern to sanitize the prefix.
* @param {Value} param0.value The value of the prefix, constrained by the `string` type.
* @returns {this} The current instance of `Prefix`.
*/
set({ pattern, value }?: {
pattern?: Pattern;
value?: Value;
}): this;
}