question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support predefining types

See original GitHub issue

(related to https://github.com/sindresorhus/query-string/issues/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?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
sindresorhuscommented, Feb 14, 2020

I would prefer something like this:

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

The type could also be a function to let the user handle the converting it from a string to a custom type. Don’t forget that it also needs to be able to handle arrays.

0reactions
sindresorhuscommented, Jun 3, 2020

If anyone wants to work on this, see the feedback given in https://github.com/sindresorhus/query-string/pull/249.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amazon EC2 Instance Types - Amazon Web Services
Amazon EC2 provides a wide selection of instance types optimized to fit different use cases. Instance types comprise varying combinations of CPU, memory, ......
Read more >
General-purpose machine family | Compute Engine ...
Support up to 96 vCPUs and 624 GB of memory. Available as both predefined machine types and custom machine types. Custom machine types...
Read more >
Creating multiple ticket forms to support different request types
A ticket form is a set of predefined ticket fields for a specific support request. The ticket form determines the fields and data...
Read more >
Printer Types with Predefined OCR Support - SAP Help Portal
SAP delivers definitions for many types of printers with the SAP System, some of which include support for OCR printing; that is the...
Read more >
Integral numeric types - C# reference - Microsoft Learn
Characteristics of the integral types. C# supports the following predefined integral types: C# type/keyword, Range, Size .NET type ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found