Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Why discard Booleans in parse? #78

@edgracilla

Description

@edgracilla

The following test will fail, since it totally disallow the non-string values (stated in test.js line 520)

it('return boolean as boolean', () => {
  query = mqs.parse({
    foo: true,
    bar: false,
  });
  assert.deepEqual(query, {
    foo: true,
    bar: false,
  });
});

But here is my use case, I'm using fastify and utilized their integrated ajv as my validator. My ajv was configured to do a type coercion, hence, if I pass the following query ?foo=true&bar=false the returned value from validator are boolean values.

{
  foo: true,
  bar: false
}

If I pass this to mqs.parse() it returns an empty object since mqs totally disallow bool values.

Turning off the coercion is not an option for me. And converting it back to string is a dirty hack. I guess it might be good if this will allow by mqs itself.

I can send a PR and test, but I want to know the importance of discarding the boolean values in test.js line 520, if there's any.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions