A suite of helper functions to simplify dealing with query strings.
When importing EvoToolkit directly as a compiled .js
file without a build step, you can still use these tools through the global EvoToolkit object.
window.evotoolkit.tools.toolName()
import queryString, { parseQuery } from './../../../node_modules/evotoolkit/src/js/tools/queryString.js';
// Using the methods whilst encapsulated in their parent object
// Converts query string to object
queryString.parse('?prop=value&prop2=value2')
/*
Returns
{
prop: 'value',
prop2: 'value2'
}
*/
// Or you can use independently if using named imports
parseQuery('?prop=value&prop2=value2')
import queryString, { stringifyQuery } from './../../../node_modules/evotoolkit/src/js/tools/queryString.js';
// Using the methods whilst encapsulated in their parent object
// Converts object to query string
queryString.stringify({
prop: 'value',
prop2: 'value2'
})
// Returns prop=value&prop2=value2
// Pass true as the second parameter to append ? to the front of the return string
queryString.stringify({
prop: 'value',
prop2: 'value2'
}, true)
// Returns ?prop=value&prop2=value2
// Or you can use independently if using named imports
stringifyQuery({
prop: 'value',
prop2: 'value2'
})