UNPKG

@vendure/ngx-translate-extract

Version:
20 lines (19 loc) 697 B
export class SortByKeyPostProcessor { name = 'SortByKey'; sortSensitivity = undefined; constructor(sortSensitivity) { if (isOfTypeSortSensitivity(sortSensitivity)) { this.sortSensitivity = sortSensitivity; } else { throw new Error(`Unknown sortSensitivity: ${sortSensitivity}`); } } process(draft) { const compareFn = this.sortSensitivity ? new Intl.Collator('en', { sensitivity: this.sortSensitivity }).compare : undefined; return draft.sort(compareFn); } } function isOfTypeSortSensitivity(keyInput) { return ['base', 'accent', 'case', 'variant'].includes(keyInput) || keyInput === undefined; }