diff --git a/types/urlencode/index.d.ts b/types/urlencode/index.d.ts new file mode 100644 index 0000000000..451626cb79 --- /dev/null +++ b/types/urlencode/index.d.ts @@ -0,0 +1,46 @@ +// Type definitions for urlencode 1.1 +// Project: https://github.com/node-modules/urlencode +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface charsetParam { + charset: string; +} + +/** + * Encode string + * @param str The string for encoding. + */ +declare function urlencode(str: string, charset?: string): string; + +declare namespace urlencode { + /** + * Encode string + * @param str The string for encoding. + */ + function encode(str: string, charset?: string): 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; +} + +export = urlencode; diff --git a/types/urlencode/tsconfig.json b/types/urlencode/tsconfig.json new file mode 100644 index 0000000000..062ab3224d --- /dev/null +++ b/types/urlencode/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "urlencode-tests.ts" + ] +} diff --git a/types/urlencode/tslint.json b/types/urlencode/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/urlencode/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/urlencode/urlencode-tests.ts b/types/urlencode/urlencode-tests.ts new file mode 100644 index 0000000000..2008ed3283 --- /dev/null +++ b/types/urlencode/urlencode-tests.ts @@ -0,0 +1,15 @@ +import urlencode from 'urlencode'; + +urlencode('苏千'); // default is utf8 +urlencode('苏千', 'gbk'); // '%CB%D5%C7%A7' + +// decode gbk +urlencode.decode('%CB%D5%C7%A7', 'gbk'); // '苏千' + +// parse gbk querystring +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 : '雾空'}}]}}; +urlencode.stringify(obj, {charset: 'gbk'});