Skip to content

Commit 30c1874

Browse files
committed
feat: added sortAsync function
added promise based sorting
1 parent 92daddb commit 30c1874

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ISC License
22

3-
Copyright 2018-2019, Saksham (DawnImpulse)
3+
Copyright 2021, Saksham Khurana (DawnImpulse)
44

55
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
66
provided that the above copyright notice and this permission notice appear in all copies.

index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export declare function sort(data: object, sort: boolean): object;
22

3-
export declare function sort(data: object): object;
3+
export declare function sort(data: object): object;
4+
5+
export declare function sortAsync(data: object,sort: boolean): Promise<object> ;
6+
7+
export declare function sortAsync(data: object): Promise<object>;

index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
ISC License
33
4-
Copyright 2018, Saksham (DawnImpulse)
4+
Copyright 2021, Saksham Khurana (DawnImpulse)
55
66
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
77
provided that the above copyright notice and this permission notice appear in all copies.
@@ -96,5 +96,25 @@ function jsonSort(data, sort) {
9696
throw new Error("must be an object/array")
9797
}
9898

99+
/**
100+
* just like normal sort but returns promise
101+
* @param data - json to be sorted
102+
* @param sort - asc (true) / desc (false)
103+
* @return Promise - promise of sorted json object
104+
*/
105+
async function jsonSortAsync(data, sort){
106+
return new Promise((resolve, reject) => {
107+
try{
108+
const response = jsonSort(data,sort)
109+
resolve(response)
110+
}catch (e) {
111+
reject(e)
112+
}
113+
})
114+
}
115+
99116
// exporting with name as sort
100-
exports.sort = jsonSort;
117+
exports.sort = jsonSort;
118+
119+
// exporting with name as sortAsync
120+
exports.sortAsync = jsonSortAsync;

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ caseless@~0.12.0:
360360
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
361361
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
362362

363-
chai@^4.2.0:
363+
chai@4.2.0:
364364
version "4.2.0"
365365
resolved "https://registry.yarnpkg.com/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5"
366366
integrity sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==
@@ -510,7 +510,7 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
510510
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
511511
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
512512

513-
coveralls@^3.0.9:
513+
coveralls@3.0.9:
514514
version "3.0.9"
515515
resolved "https://registry.yarnpkg.com/coveralls/-/coveralls-3.0.9.tgz#8cfc5a5525f84884e2948a0bf0f1c0e90aac0420"
516516
integrity sha512-nNBg3B1+4iDox5A5zqHKzUTiwl2ey4k2o0NEcVZYvl+GOSJdKBj4AJGKLv6h3SvWch7tABHePAQOSZWM9E2hMg==
@@ -1397,7 +1397,7 @@ mkdirp@0.5.1, mkdirp@^0.5.1:
13971397
dependencies:
13981398
minimist "0.0.8"
13991399

1400-
mocha@^6.2.2:
1400+
mocha@6.2.2:
14011401
version "6.2.2"
14021402
resolved "https://registry.yarnpkg.com/mocha/-/mocha-6.2.2.tgz#5d8987e28940caf8957a7d7664b910dc5b2fea20"
14031403
integrity sha512-FgDS9Re79yU1xz5d+C4rv1G7QagNGHZ+iXF81hO8zY35YZZcLEsJVfFolfsqKFWunATEvNzMK0r/CwWd/szO9A==
@@ -1461,7 +1461,7 @@ node-preload@^0.2.0:
14611461
dependencies:
14621462
process-on-spawn "^1.0.0"
14631463

1464-
nyc@^15.0.0:
1464+
nyc@15.0.0:
14651465
version "15.0.0"
14661466
resolved "https://registry.yarnpkg.com/nyc/-/nyc-15.0.0.tgz#eb32db2c0f29242c2414fe46357f230121cfc162"
14671467
integrity sha512-qcLBlNCKMDVuKb7d1fpxjPR8sHeMVX0CHarXAVzrVWoFrigCkYR8xcrjfXSPi5HXM7EU78L6ywO7w1c5rZNCNg==
@@ -1800,7 +1800,7 @@ restore-cursor@^2.0.0:
18001800
onetime "^2.0.0"
18011801
signal-exit "^3.0.2"
18021802

1803-
rewire@^4.0.1:
1803+
rewire@4.0.1:
18041804
version "4.0.1"
18051805
resolved "https://registry.yarnpkg.com/rewire/-/rewire-4.0.1.tgz#ba1100d400a9da759fe599fc6e0233f0879ed6da"
18061806
integrity sha512-+7RQ/BYwTieHVXetpKhT11UbfF6v1kGhKFrtZN7UDL2PybMsSt/rpLWeEUGF5Ndsl1D5BxiCB14VDJyoX+noYw==

0 commit comments

Comments
 (0)