@typescript-package/wrapper
Version:
A lightweight TypeScript library to wrap the text with the opening and closing chars.
156 lines (155 loc) • 10.5 kB
TypeScript
/**
* The `Wrap` object is based on the `String` object and represents the immutable primitive value of the text wrapped by the opening and
* closing chars. It is designed to preserve the type names of the supplied opening, text, and closing chars by using the generic type
* variables.
*/
export declare class Wrap<Opening extends string = string, Text extends string = '', Closing extends string = string> extends String {
#private;
/**
* The `get` accessor gets the closing of the wrap by returning the `#closing` property of a specified object.
* @returns The return value is closing of the wrap of a generic type variable `Closing`.
*/
get closing(): Closing;
/**
* The `get` accessor gets the opening of the wrap by returning the `#opening` property of a specified object.
* @returns The return value is the opening of the wrap of a generic type variable `Opening`.
*/
get opening(): Opening;
/**
* The `get` accessor gets the text of the `Wrap` by returning the `#text` property of a specified object.
* @returns The return value is the text of a generic type variable `Text`.
*/
get text(): Text;
/**
* The `get` accessor, with the help of `toStringTag`, changes the default tag to `Wrap` for an instance of `Wrap`. It can be read by
* the `typeOf()` function of `@typescript-package/type`.
* @returns The return value is the word 'Wrap` of a `string`.
*/
get [Symbol.toStringTag](): string;
/**
* The method checks whether the text has given `closing` chars at the end.
* @param text The text of `string` type, to check whether it contains given `closing` chars.
* @param closing The closing chars of `string` type to check if a given `text` contains.
* @returns The return value is a `boolean` indicating whether the `text` contains `closing` chars at the end.
*/
static hasClosing(text: string, closing: string): boolean;
/**
* Checks whether the text has `opening` chars at the beginning.
* @param text The text of `string`, to check whether it contains given `opening` chars.
* @param opening The opening chars of `string` to check if a given `text` contains.
* @returns The return value is a `boolean` indicating whether the `text` contains `opening` chars at the beginning.
*/
static hasOpening(text: string, opening: string): boolean;
/**
* The method checks whether the `value` of any type is the `Wrap` instance of any or given `opening` and `closing` chars.
* @param value The value of any type to test against the `Wrap` instance of any or given opening and closing.
* @param opening Optional opening chars of a generic type variable `Opening` to check if the given `value` contains.
* @param closing Optional closing chars of a generic type variable `Closing` to check if the given `value` contains.
* @param text An optional text of a generic type variable `Text` to check if the given `value` contains.
* @returns The return value is a `boolean` type indicating whether the value is an instance of `Wrap` of any, or the given opening,
* closing, and text.
*/
static isWrap<Opening extends string = string, Closing extends string = string, Text extends string = ``>(value: any, opening?: Opening, closing?: Closing, text?: Text): value is Wrap<Opening, Text, Closing>;
/**
* Creates a new `Wrap` instance of the opening and closing chars and optional text to wrap.
* @param opening Opening characters of the generic type variable `Opening` placed before the given `text`. An empty `string` indicates
* that for the `hasOpening()` and `isWrapped()` methods, the opening chars are `undefined`, returning `false`.
* @param closing Closing characters of the generic type variable `Closing` placed after the given `text`. An empty `string` indicates
* that for the `hasClosing()` and `isWrapped()` methods, the closing chars are `undefined`, returning `false`.
* @param text An optional text placed between the given `opening` and `closing` chars on the template `${Opening}${Text}${Closing}`.
*/
constructor(opening: Opening, closing: Closing, text?: Text);
/**
* Gets the closing chars of the wrap by returning the `#closing` property of a specified object.
* @returns The return value is closing chars of a generic type variable `Closing`.
*/
getClosing(): Closing;
/**
* Gets the opening chars of the wrap by returning the `#opening` property of a specified object.
* @returns The return value is opening chars of a generic type variable `Opening`.
*/
getOpening(): Opening;
/**
* Gets the text of the wrap by returning the `#text` property of a specified object, without the opening and closing chars of the `Wrap`.
* @returns The return value is the text of a generic type variable `Text`.
*/
getText(): Text;
/**
* Checks whether the primitive value of a specified object has the closing chars or given `closing` chars. If given `closing` chars in
* the constructor are the empty `string`, the method returns `false`.
* @param closing Optional closing chars of a `string` type to check whether the primitive value contains them at the **end**.
* @returns The return value is a `boolean` indicating whether the primitive value has the closing chars or given closing chars.
*/
hasClosing(closing?: string): boolean;
/**
* Checks whether the primitive value of a specified object has the opening chars or given `opening` chars. If given `opening` chars in
* the constructor are the empty `string`, the method returns `false`.
* @param opening Optional opening chars of a `string` type to check if the primitive value contains them at the **beginning**.
* @returns The return value is a `boolean` indicating whether the primitive value has the opening chars or given `opening` chars.
*/
hasOpening(opening?: string): boolean;
/**
* The method checks whether the text of a specified `Wrap` object is defined, which means it's a `string` of at least one char and
* optionally equal to the given `text`.
* @param text Optional text of `string` type to check whether it's equal to the text of the `Wrap` object.
* @returns The return value is a `boolean` indicating whether the text is defined and optionally equal to the given text.
*/
hasText(text?: string): boolean;
/**
* The method checks whether the primitive value of the specified `object` is wrapped by the opening and closing chars of an instance or
* given `opening` and `closing` chars. If given `opening` or `closing` chars in the constructor are the empty `string`, the method
* returns `false`.
* @param opening Optional opening chars of a `string` type to check if the primitive value contains them at the beginning. The default
* value is picked from the private `#opening` property of an instance.
* @param closing Optional closing chars of a `string` type to check if the primitive value contains them at the end. The default value is
* picked from the private `#closing` property of an instance.
* @returns The return value is a `boolean` indicating whether the object has both opening and closing chars or given `opening` and
* `closing` chars.
*/
isWrapped(opening?: string, closing?: string): boolean;
/**
* Returns the primitive value with replaced closing chars.
* @param closing The closing chars of a generic type variable `ReplaceClosing` to replace the closing chars in the primitive value.
* @returns The return value is the primitive value with replaced closing chars of a generic type variables in order `Opening`, `Text` and
* `ReplaceClosing` on the template `${Opening}${Text}${ReplaceClosing}`.
*/
replaceClosing<ReplaceClosing extends string = ''>(closing: ReplaceClosing): `${Opening}${Text}${ReplaceClosing}`;
/**
* Returns the primitive value with replaced opening chars.
* @param opening The opening chars of a generic type variable `ReplaceOpening` to replace the opening chars in the primitive value.
* @returns The return value is the primitive value with replaced opening chars of a generic type variables in order `ReplaceOpening`,
* `Text` and `Closing` on the template `${ReplaceOpening}${Text}${Closing}`.
*/
replaceOpening<ReplaceOpening extends string = ''>(opening: ReplaceOpening): `${ReplaceOpening}${Text}${Closing}`;
/**
* Returns the primitive value with replaced text.
* @param text The text of a generic type variable `ReplaceText` to replace the text in the primitive value.
* @returns The return value is the primitive value with replaced text of a generic type variables in order `Opening`, `ReplaceText`
* and `Closing` on the template `${Opening}${ReplaceText}${Closing}`.
*/
replaceText<ReplaceText extends string = ''>(text: ReplaceText): `${Opening}${ReplaceText}${Closing}`;
/**
* Checks whether the wrapped text starts with the specified opening characters.
* @param opening Optional opening characters to check against. Defaults to the instance's `#opening`.
* @returns The returned value is a `boolean` indicating whether the wrapped text starts with the given or default opening characters.
*/
startsWith(opening?: string): boolean;
/**
* Checks whether the wrapped text ends with the specified closing characters.
* @param closing Optional closing characters to check against. Defaults to the instance's `#closing`.
* @returns The returned value is a `boolean` indicating whether the wrapped text ends with the given or default closing characters.
*/
endsWith(closing?: string): boolean;
/**
* Gets the wrap, the primitive value of a specified `Wrap` object.
* @returns The return value is the wrap of generic type variables in order `Opening`, `Text`, and `Closing` on the template
* `${Opening}${Text}${Closing}`.
*/
toString(): `${Opening}${Text}${Closing}`;
/**
* Returns the wrap, primitive value of a specified `Wrap` object.
* @returns The return value is the wrap of generic type variables in order `Opening`, `Text`, and `Closing` on the template
* `${Opening}${Text}${Closing}`.
*/
valueOf(): `${Opening}${Text}${Closing}`;
}