To use this function add it to the class library file named vCenterServerService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: vCenterServerService.ts
Function VcManagedEntitySortLocale
Description: Orchestrator Function to Sort an Array of VcManagedEntity by any Property Value ignoring case and locale specific characters
public VcManagedEntitySortLocale<T>(arrVcManagedEntity: T[], enumSortOrder: SortOrder, strPropertyName: string = "name"): T[] {
// 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"
};
arrVcManagedEntity = arrVcManagedEntity.sort((objVcManagedEntityA: T, objVcManagedEntityB: T): number => {
let intComparison: number;
if (enumSortOrder === SortOrder.Forward) {
intComparison = new Intl.Collator("en", objCollatorOptions).compare(objVcManagedEntityA[strPropertyName], objVcManagedEntityB[strPropertyName])
}
else if (enumSortOrder === SortOrder.Reverse) {
intComparison = new Intl.Collator("en", objCollatorOptions).compare(objVcManagedEntityB[strPropertyName], objVcManagedEntityA[strPropertyName])
}
return intComparison;
});
return arrVcManagedEntity;
}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.
