Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: [10, 12]
steps:
Expand Down
1 change: 1 addition & 0 deletions __tests__/order.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-types */
import order from '../src/order';
import {PropertyMap} from '../src/models';

Expand Down
1 change: 1 addition & 0 deletions __tests__/stringify.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-types */
import stringify from '../src/stringify';
import {PropertyMap} from '../src/models';

Expand Down
33 changes: 15 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "json-order",
"version": "0.0.0-development",
"description": "Control the order of properties in JSON via a lookup object - including nested properties.",
"main": "src/index.js",
"types": "src/index.d.ts",
"main": "index.js",
"types": "index.d.ts",
"files": [
"src"
"dist"
],
"repository": {
"type": "git",
Expand All @@ -20,15 +20,14 @@
"test:cover": "jest --coverage",
"test:watch": "jest --watch",
"test:ci": "jest --ci --coverage",
"compile": "tsc",
"compile": "tsc -p tsconfig.build.json",
"lint": "eslint **/*.{t,j}s",
"lint:fix": "yarn lint --fix",
"semantic-release": "semantic-release"
},
"lint-staged": {
"*.{{t,j}s{,x}}": [
"eslint --fix",
"git add"
"eslint --fix"
]
},
"husky": {
Expand All @@ -50,22 +49,20 @@
"@types/babel__core": "^7.1.10",
"@types/jest": "^26.0.3",
"@types/lodash.clonedeep": "^4.5.6",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"eslint": "^6.8.0",
"@typescript-eslint/eslint-plugin": "^4.4.0",
"@typescript-eslint/parser": "^4.4.0",
"eslint": "^7.10.0",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jest": "^23.1.1",
"eslint-plugin-jest": "^24.1.0",
"eslint-plugin-prettier": "^3.1.2",
"husky": "^4.0.1",
"jest": "^25.1.0",
"jest-junit": "^11.0.1",
"lint-staged": "8.2.1",
"prettier": "^1.19.1",
"ts-jest": "^25.0.0",
"tslint": "^6.0.0",
"typescript": "3.9.7",
"semantic-release": "^17.1.2"
"jest": "^26.5.2",
"lint-staged": "10.4.0",
"prettier": "^2.1.2",
"semantic-release": "^17.1.2",
"ts-jest": "^26.4.1",
"typescript": "4.0.3"
},
"dependencies": {
"lodash.clonedeep": "^4.5.0"
Expand Down
12 changes: 7 additions & 5 deletions src/order.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */

import clonedeep from 'lodash.clonedeep';
import {PropertyMap} from './models';

Expand All @@ -15,7 +17,7 @@ const getProperty = (

const value = key
.split(separator)
.filter(s => s.length > 0)
.filter((s) => s.length > 0)
.reduce((o: object, x: string) => {
exists = o && o.hasOwnProperty(x);

Expand All @@ -37,11 +39,11 @@ const setProperty = (
) => {
key
.split(separator)
.filter(s => s.length > 0)
.filter((s) => s.length > 0)
.reduce((o: object, x: string, idx: number, src: Array<string>): object => {
if (idx === src.length - 1) {
const valueToSet = Array.isArray(value)
? clonedeep(value).map(p => (typeof p === 'object' ? {} : p))
? clonedeep(value).map((p) => (typeof p === 'object' ? {} : p))
: value;
o[x] = valueToSet;
}
Expand Down Expand Up @@ -87,7 +89,7 @@ const order = <T extends object>(
const prefixLength = (mapKeys[0] && mapKeys[0].length) || 0;

const resultObject = {};
mapKeys.forEach(mk => {
mapKeys.forEach((mk) => {
const childKeys = map[mk];

// Remove prefix
Expand All @@ -102,7 +104,7 @@ const order = <T extends object>(
setProperty(resultObject, parentKey, defaultValue, separator);

// Fetch value from source and set on output
childKeys.forEach(key =>
childKeys.forEach((key) =>
copyProperty(
sourceObject,
resultObject,
Expand Down
4 changes: 3 additions & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */

import {OrderedParseResult, PropertyMap} from './models';

const traverseObject = <T extends object>(
Expand All @@ -17,7 +19,7 @@ const traverseObject = <T extends object>(
map[`${parentKey}`] = childKeys;
}

childKeys.forEach(childKey => {
childKeys.forEach((childKey) => {
const value = obj[childKey];

if (typeof value === 'object') {
Expand Down
2 changes: 2 additions & 0 deletions src/stringify.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */

import {PropertyMap} from './models';
import order from './order';

Expand Down
28 changes: 28 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es5",
"sourceMap": false,
"allowJs": false,
"moduleResolution": "node",
"outDir": "dist",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strict": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": true,
"lib": [
"es2015",
],
"declaration": true
},
"exclude": [
"node_modules",
"jest.config.js",
"commitlint.config.js",
]
}
5 changes: 5 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"files": ["src/index.ts"],
"include": ["src"]
}
32 changes: 2 additions & 30 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es5",
"sourceMap": false,
"allowJs": false,
"moduleResolution": "node",
"outDir": "dist",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strict": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": true,
"lib": [
"es2015",
],
"declaration": true
},
"include": [
"src",
"__tests__"
],
"exclude": [
"node_modules",
"jest.config.js",
"commitlint.config.js"
]
"extends": "./tsconfig.base.json",
"include": ["src", "__tests__"]
}
Loading