@hugoalh/string-dissect
Version:
A module to dissect the string; Safe with the emojis, URLs, and words.
68 lines • 2.36 kB
TypeScript
export interface StringDissectorOptions {
/**
* The locales to use in the operation. The JavaScript implementation examines locales, and then computes a locale it understands that comes closest to satisfying the expressed preference. By default, the implementation's default locale will be used.
*
* For more information, please visit https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument.
*/
locales?: Intl.LocalesArgument;
/**
* Whether to output string segments of ANSI escape codes.
* @default {true}
*/
outputANSI?: boolean;
/**
* Whether to prevent URLs get splitted.
* @default {true}
*/
safeURLs?: boolean;
/**
* Whether to prevent words get splitted.
* @default {true}
*/
safeWords?: boolean;
}
export type StringSegmentType = "ansi" | "character" | "emoji" | "url" | "word";
export interface StringSegmentDescriptor {
/**
* String segment end index of the input string.
*/
indexEnd: number;
/**
* String segment start index of the input string.
*/
indexStart: number;
/**
* Type of the string segment.
*/
type: StringSegmentType;
/**
* Value of the string segment.
*/
value: string;
}
/**
* String dissector to dissect the string; Safe with the emojis, URLs, and words.
*/
export declare class StringDissector {
#private;
/**
* Initialize.
* @param {StringDissectorOptions} [options={}] Options.
*/
constructor(options?: StringDissectorOptions);
/**
* Dissect the string.
* @param {string} item String that need to dissect.
* @returns {Generator<StringSegmentDescriptor>} An iterable segment descriptors from the dissected string.
*/
dissect(item: string): Generator<StringSegmentDescriptor>;
}
export default StringDissector;
/**
* Dissect the string; Safe with the emojis, URLs, and words.
* @param {string} item String that need to dissect.
* @param {StringDissectorOptions} [options={}] Options.
* @returns {Generator<StringSegmentDescriptor>} An iterable segment descriptors from the dissected string.
*/
export declare function dissectString(item: string, options?: StringDissectorOptions): Generator<StringSegmentDescriptor>;
//# sourceMappingURL=mod.d.ts.map