xcn 1.0.0 → 1.1.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/LICENSE +2 -2
- package/README.md +1 -5
- package/cjs/index.js +67 -0
- package/es/index.js +62 -0
- package/{index.d.ts → es/src/index.d.ts} +1 -0
- package/package.json +34 -38
- package/index.cjs +0 -1
- package/index.mjs +0 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) <2025> <
|
|
3
|
+
Copyright (c) <2025> <Mr.MudBean>
|
|
4
4
|
|
|
5
5
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
6
|
purpose with or without fee is hereby granted, provided that the above
|
|
@@ -16,7 +16,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
16
16
|
|
|
17
17
|
# MIT 许可证
|
|
18
18
|
|
|
19
|
-
版权所有 (c) [2025] [
|
|
19
|
+
版权所有 (c) [2025] [泥豆君]
|
|
20
20
|
|
|
21
21
|
特此免费授予任何获得本软件及相关文档文件(以下简称“软件”)副本的人不受限制地处置该软件的权利,包括不受限制地使用、复制、修改、合并、发布、分发、再许可和/或出售该软件副本的权利,并允许向其提供该软件的人这样做,但须遵守以下条件:
|
|
22
22
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# xcn
|
|
2
2
|
|
|
3
|
-
[&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/xcn) [?logo=github>)](https://github.com/
|
|
3
|
+
[&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/xcn) [?logo=github>)](https://github.com/MrMudBean/xcn/issues)
|
|
4
4
|
|
|
5
5
|
`xcn = mix + class name` 组装 html 元素的 class 属性值,`xcn` 仅是 `mix-cn` 的缩写。
|
|
6
6
|
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
10
|
npm install --save xcn@latest
|
|
11
|
-
# 或者
|
|
12
|
-
npm install --save mix-cn@latest
|
|
13
11
|
```
|
|
14
12
|
|
|
15
13
|
## 使用
|
|
@@ -24,8 +22,6 @@ import { xcn } from 'xcn';
|
|
|
24
22
|
> xcn('a', { c: false }, true , false ,null , {d: true}, 'b');
|
|
25
23
|
|
|
26
24
|
'a b d'
|
|
27
|
-
|
|
28
|
-
|
|
29
25
|
```
|
|
30
26
|
|
|
31
27
|
## 文档地址
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var aTypeOfJs = require('a-type-of-js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* 合并 class
|
|
10
|
+
*
|
|
11
|
+
* merge class name
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
function xcn(...classNameList) {
|
|
15
|
+
/** 临时 */
|
|
16
|
+
const template = [];
|
|
17
|
+
/** 移除空白 */
|
|
18
|
+
const removeBlank = (str) => str
|
|
19
|
+
.trim()
|
|
20
|
+
.replace(/undefined/g, ' ')
|
|
21
|
+
.replace(/\s+/g, ' ')
|
|
22
|
+
.split(' ')
|
|
23
|
+
.sort()
|
|
24
|
+
.join(' ');
|
|
25
|
+
/** 混合值 */
|
|
26
|
+
const mergeNewValue = (newValue) => {
|
|
27
|
+
if (aTypeOfJs.isUndefined(newValue) || !aTypeOfJs.isString(newValue))
|
|
28
|
+
return;
|
|
29
|
+
const newList = removeBlank(newValue).split(' ');
|
|
30
|
+
if (newList.length)
|
|
31
|
+
template.push(...newList);
|
|
32
|
+
};
|
|
33
|
+
classNameList.forEach(classNameItem => {
|
|
34
|
+
// 数据为 undefined 或 null 或 false 或 true 或 '' 或 [] 或 {}
|
|
35
|
+
if (!classNameItem || aTypeOfJs.isTrue(classNameItem))
|
|
36
|
+
return;
|
|
37
|
+
// 数据为数组类型
|
|
38
|
+
if (aTypeOfJs.isArray(classNameItem))
|
|
39
|
+
classNameItem.forEach(childItem => mergeNewValue(xcn(childItem)));
|
|
40
|
+
// 数据为 string 类型
|
|
41
|
+
else if (aTypeOfJs.isString(classNameItem) || aTypeOfJs.isNumber(classNameItem))
|
|
42
|
+
mergeNewValue(classNameItem.toString());
|
|
43
|
+
// 数据为函数类型
|
|
44
|
+
else if (aTypeOfJs.isFunction(classNameItem)) {
|
|
45
|
+
const result = classNameItem();
|
|
46
|
+
if (aTypeOfJs.isString(result))
|
|
47
|
+
mergeNewValue(result);
|
|
48
|
+
else
|
|
49
|
+
result.forEach(item => mergeNewValue(xcn(item)));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// 数据为 object 类型
|
|
53
|
+
for (const key in classNameItem) {
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(classNameItem, key)) {
|
|
55
|
+
const element = classNameItem[key];
|
|
56
|
+
if (true === element)
|
|
57
|
+
mergeNewValue(key);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const result = removeBlank(Array.from(new Set(template)).filter(Boolean).join(' '));
|
|
63
|
+
return (result ?? undefined);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.default = xcn;
|
|
67
|
+
exports.xcn = xcn;
|
package/es/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isTrue, isArray, isString, isNumber, isFunction, isUndefined } from 'a-type-of-js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* 合并 class
|
|
6
|
+
*
|
|
7
|
+
* merge class name
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
function xcn(...classNameList) {
|
|
11
|
+
/** 临时 */
|
|
12
|
+
const template = [];
|
|
13
|
+
/** 移除空白 */
|
|
14
|
+
const removeBlank = (str) => str
|
|
15
|
+
.trim()
|
|
16
|
+
.replace(/undefined/g, ' ')
|
|
17
|
+
.replace(/\s+/g, ' ')
|
|
18
|
+
.split(' ')
|
|
19
|
+
.sort()
|
|
20
|
+
.join(' ');
|
|
21
|
+
/** 混合值 */
|
|
22
|
+
const mergeNewValue = (newValue) => {
|
|
23
|
+
if (isUndefined(newValue) || !isString(newValue))
|
|
24
|
+
return;
|
|
25
|
+
const newList = removeBlank(newValue).split(' ');
|
|
26
|
+
if (newList.length)
|
|
27
|
+
template.push(...newList);
|
|
28
|
+
};
|
|
29
|
+
classNameList.forEach(classNameItem => {
|
|
30
|
+
// 数据为 undefined 或 null 或 false 或 true 或 '' 或 [] 或 {}
|
|
31
|
+
if (!classNameItem || isTrue(classNameItem))
|
|
32
|
+
return;
|
|
33
|
+
// 数据为数组类型
|
|
34
|
+
if (isArray(classNameItem))
|
|
35
|
+
classNameItem.forEach(childItem => mergeNewValue(xcn(childItem)));
|
|
36
|
+
// 数据为 string 类型
|
|
37
|
+
else if (isString(classNameItem) || isNumber(classNameItem))
|
|
38
|
+
mergeNewValue(classNameItem.toString());
|
|
39
|
+
// 数据为函数类型
|
|
40
|
+
else if (isFunction(classNameItem)) {
|
|
41
|
+
const result = classNameItem();
|
|
42
|
+
if (isString(result))
|
|
43
|
+
mergeNewValue(result);
|
|
44
|
+
else
|
|
45
|
+
result.forEach(item => mergeNewValue(xcn(item)));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// 数据为 object 类型
|
|
49
|
+
for (const key in classNameItem) {
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(classNameItem, key)) {
|
|
51
|
+
const element = classNameItem[key];
|
|
52
|
+
if (true === element)
|
|
53
|
+
mergeNewValue(key);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const result = removeBlank(Array.from(new Set(template)).filter(Boolean).join(' '));
|
|
59
|
+
return (result ?? undefined);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { xcn as default, xcn };
|
package/package.json
CHANGED
|
@@ -1,59 +1,55 @@
|
|
|
1
1
|
{
|
|
2
|
-
"main": "index.cjs",
|
|
3
|
-
"module": "index.mjs",
|
|
4
|
-
"types": "index.d.ts",
|
|
5
2
|
"name": "xcn",
|
|
6
3
|
"type": "module",
|
|
7
|
-
"version": "1.
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
4
|
+
"version": "1.1.0",
|
|
5
|
+
"main": "cjs/index.js",
|
|
6
|
+
"module": "es/index.js",
|
|
7
|
+
"types": "es/src/index.d.ts",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "泥豆君",
|
|
10
|
+
"email": "Mr.MudBean@outlook.com",
|
|
11
|
+
"url": "https://earthnut.dev"
|
|
12
12
|
},
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public",
|
|
15
15
|
"registry": "https://registry.npmjs.org/"
|
|
16
16
|
},
|
|
17
|
+
"description": "一个用于字符串拼接的小工具,多用于 class name 的拼接",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"license": "MIT",
|
|
17
20
|
"files": [
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
21
|
+
"cjs",
|
|
22
|
+
"es",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"README.md"
|
|
22
25
|
],
|
|
23
26
|
"exports": {
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
"import": "./es/index.js",
|
|
28
|
+
"default": "./es/index.js",
|
|
29
|
+
"require": "./cjs/index.js",
|
|
30
|
+
"types": "./es/src/index.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"xcn",
|
|
34
|
+
"混合 className",
|
|
35
|
+
"拼接字符串"
|
|
36
|
+
],
|
|
37
|
+
"homepage": "https://earthnut.dev/npm/xcn",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"a-type-of-js": "^2.0.0"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/MrMudBean/xcn/issues",
|
|
43
|
+
"email": "Mr.MudBean@outlook.com"
|
|
34
44
|
},
|
|
35
45
|
"repository": {
|
|
36
46
|
"type": "git",
|
|
37
|
-
"url": "git+https://github.com/
|
|
38
|
-
},
|
|
39
|
-
"author": {
|
|
40
|
-
"name": "🥜",
|
|
41
|
-
"email": "earthnut.dev@outlook.com",
|
|
42
|
-
"url": "https://earthnut.dev"
|
|
47
|
+
"url": "git+https://github.com/MrMudBean/xcn.git"
|
|
43
48
|
},
|
|
44
49
|
"browserslist": [
|
|
45
|
-
"
|
|
50
|
+
"last 2 versions not ie <= 11"
|
|
46
51
|
],
|
|
47
52
|
"engines": {
|
|
48
53
|
"node": ">=18.0.0"
|
|
49
|
-
},
|
|
50
|
-
"keywords": [
|
|
51
|
-
"xcn",
|
|
52
|
-
"mix-cn"
|
|
53
|
-
],
|
|
54
|
-
"homepage": "https://earthnut.dev/npm/xcn",
|
|
55
|
-
"bugs": {
|
|
56
|
-
"url": "https://github.com/earthnutDev/xcn/issues",
|
|
57
|
-
"email": "earthnut.dev@outlook.com"
|
|
58
54
|
}
|
|
59
55
|
}
|
package/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var i=require("a-type-of-js");exports.xcn=function r(...e){const t=[],n=i=>i.trim().replace(/undefined/g," ").replace(/\s+/g," ").split(" ").sort().join(" "),s=r=>{if(i.isUndefined(r)||!i.isString(r))return;const e=n(r).split(" ");e.length&&t.push(...e)};return e.forEach(e=>{if(e&&!i.isTrue(e))if(i.isArray(e))e.forEach(i=>s(r(i)));else if(i.isString(e)||i.isNumber(e))s(e.toString());else if(i.isFunction(e)){const t=e();i.isString(t)?s(t):t.forEach(i=>s(r(i)))}else for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){!0===e[i]&&s(i)}}),n(Array.from(new Set(t)).filter(Boolean).join(" "))??void 0};
|
package/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isTrue as e,isArray as o,isString as r,isNumber as t,isFunction as i,isUndefined as n}from"a-type-of-js";function f(...s){const c=[],l=e=>e.trim().replace(/undefined/g," ").replace(/\s+/g," ").split(" ").sort().join(" "),p=e=>{if(n(e)||!r(e))return;const o=l(e).split(" ");o.length&&c.push(...o)};s.forEach(n=>{if(n&&!e(n))if(o(n))n.forEach(e=>p(f(e)));else if(r(n)||t(n))p(n.toString());else if(i(n)){const e=n();r(e)?p(e):e.forEach(e=>p(f(e)))}else for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){!0===n[e]&&p(e)}});return l(Array.from(new Set(c)).filter(Boolean).join(" "))??void 0}export{f as xcn};
|