From 118018bf3bbe1633b78edbec70f685fbd110ec22 Mon Sep 17 00:00:00 2001 From: kimcoder Date: Thu, 27 Dec 2018 19:32:08 +0900 Subject: [PATCH] declare urlencode function ad namespace --- types/urlencode/index.d.ts | 58 ++++++++++++++++-------------- types/urlencode/tsconfig.json | 2 +- types/urlencode/urlencode-tests.ts | 8 ++--- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/types/urlencode/index.d.ts b/types/urlencode/index.d.ts index 0b70cc34be..88281a4120 100644 --- a/types/urlencode/index.d.ts +++ b/types/urlencode/index.d.ts @@ -3,38 +3,44 @@ // Definitions by: My Self // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/*~ If this module is a UMD module that exposes a global variable 'myLib' when - *~ loaded outside a module loader environment, declare that global here. - *~ Otherwise, delete this declaration. - */ -export as namespace urlencode; +interface charsetParam { + charset: string; +} /** * Encode string * @param str The string for encoding. */ -export function encode(str: string, charset?: string): string; +declare function urlencode(str: string, charset?: string): string; -/** - * Decode string - * @param encodedString The encoded string. - */ -export function decode(encodedString: string, charset?: string): string; +declare namespace urlencode { + /** + * Encode string + * @param str The string for encoding. + */ + function encode(str: string, charset?: string): string; -/** - * Parse querystring - * @param queryString Querystring - * @param charsetParam The charset for parsing - */ -export function parse(queryString: string, charsetParam: charsetParam): any; -export interface charsetParam { - charset: string; + /** + * Decode string + * @param encodedString The encoded string. + */ + function decode(encodedString: string, charset?: string): string; + + /** + * Parse querystring + * @param queryString Querystring + * @param charsetParam The charset for parsing + */ + function parse(queryString: string, charsetParam: charsetParam): any; + interface charsetParam { + charset: string; + } + /** + * Stringify object + * @param obj Query Object + * @param charsetParam The charset for parsing + */ + function stringify(obj: any, prefix?: charsetParam, charsetParam?: charsetParam): string; } -/** - * Stringify object - * @param obj Query Object - * @param charsetParam The charset for parsing - */ -export function stringify(obj: any, prefix?: charsetParam, charsetParam?: charsetParam): string; -export default encode; +export default urlencode; diff --git a/types/urlencode/tsconfig.json b/types/urlencode/tsconfig.json index 197f1167a4..8808d5debf 100644 --- a/types/urlencode/tsconfig.json +++ b/types/urlencode/tsconfig.json @@ -7,7 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, - "strictFunctionTypes": false, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" diff --git a/types/urlencode/urlencode-tests.ts b/types/urlencode/urlencode-tests.ts index 5ee486a92b..2008ed3283 100644 --- a/types/urlencode/urlencode-tests.ts +++ b/types/urlencode/urlencode-tests.ts @@ -1,15 +1,15 @@ -import urlencode, { decode , parse, stringify } from 'urlencode'; +import urlencode from 'urlencode'; urlencode('苏千'); // default is utf8 urlencode('苏千', 'gbk'); // '%CB%D5%C7%A7' // decode gbk -decode('%CB%D5%C7%A7', 'gbk'); // '苏千' +urlencode.decode('%CB%D5%C7%A7', 'gbk'); // '苏千' // parse gbk querystring -parse('nick=%CB%D5%C7%A7', {charset: 'gbk'}); // {nick: '苏千'} +urlencode.parse('nick=%CB%D5%C7%A7', {charset: 'gbk'}); // {nick: '苏千'} // stringify obj with gbk encoding const str = 'x[y][0][v][w]=' + urlencode('雾空', 'gbk'); // x[y][0][v][w]=%CE%ED%BF%D5 const obj = {x: {y : [{v : {w : '雾空'}}]}}; -stringify(obj, {charset: 'gbk'}); +urlencode.stringify(obj, {charset: 'gbk'});