Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various bugs #1

Open
theBowja opened this issue Feb 20, 2024 · 2 comments
Open

Various bugs #1

theBowja opened this issue Feb 20, 2024 · 2 comments

Comments

@theBowja
Copy link

  1. Properties with undefined values should be removed from the output.
  2. Strings with \n newline characters aren't handled properly.
  3. Support tab indent?
const perfectJson = require('perfect-json');
const data = {
  name: 'Dmitriy',
  surname: 'Pushkov',
  asdf: undefined,
  skills: ['Java\nScript', 'Node.js', 'ES6'],
  env: { node: '14.0.0', eslint: true, babel: true, typescript: false }
};

console.log(perfectJson(data, {
  singleLine: ({ key }) => {
    return ['skills', 'env'].includes(key);
  }
}));

Actual (improper json):

{
  "name": "Dmitriy",
  "surname": "Pushkov",
  "asdf": undefined,
  "skills": ["Java
Script", "Node.js", "ES6"],
  "env": { "node": "14.0.0", "eslint": true, "babel": true, "typescript": false }
}

Expected:

{
  "name": "Dmitriy",
  "surname": "Pushkov",
  "skills": ["Java\nScript", "Node.js", "ES6"],
  "env": { "node": "14.0.0", "eslint": true, "babel": true, "typescript": false }
}
@theBowja
Copy link
Author

@theBowja
Copy link
Author

also need to take into account Date and BigInt

    if (item instanceof Date) {
      return JSON.stringify(item);
    }
    if (typeof item === 'bigint') {
      return JSON.stringify(item);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant