typia 4.1.14 → 4.1.15-dev.20230803-2

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.
@@ -2,35 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.$string = void 0;
4
4
  var $string = function (str) {
5
- if (str.length > 41)
6
- return JSON.stringify(str);
7
5
  var length = str.length;
6
+ if (length > 41)
7
+ return JSON.stringify(str);
8
8
  var result = "";
9
- var last = 0;
10
- var found = false;
11
- var surrogateFound = false;
9
+ var last = -1;
12
10
  var point = 255;
13
- for (var i = 0; i < length && point >= 32; i++) {
11
+ for (var i = 0; i < length; ++i) {
14
12
  point = str.charCodeAt(i);
15
- if (0xd800 <= point && point <= 0xdfff) {
16
- surrogateFound = true;
17
- break;
13
+ if (point < 32) {
14
+ return JSON.stringify(str);
15
+ }
16
+ if (point >= 0xd800 && point <= 0xdfff) {
17
+ return JSON.stringify(str);
18
18
  }
19
- if (point === 34 || point === 92) {
19
+ if (point === 0x22 ||
20
+ point === 0x5c) {
21
+ last === -1 && (last = 0);
20
22
  result += str.slice(last, i) + "\\";
21
23
  last = i;
22
- found = true;
23
24
  }
24
25
  }
25
- if (!found) {
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, "\"");
26
+ return ((last === -1 && '"' + str + '"') || '"' + result + str.slice(last) + '"');
34
27
  };
35
28
  exports.$string = $string;
36
29
  //# sourceMappingURL=$string.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"$string.js","sourceRoot":"","sources":["../../src/functional/$string.ts"],"names":[],"mappings":";;;AAGO,IAAM,OAAO,GAAG,UAAC,GAAW;IAC/B,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAEhD,IAAM,MAAM,GAAG,GAAG,CAAC,MA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AAS,CAAC,GAAG,CAAC,CAAC;IAE5C,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,MAAM,EAAE,EAAE,CAAC,EAAE;QAC7B,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;AA/BW,QAAA,OAAO,WA+BlB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typia",
3
- "version": "4.1.14",
3
+ "version": "4.1.15-dev.20230803-2",
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.4.0",
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,45 @@
1
- /**
2
- * @internal
3
- */
4
- export const $string = (str: string): string => {
5
- if (str.length > 41) return JSON.stringify(str);
6
-
7
- const length = str.length;
8
- let result = "";
9
- let last = 0;
10
- let found = false;
11
- let surrogateFound = false;
12
- let point = 255;
13
-
14
- // eslint-disable-next-line
15
- for (let i = 0; i < length && point >= 32; i++) {
16
- point = str.charCodeAt(i);
17
- if (0xd800 <= point && point <= 0xdfff) {
18
- // The current character is a surrogate.
19
- surrogateFound = true;
20
- break;
21
- }
22
- if (point === 34 || point === 92) {
23
- result += str.slice(last, i) + "\\";
24
- last = i;
25
- found = true;
26
- }
27
- }
28
-
29
- if (!found) {
30
- result = str;
31
- } else {
32
- result += str.slice(last);
33
- }
34
- return point < 32 || surrogateFound === true
35
- ? JSON.stringify(str)
36
- : `"${result}"`;
37
- };
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
+ *
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
13
+ */
14
+ export const $string = (str: string): string => {
15
+ const length = str.length;
16
+ if (length > 41) return JSON.stringify(str);
17
+
18
+ let result = "";
19
+ let last = -1;
20
+ let point = 255;
21
+
22
+ // eslint-disable-next-line
23
+ for (let i = 0; i < length; ++i) {
24
+ point = str.charCodeAt(i);
25
+ if (point < 32) {
26
+ return JSON.stringify(str);
27
+ }
28
+ if (point >= 0xd800 && point <= 0xdfff) {
29
+ // The current character is a surrogate.
30
+ return JSON.stringify(str);
31
+ }
32
+ if (
33
+ point === 0x22 || // '"'
34
+ point === 0x5c // '\'
35
+ ) {
36
+ last === -1 && (last = 0);
37
+ result += str.slice(last, i) + "\\";
38
+ last = i;
39
+ }
40
+ }
41
+
42
+ return (
43
+ (last === -1 && '"' + str + '"') || '"' + result + str.slice(last) + '"'
44
+ );
45
+ };