Skip to content

Commit 25a1d96

Browse files
committed
New : Typescript support
Added support for typescript by adding declaration file
1 parent 4d5167d commit 25a1d96

File tree

4 files changed

+290
-85
lines changed

4 files changed

+290
-85
lines changed

README.md

Lines changed: 75 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,97 @@
1+
# json-keys-sort
2+
[![Build Status](https://travis-ci.org/DawnImpulse/json-keys-sort.svg?branch=master)](https://travis-ci.org/DawnImpulse/json-keys-sort) ![wait-loop](https://img.shields.io/npm/dt/json-keys-sort.svg)
3+
> Sorting a json object based on keys either ascending or descending & even recursively
4+
5+
### Latest Changes
6+
- `v1.3.0`
7+
- Added support for Typescript
8+
### Example -
9+
> Note : focus on **keys** not values
110
2-
# json-keys-sort
3-
[![Build Status](https://travis-ci.org/DawnImpulse/json-keys-sort.svg?branch=master)](https://travis-ci.org/DawnImpulse/json-keys-sort)
4-
> Sorting a json object based on keys either ascending or descending & even recursively
11+
~~~~
12+
const json = require('json-keys-sort');
13+
var data = {
14+
"zoho": 4,
15+
"drake": 2,
16+
"yogo": {
17+
"jout": "3.2",
18+
"aou": {
19+
"yoyo": "3.1.3",
20+
"aalo": "3.1.1",
21+
"go": "3.1.2"
22+
}
23+
},
24+
"abc": 1
25+
}
26+
27+
json.sort(data,true)
28+
~~~~
29+
30+
Output will be -
31+
~~~~
32+
{
33+
"abc": 1,
34+
"drake": 2,
35+
"yogo": {
36+
"aou": {
37+
"aalo": "3.1.1",
38+
"go": "3.1.2",
39+
"yoyo": "3.1.3"
40+
},
41+
"jout": "3.2"
42+
},
43+
"zoho": 4
44+
}
45+
~~~~
46+
47+
+ function parameters
48+
- data : the json object to sort
49+
- sort :
50+
- true (default) : ascending sort , since it is default you can only call `json.sort(data)`
51+
- false : descending sort
52+
> Note : the function assumes that you always provide a json object
553
6-
7-
### Example -
8-
> Note : focus on **keys** not values
9-
10-
~~~~
11-
const json = require('json-keys-sort');
12-
var data = {
13-
"zoho": 4,
14-
"drake": 2,
15-
"yogo": {
16-
"jout": "3.2",
17-
"aou": {
18-
"yoyo": "3.1.3",
19-
"aalo": "3.1.1",
20-
"go": "3.1.2"
21-
}
22-
},
23-
"abc": 1
24-
}
25-
26-
json.sort(data,true)
27-
~~~~
28-
29-
Output will be -
30-
~~~~
31-
{
32-
"abc": 1,
33-
"drake": 2,
34-
"yogo": {
35-
"aou": {
36-
"aalo": "3.1.1",
37-
"go": "3.1.2",
38-
"yoyo": "3.1.3"
39-
},
40-
"jout": "3.2"
41-
},
42-
"zoho": 4
43-
}
44-
~~~~
45-
46-
+ function parameters
47-
- data : the json object to sort
48-
- sort :
49-
- true (default) : ascending sort , since it is default you can only call `json.sort(data)`
50-
- false : descending sort
51-
> Note : the function assumes that you always provide a json object
52-
53-
+ The function work recursively and sort all the inner json objects too.
54+
+ The function work recursively and sort all the inner json objects too.
5455

5556
### Versions
5657

57-
+ `v1.2.0`
58-
+ Improvement : json array support
59-
+ `v1.1.0`
60-
+ Bug Fixed : descending sort fix
61-
+ Improvement: auto build testing via travis-ci
62-
+ `v1.0.1`
63-
+ Bug Fixed : data null checks & default true fix
64-
+ `v1.0.0`
65-
+ Initial release - containing basic `sort` function only.
58+
+ `v1.3.0`
59+
+ Included support for typescript (added declaration file)
60+
61+
+ `v1.2.0`
62+
+ Improvement : json array support
6663

67-
> Pull requests are always welcomed (kindly sign commits with GPG keys. **THANKS**)
64+
+ `v1.1.0`
65+
+ Bug Fixed : descending sort fix
66+
+ Improvement: auto build testing via travis-ci
6867

69-
68+
+ `v1.0.1`
69+
+ Bug Fixed : data null checks & default true fix
7070

71-
### Contact
71+
+ `v1.0.0`
72+
+ Initial release - containing basic `sort` function only.
7273

74+
> Pull requests are always welcomed (kindly sign commits with GPG keys. **THANKS**)
75+
76+
### Contact
77+
7378
+ Twitter - [@dawnimpulse](https://twitter.com/dawnimpulse)
74-
79+
+ Email - [dawnimpulse@gmail.com](mailto:dawnimpulse@gmail.com)
7580

76-
77-
### License (ISC)
81+
82+
### License (ISC)
7883
~~~~
79-
8084
ISC Licence
8185
82-
83-
84-
Copyright 2018 Saksham (DawnImpulse)
85-
86-
86+
Copyright 2018-2019 Saksham (DawnImpulse)
8787
8888
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
89-
9089
provided that the above copyright notice and this permission notice appear in all copies.
9190
92-
93-
9491
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
95-
9692
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
97-
9893
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
94+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISIN
95+
~~~~
9996

100-
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
101-
102-
OR PERFORMANCE OF THIS SOFTWARE.
103-
104-
~~~~
97+
> Written with [StackEdit](https://stackedit.io/).

index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare function sort(data: JSON, sort: boolean): JSON;
2+
3+
export declare function sort(data: JSON): JSON;

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "json-keys-sort",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Sorting a json object based on keys either ascending or descending & even recursively",
55
"main": "index.js",
6+
"types": "index.d.ts",
67
"scripts": {
78
"test": "mocha index.test.js"
89
},
@@ -15,12 +16,18 @@
1516
"sorting",
1617
"json-sort",
1718
"sort-json",
18-
"key-sort-json"
19+
"key-sort-json",
20+
"json-sort",
21+
"object-sort",
22+
"key-sorting",
23+
"json-sorting",
24+
"json-key-sorting"
1925
],
2026
"author": "DawnImpulse",
2127
"license": "ISC",
2228
"devDependencies": {
2329
"chai": "^4.2.0",
2430
"mocha": "^5.2.0"
25-
}
31+
},
32+
"dependencies": {}
2633
}

0 commit comments

Comments
 (0)