diff --git a/types/ungap__url-search-params/index.d.ts b/types/ungap__url-search-params/index.d.ts new file mode 100644 index 0000000000..e48849d1a8 --- /dev/null +++ b/types/ungap__url-search-params/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for @ungap/url-search-params 0.1 +// Project: https://github.com/ungap/url-search-params +// Definitions by: Nick +// Neha +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/** + * Based on definitions of lib.dom and lib.dom.iteralbe + */ +declare class URLSearchParams { + constructor(init?: string[][] | Record | string | URLSearchParams); + + append(name: string, value: string): void; + delete(name: string): void; + get(name: string): string | null; + getAll(name: string): string[]; + has(name: string): boolean; + set(name: string, value: string): void; + sort(): void; + forEach(callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any): void; + [Symbol.iterator](): IterableIterator<[string, string]>; + + entries(): IterableIterator<[string, string]>; + keys(): IterableIterator; + values(): IterableIterator; +} + +export = URLSearchParams; diff --git a/types/ungap__url-search-params/tsconfig.json b/types/ungap__url-search-params/tsconfig.json new file mode 100644 index 0000000000..8c90ed23cc --- /dev/null +++ b/types/ungap__url-search-params/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es5", + "es6" + ], + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ungap__url-search-params-tests.ts" + ] +} diff --git a/types/ungap__url-search-params/tslint.json b/types/ungap__url-search-params/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/ungap__url-search-params/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/ungap__url-search-params/ungap__url-search-params-tests.ts b/types/ungap__url-search-params/ungap__url-search-params-tests.ts new file mode 100644 index 0000000000..74fee88f71 --- /dev/null +++ b/types/ungap__url-search-params/ungap__url-search-params-tests.ts @@ -0,0 +1,33 @@ +import URLSearchParams = require("url-search-params"); + +new URLSearchParams([["1", "2"]]); +new URLSearchParams({ x: "y" }); +new URLSearchParams(); +new URLSearchParams(new URLSearchParams()); + +const params = new URLSearchParams("a=1&b=2"); + +params.append("b", "3"); +params.delete("a"); +params.delete("c"); +params.get("b"); +params.get("d"); +params.getAll("b"); +params.has("b"); +params.keys(); +params.set("b", "4"); +params.set("c", "5"); +params.toString(); +params.values(); + +params.forEach((value, key, params) => { + const test: [string, string, URLSearchParams] = [value, key, params]; +}); + +for (const [key, value] of params) { + const test: [string, string] = [key, value]; +} + +for (const [key, value] of params.entries()) { + const test: [string, string] = [key, value]; +}