1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00

org user apis, sort function utils

This commit is contained in:
Kyle Spearrin
2018-07-06 15:00:55 -04:00
parent e25ad93082
commit 7b23b90054
7 changed files with 87 additions and 37 deletions

View File

@@ -1,3 +1,5 @@
import { I18nService } from '../abstractions/i18n.service';
// tslint:disable-next-line
const nodeURL = typeof window === 'undefined' ? require('url').URL : null;
@@ -149,6 +151,23 @@ export class Utils {
return url != null ? url.host : null;
}
static getSortFunction(i18nService: I18nService, prop: string) {
return (a: any, b: any) => {
if (a[prop] == null && b[prop] != null) {
return -1;
}
if (a[prop] != null && b[prop] == null) {
return 1;
}
if (a[prop] == null && b[prop] == null) {
return 0;
}
return i18nService.collator ? i18nService.collator.compare(a[prop], b[prop]) :
a[prop].localeCompare(b[prop]);
};
}
private static getUrl(uriString: string): URL {
if (uriString == null) {
return null;