Skip to content

Commit

Permalink
docs: add additional example + documentation message
Browse files Browse the repository at this point in the history
  • Loading branch information
scottenock committed Jul 8, 2024
1 parent dab36a6 commit 965d441
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ export type ParseOptions = {
//=> {foo: ['1', '2', '3']}
```
*/
readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'colon-list-separator' | 'none';
readonly arrayFormat?:
| 'bracket'
| 'index'
| 'comma'
| 'separator'
| 'bracket-separator'
| 'colon-list-separator'
| 'none';

/**
The character used to separate array elements when using `{arrayFormat: 'separator'}`.
Expand Down Expand Up @@ -175,7 +182,9 @@ export type ParseOptions = {
Use this feature to override the type for a value. This can be useful when the type is ambiguous such as a phone number (see example 1 and 2).
NOTE: array types (`string[]` and `number[]`) will not work if `arrayFormat` is set to `none`.
It is possible to provide a custom function as the parameter type. The parameter's value will equal the function's return value (see example 4).
NOTE: array types (`string[]` and `number[]`) will have no effect if `arrayFormat` is set to `none` (see example 5).
@default {}
Expand Down Expand Up @@ -233,12 +242,25 @@ export type ParseOptions = {
//=> {age: 40, id: '01234', zipcode: '90210 }
```
@example
Array types will have no effect when `arrayFormat` is set to `none`
```
queryString.parse('ids=001%2C002%2C003&foods=apple%2Corange%2Cmango', {
arrayFormat: 'none',
types: {
ids: 'number[]',
foods: 'string[]',
},
}
//=> {ids:'001,002,003', foods:'apple,orange,mango'}
```
@example
Parse a query utilizing all types:
```
import queryString from 'query-string';
queryString.parse('ids=001%2C002%2C003&items=1%2C2%2C3&price=22%2E00&numbers=1%2C2%2C3&double=5&number=20', {
queryString.parse('?ids=001%2C002%2C003&items=1%2C2%2C3&price=22%2E00&numbers=1%2C2%2C3&double=5&number=20', {
arrayFormat: 'comma',
types: {
ids: 'string',
Expand All @@ -252,7 +274,10 @@ export type ParseOptions = {
//=> {ids: '001,002,003', items: ['1', '2', '3'], price: '22.00', numbers: [1, 2, 3], double: 10, number: 20}
```
*/
readonly types?: Record<string, 'number' | 'string' | 'string[]' | 'number[]' | ((value: string) => unknown)>;
readonly types?: Record<
string,
'number' | 'string' | 'string[]' | 'number[]' | ((value: string) => unknown)
>;
};

// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down

0 comments on commit 965d441

Please sign in to comment.