diff --git a/types/urlencode/index.d.ts b/types/urlencode/index.d.ts new file mode 100644 index 0000000000..a74269e486 --- /dev/null +++ b/types/urlencode/index.d.ts @@ -0,0 +1,51 @@ +// Type definitions for urlencode 1.1 +// Project: https://github.com/node-modules/urlencode +// 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; + +/** + * Encode string + * @param str The string for encoding. + */ +export function encode(str: string, charset?: string): string; + +/** + * Decode string + * @param encodedString The encoded string. + */ +export function decode(encodedString: string, charset?: string): string; + +/** + * Parse querystring + * @param queryString Querystring + * @param charsetParam The charset for parsing + */ +export function parse(queryString: string, charsetParam: charsetParam): string; +export interface charsetParam { + charset: string; +} +/** + * Stringify object + * @param obj Querystring + * @param charsetParam The charset for parsing + */ +export function stringify(obj: any, prefix?: charsetParam, charsetParam?: charsetParam): any; + +export default encode; + +// export namespace subProp { +// /*~ For example, given this definition, someone could write: +// *~ import { subProp } from 'yourModule'; +// *~ subProp.foo(); +// *~ or +// *~ import * as yourMod from 'yourModule'; +// *~ yourMod.subProp.foo(); +// */ +// export function foo(): void; +// } \ No newline at end of file diff --git a/types/urlencode/tsconfig.json b/types/urlencode/tsconfig.json new file mode 100644 index 0000000000..bbcc857ffe --- /dev/null +++ b/types/urlencode/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": 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..5abdb8f9a2 --- /dev/null +++ b/types/urlencode/urlencode-tests.ts @@ -0,0 +1,15 @@ +import urlencode, { decode , parse, stringify } from 'urlencode'; + +urlencode('苏千'); // default is utf8 +urlencode('苏千', 'gbk'); // '%CB%D5%C7%A7' + +// decode gbk +decode('%CB%D5%C7%A7', 'gbk'); // '苏千' + +// parse gbk querystring +parse('nick=%CB%D5%C7%A7', {charset: 'gbk'}); // {nick: '苏千'} + +// stringify obj with gbk encoding +var str = 'x[y][0][v][w]=' + urlencode('雾空', 'gbk'); // x[y][0][v][w]=%CE%ED%BF%D5 +var obj = {'x' : {'y' : [{'v' : {'w' : '雾空'}}]}}; +stringify(obj, {charset: 'gbk'}) \ No newline at end of file