@omnific/utils 0.3.1 → 0.4.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/dist/kebabCase.d.ts +14 -0
- package/dist/kebabCase.js +30 -0
- package/dist/main.d.ts +2 -1
- package/dist/main.js +2 -1
- package/package.json +5 -5
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region kebabCase.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* 将字符串转换为 kebab-case。
|
|
4
|
+
*
|
|
5
|
+
* @param value 待转换字符串。
|
|
6
|
+
* @returns 转换后的 kebab-case 字符串。
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* kebabCase('camelCase') // 'camel-case'
|
|
10
|
+
* kebabCase('some whitespace') // 'some-whitespace'
|
|
11
|
+
* kebabCase('HTTPRequest') // 'http-request'
|
|
12
|
+
*/
|
|
13
|
+
export declare function kebabCase(value: string): string;
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region kebabCase.ts
|
|
2
|
+
/**
|
|
3
|
+
* 用于拆分常见命名格式的正则;实现参考 es-toolkit 的 `kebabCase`。
|
|
4
|
+
*/
|
|
5
|
+
const CASE_SPLIT_PATTERN = /\p{Lu}?\p{Ll}+|[0-9]+|\p{Lu}+(?!\p{Ll})|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu;
|
|
6
|
+
/**
|
|
7
|
+
* 将字符串拆分为单词。
|
|
8
|
+
*
|
|
9
|
+
* @param value 待拆分字符串。
|
|
10
|
+
* @returns 拆分后的单词数组。
|
|
11
|
+
*/
|
|
12
|
+
function words(value) {
|
|
13
|
+
return [...value.match(CASE_SPLIT_PATTERN) ?? []];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 将字符串转换为 kebab-case。
|
|
17
|
+
*
|
|
18
|
+
* @param value 待转换字符串。
|
|
19
|
+
* @returns 转换后的 kebab-case 字符串。
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* kebabCase('camelCase') // 'camel-case'
|
|
23
|
+
* kebabCase('some whitespace') // 'some-whitespace'
|
|
24
|
+
* kebabCase('HTTPRequest') // 'http-request'
|
|
25
|
+
*/
|
|
26
|
+
function kebabCase(value) {
|
|
27
|
+
return words(value).map((word) => word.toLowerCase()).join("-");
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { kebabCase };
|
package/dist/main.d.ts
CHANGED
|
@@ -20,8 +20,9 @@ import { isStringEmpty } from "./isStringEmpty.js";
|
|
|
20
20
|
import { isSymbol } from "./isSymbol.js";
|
|
21
21
|
import { isURLSearchParameters } from "./isURLSearchParameters.js";
|
|
22
22
|
import { isUndefined } from "./isUndefined.js";
|
|
23
|
+
import { kebabCase } from "./kebabCase.js";
|
|
23
24
|
import { parseJson } from "./parseJson.js";
|
|
24
25
|
import { ThrottleOptions, ThrottledFunction, throttle } from "./throttle.js";
|
|
25
26
|
import resolveValue from "./resolveValue.js";
|
|
26
27
|
import { uniqueId } from "./uniqueId.js";
|
|
27
|
-
export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type ThrottleOptions, type ThrottledFunction, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, parseJson, resolveValue, throttle, uniqueId };
|
|
28
|
+
export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type ThrottleOptions, type ThrottledFunction, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, kebabCase, parseJson, resolveValue, throttle, uniqueId };
|
package/dist/main.js
CHANGED
|
@@ -21,7 +21,8 @@ import { isURLSearchParameters } from "./isURLSearchParameters.js";
|
|
|
21
21
|
import { parseJson } from "./parseJson.js";
|
|
22
22
|
import { isSymbol } from "./isSymbol.js";
|
|
23
23
|
import { get } from "./get.js";
|
|
24
|
+
import { kebabCase } from "./kebabCase.js";
|
|
24
25
|
import { throttle } from "./throttle.js";
|
|
25
26
|
import resolveValue from "./resolveValue.js";
|
|
26
27
|
import { uniqueId } from "./uniqueId.js";
|
|
27
|
-
export { createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, parseJson, resolveValue, throttle, uniqueId };
|
|
28
|
+
export { createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, kebabCase, parseJson, resolveValue, throttle, uniqueId };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnific/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Shared utility predicates for Omnific packages",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"dist",
|
|
39
39
|
"README.md"
|
|
40
40
|
],
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@omnific/tsconfig": "0.2.0"
|
|
43
|
+
},
|
|
41
44
|
"scripts": {
|
|
42
45
|
"build": "tsdown -c tsdown.config.mjs",
|
|
43
46
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
44
|
-
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"@omnific/tsconfig": "workspace:*"
|
|
47
47
|
}
|
|
48
|
-
}
|
|
48
|
+
}
|