@vendure/ngx-translate-extract
Version:
Extract strings from projects using ngx-translate
20 lines (19 loc) • 697 B
JavaScript
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;
}