Important: This documentation applies to v2 of this package.
For v3 docs see vpic.shaggytech.com

Module

utils/makeQueryString

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 true to add empty parameter values to the returned query string.

  • Given params of { paramName: "" } , setting this to true will use 'paramName=' in the final query string.
  • GetCanadianVehicleSpecifications is the only API Action that requires this functionality.

View Source utils/makeQueryString.ts, line 59

A query string of search parameters for use in a final Fetch.get URL.

Promise.<string>
Examples

When loaded from the browser via html script tags

// <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"

When loaded as a module

import { makeQueryString } from '@shaggytools/nhtsa-api-wrapper'
const qs = await makeQueryString({ modelYear: 2010 }).catch(error => error)
console.log(qs) // "?modelYear=2010"

Single Param:

const qs = await makeQueryString({
  modelYear: 2019
}).catch(error => error)
console.log(qs) // "?modelYear=2019"

Multiple Params:

const qs = await makeQueryString({
  whatever: 'some value',
  modelYear: 2006,
  page: "2"
}).catch(error => error)

console.log(qs) // "?whatever=some%20value&modelYear=2006&page=2"

Empty Params Object:

const qs = await makeQueryString({}).catch(error => error)

console.log(qs) // ""

Using allowEmptyStringValues option:

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

View Source utils/makeQueryString.ts, line 106

Example
{
modelYear: 2009,
whatever: 'something'
}