@autobe/utils 0.23.1 → 0.24.0
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/StringUtil.js +26 -28
- package/lib/StringUtil.js.map +1 -1
- package/package.json +2 -2
- package/src/StringUtil.ts +31 -30
package/lib/StringUtil.js
CHANGED
|
@@ -4,42 +4,40 @@ exports.StringUtil = void 0;
|
|
|
4
4
|
var StringUtil;
|
|
5
5
|
(function (StringUtil) {
|
|
6
6
|
function trim(strings, ...values) {
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
const lines = str.split("\n");
|
|
10
|
-
// Remove only indentation, not empty lines
|
|
11
|
-
const nonEmptyLines = lines.filter((line) => line.trim() !== "");
|
|
12
|
-
if (nonEmptyLines.length === 0)
|
|
13
|
-
return str; // Return original if all lines are empty
|
|
14
|
-
// Find minimum indentation among all non-empty lines
|
|
15
|
-
const indentLengths = nonEmptyLines.map((line) => {
|
|
16
|
-
var _a;
|
|
17
|
-
const leadingWhitespace = ((_a = line.match(/^[ \t]*/)) === null || _a === void 0 ? void 0 : _a[0]) || "";
|
|
18
|
-
return leadingWhitespace.length;
|
|
19
|
-
});
|
|
20
|
-
const indentLength = Math.min(...indentLengths);
|
|
21
|
-
// Remove indentation from all lines
|
|
22
|
-
const trimmedLines = lines.map((line) => {
|
|
23
|
-
if (line.trim() === "")
|
|
24
|
-
return "";
|
|
25
|
-
return line.slice(indentLength);
|
|
26
|
-
});
|
|
27
|
-
return trimmedLines.join("\n");
|
|
28
|
-
});
|
|
29
|
-
// Combine the indentation-removed strings with values
|
|
30
|
-
let result = processedStrings[0];
|
|
7
|
+
// 먼저 모든 template string 부분들을 합쳐서 전체 구조를 파악
|
|
8
|
+
let combined = strings[0];
|
|
31
9
|
for (let i = 0; i < values.length; i++) {
|
|
32
|
-
|
|
10
|
+
combined += `__PLACEHOLDER_${i}__` + strings[i + 1];
|
|
33
11
|
}
|
|
34
|
-
//
|
|
35
|
-
const lines =
|
|
12
|
+
// 줄별로 나누기
|
|
13
|
+
const lines = combined.split("\n");
|
|
14
|
+
// 앞뒤 빈 줄 제거
|
|
36
15
|
while (lines.length > 0 && lines[0].trim() === "") {
|
|
37
16
|
lines.shift();
|
|
38
17
|
}
|
|
39
18
|
while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
|
|
40
19
|
lines.pop();
|
|
41
20
|
}
|
|
42
|
-
|
|
21
|
+
if (lines.length === 0)
|
|
22
|
+
return "";
|
|
23
|
+
// 비어있지 않은 줄들에서 최소 indentation 찾기
|
|
24
|
+
const nonEmptyLines = lines.filter((line) => line.trim() !== "");
|
|
25
|
+
const minIndent = Math.min(...nonEmptyLines.map((line) => {
|
|
26
|
+
const match = line.match(/^[ \t]*/);
|
|
27
|
+
return match ? match[0].length : 0;
|
|
28
|
+
}));
|
|
29
|
+
// 모든 줄에서 최소 indentation 제거
|
|
30
|
+
const dedentedLines = lines.map((line) => {
|
|
31
|
+
if (line.trim() === "")
|
|
32
|
+
return "";
|
|
33
|
+
return line.slice(minIndent);
|
|
34
|
+
});
|
|
35
|
+
// placeholder를 실제 값으로 교체
|
|
36
|
+
let result = dedentedLines.join("\n");
|
|
37
|
+
for (let i = 0; i < values.length; i++) {
|
|
38
|
+
result = result.replace(`__PLACEHOLDER_${i}__`, String(values[i]));
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
43
41
|
}
|
|
44
42
|
StringUtil.trim = trim;
|
|
45
43
|
function singleLine(strings, ...values) {
|
package/lib/StringUtil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringUtil.js","sourceRoot":"","sources":["../src/StringUtil.ts"],"names":[],"mappings":";;;AAAA,IAAiB,UAAU,
|
|
1
|
+
{"version":3,"file":"StringUtil.js","sourceRoot":"","sources":["../src/StringUtil.ts"],"names":[],"mappings":";;;AAAA,IAAiB,UAAU,CA0D1B;AA1DD,WAAiB,UAAU;IACzB,SAAgB,IAAI,CAClB,OAA6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
2
|
"name": "@autobe/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "AI backend server code generator",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"keywords": [],
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@samchon/openapi": "^4.7.1",
|
|
28
28
|
"tstl": "^3.0.0",
|
|
29
29
|
"typia": "^9.7.2",
|
|
30
|
-
"@autobe/interface": "^0.
|
|
30
|
+
"@autobe/interface": "^0.24.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"rimraf": "^6.0.1",
|
package/src/StringUtil.ts
CHANGED
|
@@ -3,38 +3,16 @@ export namespace StringUtil {
|
|
|
3
3
|
strings: TemplateStringsArray,
|
|
4
4
|
...values: any[]
|
|
5
5
|
): string {
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
const lines = str.split("\n");
|
|
9
|
-
|
|
10
|
-
// Remove only indentation, not empty lines
|
|
11
|
-
const nonEmptyLines = lines.filter((line) => line.trim() !== "");
|
|
12
|
-
if (nonEmptyLines.length === 0) return str; // Return original if all lines are empty
|
|
13
|
-
|
|
14
|
-
// Find minimum indentation among all non-empty lines
|
|
15
|
-
const indentLengths = nonEmptyLines.map((line) => {
|
|
16
|
-
const leadingWhitespace = line.match(/^[ \t]*/)?.[0] || "";
|
|
17
|
-
return leadingWhitespace.length;
|
|
18
|
-
});
|
|
19
|
-
const indentLength = Math.min(...indentLengths);
|
|
20
|
-
|
|
21
|
-
// Remove indentation from all lines
|
|
22
|
-
const trimmedLines = lines.map((line) => {
|
|
23
|
-
if (line.trim() === "") return "";
|
|
24
|
-
return line.slice(indentLength);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return trimmedLines.join("\n");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// Combine the indentation-removed strings with values
|
|
31
|
-
let result: string = processedStrings[0];
|
|
6
|
+
// 먼저 모든 template string 부분들을 합쳐서 전체 구조를 파악
|
|
7
|
+
let combined = strings[0];
|
|
32
8
|
for (let i = 0; i < values.length; i++) {
|
|
33
|
-
|
|
9
|
+
combined += `__PLACEHOLDER_${i}__` + strings[i + 1];
|
|
34
10
|
}
|
|
35
11
|
|
|
36
|
-
//
|
|
37
|
-
const lines
|
|
12
|
+
// 줄별로 나누기
|
|
13
|
+
const lines = combined.split("\n");
|
|
14
|
+
|
|
15
|
+
// 앞뒤 빈 줄 제거
|
|
38
16
|
while (lines.length > 0 && lines[0].trim() === "") {
|
|
39
17
|
lines.shift();
|
|
40
18
|
}
|
|
@@ -42,7 +20,30 @@ export namespace StringUtil {
|
|
|
42
20
|
lines.pop();
|
|
43
21
|
}
|
|
44
22
|
|
|
45
|
-
|
|
23
|
+
if (lines.length === 0) return "";
|
|
24
|
+
|
|
25
|
+
// 비어있지 않은 줄들에서 최소 indentation 찾기
|
|
26
|
+
const nonEmptyLines = lines.filter((line) => line.trim() !== "");
|
|
27
|
+
const minIndent = Math.min(
|
|
28
|
+
...nonEmptyLines.map((line) => {
|
|
29
|
+
const match = line.match(/^[ \t]*/);
|
|
30
|
+
return match ? match[0].length : 0;
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// 모든 줄에서 최소 indentation 제거
|
|
35
|
+
const dedentedLines = lines.map((line) => {
|
|
36
|
+
if (line.trim() === "") return "";
|
|
37
|
+
return line.slice(minIndent);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// placeholder를 실제 값으로 교체
|
|
41
|
+
let result = dedentedLines.join("\n");
|
|
42
|
+
for (let i = 0; i < values.length; i++) {
|
|
43
|
+
result = result.replace(`__PLACEHOLDER_${i}__`, String(values[i]));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
export function singleLine(
|