UNPKG

@acrool/js-utils

Version:

Common javascript utils methods for project development

102 lines (101 loc) 2.61 kB
/** * 文本中的每個單詞以大寫字母開頭 * ex: helloWorld -> HelloWorld * * @param str 需要轉換的字串 */ export declare function toCapitalize(str: string): string; /** * 大寫底線轉小駝峰 * ex: Hello_World -> helloWorld * * @param str 需要轉換的字串 */ export declare function upperLineToLowerCase(str: string): string; /** * -轉小駝峰 * ex: Hello_World -> helloWorld * * @param str 需要轉換的字串 * */ export declare function dashToLowerCase(str: string): string; /** * 語言代碼格式轉換 * ex: en-us -> en-US * * @param localeCode 需要轉換的字串lowerLocaleToISOCode */ export declare function lowerLocaleToISOCode(localeCode: string): string; /** * 小駝峰轉小寫底線 * ex: helloWorld -> HELLO_WORLD * * @param str 需要轉換的字串 */ export declare function lowerCaseToLowerDashCase(str: string): string; /** * 小駝峰轉大寫底線 * ex: helloWorld -> HELLO_WORLD * * @param str 需要轉換的字串 */ export declare function lowerCaseToUpLineCase(str: string): string; /** * 字串分割 (發生例外錯誤回傳 空陣列) * * @param str * @param separator */ export declare function stringSplit(str: string, separator: string): string[]; /** * Json Decode * ex: {'name':'jack"} -> { * name: 'jack' * } * * @param jsonString */ export declare function jsonDecode<T = unknown>(jsonString: string): T | undefined; /** * 去頭去尾 * @param str * @param startStr * @param endStr */ export declare function removeStartEnd(str: string, startStr: string, endStr: string): string; /** * 去除undefined value * @param obj */ export declare function removeUndefinedValues(obj: any): { [k: string]: unknown; }; /** * 去除 Html tag * @param htmlStr 要被過濾的字串 * @param whileTag 想保留的 Tag */ export declare function removeHtmlTag(htmlStr: string | number, whileTag?: string[]): string; /** * 過濾只剩下數字 * ex: asd1234 -> 1234 * * @param value * @param defaultValue */ export declare function filterNumber(value: any, defaultValue?: number): number; /** * 解析分離字串和數字(包含浮點數與負數) * expect(decodeStrAndNumber('a-45.22-35.21')).toBe(['a', -45.22, -35.21]); * * @param value */ export declare function decodeStrAndNumber(value: string): Array<string | number>; /** * 解析分離字串和數字(包含浮點數與負數) * expect(decodeStrAndNumber('a-45.22-35.21')).toBe(['a', -45.22, -35.21]); * * @param value */ export declare function decodeStrAndNumberGroup(value: string): Array<string | number>;