@typescript-package/affix
Version:
A lightweight TypeScript library for different kind of affixes.
84 lines (83 loc) • 4.24 kB
TypeScript
import { Affix } from "./affix.class";
import { CircumfixTemplate } from "@typedly/affix";
/**
* @description A class to manage circumfixes that can be applied to strings.
* @export
* @class Circumfix
* @template {string} [Start=string] The type of circumfix constrained by the `string`. Defaults to `string`.
* @template {string} [End=Start] The type of circumfix end constrained by the `string`, defaults to the same type as `Start`.
* @template {RegExp | string | undefined} [Pattern=RegExp | string | undefined] The type of pattern constrained by the `RegExp` or `string`.
* @extends {Affix<[Start, End], 'circumfix', Pattern>}
*/
export declare class Circumfix<Start extends string = string, End extends string = Start, Pattern extends RegExp | string | undefined = RegExp | string | undefined> extends Affix<[Start, End], 'circumfix', Pattern> {
/**
* @description Inserts a circumfix to a given stem with an optional delimiter.
* @public
* @static
* @template {string} [Start=string] The type of circumfix start constrained by the `string`. Defaults to `string`.
* @template {string} [Stem=string] The type of stem constrained by the `string`. Defaults to `string`.
* @template {string} [End=Start] The type of circumfix end constrained by the `string`, defaults to the same type as `Start`.
* @template {string} [Delimiter=''] The type of delimiter constrained by the `string`, defaults to an empty string.
* @param {Stem} stem The stem to which the circumfix will be inserted.
* @param {(Start | [Start, End])} [circumfix=Circumfix.default as Start] The circumfix to be applied.
* @param {Delimiter} [delimiter='' as Delimiter] The delimiter to be used.
* @returns {CircumfixTemplate<Start, Stem, End, Delimiter>} The resulting circumfixed string.
*/
static insert<Start extends string = string, Stem extends string = string, End extends string = Start, Delimiter extends string = ''>(stem: Stem, circumfix?: Start | [Start, End], delimiter?: Delimiter): CircumfixTemplate<Start, Stem, End, Delimiter>;
/**
* @inheritdoc
* @public
* @static
* @type {string}
*/
static tagName: string;
/**
* @description The default circumfix value, which is an empty string. This is used when no circumfix is provided.
* @public
* @static
* @type {string | [string, string]}
*/
static default: string | [string, string];
/**
* @description Returns the `string` tag representation of the `Circumfix` class when used in `Object.prototype.toString.call(instance)`.
* @public
* @readonly
* @type {string}
*/
get [Symbol.toStringTag](): string;
/**
* @description The circumfix value, which is a tuple containing the start and end of the circumfix.
* @public
* @readonly
* @type {[Start, End]}
*/
get circumfix(): [Start, End];
/**
* @description The end of the circumfix, which is the second element of the tuple.
* @public
* @readonly
* @type {End}
*/
get end(): End;
/**
* @description The start of the circumfix, which is the first element of the tuple.
* @public
* @readonly
* @type {Start}
*/
get start(): Start;
/**
* Creates an instance of `Circumfix`.
* @constructor
* @param {Start} [start='' as Value] The value of the prefix, constrained by the `string` type. Defaults to an empty string.
* @param {End} [end=start as End] The value of the suffix, constrained by the `string` type, defaults to the same type as `start`.
* @param {Pattern} [pattern=Circumfix.pattern] The pattern to sanitize the prefix. Defaults to the static `Circumfix.pattern`.
*/
constructor(start?: Start, end?: End, pattern?: Pattern);
/**
* @description Inserts the circumfix to a given stem with an optional delimiter.
* @param {string} stem The stem to which the circumfix will be inserted.
* @returns {string} The resulting string with the circumfix inserted.
*/
insertTo<Stem extends string = string, Delimiter extends string = ''>(stem: Stem, delimiter?: Delimiter): CircumfixTemplate<Start, Stem, End, Delimiter>;
}