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
publicstaticcompareTwoStringLocale(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
letobjCollatorOptions: 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"
};
letobjIntlCollator: Intl.Collator=newIntl.Collator("en",objCollatorOptions);
if (enumSortOrder===SortOrder.Forward){
returnobjIntlCollator.compare(strA,strB);
}
elseif (enumSortOrder===SortOrder.Reverse){
returnobjIntlCollator.compare(strB,strA);
}
}Enumeration: SortOrder
exportenumSortOrder{
Forward="Forward",
Reverse="Reverse"
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
