Skip to content

Commit

Permalink
Add documentation and an order function (#30)
Browse files Browse the repository at this point in the history
* Update and add documentation

* Fix build

* fix up linging and CI CD

* Package
  • Loading branch information
develohpanda authored Dec 21, 2019
1 parent e361e9e commit 39ac11d
Show file tree
Hide file tree
Showing 23 changed files with 3,361 additions and 2,011 deletions.
167 changes: 0 additions & 167 deletions .circleci/config.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
dist
coverage
jest.config.js
48 changes: 48 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.json",
"tsconfigRootDir": "."
},
"env": {
"jest/globals": true
},
"plugins": [
"@typescript-eslint",
"jest",
"prettier"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended",
"plugin:import/typescript",
"plugin:import/errors",
"plugin:import/warnings"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/array-type": [
"warn",
{
"default": "generic"
}
],
"@typescript-eslint/no-explicit-any": "off",
"import/prefer-default-export": "off",
"no-undef": "off",
"no-unused-expressions": [
"warn",
{
"allowShortCircuit": true,
"allowTernary": true
}
],
"no-prototype-builtins": "off"
}
}
7 changes: 0 additions & 7 deletions .npmignore

This file was deleted.

10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"trailingComma": "es5",
"printWidth": 80,
"useTabs": false,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"bracketSpacing": false,
"quoteProps": "consistent"
}
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"pmneo.tsimporter",
"coenraads.bracket-pair-colorizer",
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"editor.rulers": [
80,
120
],
"editor.formatOnSave": false,
"eslint.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# json-order
# 📚 json-order

[![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)
[![npm](https://img.shields.io/npm/v/json-order?logo=npm)](https://www.npmjs.com/package/json-order)
[![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)

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**.

Expand Down Expand Up @@ -31,6 +32,18 @@ const jsonString = orderedJson.stringify(srcObj, map, 2);
- `separator` [optional]: a non-empty `string` that controls what the key separator is in the generated map. Defaults to `~`.
- `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).

### `order`

To duplicate a JS object but containing a particular property order:
```js
const orderedObj = orderedJson.order(srcObj, map, 2);
```

#### Parameters
- `srcObj`: an object with the properties in any order
- `map` [optional]: the property map generated by `parse` above. If the map is unset, the response is a standard `JSON.stringify`.
- `separator` [optional]: a non-empty `string` that controls what the key separator is in the generated map. Defaults to `~`.

## Example

An object with a particular property order:
Expand Down
19 changes: 12 additions & 7 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import orderedJSON from '../src/index';
import order from '../src/order';
import parse from '../src/parse';
import stringify from '../src/stringify';
import orderedJSON from '../src';

describe('package export', () => {
it('parse correctly configured', () => {
expect(orderedJSON.parse).toBe(parse);
});
it('parse correctly configured', () => {
expect(orderedJSON.parse).toBe(parse);
});

it('stringify correctly configured', () => {
expect(orderedJSON.stringify).toBe(stringify);
});
it('stringify correctly configured', () => {
expect(orderedJSON.stringify).toBe(stringify);
});

it('order correctly configured', () => {
expect(orderedJSON.order).toBe(order);
});
});
Loading

0 comments on commit 39ac11d

Please sign in to comment.