Methods
# async static makeQueryString(params, allowEmptyStringValuesopt) → {Promise.<string>}
Utility method to generate a query string compatible with the NHSTA API, for use in an API URL string.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
params |
object | Object of Type QueryStringParameters. |
||
allowEmptyStringValues |
boolean |
<optional> |
false | Set to
|
A query string of search parameters for use in a final Fetch.get URL.
Promise.<string>
Examples
// <script type="text/javascript" src="https://www.npmjs.com/package/@shaggytools/nhtsa-api-wrapper"></script>
const qs = await NHTSA.makeQueryString({ modelYear: 2010 }).catch(error => error)
console.log(qs) // "?modelYear=2010"
import { makeQueryString } from '@shaggytools/nhtsa-api-wrapper'
const qs = await makeQueryString({ modelYear: 2010 }).catch(error => error)
console.log(qs) // "?modelYear=2010"
const qs = await makeQueryString({
modelYear: 2019
}).catch(error => error)
console.log(qs) // "?modelYear=2019"
const qs = await makeQueryString({
whatever: 'some value',
modelYear: 2006,
page: "2"
}).catch(error => error)
console.log(qs) // "?whatever=some%20value&modelYear=2006&page=2"
const qs = await makeQueryString({}).catch(error => error)
console.log(qs) // ""
const qs = await makeQueryString({
year: 2016,
vehicleType: '',
make: 'Audi'
}, true).catch(error => error)
console.log(qs) // "?year=2016&vehicleType=&make=Audi"
Type Definitions
object
# QueryStringParameters
Object containing Key:Value pairs to build the URL query string with.
- Parameter values may be either strings or numbers.
Properties:
Name | Type | Description |
---|---|---|
propName: |
string | number | undefined | string |
Example
{
modelYear: 2009,
whatever: 'something'
}