Skip to content

Support predefining types #210

@MaxDonchenko

Description

@MaxDonchenko

(related to #201)

Consider 2 examples:

const search1 = '?phoneNumber=%2B380951234567&subtopicId=2&topicId=1';
const result1 = queryString.parse(search, {
  parseBooleans: true,
  parseNumbers: true,
});

const search2 = '?phoneNumber=a%2B380951234567&subtopicId=2&topicId=1';
const result2 = queryString.parse(search, {
  parseBooleans: true,
  parseNumbers: true,
});

console.log('result1', result1);
// {
//   phoneNumber: 380951234567,
//   subtopicId: 2,
//   topicId: 1,
// };
console.log('result2', result2);
// {
//   phoneNumber: 'a+380951234567',
//   subtopicId: 2,
//   topicId: 1,
// };

In the 1st example, "+" sign (%2B escaped) is ignored thus reducing to the number parsing, which is not what it supposed to be.

The main goal is to keep parsing numbers for parameters which values starts on the number and parse as plain string otherwise.

Does it look feasible to make a PR on this or should I not use parseNumbers option in that case?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions