forked from flow-typed/flow-typed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add libdefs for qs (flow-typed#1541)
* Add libdefs for qs * Update qs folder name * Update test
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
declare module "qs" { | ||
declare type ParseOptions = { | ||
allowPrototypes?: boolean, | ||
arrayLimit?: number, | ||
decoder?: Function, | ||
delimiter?: string, | ||
depth?: number, | ||
parameterLimit?: number, | ||
plainObjects?: boolean, | ||
strictNullHandling?: boolean, | ||
ignoreQueryPrefix?: boolean, | ||
parseArrays?: boolean, | ||
allowDots?: boolean | ||
}; | ||
|
||
declare type ArrayFormat = "brackets" | "indices" | "repeat"; | ||
|
||
declare type FilterFunction = (prefix: string, value: any) => any; | ||
declare type FilterArray = Array<string | number>; | ||
declare type Filter = FilterArray | FilterFunction; | ||
|
||
declare type StringifyOptions = { | ||
encoder?: Function, | ||
delimiter?: string, | ||
strictNullHandling?: boolean, | ||
skipNulls?: boolean, | ||
encode?: boolean, | ||
sort?: Function, | ||
allowDots?: boolean, | ||
serializeDate?: Function, | ||
encodeValuesOnly?: boolean, | ||
format?: string, | ||
addQueryPrefix?: boolean, | ||
arrayFormat?: ArrayFormat, | ||
filter?: Filter | ||
}; | ||
|
||
declare type Formatter = (any) => string; | ||
|
||
declare type Formats = { | ||
RFC1738: string, | ||
RFC3986: string, | ||
"default": string, | ||
formatters: { | ||
RFC1738: Formatter, | ||
RFC3986: Formatter | ||
} | ||
}; | ||
|
||
declare module.exports: { | ||
parse(str: string, opts?: ParseOptions): Object, | ||
stringify(obj: Object | Array<any>, opts?: StringifyOptions): string, | ||
formats: Formats | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// @flow | ||
|
||
import { parse, stringify, formats } from "qs"; | ||
|
||
function noop() {} | ||
|
||
parse("test"); | ||
|
||
// $ExpectError: should be a string | ||
parse({}); | ||
|
||
parse("test"); | ||
|
||
parse("test", { | ||
allowPrototypes: true, | ||
arrayLimit: 5, | ||
decoder: noop, | ||
delimiter: "/", | ||
depth: 10, | ||
parameterLimit: 15, | ||
plainObjects: true, | ||
strictNullHandling: true, | ||
ignoreQueryPrefix: true, | ||
parseArrays: true, | ||
allowDots: true | ||
}); | ||
|
||
const obj = { test: null }; | ||
|
||
stringify(obj); | ||
|
||
stringify([1, 2, "test"]); | ||
|
||
stringify(obj, { | ||
encoder: noop, | ||
delimiter: "/", | ||
strictNullHandling: true, | ||
skipNulls: true, | ||
encode: true, | ||
sort: noop, | ||
allowDots: true, | ||
serializeDate: noop, | ||
encodeValuesOnly: true, | ||
format: "/", | ||
addQueryPrefix: true | ||
}); | ||
|
||
stringify(obj, { arrayFormat: "brackets" }); | ||
stringify(obj, { arrayFormat: "indices" }); | ||
stringify(obj, { arrayFormat: "repeat" }); | ||
|
||
// $ExpectError: arrayFormat is not an enum value | ||
stringify(obj, { arrayFormat: false }); | ||
// $ExpectError: arrayFormat is not an enum value | ||
stringify(obj, { arrayFormat: "test" }); | ||
|
||
// $ExpectError: should be an object | ||
stringify("test"); |