To use this function add it to the class library file named Utilities.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: Utilities.ts
Function compareTwoStringLocale
Description: Orchestrator Function to Compare Two Strings using International Locale
public static compareTwoStringLocale(strA: string, strB: string, enumSortOrder: SortOrder = SortOrder.Forward): number {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#casefirst
let objCollatorOptions: Intl.CollatorOptions = {
usage: "sort",
localeMatcher: "lookup",
numeric: true,
caseFirst: "false",
sensitivity: "base",
ignorePunctuation: true,
//collation: "big5han" | "compat" | "dict" | "direct" | "ducet" | "emoji" | "eor" | "gb2312" | "phonebk" | "phonetic" | "pinyin" | "reformed" | "searchjl" | "stroke" | "trad" | "unihan" | "zhuyin"
};
let objIntlCollator: Intl.Collator = new Intl.Collator("en", objCollatorOptions);
if (enumSortOrder === SortOrder.Forward) {
return objIntlCollator.compare(strA, strB);
}
else if (enumSortOrder === SortOrder.Reverse) {
return objIntlCollator.compare(strB, strA);
}
}Enumeration: SortOrder
export enum SortOrder {
Forward = "Forward",
Reverse = "Reverse"
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
