typia 4.1.14 → 4.1.15-dev.20230803
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/lib/functional/$string.js +12 -21
- package/lib/functional/$string.js.map +1 -1
- package/package.json +2 -2
- package/src/functional/$string.ts +26 -20
- package/src/metadata/Metadata.ts +607 -607
|
@@ -2,35 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.$string = void 0;
|
|
4
4
|
var $string = function (str) {
|
|
5
|
-
|
|
6
|
-
return JSON.stringify(str);
|
|
7
|
-
var length = str.length;
|
|
5
|
+
var len = str.length;
|
|
8
6
|
var result = "";
|
|
9
|
-
var last =
|
|
10
|
-
var found = false;
|
|
11
|
-
var surrogateFound = false;
|
|
7
|
+
var last = -1;
|
|
12
8
|
var point = 255;
|
|
13
|
-
for (var i = 0; i <
|
|
9
|
+
for (var i = 0; i < len; ++i) {
|
|
14
10
|
point = str.charCodeAt(i);
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
break;
|
|
11
|
+
if (point < 32) {
|
|
12
|
+
return JSON.stringify(str);
|
|
18
13
|
}
|
|
19
|
-
if (point
|
|
14
|
+
if (point >= 0xd800 && point <= 0xdfff) {
|
|
15
|
+
return JSON.stringify(str);
|
|
16
|
+
}
|
|
17
|
+
if (point === 0x22 ||
|
|
18
|
+
point === 0x5c) {
|
|
19
|
+
last === -1 && (last = 0);
|
|
20
20
|
result += str.slice(last, i) + "\\";
|
|
21
21
|
last = i;
|
|
22
|
-
found = true;
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
result = str;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
result += str.slice(last);
|
|
30
|
-
}
|
|
31
|
-
return point < 32 || surrogateFound === true
|
|
32
|
-
? JSON.stringify(str)
|
|
33
|
-
: "\"".concat(result, "\"");
|
|
24
|
+
return ((last === -1 && '"' + str + '"') || '"' + result + str.slice(last) + '"');
|
|
34
25
|
};
|
|
35
26
|
exports.$string = $string;
|
|
36
27
|
//# sourceMappingURL=$string.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"$string.js","sourceRoot":"","sources":["../../src/functional/$string.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"$string.js","sourceRoot":"","sources":["../../src/functional/$string.ts"],"names":[],"mappings":";;;AAaO,IAAM,OAAO,GAAG,UAAC,GAAW;IAC/B,IAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC;IACvB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC;IACd,IAAI,KAAK,GAAG,GAAG,CAAC;IAGhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE,CAAC,EAAE;QAC1B,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,KAAK,GAAG,EAAE,EAAE;YACZ,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;SAC9B;QACD,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,EAAE;YAEpC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;SAC9B;QACD,IACI,KAAK,KAAK,IAAI;YACd,KAAK,KAAK,IAAI,EAChB;YACE,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;YAC1B,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;YACpC,IAAI,GAAG,CAAC,CAAC;SACZ;KACJ;IAED,OAAO,CACH,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,CAC3E,CAAC;AACN,CAAC,CAAC;AA7BW,QAAA,OAAO,WA6BlB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typia",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.15-dev.20230803",
|
|
4
4
|
"description": "Superfast runtime validators with only one line",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"d3": "^5.16.0",
|
|
108
108
|
"eslint-plugin-deprecation": "^1.4.1",
|
|
109
109
|
"express": "^4.18.2",
|
|
110
|
-
"fast-json-stringify": "^5.
|
|
110
|
+
"fast-json-stringify": "^5.8.0",
|
|
111
111
|
"fastify": "^4.9.2",
|
|
112
112
|
"io-ts": "^2.2.19",
|
|
113
113
|
"jsdom": "^21.1.1",
|
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* In the past, name of `typia` was `typescript-json`, and supported
|
|
3
|
+
* JSON serialization by wrapping `fast-json-stringify. `typescript-json` was
|
|
4
|
+
* a helper library of `fast-json-stringify`, which can skip manual JSON schema
|
|
5
|
+
* definition just by putting pure TypeScript type.
|
|
6
|
+
*
|
|
7
|
+
* This `$string` function is a part of `fast-json-stringify` at that time, and
|
|
8
|
+
* still being used in `typia` for the string serialization.
|
|
9
|
+
*
|
|
2
10
|
* @internal
|
|
11
|
+
* @reference https://github.com/fastify/fast-json-stringify/blob/master/lib/serializer.js
|
|
12
|
+
* @blog https://dev.to/samchon/good-bye-typescript-is-ancestor-of-typia-20000x-faster-validator-49fi
|
|
3
13
|
*/
|
|
4
14
|
export const $string = (str: string): string => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const length = str.length;
|
|
15
|
+
const len = str.length;
|
|
8
16
|
let result = "";
|
|
9
|
-
let last =
|
|
10
|
-
let found = false;
|
|
11
|
-
let surrogateFound = false;
|
|
17
|
+
let last = -1;
|
|
12
18
|
let point = 255;
|
|
13
19
|
|
|
14
20
|
// eslint-disable-next-line
|
|
15
|
-
for (let i = 0; i <
|
|
21
|
+
for (let i = 0; i < len; ++i) {
|
|
16
22
|
point = str.charCodeAt(i);
|
|
17
|
-
if (
|
|
23
|
+
if (point < 32) {
|
|
24
|
+
return JSON.stringify(str);
|
|
25
|
+
}
|
|
26
|
+
if (point >= 0xd800 && point <= 0xdfff) {
|
|
18
27
|
// The current character is a surrogate.
|
|
19
|
-
|
|
20
|
-
break;
|
|
28
|
+
return JSON.stringify(str);
|
|
21
29
|
}
|
|
22
|
-
if (
|
|
30
|
+
if (
|
|
31
|
+
point === 0x22 || // '"'
|
|
32
|
+
point === 0x5c // '\'
|
|
33
|
+
) {
|
|
34
|
+
last === -1 && (last = 0);
|
|
23
35
|
result += str.slice(last, i) + "\\";
|
|
24
36
|
last = i;
|
|
25
|
-
found = true;
|
|
26
37
|
}
|
|
27
38
|
}
|
|
28
39
|
|
|
29
|
-
|
|
30
|
-
result
|
|
31
|
-
|
|
32
|
-
result += str.slice(last);
|
|
33
|
-
}
|
|
34
|
-
return point < 32 || surrogateFound === true
|
|
35
|
-
? JSON.stringify(str)
|
|
36
|
-
: `"${result}"`;
|
|
40
|
+
return (
|
|
41
|
+
(last === -1 && '"' + str + '"') || '"' + result + str.slice(last) + '"'
|
|
42
|
+
);
|
|
37
43
|
};
|