mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
declare urlencode function ad namespace
This commit is contained in:
Vendored
+32
-26
@@ -3,38 +3,44 @@
|
||||
// Definitions by: My Self <https://github.com/kimcoder>
|
||||
// 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;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": false,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
|
||||
@@ -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'});
|
||||
|
||||
Reference in New Issue
Block a user