UNPKG

@kwiz/common

Version:

KWIZ common utilities and helpers for M365 platform

73 lines (72 loc) 4.21 kB
import { IDictionary } from "../types/common.types"; export declare function endsWith(str: string, value: string, ignoreCase?: boolean): boolean; export declare function startsWith(str: string, value: string, ignoreCase?: boolean): boolean; /** remove space at start or end */ export declare function trim(str: string): string; export declare function trimEnd(str: string): string; export declare function trimStart(str: string): string; export declare function splice(str: string, start: number, delCount: number, insert: string): string; export declare function padRight(value: string | number, length: number, fillString?: string): string; export declare function padLeft(value: string | number, length: number, fillString?: string): string; /** returns array of [token] found inside the string * supports token formats [Author??Created by {0}::Unknown author] will return "Author" as the token * */ export declare function GetTokens(StringFormat: string): string[]; /** replaces a string with [token] and [otherToken] with their matched provided values * supports token formats [Author??Created by {0}::Unknown author] */ export declare function ReplaceTokens(StringFormat: string, TokenValues: IDictionary<string>, options?: { /**set to true if you want to keep "[token]" in the string when a token value wasn't provided */ keepMissingTokens?: boolean; }): string; /** calls replace tokens on every dictionary value, or set null keys to "". This function ignores null/empty dictionaries */ export declare function ReplaceTokensInDictionary(Dictionary: IDictionary<string>, TokenValues: IDictionary<string>): void; /** Normalizes a guid string, lower case and removes {} */ export declare function normalizeGuid(text: string, removeDashes?: boolean): string; export declare function isEmptyGuid(guid: { toString(): string; }): boolean; export declare function escapeRegExp(text: string): string; export declare function isValidDomainLogin(login: string): boolean; export declare function stripRichTextWhitespace(value: string): string; /** allows min length 1, letters, numbers underscore only */ export declare function isValidVarName(text: string): boolean; /** allows min length 1, letters, numbers underscore and hyphen only */ export declare function isValidHeaderName(text: string): boolean; /** returns token info with format */ export declare function GetTokenInfo(text: string): { tokenName: string; hasFormat: boolean; getValue: (value: string) => string; }; /** return true if both strings are the same, or both are empty/null/undefined */ export declare function stringEqualsOrEmpty(str1: string, str2: string, ignoreCase?: boolean): boolean; /** return true if str1 contains str2 */ export declare function stringContains(str1: string, str2: string, ignoreCase?: boolean): boolean; export declare function cleanupString(str: string, options: { replaceNewLines?: string; collapseMultipleSpaces?: string; collapseMultipleDashes?: string; collapseMultipleUnderscore?: string; }): string; /** normalizes &#160; to &nbsp; see Issue 752 */ export declare function normalizeHtmlSpace(html: string): string; export declare function replaceAll(str: string, find: string, replace: string, ignoreCase?: boolean): string; export declare function capitalizeFirstLetter(str: string): string; export declare function escapeXml(unsafe: string, isAttribute?: boolean): string; /** uses regex str.match to replace each match by calling the replacer function (imported from CMS) */ export declare function replaceRegex(str: string, regex: RegExp, replacer: (match: string) => string | null): string; /** masks a long string, keeping X number for characters at the start/end and replacing the middle with the mask string (default: CC*****CCC) */ export declare function maskString(str: string, options?: { /** mask string, default ***** */ mask?: string; /** characters to keep at start, default 2 */ start?: number; /** characters to keep at end, default 2 */ end?: number; }): string; export declare function splitString(str: string, options: { maxLength?: number; marker?: string | RegExp; clearEmptyEntries?: boolean; }): string[];