xcn 0.0.0 → 0.1.1
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/LICENSE +6 -0
- package/README.md +27 -7
- package/index.cjs +1 -0
- package/index.d.ts +25 -0
- package/index.mjs +1 -0
- package/package.json +49 -16
- package/src/index.d.ts +0 -0
- package/index.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Copyright (c) <2025> <earthnut.dev>
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
|
+
|
|
5
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
6
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# xcn
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/xcn) [&color=rgb(0,0,0)>)](https://coveralls.io/github/earthnutDev/xcn?branch=main) [&color=rgb(0,0,0)>)](https://codecov.io/gh/earthnutDev/xcn) [?logo=github>)](https://github.com/earthnutDev/xcn/issues)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
xcn = mix + class name
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
组装 html 元素的 class 属性值.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## 安装
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
```sh
|
|
12
|
+
npm install --save xcn@latest
|
|
13
|
+
```
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { xcn } from 'xcn';
|
|
19
|
+
|
|
20
|
+
> xcn('a' , 'b' ,'c');
|
|
21
|
+
|
|
22
|
+
'a b c'
|
|
23
|
+
|
|
24
|
+
> xcn('a', { c: false }, true , false ,null , {d: true}, 'b');
|
|
25
|
+
|
|
26
|
+
'a b d'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 文档地址
|
|
32
|
+
|
|
33
|
+
参看 [https://earthnut.dev/xcn/](https://earthnut.dev/xcn/)
|
package/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var i=require("a-type-of-js");exports.xcn=function e(...r){const t=[],n=i=>i.trim().replace(/undefined/g," ").replace(/\s+/g," ").split(" ").sort().join(" "),s=e=>{if(i.isUndefined(e)||!i.isString(e))return;const r=n(e).split(" ");r.length&&t.push(...r)};return r.forEach((r=>{if(r&&!i.isTrue(r))if(i.isArray(r))r.forEach((i=>s(e(i))));else if(i.isString(r)||i.isNumber(r))s(r.toString());else if(i.isFunction(r)){const t=r();i.isString(t)?s(t):t.forEach((i=>s(e(i))))}else for(const i in r)if(Object.prototype.hasOwnProperty.call(r,i)){!0===r[i]&&s(i)}})),n(new Array(...new Set(t)).join(" "))??void 0};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 参数的数据类型
|
|
3
|
+
*/
|
|
4
|
+
type ClassNameItem = null | number | string | boolean | undefined | (() => string) | (() => ClassNameItem[]) | ClassNameItem[] | Record<string, boolean | undefined>;
|
|
5
|
+
/**
|
|
6
|
+
* 使用 infer 判断出当前的数据类型
|
|
7
|
+
*
|
|
8
|
+
* 字符串为具体的字符串值而非 string
|
|
9
|
+
*/
|
|
10
|
+
type TypeofClassNameItem<T> = T extends null | boolean | undefined ? '' : T extends readonly [unknown, infer U] ? TypeofClassNameItem<U> | '' : T extends readonly [unknown, infer U, infer V] ? TypeofClassNameItem<U> | TypeofClassNameItem<V> : T extends Record<string, boolean | undefined> ? keyof T | '' : T extends () => string ? string : T;
|
|
11
|
+
/**
|
|
12
|
+
* 递归判断当前返回的数据类型
|
|
13
|
+
*/
|
|
14
|
+
type XCN<T> = T extends [infer U, ...infer V] ? `${U & string} ${XCN<V>}` : '';
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* 合并 class
|
|
18
|
+
*
|
|
19
|
+
* merge class name
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare function xcn<T extends ClassNameItem[]>(...classNameList: T): XCN<{
|
|
23
|
+
[K in keyof T]: TypeofClassNameItem<T[K]>;
|
|
24
|
+
}>;
|
|
25
|
+
export {};
|
package/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isTrue as e,isArray as t,isString as o,isNumber as r,isFunction as n,isUndefined as i}from"a-type-of-js";function f(...s){const c=[],p=e=>e.trim().replace(/undefined/g," ").replace(/\s+/g," ").split(" ").sort().join(" "),l=e=>{if(i(e)||!o(e))return;const t=p(e).split(" ");t.length&&c.push(...t)};s.forEach((i=>{if(i&&!e(i))if(t(i))i.forEach((e=>l(f(e))));else if(o(i)||r(i))l(i.toString());else if(n(i)){const e=i();o(e)?l(e):e.forEach((e=>l(f(e))))}else for(const e in i)if(Object.prototype.hasOwnProperty.call(i,e)){!0===i[e]&&l(e)}}));return p(new Array(...new Set(c)).join(" "))??void 0}export{f as xcn};
|
package/package.json
CHANGED
|
@@ -1,26 +1,59 @@
|
|
|
1
1
|
{
|
|
2
|
+
"main": "index.cjs",
|
|
3
|
+
"module": "index.mjs",
|
|
4
|
+
"types": "index.d.ts",
|
|
2
5
|
"name": "xcn",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"homepage": "https://earthnut.dev/vue",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"version": "0.1.1",
|
|
8
|
+
"description": "一个用于字符串拼接的小工具,常用于 class name 的拼接",
|
|
7
9
|
"license": "ISC",
|
|
8
|
-
"
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"a-type-of-js": "^1.0.2"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"registry": "https://registry.npmjs.org/"
|
|
16
|
+
},
|
|
9
17
|
"files": [
|
|
10
|
-
"index.
|
|
18
|
+
"index.mjs",
|
|
19
|
+
"index.cjs",
|
|
20
|
+
"index.d.ts",
|
|
21
|
+
"src"
|
|
11
22
|
],
|
|
12
|
-
"
|
|
13
|
-
"
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"default": "./index.mjs",
|
|
27
|
+
"types": "./index.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"default": "./index.cjs",
|
|
31
|
+
"types": "./index.d.ts"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
14
34
|
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"earthnut"
|
|
17
|
-
],
|
|
18
35
|
"repository": {
|
|
19
36
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/
|
|
37
|
+
"url": "git+https://github.com/earthnutDev/xcn.git"
|
|
21
38
|
},
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
39
|
+
"author": {
|
|
40
|
+
"name": "🥜",
|
|
41
|
+
"email": "earthnut.dev@outlook.com",
|
|
42
|
+
"url": "https://earthnut.dev"
|
|
43
|
+
},
|
|
44
|
+
"browserslist": [
|
|
45
|
+
"node>=18.0.0"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"xcn",
|
|
52
|
+
"mix-cn"
|
|
53
|
+
],
|
|
54
|
+
"homepage": "https://earthnut.dev/xcn",
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/earthnutDev/xcn/issues",
|
|
57
|
+
"email": "earthnut.dev@outlook.com"
|
|
25
58
|
}
|
|
26
|
-
}
|
|
59
|
+
}
|
package/src/index.d.ts
ADDED
|
File without changes
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log("hello ,iggg!");
|