Skip to content

Commit 39ac11d

Browse files
authored
Add documentation and an order function (#30)
* Update and add documentation * Fix build * fix up linging and CI CD * Package
1 parent e361e9e commit 39ac11d

23 files changed

+3361
-2011
lines changed

.circleci/config.yml

Lines changed: 0 additions & 167 deletions
This file was deleted.

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
dist
3+
coverage
4+
jest.config.js

.eslintrc.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"ecmaVersion": 2018,
5+
"sourceType": "module",
6+
"project": "./tsconfig.json",
7+
"tsconfigRootDir": "."
8+
},
9+
"env": {
10+
"jest/globals": true
11+
},
12+
"plugins": [
13+
"@typescript-eslint",
14+
"jest",
15+
"prettier"
16+
],
17+
"extends": [
18+
"eslint:recommended",
19+
"plugin:@typescript-eslint/eslint-recommended",
20+
"plugin:@typescript-eslint/recommended",
21+
"prettier/@typescript-eslint",
22+
"plugin:prettier/recommended",
23+
"plugin:import/typescript",
24+
"plugin:import/errors",
25+
"plugin:import/warnings"
26+
],
27+
"rules": {
28+
"@typescript-eslint/explicit-function-return-type": "off",
29+
"@typescript-eslint/no-unused-vars": "off",
30+
"@typescript-eslint/array-type": [
31+
"warn",
32+
{
33+
"default": "generic"
34+
}
35+
],
36+
"@typescript-eslint/no-explicit-any": "off",
37+
"import/prefer-default-export": "off",
38+
"no-undef": "off",
39+
"no-unused-expressions": [
40+
"warn",
41+
{
42+
"allowShortCircuit": true,
43+
"allowTernary": true
44+
}
45+
],
46+
"no-prototype-builtins": "off"
47+
}
48+
}

.npmignore

Lines changed: 0 additions & 7 deletions
This file was deleted.

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"trailingComma": "es5",
3+
"printWidth": 80,
4+
"useTabs": false,
5+
"tabWidth": 2,
6+
"semi": true,
7+
"singleQuote": true,
8+
"bracketSpacing": false,
9+
"quoteProps": "consistent"
10+
}

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"dbaeumer.vscode-eslint",
4+
"pmneo.tsimporter",
5+
"coenraads.bracket-pair-colorizer",
6+
]
7+
}

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"editor.rulers": [
3+
80,
4+
120
5+
],
6+
"editor.formatOnSave": false,
7+
"eslint.enable": true,
8+
"editor.codeActionsOnSave": {
9+
"source.fixAll.eslint": true
10+
}
11+
}

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# json-order
1+
# 📚 json-order
22

3-
[![npm version](https://badge.fury.io/js/json-order.svg)](https://badge.fury.io/js/json-order) [![CircleCI](https://circleci.com/gh/develohpanda/json-order.svg?style=svg)](https://circleci.com/gh/develohpanda/json-order)
3+
[![npm](https://img.shields.io/npm/v/json-order?logo=npm)](https://www.npmjs.com/package/json-order)
4+
[![Azure DevOps builds](https://img.shields.io/azure-devops/build/develohpanda/5974ee25-e62e-483b-b9aa-c3560b2a7be1/1?label=Azure%20Pipelines&logo=Azure%20Pipelines)](https://dev.azure.com/json-order/_build?definitionId=1)
45

56
json-order allows for conversion between JS Objects and a JSON string while keeping property order, controlled via a property map. **All manner of nesting is supported**.
67

@@ -31,6 +32,18 @@ const jsonString = orderedJson.stringify(srcObj, map, 2);
3132
- `separator` [optional]: a non-empty `string` that controls what the key separator is in the generated map. Defaults to `~`.
3233
- `space` [optional]: a `number` used to insert white space into the output JSON string for readability purposes, as per the `JSON.stringify` [documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Parameters).
3334

35+
### `order`
36+
37+
To duplicate a JS object but containing a particular property order:
38+
```js
39+
const orderedObj = orderedJson.order(srcObj, map, 2);
40+
```
41+
42+
#### Parameters
43+
- `srcObj`: an object with the properties in any order
44+
- `map` [optional]: the property map generated by `parse` above. If the map is unset, the response is a standard `JSON.stringify`.
45+
- `separator` [optional]: a non-empty `string` that controls what the key separator is in the generated map. Defaults to `~`.
46+
3447
## Example
3548

3649
An object with a particular property order:

__tests__/index.test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import orderedJSON from '../src/index';
1+
import order from '../src/order';
22
import parse from '../src/parse';
33
import stringify from '../src/stringify';
4+
import orderedJSON from '../src';
45

56
describe('package export', () => {
6-
it('parse correctly configured', () => {
7-
expect(orderedJSON.parse).toBe(parse);
8-
});
7+
it('parse correctly configured', () => {
8+
expect(orderedJSON.parse).toBe(parse);
9+
});
910

10-
it('stringify correctly configured', () => {
11-
expect(orderedJSON.stringify).toBe(stringify);
12-
});
11+
it('stringify correctly configured', () => {
12+
expect(orderedJSON.stringify).toBe(stringify);
13+
});
14+
15+
it('order correctly configured', () => {
16+
expect(orderedJSON.order).toBe(order);
17+
});
1318
});

0 commit comments

Comments
 (0)