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

When space is set identation does not work correctly for nested objects and arrays in stringifyAsync. #32

Open
ErgerSusha opened this issue Aug 31, 2021 · 1 comment

Comments

@ErgerSusha
Copy link

If you set space parameter and call stringifyAsync nested object and arrays are not indented properly. Here is a test suite, that confirms such behavior:

'use strict';

const yj = require('../index');
const tap = require('tap');

const obj = {
  name: 'Jacqueline Poole',
  gender: 'female',
  age: {
    value: 40
  },
  agesArray: [
    10,
    20,
    30
  ]
};

yj.stringifyAsync(obj, null, '  ', (err, str) => {
  if (!err)
    tap.equal(str, '{\n  "name": "Jacqueline Poole",\n  "gender": "female",\n  "age": ' +
      '{\n    "value": 40\n  },\n  "agesArray": [\n    10,\n    20,\n    30\n  ]\n}');
  else
    tap.fail(err);
});

Output:

not ok 1 - should be equal
  ---
  found: |-
    {
      "name": "Jacqueline Poole",
      "gender": "female",
      "age": {
      "value": 40
    },
      "agesArray": [
      10,
      20,
      30
    ]
    }
  wanted: |-
    {
      "name": "Jacqueline Poole",
      "gender": "female",
      "age": {
        "value": 40
      },
      "agesArray": [
        10,
        20,
        30
      ]
    }
@gireeshpunathil
Copy link
Member

thanks @ErgerSusha for reporting this bug. I will look into it; and meanwhile feel free to come up with a PR, if you have ideas on how to fix it!

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

2 participants