Skip to content

Commit

Permalink
fix: json stringifycation
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ferreiro Val committed Jun 20, 2019
1 parent f9c9713 commit 335e489
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/@best/store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import chalk from 'chalk';
import { BenchmarkResultsSnapshot, FrozenGlobalConfig } from "@best/types";

function formatJSON(json: any) {
return stringify(json, { indent: "2", maxLength: 90 });
return stringify(json, { indent: 2, maxLength: 90 });
}

function getStoredFileMapping(benchmarkFolder: string, artifactsFolder: string) {
Expand Down
10 changes: 5 additions & 5 deletions packages/@best/store/src/pretty-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const stringOrChar = /("(?:[^\\"]|\\.)*")|[:,]/g;
const prettify = (string: string) => string.replace(stringOrChar, (match, str: string) => (str ? match : match + ' '));
const comma = (array: any[], index: number) => (index === array.length - 1 ? 0 : 1);

export function stringify(o:any = {}, { indent = "2", maxLength = 80, inlineArray = true } = {}) {
indent = JSON.stringify([1], null, indent).slice(2, -3);
maxLength = indent === '' ? Infinity : maxLength;
export function stringify(o:any = {}, { indent = 2, maxLength = 80, inlineArray = true } = {}) {
const indentString = JSON.stringify([1], null, indent).slice(2, -3);
maxLength = indentString === '' ? Infinity : maxLength;

return (function _stringify(obj, currentIndent, reserved): string {
if (obj && typeof obj.toJSON === 'function') {
Expand All @@ -34,7 +34,7 @@ export function stringify(o:any = {}, { indent = "2", maxLength = 80, inlineArra
}

if (typeof obj === 'object' && obj !== null) {
const nextIndent = currentIndent + indent;
const nextIndent = currentIndent + indentString;
const items = [];
let delimiters;

Expand All @@ -58,7 +58,7 @@ export function stringify(o:any = {}, { indent = "2", maxLength = 80, inlineArra
}

if (items.length > 0 && delimiters) {
return [delimiters[0], indent + items.join(',\n' + nextIndent), delimiters[1]].join(
return [delimiters[0], indentString + items.join(',\n' + nextIndent), delimiters[1]].join(
'\n' + currentIndent,
);
}
Expand Down

0 comments on commit 335e489

Please sign in to comment.