@thirteen-13/string-utility
Version:
string utility function
184 lines (183 loc) • 12.2 kB
TypeScript
export declare const isString: (str: unknown) => str is string;
export declare const capitalize: (str: string) => string;
export declare const toCamelCase: (str: string) => string;
export declare const toKebabCase: (str: string) => string;
export declare const toSnakeCase: (str: string) => string;
export declare const reverse: (str: string) => string;
export declare const truncate: (str: string, length: number) => string;
export declare const stripHtml: (str: string) => string;
export declare const escapeHtml: (str: string) => string;
export declare const isUpperCase: (str: string) => boolean;
export declare const isLowerCase: (str: string) => boolean;
export declare const repeat: (str: string, count: number) => string;
export declare const padLeft: (str: string, length: number, char?: string) => string;
export declare const padRight: (str: string, length: number, char?: string) => string;
export declare const contains: (str: string, substr: string) => boolean;
export declare const startsWith: (str: string, prefix: string) => boolean;
export declare const endsWith: (str: string, suffix: string) => boolean;
export declare const removeNonAlpha: (str: string) => string;
export declare const removeNonNumeric: (str: string) => string;
export declare const removeWhitespace: (str: string) => string;
export declare const countOccurrences: (str: string, sub: string) => number;
export declare const slugify: (str: string) => string;
export declare const getInitials: (str: string) => string;
export declare const isStrictPalindrome: (str: string) => boolean;
export declare const isLoosePalindrome: (str: string) => boolean;
export declare const extractNumbers: (str: string) => number[];
export declare const extractWords: (str: string) => string[];
export declare const maskString: (str: string, start: number, end: number, maskChar?: string) => string;
export declare const randomString: (length: number) => string;
export declare const isAlpha: (str: string) => boolean;
export declare const isAlphanumeric: (str: string) => boolean;
export declare const isEmail: (str: string) => boolean;
export declare const extractEmails: (str: string) => string[];
export declare const extractUrls: (str: string) => string[];
export declare const titleCase: (str: string) => string;
export declare const swapCase: (str: string) => string;
export declare const removeDuplicateWords: (str: string) => string;
export declare const safeString: (str: string) => string;
export declare const compressWhitespace: (str: string) => string;
export declare const charFrequency: (str: string) => Record<string, number>;
export declare const levenshteinDistance: (a: string, b: string) => number;
export declare const toPascalCase: (str: string) => string;
export declare const toDotCase: (str: string) => string;
export declare const toSpaceCase: (str: string) => string;
export declare const endsWithAny: (str: string, suffixes: string[]) => boolean;
export declare const startsWithAny: (str: string, prefixes: string[]) => boolean;
export declare const trimChar: (str: string, char: string) => string;
export declare const removeDiacritics: (str: string) => string;
export declare const getUniqueCharacters: (str: string) => string[];
export declare const stringToCharCodeArray: (str: string) => number[];
export declare const charCodeArrayToString: (arr: number[]) => string;
export declare const wrap: (str: string, wrapper: string) => string;
export declare const ensureStartsWith: (str: string, prefix: string) => string;
export declare const ensureEndsWith: (str: string, suffix: string) => string;
export declare const repeatStringUntilLength: (str: string, targetLength: number) => string;
export declare const collapseNewlines: (str: string) => string;
export declare const stringToAsciiSum: (str: string) => number;
export declare const getCharAtSafe: (str: string, index: number) => string;
export declare const isWhitespace: (str: string) => boolean;
export declare const isEmpty: (str: string) => boolean;
export declare const isBlank: (str: string) => boolean;
export declare const getNthWord: (str: string, n: number) => string;
export declare const countVowels: (str: string) => number;
export declare const countConsonants: (str: string) => number;
export declare const stripPunctuation: (str: string) => string;
export declare const extractHashtags: (str: string) => string[];
export declare const extractMentions: (str: string) => string[];
export declare const hasRepeatedCharacters: (str: string) => boolean;
export declare const isHexColor: (str: string) => boolean;
export declare const isRgbColor: (str: string) => boolean;
export declare const getLastNChars: (str: string, n: number) => string;
export declare const getFirstNChars: (str: string, n: number) => string;
export declare const containsAny: (str: string, items: string[]) => boolean;
export declare const replaceAll: (str: string, find: string, replace: string) => string;
export declare const isAllUpperCase: (str: string) => boolean;
export declare const isAllLowerCase: (str: string) => boolean;
export declare const toCharArray: (str: string) => string[];
export declare const reverseWords: (str: string) => string;
export declare const countWords: (str: string) => number;
export declare const repeatWithSeparator: (str: string, count: number, sep: string) => string;
export declare const trimStart: (str: string) => string;
export declare const trimEnd: (str: string) => string;
export declare const obfuscateEmail: (email: string) => string;
export declare const base64Encode: (str: string) => string;
export declare const base64Decode: (str: string) => string;
export declare const camelToSnake: (str: string) => string;
export declare const snakeToCamel: (str: string) => string;
export declare const removeTrailingSlash: (str: string) => string;
export declare const removeLeadingSlash: (str: string) => string;
export declare const splitByLength: (str: string, length: number) => string[];
export declare const truncateWords: (str: string, numWords: number) => string;
export declare const isUUID: (str: string) => boolean;
export declare const generateUUID: () => string;
export declare const removeDuplicateChars: (str: string) => string;
export declare const percentEncode: (str: string) => string;
export declare const percentDecode: (str: string) => string;
export declare const getByteLength: (str: string) => number;
export declare const endsWithPunctuation: (str: string) => boolean;
export declare const stringSimilarity: (a: string, b: string) => number;
export declare const censor: (str: string, words: string[], mask?: string) => string;
export declare const safeJsonParse: <T = unknown>(str: string) => T | null;
export declare const mirrorString: (str: string) => string;
export declare const removeHtmlTags: (str: string) => string;
export declare const unescapeHtml: (str: string) => string;
export declare const countCharacterOccurrences: (str: string, char: string) => number;
export declare const extractInitials: (str: string) => string;
export declare const stripAnsiCodes: (str: string) => string;
export declare const removeAllNumbers: (str: string) => string;
export declare const extractAllNumbers: (str: string) => string[];
export declare const padCenter: (str: string, length: number, padChar?: string) => string;
export declare const hasEmoji: (str: string) => boolean;
export declare const extractEmoji: (str: string) => string[];
export declare const toCurrencyFormat: (numStr: string, currency?: string) => string;
export declare const stripSpaces: (str: string) => string;
export declare const extractDomain: (url: string) => string | null;
export declare const extractTLD: (url: string) => string | null;
export declare const removeAlphanumeric: (str: string) => string;
export declare const getMiddleCharacter: (str: string) => string;
export declare const insertAt: (str: string, index: number, value: string) => string;
export declare const removeAt: (str: string, index: number, count?: number) => string;
export declare const reverseSentences: (str: string) => string;
export declare const capitalizeSentences: (str: string) => string;
export declare const decapitalize: (str: string) => string;
export declare const toUpperFirstChar: (str: string) => string;
export declare const toLowerFirstChar: (str: string) => string;
export declare const removeQuotes: (str: string) => string;
export declare const surroundWithQuotes: (str: string, quoteType?: "\"" | "'") => string;
export declare const formatPhoneNumber: (num: string) => string;
export declare const convertToBinary: (str: string) => string;
export declare const binaryToString: (bin: string) => string;
export declare const convertToHex: (str: string) => string;
export declare const hexToString: (hex: string) => string;
export declare const htmlEntityEncode: (str: string) => string;
export declare const htmlEntityDecode: (str: string) => string;
export declare const countLines: (str: string) => number;
export declare const getFirstLine: (str: string) => string;
export declare const getLastLine: (str: string) => string;
export declare const highlightSubstr: (str: string, substr: string, tagOpen?: string, tagClose?: string) => string;
export declare const replaceAt: (str: string, index: number, char: string) => string;
export declare const stripLeadingZeros: (str: string) => string;
export declare const removeDuplicatesWords: (str: string) => string;
export declare const sortWords: (str: string) => string;
export declare const uniqueWords: (str: string) => string[];
export declare const toTitleCase: (str: string) => string;
export declare const slugToCamelCase: (str: string) => string;
export declare const camelCaseToSlug: (str: string) => string;
export declare const removeSpecialChars: (str: string) => string;
export declare const countPunctuation: (str: string) => number;
export declare const countUppercase: (str: string) => number;
export declare const countLowercase: (str: string) => number;
export declare const shuffleCharacters: (str: string) => string;
export declare const containsUppercase: (str: string) => boolean;
export declare const containsLowercase: (str: string) => boolean;
export declare const rotateString: (str: string, n: number) => string;
export declare const toggleCase: (str: string) => string;
export declare const reverseEachWord: (str: string) => string;
export declare const splitToWords: (str: string) => string[];
export declare const countSentences: (str: string) => number;
export declare const extractSentences: (str: string) => string[];
export declare const generateAcronym: (str: string) => string;
export declare const titleToSlug: (str: string) => string;
export declare const sanitizeFileName: (str: string) => string;
export declare const isIpAddress: (str: string) => boolean;
export declare const isUrl: (str: string) => boolean;
export declare const getFileExtension: (str: string) => string;
export declare const removeFileExtension: (str: string) => string;
export declare const isNumericString: (str: string) => boolean;
export declare const compactWhitespace: (str: string) => string;
export declare const unescapeBackslashes: (str: string) => string;
export declare const stringToUnicode: (str: string) => string;
export declare const unicodeToString: (unicodeStr: string) => string;
export declare const removeVowels: (str: string) => string;
export declare const removeConsonants: (str: string) => string;
export declare const alternateCase: (str: string) => string;
export declare const randomStringBase36: (length: number) => string;
export declare const obfuscatePhoneNumber: (num: string) => string;
export declare const countWordsByLength: (str: string) => Record<number, number>;
export declare const stringToArrayBuffer: (str: string) => ArrayBuffer;
export declare const arrayBufferToString: (buf: ArrayBuffer) => string;
export declare const isStrongPassword: (str: string) => boolean;
export declare const getLongestWord: (str: string) => string;
export declare const getShortestWord: (str: string) => string;
export declare const getAllIndexesOf: (str: string, target: string, overlapping?: boolean) => number[];