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

Support passing a function or predefined config to parseNumbers #387

Closed
joeyfigaro opened this issue Jun 26, 2024 · 1 comment
Closed

Support passing a function or predefined config to parseNumbers #387

joeyfigaro opened this issue Jun 26, 2024 · 1 comment

Comments

@joeyfigaro
Copy link

joeyfigaro commented Jun 26, 2024

I'm basically looking to achieve the opposite of #199 – I want ["123", "00A", "441"] to remain ["123", "00A", "441"]. For our current needs the only properties that would have these arrays are known ahead of time, and arrays don't appear anywhere else...so something like { parseNumbers: "except-arrays" } would work.

Alternatively, parseNumbers could take a function that receives the current value's associated key so we can provide a callback that returns true or false given the name of the property.

If this is something you'd be interested in supporting, I'm happy to take a crack at a PR.

Update: it looks like we could update this area if we ended up supporting callback functions for parseNumbers

@scottenock
Copy link
Contributor

Hey @joeyfigaro , this behaviour is now possible via the types feature we implemented here: #385

For your specific use case you would use the type string[]

test('Using types option: you can ignore parseNumbers for specific arrays', t => {
	t.deepEqual(queryString.parse('id=123&numberArray=123,00A,441&number=23', {
		arrayFormat: 'comma',
		parseNumbers: true,
		types: {
			id: 'number',
			numberArray: 'string[]'
		},
	}), {
		id: 123,
		numberArray: ['123', '00A', '441'],
		number: 23
	});
});

Let me know if I've missed something. Could you please close out this issue, cheers!

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

3 participants