xcn 0.1.0 → 0.1.2-alpha.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 CHANGED
@@ -1,6 +1,25 @@
1
+ # MIT License
2
+
1
3
  Copyright (c) <2025> <earthnut.dev>
2
4
 
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.
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+
17
+ # MIT 许可证
18
+
19
+ 版权所有 (c) [2025] [花生亻]
20
+
21
+ 特此免费授予任何获得本软件及相关文档文件(以下简称“软件”)副本的人不受限制地处置该软件的权利,包括不受限制地使用、复制、修改、合并、发布、分发、再许可和/或出售该软件副本的权利,并允许向其提供该软件的人这样做,但须遵守以下条件:
22
+
23
+ 上述版权声明和本许可声明应包含在所有副本或软件的重要部分中。
24
+
25
+ 软件按“原样”提供,不附带任何形式的明示或暗示的保证,包括但不限于适销性、特定用途适用性和不侵权的保证。在任何情况下,作者或版权持有人均不对因合同、侵权或其他方式引起的任何索赔、损害或其他责任负责,无论是在与软件或软件的使用或其他交易有关的任何诉讼中。
package/README.md CHANGED
@@ -30,4 +30,4 @@ import { xcn } from 'xcn';
30
30
 
31
31
  ## 文档地址
32
32
 
33
- 参看 [https://earthnut.dev/xcn/](https://earthnut.dev/xcn/)
33
+ 参看 [https://earthnut.dev/npm/xcn/](https://earthnut.dev/npm/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};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 参数的数据类型
3
3
  */
4
- export type ClassNameItem = null | number | string | boolean | undefined | (() => string) | (() => ClassNameItem[]) | ClassNameItem[] | Record<string, boolean | undefined>;
4
+ type ClassNameItem = null | number | string | boolean | undefined | (() => string) | (() => ClassNameItem[]) | ClassNameItem[] | Record<string, boolean | undefined>;
5
5
  /**
6
6
  * 使用 infer 判断出当前的数据类型
7
7
  *
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,33 +1,34 @@
1
1
  {
2
- "main": "cjs/index.cjs",
3
- "module": "mjs/index.mjs",
4
- "types": "types/index.d.ts",
2
+ "main": "index.cjs",
3
+ "module": "index.mjs",
4
+ "types": "index.d.ts",
5
5
  "name": "xcn",
6
6
  "type": "module",
7
- "version": "0.1.0",
7
+ "version": "0.1.2-alpha.0",
8
8
  "description": "一个用于字符串拼接的小工具,常用于 class name 的拼接",
9
9
  "license": "ISC",
10
10
  "dependencies": {
11
- "a-type-of-js": ">=0.2.0 <1.0.0"
11
+ "a-type-of-js": "^1.0.2"
12
12
  },
13
13
  "publishConfig": {
14
14
  "access": "public",
15
15
  "registry": "https://registry.npmjs.org/"
16
16
  },
17
17
  "files": [
18
- "mjs/",
19
- "cjs/",
20
- "types/"
18
+ "index.mjs",
19
+ "index.cjs",
20
+ "index.d.ts",
21
+ "src"
21
22
  ],
22
23
  "exports": {
23
24
  ".": {
24
25
  "import": {
25
- "default": "./mjs/index.mjs",
26
- "types": "./types/index.d.ts"
26
+ "default": "./index.mjs",
27
+ "types": "./index.d.ts"
27
28
  },
28
29
  "require": {
29
- "default": "./cjs/index.cjs",
30
- "types": "./types/index.d.ts"
30
+ "default": "./index.cjs",
31
+ "types": "./index.d.ts"
31
32
  }
32
33
  }
33
34
  },
@@ -36,7 +37,7 @@
36
37
  "url": "git+https://github.com/earthnutDev/xcn.git"
37
38
  },
38
39
  "author": {
39
- "name": "earthnut",
40
+ "name": "🥜",
40
41
  "email": "earthnut.dev@outlook.com",
41
42
  "url": "https://earthnut.dev"
42
43
  },
package/cjs/index.cjs DELETED
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var index = require('./src/index.cjs');
6
-
7
-
8
-
9
- exports.default = index.xcn;
10
- exports.xcn = index.xcn;
package/cjs/src/index.cjs DELETED
@@ -1,73 +0,0 @@
1
- 'use strict';
2
-
3
- var aTypeOfJs = require('a-type-of-js');
4
-
5
- /**
6
- *
7
- * 合并 class
8
- *
9
- * merge class name
10
- *
11
- */
12
- function xcn(...classNameList) {
13
- const template = [];
14
- /**
15
- * 移除空白
16
- */
17
- const removeBlank = (str) => str
18
- .trim()
19
- .replace(/undefined/g, ' ')
20
- .replace(/\s+/g, ' ')
21
- .split(' ')
22
- .sort()
23
- .join(' ');
24
- /**
25
- * 混合值
26
- */
27
- const mergeNewValue = (newValue) => {
28
- if (newValue === undefined || typeof newValue !== 'string')
29
- return;
30
- const newList = removeBlank(newValue).split(' ');
31
- if (newList.length)
32
- template.push(...newList);
33
- };
34
- classNameList.forEach(classNameItem => {
35
- // 数据为 undefined 或 null 或 false 或 true 或 '' 或 [] 或 {}
36
- if (!classNameItem || classNameItem === true) {
37
- return;
38
- }
39
- // 数据为数组类型
40
- if (Array.isArray(classNameItem) === true) {
41
- classNameItem.forEach(childItem => mergeNewValue(xcn(childItem)));
42
- }
43
- // 数据为 string 类型
44
- else if ('string' === typeof classNameItem ||
45
- 'number' === typeof classNameItem) {
46
- mergeNewValue(classNameItem.toString());
47
- }
48
- // 数据为函数类型
49
- else if (aTypeOfJs.isFunction(classNameItem)) {
50
- const result = classNameItem();
51
- if (aTypeOfJs.isString(result)) {
52
- mergeNewValue(result);
53
- }
54
- else {
55
- result.forEach(item => mergeNewValue(xcn(item)));
56
- }
57
- }
58
- else {
59
- // 数据为 object 类型
60
- for (const key in classNameItem) {
61
- if (Object.prototype.hasOwnProperty.call(classNameItem, key)) {
62
- const element = classNameItem[key];
63
- if (true === element)
64
- mergeNewValue(key);
65
- }
66
- }
67
- }
68
- });
69
- const result = removeBlank(new Array(...new Set(template)).join(' '));
70
- return (result || undefined);
71
- }
72
-
73
- exports.xcn = xcn;
package/mjs/index.mjs DELETED
@@ -1,5 +0,0 @@
1
- import { xcn } from './src/index.mjs';
2
-
3
-
4
-
5
- export { xcn as default, xcn };
package/mjs/src/index.mjs DELETED
@@ -1,71 +0,0 @@
1
- import { isFunction, isString } from 'a-type-of-js';
2
-
3
- /**
4
- *
5
- * 合并 class
6
- *
7
- * merge class name
8
- *
9
- */
10
- function xcn(...classNameList) {
11
- const template = [];
12
- /**
13
- * 移除空白
14
- */
15
- const removeBlank = (str) => str
16
- .trim()
17
- .replace(/undefined/g, ' ')
18
- .replace(/\s+/g, ' ')
19
- .split(' ')
20
- .sort()
21
- .join(' ');
22
- /**
23
- * 混合值
24
- */
25
- const mergeNewValue = (newValue) => {
26
- if (newValue === undefined || typeof newValue !== 'string')
27
- return;
28
- const newList = removeBlank(newValue).split(' ');
29
- if (newList.length)
30
- template.push(...newList);
31
- };
32
- classNameList.forEach(classNameItem => {
33
- // 数据为 undefined 或 null 或 false 或 true 或 '' 或 [] 或 {}
34
- if (!classNameItem || classNameItem === true) {
35
- return;
36
- }
37
- // 数据为数组类型
38
- if (Array.isArray(classNameItem) === true) {
39
- classNameItem.forEach(childItem => mergeNewValue(xcn(childItem)));
40
- }
41
- // 数据为 string 类型
42
- else if ('string' === typeof classNameItem ||
43
- 'number' === typeof classNameItem) {
44
- mergeNewValue(classNameItem.toString());
45
- }
46
- // 数据为函数类型
47
- else if (isFunction(classNameItem)) {
48
- const result = classNameItem();
49
- if (isString(result)) {
50
- mergeNewValue(result);
51
- }
52
- else {
53
- result.forEach(item => mergeNewValue(xcn(item)));
54
- }
55
- }
56
- else {
57
- // 数据为 object 类型
58
- for (const key in classNameItem) {
59
- if (Object.prototype.hasOwnProperty.call(classNameItem, key)) {
60
- const element = classNameItem[key];
61
- if (true === element)
62
- mergeNewValue(key);
63
- }
64
- }
65
- }
66
- });
67
- const result = removeBlank(new Array(...new Set(template)).join(' '));
68
- return (result || undefined);
69
- }
70
-
71
- export { xcn };
package/types/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { xcn } from './src/index';
2
- export { xcn };
3
- export default xcn;
File without changes
@@ -1 +0,0 @@
1
- export {};