Skip to content

Commit

Permalink
fix(inspect): do not use JSON.stringify for inspecting objects
Browse files Browse the repository at this point in the history
JSON.stringify is not a true representation of an object and hence
it can confuse users
  • Loading branch information
thetutlage committed May 2, 2020
1 parent ddd5541 commit 8fc7e95
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 136 deletions.
8 changes: 8 additions & 0 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@ class User extends Base {
username: 'virk',
email: 'virk@adonisjs.com',
isAdmin: true,
profile: {
avatarUrl: 'foo',
},
lastLoginAt: null,
}

public parent: User
public get username () {
return this.attributes.username
}

public toJSON () {
return {}
}
}

const user = new User()
user.parent = user
console.log(user)

createServer((_req, res) => {
res.writeHead(200, { 'content-type': 'text/html' })
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
]
},
"dependencies": {
"@poppinss/inspect": "^1.0.1",
"edge-error": "^1.0.4",
"edge-lexer": "^3.0.3",
"edge-parser": "^5.0.6",
Expand Down
134 changes: 0 additions & 134 deletions src/Edge/globals/PrettyPrint.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/Edge/globals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/

import truncatise from 'truncatise'
import { PrettyPrint } from './PrettyPrint'
import inspect from '@poppinss/inspect'
import { safeValue } from '../../Context'

export const GLOBALS = {
inspect: (value) => {
return safeValue(new PrettyPrint().print(value))
return safeValue(inspect.string.html(value))
},
truncate: (value: string, length: number = 20, options?: { strict: boolean, suffix: string }) => {
return truncatise(value, {
Expand Down

0 comments on commit 8fc7e95

Please sign in to comment.