]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/core-utils/miscs/miscs.ts
Instance homepage support (#4007)
[github/Chocobozzz/PeerTube.git] / shared / core-utils / miscs / miscs.ts
index 71703faacbd39acb32b5031b0502d5ae279c12b0..4780ca922d9d615843493b89a780092f2976a650 100644 (file)
@@ -28,9 +28,24 @@ function isCatchable (value: any) {
   return value && typeof value.catch === 'function'
 }
 
+function sortObjectComparator (key: string, order: 'asc' | 'desc') {
+  return (a: any, b: any) => {
+    if (a[key] < b[key]) {
+      return order === 'asc' ? -1 : 1
+    }
+
+    if (a[key] > b[key]) {
+      return order === 'asc' ? 1 : -1
+    }
+
+    return 0
+  }
+}
+
 export {
   randomInt,
   compareSemVer,
   isPromise,
-  isCatchable
+  isCatchable,
+  sortObjectComparator
 }