befly 3.20.7 → 3.20.8
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/package.json +2 -2
- package/utils/util.js +4 -15
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.20.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.20.8",
|
|
4
|
+
"gitHead": "c5906450b26c4f674094344de80a750c5f753736",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|
package/utils/util.js
CHANGED
|
@@ -130,6 +130,7 @@ export function forOwn(obj, iteratee) {
|
|
|
130
130
|
// 将字符串拆分为词段(用于 camelCase/snakeCase)
|
|
131
131
|
function toWordParts(input) {
|
|
132
132
|
const normalized = String(input)
|
|
133
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
|
|
133
134
|
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
134
135
|
.replace(/[^a-zA-Z0-9]+/g, " ")
|
|
135
136
|
.trim();
|
|
@@ -169,29 +170,17 @@ export function camelCase(input) {
|
|
|
169
170
|
return [first].concat(rest).join("");
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
// 归一化字符串为词序列
|
|
173
|
-
function normalizeToWords(input) {
|
|
174
|
-
return String(input)
|
|
175
|
-
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
176
|
-
.replace(/[^a-zA-Z0-9]+/g, " ")
|
|
177
|
-
.trim();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
173
|
/**
|
|
181
174
|
* 把字符串转为 snake_case。
|
|
182
175
|
* - 主要用于表名/字段名(例如 userId -> user_id)。
|
|
183
176
|
*/
|
|
184
177
|
export function snakeCase(input) {
|
|
185
|
-
const
|
|
186
|
-
if (
|
|
178
|
+
const parts = toWordParts(input);
|
|
179
|
+
if (parts.length === 0) {
|
|
187
180
|
return "";
|
|
188
181
|
}
|
|
189
182
|
|
|
190
|
-
return
|
|
191
|
-
.split(/\s+/)
|
|
192
|
-
.filter((p) => p.length > 0)
|
|
193
|
-
.map((p) => p.toLowerCase())
|
|
194
|
-
.join("_");
|
|
183
|
+
return parts.map((p) => p.toLowerCase()).join("_");
|
|
195
184
|
}
|
|
196
185
|
|
|
197
186
|
/**
|