@api-client/core 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/browser.d.ts +3 -0
- package/build/browser.js +6 -0
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +3 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -1
- package/build/src/lib/calculators/DataCalculator.d.ts +27 -0
- package/build/src/lib/calculators/DataCalculator.js +88 -0
- package/build/src/lib/calculators/DataCalculator.js.map +1 -0
- package/build/src/lib/parsers/UrlEncoder.d.ts +51 -0
- package/build/src/lib/parsers/UrlEncoder.js +74 -0
- package/build/src/lib/parsers/UrlEncoder.js.map +1 -0
- package/build/src/lib/parsers/UrlParser.d.ts +104 -0
- package/build/src/lib/parsers/UrlParser.js +189 -0
- package/build/src/lib/parsers/UrlParser.js.map +1 -0
- package/build/src/lib/parsers/UrlValueParser.d.ts +92 -0
- package/build/src/lib/parsers/UrlValueParser.js +172 -0
- package/build/src/lib/parsers/UrlValueParser.js.map +1 -0
- package/build/src/testing/TestCliHelper.d.ts +7 -1
- package/build/src/testing/TestCliHelper.js +10 -1
- package/build/src/testing/TestCliHelper.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/calculators/DataCalculator.ts +91 -0
- package/src/lib/parsers/UrlEncoder.ts +74 -0
- package/src/lib/parsers/UrlParser.ts +201 -0
- package/src/lib/parsers/UrlValueParser.ts +211 -0
- package/src/testing/TestCliHelper.ts +12 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UrlParser.js","sourceRoot":"","sources":["../../../../src/lib/parsers/UrlParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA0B,MAAM,qBAAqB,CAAC;AAE7E;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,cAAc;IAC3C;;OAEG;IACH,YAAY,KAAa,EAAE,IAA6B;QACtD,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAA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GAAG,EAAE,CAAC;QAChB,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC;YACxB,MAAM,IAAI,IAAI,CAAC;SAChB;QACD,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC;SACrB;QACD,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBACnE,MAAM;aACP;iBAAM;gBACL,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;oBACxB,MAAM,IAAI,GAAG,CAAC;iBACf;gBACD,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC;aACrB;SACF;aAAM,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE;YACnC,MAAM,IAAI,GAAG,CAAC;SACf;QACH,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,MAAM,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC;YAC5B,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;YACtB,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;SAC7B;QACD,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;SAC7B;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export interface IUrlValueParserOptions {
|
|
2
|
+
/**
|
|
3
|
+
* A query string delimiter to use when processing query parameters.
|
|
4
|
+
*/
|
|
5
|
+
queryDelimiter?: string;
|
|
6
|
+
}
|
|
7
|
+
interface DataValues {
|
|
8
|
+
/**
|
|
9
|
+
* A protocol value in format `protocol` + ':'
|
|
10
|
+
*/
|
|
11
|
+
protocol?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The authority part of the URL value
|
|
14
|
+
*/
|
|
15
|
+
host?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Path part of the URL.
|
|
18
|
+
*/
|
|
19
|
+
path?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Anchor part of the URL.
|
|
22
|
+
*/
|
|
23
|
+
anchor?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Search part of the URL.
|
|
26
|
+
*/
|
|
27
|
+
search?: string;
|
|
28
|
+
opts?: IUrlValueParserOptions | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Implements logic for parsing URL string.
|
|
32
|
+
*/
|
|
33
|
+
export declare class UrlValueParser {
|
|
34
|
+
protected __data: DataValues;
|
|
35
|
+
constructor(opts?: IUrlValueParserOptions);
|
|
36
|
+
/**
|
|
37
|
+
* @returns Class options.
|
|
38
|
+
*/
|
|
39
|
+
get opts(): IUrlValueParserOptions;
|
|
40
|
+
/**
|
|
41
|
+
* Sets parser options.
|
|
42
|
+
* Unknown options are ignored.
|
|
43
|
+
*/
|
|
44
|
+
set opts(opts: IUrlValueParserOptions | undefined);
|
|
45
|
+
/**
|
|
46
|
+
* Returns protocol value in format `protocol` + ':'
|
|
47
|
+
*
|
|
48
|
+
* @param value URL to parse.
|
|
49
|
+
* @return Value of the protocol or undefined if value not set
|
|
50
|
+
*/
|
|
51
|
+
protected _parseProtocol(value: string): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Gets a host value from the url.
|
|
54
|
+
* It reads the whole authority value of given `value`. It doesn't parses it
|
|
55
|
+
* to host, port and
|
|
56
|
+
* credentials parts. For URL panel it's enough.
|
|
57
|
+
*
|
|
58
|
+
* @param value The URL to parse
|
|
59
|
+
* @return Value of the host or undefined.
|
|
60
|
+
*/
|
|
61
|
+
protected _parseHost(value: string): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Parses the path part of the URL.
|
|
64
|
+
*
|
|
65
|
+
* @param value URL value
|
|
66
|
+
* @returns Path part of the URL
|
|
67
|
+
*/
|
|
68
|
+
protected _parsePath(value: string): string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Returns query parameters string (without the '?' sign) as a whole.
|
|
71
|
+
*
|
|
72
|
+
* @param value The URL to parse
|
|
73
|
+
* @returns Value of the search string or undefined.
|
|
74
|
+
*/
|
|
75
|
+
protected _parseSearch(value: string): string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Reads a value of the anchor (or hash) parameter without the `#` sign.
|
|
78
|
+
*
|
|
79
|
+
* @param value The URL to parse
|
|
80
|
+
* @returns Value of the anchor (hash) or undefined.
|
|
81
|
+
*/
|
|
82
|
+
protected _parseAnchor(value: string): string | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Returns an array of items where each item is an array where first
|
|
85
|
+
* item is param name and second is it's value. Both always strings.
|
|
86
|
+
*
|
|
87
|
+
* @param search Parsed search parameter
|
|
88
|
+
* @returns Always returns an array.
|
|
89
|
+
*/
|
|
90
|
+
protected _parseSearchParams(search?: string): string[][];
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implements logic for parsing URL string.
|
|
3
|
+
*/
|
|
4
|
+
export class UrlValueParser {
|
|
5
|
+
__data;
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
this.__data = {};
|
|
8
|
+
this.opts = opts;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @returns Class options.
|
|
12
|
+
*/
|
|
13
|
+
get opts() {
|
|
14
|
+
return this.__data.opts || {
|
|
15
|
+
queryDelimiter: '&',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sets parser options.
|
|
20
|
+
* Unknown options are ignored.
|
|
21
|
+
*/
|
|
22
|
+
set opts(opts) {
|
|
23
|
+
const options = (opts || {});
|
|
24
|
+
this.__data.opts = {
|
|
25
|
+
queryDelimiter: options.queryDelimiter || '&'
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns protocol value in format `protocol` + ':'
|
|
30
|
+
*
|
|
31
|
+
* @param value URL to parse.
|
|
32
|
+
* @return Value of the protocol or undefined if value not set
|
|
33
|
+
*/
|
|
34
|
+
_parseProtocol(value) {
|
|
35
|
+
if (!value) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const delimiterIndex = value.indexOf('://');
|
|
39
|
+
if (delimiterIndex !== -1) {
|
|
40
|
+
return value.substring(0, delimiterIndex + 1);
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gets a host value from the url.
|
|
46
|
+
* It reads the whole authority value of given `value`. It doesn't parses it
|
|
47
|
+
* to host, port and
|
|
48
|
+
* credentials parts. For URL panel it's enough.
|
|
49
|
+
*
|
|
50
|
+
* @param value The URL to parse
|
|
51
|
+
* @return Value of the host or undefined.
|
|
52
|
+
*/
|
|
53
|
+
_parseHost(value) {
|
|
54
|
+
if (!value) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
let result = value;
|
|
58
|
+
const delimiterIndex = result.indexOf('://');
|
|
59
|
+
if (delimiterIndex !== -1) {
|
|
60
|
+
result = result.substring(delimiterIndex + 3);
|
|
61
|
+
}
|
|
62
|
+
if (!result) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
// We don't need specifics here (username, password, port)
|
|
66
|
+
const host = result.split('/')[0];
|
|
67
|
+
return host;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parses the path part of the URL.
|
|
71
|
+
*
|
|
72
|
+
* @param value URL value
|
|
73
|
+
* @returns Path part of the URL
|
|
74
|
+
*/
|
|
75
|
+
_parsePath(value) {
|
|
76
|
+
if (!value) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
let result = value;
|
|
80
|
+
const isBasePath = result[0] === '/';
|
|
81
|
+
if (!isBasePath) {
|
|
82
|
+
const index = result.indexOf('://');
|
|
83
|
+
if (index !== -1) {
|
|
84
|
+
result = result.substring(index + 3);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
let index = result.indexOf('?');
|
|
88
|
+
if (index !== -1) {
|
|
89
|
+
result = result.substring(0, index);
|
|
90
|
+
}
|
|
91
|
+
index = result.indexOf('#');
|
|
92
|
+
if (index !== -1) {
|
|
93
|
+
result = result.substring(0, index);
|
|
94
|
+
}
|
|
95
|
+
const lastIsSlash = result[result.length - 1] === '/';
|
|
96
|
+
const parts = result.split('/').filter((part) => !!part);
|
|
97
|
+
if (!isBasePath) {
|
|
98
|
+
parts.shift();
|
|
99
|
+
}
|
|
100
|
+
let path = `/${parts.join('/')}`;
|
|
101
|
+
if (lastIsSlash && parts.length > 1) {
|
|
102
|
+
path += '/';
|
|
103
|
+
}
|
|
104
|
+
return path;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns query parameters string (without the '?' sign) as a whole.
|
|
108
|
+
*
|
|
109
|
+
* @param value The URL to parse
|
|
110
|
+
* @returns Value of the search string or undefined.
|
|
111
|
+
*/
|
|
112
|
+
_parseSearch(value) {
|
|
113
|
+
if (!value) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
let index = value.indexOf('?');
|
|
117
|
+
if (index === -1) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
const result = value.substring(index + 1);
|
|
121
|
+
index = result.indexOf('#');
|
|
122
|
+
if (index === -1) {
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
return result.substring(0, index);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Reads a value of the anchor (or hash) parameter without the `#` sign.
|
|
129
|
+
*
|
|
130
|
+
* @param value The URL to parse
|
|
131
|
+
* @returns Value of the anchor (hash) or undefined.
|
|
132
|
+
*/
|
|
133
|
+
_parseAnchor(value) {
|
|
134
|
+
if (!value) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const index = value.indexOf('#');
|
|
138
|
+
if (index === -1) {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
return value.substring(index + 1);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns an array of items where each item is an array where first
|
|
145
|
+
* item is param name and second is it's value. Both always strings.
|
|
146
|
+
*
|
|
147
|
+
* @param search Parsed search parameter
|
|
148
|
+
* @returns Always returns an array.
|
|
149
|
+
*/
|
|
150
|
+
_parseSearchParams(search) {
|
|
151
|
+
const result = [];
|
|
152
|
+
if (!search) {
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
const parts = search.split(this.opts.queryDelimiter);
|
|
156
|
+
parts.forEach((item) => {
|
|
157
|
+
const _part = ['', ''];
|
|
158
|
+
const _params = item.split('=');
|
|
159
|
+
let _name = _params.shift();
|
|
160
|
+
if (!_name && _name !== '') {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
_name = _name.trim();
|
|
164
|
+
const _value = _params.join('=').trim();
|
|
165
|
+
_part[0] = _name;
|
|
166
|
+
_part[1] = _value;
|
|
167
|
+
result.push(_part);
|
|
168
|
+
});
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=UrlValueParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UrlValueParser.js","sourceRoot":"","sources":["../../../../src/lib/parsers/UrlValueParser.ts"],"names":[],"mappings":"AA+BA;;GAEG;AACH,MAAM,OAAO,cAAc;IACf,MAAM,CAAa;IAE7B,YAAY,IAA6B;QACvC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,I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K,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;YAC5B,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,EAAE,EAAE;gBAC1B,OAAO;aACR;YACD,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;YACrB,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YACxC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;YACjB,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;YAClB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -3,6 +3,11 @@ export interface ITestRunCommandOptions {
|
|
|
3
3
|
noCleaning?: boolean;
|
|
4
4
|
}
|
|
5
5
|
export declare class TestCliHelper {
|
|
6
|
+
/**
|
|
7
|
+
* The globally set test timeout.
|
|
8
|
+
* @default 2000 The mocha default test timeout.
|
|
9
|
+
*/
|
|
10
|
+
static testTimeout: number;
|
|
6
11
|
static cleanTerminalOutput(s: string): string;
|
|
7
12
|
static splitLines(table: string): string[];
|
|
8
13
|
/**
|
|
@@ -17,7 +22,8 @@ export declare class TestCliHelper {
|
|
|
17
22
|
* ```
|
|
18
23
|
*
|
|
19
24
|
* @param fn The function to execute.
|
|
25
|
+
* @param timeout The test timeout. After this time the output is reset.
|
|
20
26
|
* @returns The terminal output.
|
|
21
27
|
*/
|
|
22
|
-
static grabOutput(fn: () => Promise<void
|
|
28
|
+
static grabOutput(fn: () => Promise<void>, timeout?: number): Promise<string>;
|
|
23
29
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export class TestCliHelper {
|
|
2
|
+
/**
|
|
3
|
+
* The globally set test timeout.
|
|
4
|
+
* @default 2000 The mocha default test timeout.
|
|
5
|
+
*/
|
|
6
|
+
static testTimeout = 2000;
|
|
2
7
|
static cleanTerminalOutput(s) {
|
|
3
8
|
let result = s.trim();
|
|
4
9
|
result = result.replace(/[^\x20-\x7E\n]/gm, '');
|
|
@@ -30,9 +35,10 @@ export class TestCliHelper {
|
|
|
30
35
|
* ```
|
|
31
36
|
*
|
|
32
37
|
* @param fn The function to execute.
|
|
38
|
+
* @param timeout The test timeout. After this time the output is reset.
|
|
33
39
|
* @returns The terminal output.
|
|
34
40
|
*/
|
|
35
|
-
static async grabOutput(fn) {
|
|
41
|
+
static async grabOutput(fn, timeout = TestCliHelper.testTimeout) {
|
|
36
42
|
const messages = [];
|
|
37
43
|
function noop() {
|
|
38
44
|
//
|
|
@@ -57,12 +63,15 @@ export class TestCliHelper {
|
|
|
57
63
|
process.stdout.write = messageHandler;
|
|
58
64
|
process.stderr.write = messageHandler;
|
|
59
65
|
console.clear = noop;
|
|
66
|
+
const handle = setTimeout(() => stop(), timeout);
|
|
60
67
|
try {
|
|
61
68
|
await fn();
|
|
62
69
|
stop();
|
|
70
|
+
clearTimeout(handle);
|
|
63
71
|
}
|
|
64
72
|
catch (e) {
|
|
65
73
|
stop();
|
|
74
|
+
clearTimeout(handle);
|
|
66
75
|
throw e;
|
|
67
76
|
}
|
|
68
77
|
return messages.join('');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestCliHelper.js","sourceRoot":"","sources":["../../../src/testing/TestCliHelper.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,aAAa;IACxB,MAAM,CAAC,mBAAmB,CAAC,CAAS;QAClC,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACtB,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;QAChD,2CAA2C;QAC3C,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;QAC/C,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,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,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QAEjD,IAAI;YACF,MAAM,EAAE,EAAE,CAAC;YACX,IAAI,EAAE,CAAC;YACP,YAAY,CAAC,MAAM,CAAC,CAAC;SACtB;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,EAAE,CAAC;YACP,YAAY,CAAC,MAAM,CAAC,CAAC;YACrB,MAAM,CAAC,CAAC;SACT;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computations related to the data like size.
|
|
3
|
+
*/
|
|
4
|
+
export class DataCalculator {
|
|
5
|
+
/**
|
|
6
|
+
* Computes size in the nearest units
|
|
7
|
+
*/
|
|
8
|
+
static bytesToSize(bytes: number, decimals = 2): string {
|
|
9
|
+
if (bytes === 0) {
|
|
10
|
+
return '0 Bytes';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const k = 1024;
|
|
14
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
15
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
16
|
+
|
|
17
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
18
|
+
const result = parseFloat((bytes / k**i).toFixed(dm));
|
|
19
|
+
return `${result} ${sizes[i]}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Calculates size of the string
|
|
24
|
+
* @param str A string to compute size from.
|
|
25
|
+
* @returns The size of the string.
|
|
26
|
+
*/
|
|
27
|
+
stringSize(str: string): number {
|
|
28
|
+
if (!str || !str.length || typeof str !== 'string') {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
let s = str.length;
|
|
32
|
+
for (let i = str.length - 1; i >= 0; i--) {
|
|
33
|
+
const code = str.charCodeAt(i);
|
|
34
|
+
if (code > 0x7f && code <= 0x7ff) {
|
|
35
|
+
s++;
|
|
36
|
+
} else if (code > 0x7ff && code <= 0xffff) {
|
|
37
|
+
/* istanbul ignore next */
|
|
38
|
+
s += 2;
|
|
39
|
+
}
|
|
40
|
+
/* istanbul ignore if */
|
|
41
|
+
if (code >= 0xDC00 && code <= 0xDFFF) {
|
|
42
|
+
i--; // trail surrogate
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return s;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param data The size of the form data
|
|
50
|
+
* @returns The size of the form data
|
|
51
|
+
*/
|
|
52
|
+
async formDataSize(data: FormData): Promise<number> {
|
|
53
|
+
if (typeof Request === 'undefined') {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
const request = new Request('/', {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
body: data,
|
|
59
|
+
});
|
|
60
|
+
if (!request.arrayBuffer) {
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
const buffer = await request.arrayBuffer();
|
|
64
|
+
return buffer.byteLength;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Computes size of the payload.
|
|
69
|
+
*
|
|
70
|
+
* @param payload The payload to compute te size for
|
|
71
|
+
* @returns The size of the payload
|
|
72
|
+
*/
|
|
73
|
+
async payloadSize(payload: unknown): Promise<number> {
|
|
74
|
+
if (!payload) {
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
if (payload instanceof ArrayBuffer) {
|
|
78
|
+
return payload.byteLength;
|
|
79
|
+
}
|
|
80
|
+
if (typeof Buffer !== 'undefined' && payload instanceof Buffer) {
|
|
81
|
+
return payload.byteLength;
|
|
82
|
+
}
|
|
83
|
+
if (payload instanceof Blob) {
|
|
84
|
+
return payload.size;
|
|
85
|
+
}
|
|
86
|
+
if (payload instanceof FormData) {
|
|
87
|
+
return this.formDataSize(payload);
|
|
88
|
+
}
|
|
89
|
+
return this.stringSize(String(payload));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export class UrlEncoder {
|
|
2
|
+
/**
|
|
3
|
+
* Returns a string where all characters that are not valid for a URL
|
|
4
|
+
* component have been escaped. The escaping of a character is done by
|
|
5
|
+
* converting it into its UTF-8 encoding and then encoding each of the
|
|
6
|
+
* resulting bytes as a %xx hexadecimal escape sequence.
|
|
7
|
+
* <p>
|
|
8
|
+
* Note: this method will convert any the space character into its escape
|
|
9
|
+
* short form, '+' rather than %20. It should therefore only be used for
|
|
10
|
+
* query-string parts.
|
|
11
|
+
*
|
|
12
|
+
* <p>
|
|
13
|
+
* The following character sets are <em>not</em> escaped by this method:
|
|
14
|
+
* <ul>
|
|
15
|
+
* <li>ASCII digits or letters</li>
|
|
16
|
+
* <li>ASCII punctuation characters:
|
|
17
|
+
*
|
|
18
|
+
* <pre>- _ . ! ~ * ' ( )</pre>
|
|
19
|
+
* </li>
|
|
20
|
+
* </ul>
|
|
21
|
+
* </p>
|
|
22
|
+
*
|
|
23
|
+
* <p>
|
|
24
|
+
* Notice that this method <em>does</em> encode the URL component delimiter
|
|
25
|
+
* characters:<blockquote>
|
|
26
|
+
*
|
|
27
|
+
* <pre>
|
|
28
|
+
* ; / ? : & = + $ , #
|
|
29
|
+
* </pre>
|
|
30
|
+
*
|
|
31
|
+
* </blockquote>
|
|
32
|
+
* </p>
|
|
33
|
+
*
|
|
34
|
+
* @param str A string containing invalid URL characters
|
|
35
|
+
* @param replacePlus When set it replaces `%20` with `+`.
|
|
36
|
+
* @returns a string with all invalid URL characters escaped
|
|
37
|
+
*/
|
|
38
|
+
static encodeQueryString(str: string, replacePlus?: boolean): string {
|
|
39
|
+
if (!str) {
|
|
40
|
+
return str;
|
|
41
|
+
}
|
|
42
|
+
// normalize
|
|
43
|
+
let result = str.toString().replace(/\r?\n/g, "\r\n");
|
|
44
|
+
// encode
|
|
45
|
+
result = encodeURIComponent(result);
|
|
46
|
+
if (replacePlus) {
|
|
47
|
+
// replace "%20" with "+" when needed
|
|
48
|
+
result = result.replace(/%20/g, "+");
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns a string where all URL component escape sequences have been
|
|
55
|
+
* converted back to their original character representations.
|
|
56
|
+
*
|
|
57
|
+
* Note: this method will convert the space character escape short form, '+',
|
|
58
|
+
* into a space. It should therefore only be used for query-string parts.
|
|
59
|
+
*
|
|
60
|
+
* @param str A string containing encoded URL component sequences
|
|
61
|
+
* @param replacePlus When set it replaces `+` with `%20`.
|
|
62
|
+
* @returns string with no encoded URL component encoded sequences
|
|
63
|
+
*/
|
|
64
|
+
static decodeQueryString(str: string, replacePlus?: boolean): string {
|
|
65
|
+
if (!str) {
|
|
66
|
+
return str;
|
|
67
|
+
}
|
|
68
|
+
let result = str;
|
|
69
|
+
if (replacePlus) {
|
|
70
|
+
result = str.replace(/\+/g, "%20");
|
|
71
|
+
}
|
|
72
|
+
return decodeURIComponent(result);
|
|
73
|
+
}
|
|
74
|
+
}
|