Orchestrator Function: Sort an Array of vCenter Managed Entity by any Property Value using International Locale

by Simon Sparks · 20 January 2026

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

protectedVcManagedEntitySortLocale<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

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);

arrVcManagedEntity=arrVcManagedEntity.sort((objVcManagedEntityA:T,objVcManagedEntityB:T):number=>{

letintComparison:number;

if (enumSortOrder===SortOrder.Forward){
intComparison=objIntlCollator.compare(objVcManagedEntityA[strPropertyName],objVcManagedEntityB[strPropertyName])
}
elseif (enumSortOrder===SortOrder.Reverse){
intComparison=objIntlCollator.compare(objVcManagedEntityB[strPropertyName],objVcManagedEntityA[strPropertyName])
}

returnintComparison;
});

returnarrVcManagedEntity;
}

Enumeration: SortOrder

exportenumSortOrder{
Forward="Forward",
Reverse="Reverse"
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like