Skip to content

Commit

Permalink
docs: clean up documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaggyTech committed May 1, 2023
1 parent fa5d19d commit 301d71d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 47 deletions.
29 changes: 15 additions & 14 deletions apps/docs/src/typedoc/modules/api_useNHTSA.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,29 @@

**useNHTSA**(): `Object`

This is the main composable function that is used to make requests to the NHTSA API.
`useNHTSA` returns a composable object containing helper functions for working with the VPIC
API. It is used internally by the package and by users to make direct requests to the VPIC API.

`useNHTSA` is a composable function that returns an object containing methods for making HTTP
requests to the NHTSA API. All request methods return a Promise that resolves to an object
containing the response data, see [NhtsaApiResponse](#TODO-LINK-TO-DOCS) type.
It returns an object containing methods for making HTTP requests to the VPIC API. All
request methods return a Promise that resolves to an object containing the full response data.

Pleas see the [`/api` README](https://github.com/shaggytech/nhtsa-api-wrapper/packages/lib/src/api)
for more information on the exported methods and how to use them.
The functions returned by the composable are:

---
- `createCachedUrl` - Builds the URL string and stores it in internal state

The exported methods are:
- `getCachedUrl` - Gets the URL stored in internal state

- `get` - Makes a GET request, uses the internal url variable if no URL is provided
- `setCachedUrl` - Directly sets the URL internal state, does not check if URL is valid

- `post` - Makes a POST request, uses the internal url variable if no URL is provided
- `clearCachedUrl` - Clears the URL stored in internal state

- `createCachedUrl` - Builds the URL string and stores it in internal state
- `createUrl` - Returns a built URL string but does not store it in internal state

- `createUrl` - Builds the URL string but does not store it in internal state
- `createPostBody` - Creates a POST body string from an object of key/value pairs

- `getCachedUrl` - Returns the internal URL string
- `get` - Makes a GET request, uses the internal url variable if no URL is provided

- `post` - Makes a POST request, uses the internal url variable if no URL is provided

#### Returns

Expand All @@ -79,4 +80,4 @@ The exported methods are:

#### Defined in

[api/useNHTSA.ts:49](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/useNHTSA.ts#L49)
[api/useNHTSA.ts:50](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/useNHTSA.ts#L50)
28 changes: 17 additions & 11 deletions apps/docs/src/typedoc/modules/utils_queryString.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,25 @@ Valid URI component types

**createQueryString**<`T`\>(`params?`, `allowEmptyParams?`): `string`

This function is used internally by other package functions. As a consumer of this package, you
should not need to use this function directly in most cases.

Utility function to generate a query string conforming to URI component standards. Takes an an
optional object of search parameters and returns an encoded query string.

The parameter `{ format: 'json' }` is hardcoded and cannot be overridden, this package provides
no support for CSV or XML formats at this time. The default query string will be "?format=json"
even if no `params` are provided by user.
This function will always override `params.format` with `{ format: 'json' }`. This is hardcoded
into the package and cannot be overridden, this package provides no support for CSV or XML
formats at this time. This means the default query string will be `"?format=json"` even if no
`params` are provided by user.

- Ignores parameters that are not strings, numbers, or booleans, and also ignores empty strings
by default.
- If first argument is not an object then it will be ignored.
- If second argument `allowEmptyParams` is set to `true`, the function will include keys with
empty string values, e.g. 'emptyKey='

This function is not exported by the package, but is used internally by other
functions. However, it _is_ exported by the package as part of the composable function
`useQueryString`, and renamed to `createString` for less verbose use.
- If you don't provide an object as the first argument, an error will be thrown. Providing an
empty object will not throw an error.

- If the second argument, `allowEmptyParams`, is set to `true`, the function will include keys
with empty string values in the final query string, e.g. 'emptyKey='.

#### Type parameters

Expand All @@ -101,14 +104,17 @@ functions. However, it _is_ exported by the package as part of the composable fu

#### Defined in

[utils/queryString.ts:94](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/queryString.ts#L94)
[utils/queryString.ts:100](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/queryString.ts#L100)

---

### encodeQueryStringParams

**encodeQueryStringParams**<`T`\>(`params`): [`QueryStringParamsEncoded`](utils_queryString.md#querystringparamsencoded)<`T`\>

This function is used internally by other package functions. As a consumer of this package, you
should not need to use this function directly in most cases.

Utility function to perform URI component encoding on all values in an object, for use in URL
query strings.

Expand Down Expand Up @@ -148,4 +154,4 @@ functions. However, it _is_ exported by the package as part of the composable fu

#### Defined in

[utils/queryString.ts:41](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/queryString.ts#L41)
[utils/queryString.ts:44](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/queryString.ts#L44)
27 changes: 14 additions & 13 deletions packages/lib/src/api/useNHTSA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,29 @@ export type CreateUrlOptions = {
}

/**
*This is the main composable function that is used to make requests to the NHTSA API.
* `useNHTSA` returns a composable object containing helper functions for working with the VPIC
* API. It is used internally by the package and by users to make direct requests to the VPIC API.
*
* `useNHTSA` is a composable function that returns an object containing methods for making HTTP
* requests to the NHTSA API. All request methods return a Promise that resolves to an object
* containing the response data, see [NhtsaApiResponse](#TODO-LINK-TO-DOCS) type.
* It returns an object containing methods for making HTTP requests to the VPIC API. All
* request methods return a Promise that resolves to an object containing the full response data.
*
* Pleas see the [`/api` README](https://github.com/shaggytech/nhtsa-api-wrapper/packages/lib/src/api)
* for more information on the exported methods and how to use them.
* The functions returned by the composable are:
*
* ---
* - `createCachedUrl` - Builds the URL string and stores it in internal state
*
* The exported methods are:
* - `getCachedUrl` - Gets the URL stored in internal state
*
* - `get` - Makes a GET request, uses the internal url variable if no URL is provided
* - `setCachedUrl` - Directly sets the URL internal state, does not check if URL is valid
*
* - `post` - Makes a POST request, uses the internal url variable if no URL is provided
* - `clearCachedUrl` - Clears the URL stored in internal state
*
* - `createCachedUrl` - Builds the URL string and stores it in internal state
* - `createUrl` - Returns a built URL string but does not store it in internal state
*
* - `createUrl` - Builds the URL string but does not store it in internal state
* - `createPostBody` - Creates a POST body string from an object of key/value pairs
*
* - `getCachedUrl` - Returns the internal URL string
* - `get` - Makes a GET request, uses the internal url variable if no URL is provided
*
* - `post` - Makes a POST request, uses the internal url variable if no URL is provided
*
*/
export const useNHTSA = () => {
Expand Down
24 changes: 15 additions & 9 deletions packages/lib/src/utils/queryString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export type QueryStringParams = Record<string, QueryStringTypes>
export type QueryStringParamsEncoded<T> = { [key in keyof T]: string }

/**
* This function is used internally by other package functions. As a consumer of this package, you
* should not need to use this function directly in most cases.
*
* Utility function to perform URI component encoding on all values in an object, for use in URL
* query strings.
*
Expand Down Expand Up @@ -68,22 +71,25 @@ export const encodeQueryStringParams = <T extends QueryStringParams>(
}

/**
* This function is used internally by other package functions. As a consumer of this package, you
* should not need to use this function directly in most cases.
*
* Utility function to generate a query string conforming to URI component standards. Takes an an
* optional object of search parameters and returns an encoded query string.
*
* The parameter `{ format: 'json' }` is hardcoded and cannot be overridden, this package provides
* no support for CSV or XML formats at this time. The default query string will be "?format=json"
* even if no `params` are provided by user.
* This function will always override `params.format` with `{ format: 'json' }`. This is hardcoded
* into the package and cannot be overridden, this package provides no support for CSV or XML
* formats at this time. This means the default query string will be `"?format=json"` even if no
* `params` are provided by user.
*
* - Ignores parameters that are not strings, numbers, or booleans, and also ignores empty strings
* by default.
* - If first argument is not an object then it will be ignored.
* - If second argument `allowEmptyParams` is set to `true`, the function will include keys with
* empty string values, e.g. 'emptyKey='
*
* This function is not exported by the package, but is used internally by other
* functions. However, it _is_ exported by the package as part of the composable function
* `useQueryString`, and renamed to `createString` for less verbose use.
* - If you don't provide an object as the first argument, an error will be thrown. Providing an
* empty object will not throw an error.
*
* - If the second argument, `allowEmptyParams`, is set to `true`, the function will include keys
* with empty string values in the final query string, e.g. 'emptyKey='.
*
* @param {QueryStringParams} params - An object of search parameters to be converted to a query
* string.
Expand Down

0 comments on commit 301d71d

Please sign in to comment.