Skip to content

Commit 5575bd9

Browse files
Fix formatting issues and update dependencies in configuration files
1 parent 0af1f39 commit 5575bd9

File tree

7 files changed

+188
-45
lines changed

7 files changed

+188
-45
lines changed

dist/index.js

Lines changed: 80 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/laradumps.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/LaraDumps.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/LaraDumps.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Json.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { _Json, _LaraDumps } from "../types";
2+
3+
export default {
4+
json(json: any): _LaraDumps {
5+
try {
6+
if(typeof(json) !== "string") {
7+
json = JSON.stringify(json);
8+
}
9+
10+
if(!this.isValidJson(json)) {
11+
this.dump(json);
12+
} else {
13+
this.sendJson(json);
14+
}
15+
} catch (error) {
16+
this.dump(this.inspect(json));
17+
return this;
18+
}
19+
},
20+
21+
inspect(json: any): _LaraDumps {
22+
const inspect = (obj: any): string => {
23+
try {
24+
return typeof obj === 'string' ? obj : JSON.stringify(obj, null, 2);
25+
} catch {
26+
return String(obj);
27+
}
28+
};
29+
30+
return this.convertJSONStringToJSON(inspect(json));
31+
},
32+
33+
convertJSONStringToJSON(object: string): object | string {
34+
let formatted = object
35+
.replace(/([{,]\s*)(\w+)\s*:/g, '$1"$2":')
36+
.replace(/:\s*'([^']*)'/g, ': "$1"')
37+
.replace(/undefined/g, 'null')
38+
.replace(/\[Object\]/g, '{}')
39+
.replace(/(\r\n|\n|\r)/gm, "");
40+
41+
try {
42+
return JSON.parse(formatted);
43+
} catch (error) {
44+
return object;
45+
}
46+
},
47+
48+
isValidJson(json: any): boolean {
49+
try {
50+
JSON.parse(json);
51+
} catch (e) {
52+
return false;
53+
}
54+
55+
return true;
56+
},
57+
58+
sendJson(json: any): _LaraDumps {
59+
json = typeof(json) !== 'string'
60+
? JSON.stringify(json)
61+
: json;
62+
63+
return this.send("json", {
64+
"json": {
65+
"string": json,
66+
"original_content": json
67+
}
68+
});
69+
},
70+
} as _Json;

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ module.exports = {
2020
resolve: {
2121
extensions: ['.tsx', '.ts', '.jsx', '.js']
2222
}
23-
};
23+
};

0 commit comments

Comments
 (0)