flooent
Version:
Fluent interface to provide an expressive syntax for common manipulations.
99 lines (98 loc) • 3.25 kB
TypeScript
declare class Stringable extends String {
["constructor"]: typeof Stringable;
constructor(value: any);
/**
* Returns the remaining text after the first occurrence of the given value.
* If the value does not exist in the string, the entire string is returned unchanged.
*/
after(part: string): this;
/**
* Returns the remaining text after the last occurrence of the given value.
* If the value does not exist in the string, the entire string is returned unchanged.
*/
afterLast(part: string): this;
/**
* Returns the text before the first occurrence of the given value.
* If the value does not exist in the string, the entire string is returned unchanged.
*/
before(part: string): this;
/**
* Returns the text before the last occurrence of the given value.
* If the value does not exist in the string, the entire string is returned unchanged.
*/
beforeLast(part: string): this;
/**
* Executes the callback if first given value evaluates to true. Result will get transformed back into a flooent string if it is a raw string.
*/
when<T>(comparison: any, then: (value: Stringable) => T): Stringable;
/**
* Executes the callback if string is empty. Result will get transformed back into a flooent string if it is a raw string.
*/
whenEmpty(then: any): Stringable;
/**
* Executes the callback and transforms the result back into a flooent string if it is a string.
*/
pipe(callback: (value: Stringable) => string): Stringable;
pipe<T>(callback: (value: Stringable) => T): T;
/**
* Tap into the chain without modifying the string.
*/
tap(fn: ((value: Stringable) => any)): Stringable;
/**
* Wraps a string with the given value.
*/
wrap(start: string, end?: string): Stringable;
/**
* Unwraps a string with the given value.
*/
unwrap(start: string, end?: string): this;
/**
* Alias for `concat`. Appends the given value to string.
*/
append(part: string): this;
/**
* Prepends the given value to string.
*/
prepend(part: string): Stringable;
/**
* Appends the given value only if string doesn't already end with it.
*/
endWith(part: string): this;
/**
* Prepends the given value only if string doesn't already start with it.
*/
startWith(part: string): Stringable;
/**
* Truncates text to given length and appends second argument if string got truncated.
*/
limit(n: number, append?: string): this;
/**
* Turns the string into title case.
*/
title(): Stringable;
/**
* Turns the string into kebab case.
*/
kebab(): Stringable;
/**
* Turns the string into snake case.
*/
snake(replacement?: string): Stringable;
/**
* Turns the string into studly case.
*/
studly(): Stringable;
/**
* Turns the string into camel case.
*/
camel(): Stringable;
/**
* Capitalizes the first character.
*/
capitalize(): Stringable;
/**
* Turns the string into URI conform slug.
*/
slug(replacement?: string): Stringable;
}
export default Stringable;