aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils/miscs/miscs.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/core-utils/miscs/miscs.ts')
-rw-r--r--shared/core-utils/miscs/miscs.ts17
1 files changed, 16 insertions, 1 deletions
diff --git a/shared/core-utils/miscs/miscs.ts b/shared/core-utils/miscs/miscs.ts
index 71703faac..4780ca922 100644
--- a/shared/core-utils/miscs/miscs.ts
+++ b/shared/core-utils/miscs/miscs.ts
@@ -28,9 +28,24 @@ function isCatchable (value: any) {
28 return value && typeof value.catch === 'function' 28 return value && typeof value.catch === 'function'
29} 29}
30 30
31function sortObjectComparator (key: string, order: 'asc' | 'desc') {
32 return (a: any, b: any) => {
33 if (a[key] < b[key]) {
34 return order === 'asc' ? -1 : 1
35 }
36
37 if (a[key] > b[key]) {
38 return order === 'asc' ? 1 : -1
39 }
40
41 return 0
42 }
43}
44
31export { 45export {
32 randomInt, 46 randomInt,
33 compareSemVer, 47 compareSemVer,
34 isPromise, 48 isPromise,
35 isCatchable 49 isCatchable,
50 sortObjectComparator
36} 51}