mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add typings for form-serialize (#27403)
* add form-serialize * minor changes to more accurately describe form-serialize defaults
This commit is contained in:
parent
1ba5f19d13
commit
f109e22895
17
types/form-serialize/form-serialize-tests.ts
Normal file
17
types/form-serialize/form-serialize-tests.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import serialize = require("form-serialize");
|
||||
|
||||
const form = document.createElement("form");
|
||||
serialize(form, { hash: true }); // $ExpectType ResultHash
|
||||
serialize(form, true); // $ExpectType ResultHash
|
||||
serialize(form, { hash: false }); // $ExpectType string
|
||||
serialize(form, false); // $ExpectType string
|
||||
serialize(form); // $ExpectType string
|
||||
|
||||
interface CustomResult {
|
||||
foo: string;
|
||||
}
|
||||
|
||||
// $ExpectType CustomResult
|
||||
serialize(form, {
|
||||
serializer: (): CustomResult => ({ foo: "bar" })
|
||||
});
|
||||
37
types/form-serialize/index.d.ts
vendored
Normal file
37
types/form-serialize/index.d.ts
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// Type definitions for form-serialize 0.7
|
||||
// Project: https://github.com/defunctzombie/form-serialize#readme
|
||||
// Definitions by: Tyler Johnson <https://github.com/tyler-johnson>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
interface ResultHash {
|
||||
[key: string]: string | string[] | ResultHash;
|
||||
}
|
||||
|
||||
interface Options<Result> {
|
||||
/** Configure the output type. If true, the output will be a js object. */
|
||||
hash?: boolean;
|
||||
/**
|
||||
* Optional serializer function to override the default one. The function takes 3 arguments (result, key,
|
||||
* value) and should return new result hash and url encoded str serializers are provided with this module
|
||||
*/
|
||||
serializer?: (result: Result, key: string, value: string) => Result;
|
||||
/** If true serialize disabled fields. */
|
||||
disabled?: boolean;
|
||||
/** If true serialize empty fields */
|
||||
empty?: boolean;
|
||||
}
|
||||
|
||||
interface OptionsHash extends Options<ResultHash> {
|
||||
hash: true;
|
||||
}
|
||||
|
||||
interface OptionsString extends Options<string> {
|
||||
hash: false;
|
||||
}
|
||||
|
||||
declare function serialize(form: HTMLFormElement, options: OptionsHash | true): ResultHash;
|
||||
declare function serialize(form: HTMLFormElement, options?: OptionsString | false): string;
|
||||
declare function serialize<Result = string>(form: HTMLFormElement, options?: Options<Result> | boolean): Result;
|
||||
|
||||
export = serialize;
|
||||
24
types/form-serialize/tsconfig.json
Normal file
24
types/form-serialize/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"form-serialize-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/form-serialize/tslint.json
Normal file
3
types/form-serialize/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user