mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
types for 'urlencode' package (#31715)
* first commit * fixed tsconfig, modify lint error * declare urlencode function ad namespace * [@types/urlencode] modify export export default urlencode -> exrpot = urlencode; * esModuleInterop, allowSyntheticDefaultImports add to tsconfig * exprot default urlencode * modify export =
This commit is contained in:
parent
778c0d9771
commit
6dbe9483fc
46
types/urlencode/index.d.ts
vendored
Normal file
46
types/urlencode/index.d.ts
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
// Type definitions for urlencode 1.1
|
||||
// Project: https://github.com/node-modules/urlencode
|
||||
// Definitions by: My Self <https://github.com/kimcoder>
|
||||
// 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;
|
||||
25
types/urlencode/tsconfig.json
Normal file
25
types/urlencode/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
1
types/urlencode/tslint.json
Normal file
1
types/urlencode/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
15
types/urlencode/urlencode-tests.ts
Normal file
15
types/urlencode/urlencode-tests.ts
Normal file
@ -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'});
|
||||
Loading…
Reference in New Issue
Block a user