xcn 0.1.2 → 1.0.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/README.md CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  [![version](<https://img.shields.io/npm/v/xcn.svg?logo=npm&logoColor=rgb(0,0,0)&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/xcn) [![issues 提交](<https://img.shields.io/badge/issues-提交-rgb(255,0,63)?logo=github>)](https://github.com/earthnutDev/xcn/issues)
4
4
 
5
- xcn = mix + class name
6
-
7
- 组装 html 元素的 class 属性值.
5
+ `xcn = mix + class name` 组装 html 元素的 class 属性值,`xcn` 仅是 `mix-cn` 的缩写。
8
6
 
9
7
  ## 安装
10
8
 
11
9
  ```sh
12
10
  npm install --save xcn@latest
11
+ # 或者
12
+ npm install --save mix-cn@latest
13
13
  ```
14
14
 
15
15
  ## 使用
package/index.cjs CHANGED
@@ -1 +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
+ "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.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  /**
2
2
  * 参数的数据类型
3
3
  */
4
- type ClassNameItem = null | number | string | boolean | undefined | (() => string) | (() => ClassNameItem[]) | ClassNameItem[] | Record<string, boolean | undefined>;
4
+ export type EnClassNameItem = null | number | string | boolean | undefined | (() => string) | (() => EnClassNameItem[]) | EnClassNameItem[] | Record<string, boolean | undefined>;
5
5
  /**
6
6
  * 使用 infer 判断出当前的数据类型
7
7
  *
8
8
  * 字符串为具体的字符串值而非 string
9
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;
10
+ export type EnTypeofClassNameItem<T> = T extends null | boolean | undefined ? '' : T extends readonly [unknown, infer U] ? EnTypeofClassNameItem<U> | '' : T extends readonly [unknown, infer U, infer V] ? EnTypeofClassNameItem<U> | EnTypeofClassNameItem<V> : T extends Record<string, boolean | undefined> ? keyof T | '' : T extends () => string ? string : T;
11
11
  /**
12
12
  * 递归判断当前返回的数据类型
13
13
  */
14
- type XCN<T> = T extends [infer U, ...infer V] ? `${U & string} ${XCN<V>}` : '';
14
+ export type EnXcn<T> = T extends [infer U, ...infer V] ? `${U & string} ${EnXcn<V>}` : '';
15
15
  /**
16
16
  *
17
17
  * 合并 class
@@ -19,7 +19,6 @@ type XCN<T> = T extends [infer U, ...infer V] ? `${U & string} ${XCN<V>}` : '';
19
19
  * merge class name
20
20
  *
21
21
  */
22
- export declare function xcn<T extends ClassNameItem[]>(...classNameList: T): XCN<{
23
- [K in keyof T]: TypeofClassNameItem<T[K]>;
22
+ export declare function xcn<T extends EnClassNameItem[]>(...classNameList: T): EnXcn<{
23
+ [K in keyof T]: EnTypeofClassNameItem<T[K]>;
24
24
  }>;
25
- export {};
package/index.mjs CHANGED
@@ -1 +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};
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};
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "types": "index.d.ts",
5
5
  "name": "xcn",
6
6
  "type": "module",
7
- "version": "0.1.2",
7
+ "version": "1.0.0",
8
8
  "description": "一个用于字符串拼接的小工具,常用于 class name 的拼接",
9
9
  "license": "ISC",
10
10
  "dependencies": {