@typescript-package/affix
Version:
A lightweight TypeScript library for different kind of affixes.
76 lines (75 loc) • 4.25 kB
TypeScript
import { Affix } from "./affix.class";
import { InfixTemplate } from "@typedly/affix";
import { SplitAt } from "../type";
/**
* @description A class to manage infixes that can be applied to strings.
* @export
* @class Infix
* @template {string} [Value=string] The type of infix 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, 'infix', Pattern>}
*/
export declare class Infix<Value extends string = string, Pattern extends RegExp | string | undefined = RegExp | string | undefined> extends Affix<Value, 'infix', Pattern> {
/**
* @description Inserts the infix into a given stem at a specified position with an optional delimiter.
* @public
* @static
* @template {string} Infix Type of the infix constrained by the `string`.
* @template {string} [Stem=string] The type of the stem string.
* @template {number} [Position=number] The type of the position number, defaults to `Math.floor(stem.length / 2)`.
* @template {string} [Delimiter=''] The type of delimiter string, defaults to an empty string.
* @param {Infix} infix The infix to insert into the stem at specified position.
* @param {Stem} stem The stem to insert the infix into its specified position.
* @param {Position} [position=Math.floor(stem.length / 2) as Position] The position of stem to insert the infix.
* @param {Delimiter} [delimiter='' as Delimiter] The delimiter to use between the two halves of stem and infix.
* @returns {InfixTemplate<SplitAt<Stem, Position>[0], Infix, SplitAt<Stem, Position>[1], Delimiter>}
*/
static insert<Stem extends string = string, Infix extends string = string, Position extends number = number, Delimiter extends string = ''>(stem: Stem, infix: Infix, position?: Position, delimiter?: Delimiter): InfixTemplate<SplitAt<Stem, Position>[0], Infix, SplitAt<Stem, Position>[1], Delimiter>;
/**
* @description Tag name for the `toStringTag`.
* @public
* @static
* @type {string}
*/
static tagName: string;
/**
* @description The default infix to use.
* @public
* @static
* @type {string}
*/
static default: string;
/**
* @description Returns the `string` tag representation of the `Infix` class when used in `Object.prototype.toString.call(instance)`.
* @public
* @readonly
* @type {string}
*/
get [Symbol.toStringTag](): string;
/**
* @description The infix value, which is a generic type variable `Value` constrained by the `string` type.
* @public
* @readonly
* @type {Value}
*/
get infix(): Value;
/**
* Creates an instance of `Infix`.
* @constructor
* @param {Value} [value='' as Value] The value of the infix, constrained by the `string` type. Defaults to an empty string.
* @param {Pattern} [pattern=Infix.pattern] The pattern to sanitize the infix. Defaults to the static `Infix.pattern`.
*/
constructor(value?: Value, pattern?: Pattern);
/**
* @description Inserts the infix into a given stem at a specified position with an optional delimiter.
* @public
* @template {string} [Stem=string] The type of the stem string.
* @template {number} [Position=number] The type of the position number, defaults to `Math.floor(stem.length / 2)`.
* @template {string} [Delimiter=''] The type of delimiter string, defaults to an empty string.
* @param {Stem} stem The stem to insert the infix into specified position of stem.
* @param {Position} [position=Math.floor(stem.length / 2) as Position] The position of stem to insert the infix.
* @param {Delimiter} [delimiter='' as Delimiter] The delimiter to use between the two halves of stem and infix.
* @returns {InfixTemplate<SplitAt<Stem, Position>[0], Value, SplitAt<Stem, Position>[1], Delimiter>}
*/
insertTo<Stem extends string = string, Position extends number = number, Delimiter extends string = ''>(stem: Stem, position?: Position, delimiter?: Delimiter): InfixTemplate<SplitAt<Stem, Position>[0], Value, SplitAt<Stem, Position>[1], Delimiter>;
}