@ceale/util 1.5.0 → 1.7.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/cjs/index.js CHANGED
@@ -29,7 +29,8 @@ var __export = (target, all) => {
29
29
  // src/index.ts
30
30
  var exports_src = {};
31
31
  __export(exports_src, {
32
- URI: () => URI
32
+ uri: () => uri,
33
+ css: () => css
33
34
  });
34
35
  module.exports = __toCommonJS(exports_src);
35
36
 
@@ -95,12 +96,12 @@ Object.defineProperty(String.prototype, "toKebabCase", {
95
96
  enumerable: false
96
97
  });
97
98
  // src/uri.ts
98
- var URI;
99
- ((URI) => {
99
+ var uri;
100
+ ((uri) => {
100
101
  const leftSlash = /^\/(?=[^\/])/g;
101
102
  const rightSlash = /(?<=[^\/])\/$/g;
102
103
  const innerSlash = /(?<=[^\/])\/(?=[^\/])/g;
103
- URI.join = (...path) => {
104
+ uri.join = (...path) => {
104
105
  return path.filter((path2) => path2.length > 0).map((path2, index, pathArray) => {
105
106
  if (index === 0) {
106
107
  return path2.replace(rightSlash, "").split(innerSlash);
@@ -129,7 +130,7 @@ var URI;
129
130
  }
130
131
  }, "");
131
132
  };
132
- })(URI ||= {});
133
+ })(uri ||= {});
133
134
  // src/class.ts
134
135
  Object.defineProperty(Function.prototype, "isDirectSubclass", {
135
136
  value: function(potentialChild) {
@@ -181,3 +182,21 @@ Object.defineProperty(Function.prototype, "isInstance", {
181
182
  configurable: true,
182
183
  enumerable: false
183
184
  });
185
+ // src/css.ts
186
+ var css;
187
+ ((css) => {
188
+ css.rule = (rule2) => {
189
+ return Object.entries(rule2).map(([key, value]) => `${key.toKebabCase()}: ${value};`).join(`
190
+ `);
191
+ };
192
+ css.selector = (selector2, rule2) => {
193
+ return selector2 + "{" + rule2 + "}";
194
+ };
195
+ css.at = (identifier, rule2) => {
196
+ return identifier + (rule2 ? "{" + rule2 + "}" : "");
197
+ };
198
+ css.join = (...rules) => {
199
+ return rules.join(`
200
+ `);
201
+ };
202
+ })(css ||= {});
package/dist/esm/index.js CHANGED
@@ -60,12 +60,12 @@ Object.defineProperty(String.prototype, "toKebabCase", {
60
60
  enumerable: false
61
61
  });
62
62
  // src/uri.ts
63
- var URI;
64
- ((URI) => {
63
+ var uri;
64
+ ((uri) => {
65
65
  const leftSlash = /^\/(?=[^\/])/g;
66
66
  const rightSlash = /(?<=[^\/])\/$/g;
67
67
  const innerSlash = /(?<=[^\/])\/(?=[^\/])/g;
68
- URI.join = (...path) => {
68
+ uri.join = (...path) => {
69
69
  return path.filter((path2) => path2.length > 0).map((path2, index, pathArray) => {
70
70
  if (index === 0) {
71
71
  return path2.replace(rightSlash, "").split(innerSlash);
@@ -94,7 +94,7 @@ var URI;
94
94
  }
95
95
  }, "");
96
96
  };
97
- })(URI ||= {});
97
+ })(uri ||= {});
98
98
  // src/class.ts
99
99
  Object.defineProperty(Function.prototype, "isDirectSubclass", {
100
100
  value: function(potentialChild) {
@@ -146,6 +146,25 @@ Object.defineProperty(Function.prototype, "isInstance", {
146
146
  configurable: true,
147
147
  enumerable: false
148
148
  });
149
+ // src/css.ts
150
+ var css;
151
+ ((css) => {
152
+ css.rule = (rule2) => {
153
+ return Object.entries(rule2).map(([key, value]) => `${key.toKebabCase()}: ${value};`).join(`
154
+ `);
155
+ };
156
+ css.selector = (selector2, rule2) => {
157
+ return selector2 + "{" + rule2 + "}";
158
+ };
159
+ css.at = (identifier, rule2) => {
160
+ return identifier + (rule2 ? "{" + rule2 + "}" : "");
161
+ };
162
+ css.join = (...rules) => {
163
+ return rules.join(`
164
+ `);
165
+ };
166
+ })(css ||= {});
149
167
  export {
150
- URI
168
+ uri,
169
+ css
151
170
  };
@@ -2,29 +2,29 @@ type AnyClass = new (...args: any[]) => any;
2
2
  declare global {
3
3
  interface Function {
4
4
  /**
5
- * 检查 `potentialChild` 是否是当前类的直接子类。
6
- * @param potentialChild 潜在的子类构造函数。
7
- * @returns 如果是直接子类,则返回 `true`;否则返回 `false`。
5
+ * 检查 `potentialChild` 是否是当前类的直接子类
6
+ * @param potentialChild 潜在的子类构造函数
7
+ * @returns 如果是直接子类,则返回 `true`;否则返回 `false`
8
8
  */
9
9
  isDirectSubclass(this: AnyClass, potentialChild: unknown): boolean;
10
10
  /**
11
- * 检查 `potentialDescendant` 是否是当前类的子孙类或当前类本身。
12
- * @param potentialDescendant 潜在的子孙类或类本身。
13
- * @returns 如果是子孙类或类本身,则返回 `true`;否则返回 `false`。
11
+ * 检查 `potentialDescendant` 是否是当前类的子孙类或当前类本身
12
+ * @param potentialDescendant 潜在的子孙类或类本身
13
+ * @returns 如果是子孙类或类本身,则返回 `true`;否则返回 `false`
14
14
  */
15
15
  isSubclass(this: AnyClass, potentialDescendant: unknown): boolean;
16
16
  /**
17
- * 检查 `potentialInstance` 是否由当前类直接构造。
18
- * 判断依据: `Object.getPrototypeOf(potentialInstance).constructor === this`。
19
- * @param potentialInstance 潜在的实例对象。
20
- * @returns 如果是由当前类直接创建的实例,则返回 `true`;否则返回 `false`。
17
+ * 检查 `potentialInstance` 是否由当前类直接构造
18
+ * 判断依据: `Object.getPrototypeOf(potentialInstance).constructor === this`
19
+ * @param potentialInstance 潜在的实例对象
20
+ * @returns 如果是由当前类直接创建的实例,则返回 `true`;否则返回 `false`
21
21
  */
22
22
  isDirectInstance(this: AnyClass, potentialInstance: unknown): boolean;
23
23
  /**
24
- * 检查 `potentialInstance` 是否是当前类或其任何子类的实例。
25
- * 内部使用 `instanceof` 操作符。
26
- * @param potentialInstance 潜在的实例对象。
27
- * @returns 如果是实例,则返回 `true`;否则返回 `false`。
24
+ * 检查 `potentialInstance` 是否是当前类或其任何子类的实例
25
+ * 内部使用 `instanceof` 操作符
26
+ * @param potentialInstance 潜在的实例对象
27
+ * @returns 如果是实例,则返回 `true`;否则返回 `false`
28
28
  */
29
29
  isInstance(this: AnyClass, potentialInstance: unknown): boolean;
30
30
  }
@@ -0,0 +1,77 @@
1
+ import type { CSSProperties } from "vue";
2
+ import type { AtRules } from "csstype";
3
+ export declare namespace css {
4
+ const RuleValueSymbol: unique symbol;
5
+ type RuleValue = string & {
6
+ [RuleValueSymbol]: never;
7
+ };
8
+ const RuleBlockValueSymbol: unique symbol;
9
+ type RuleBlockValue = string & {
10
+ [RuleBlockValueSymbol]: never;
11
+ };
12
+ const AtValueSymbol: unique symbol;
13
+ type AtValue = string & {
14
+ [AtValueSymbol]: never;
15
+ };
16
+ /**
17
+ * 从一个样式对象,创建一个 CSS 规则字符串
18
+ * @param styles 一个样式对象,使用 Vue 的 `CSSProperties` 类型,同时允许自定义属性
19
+ * @returns 返回类型为`RuleValue`的字符串,可以传入`css.selector()`和`css.at()`
20
+ *
21
+ * @example
22
+ * css.rule({
23
+ * backgroundColor: "red",
24
+ * fontSize: "16px",
25
+ * "--my-custom-var": "blue"
26
+ * })
27
+ */
28
+ export const rule: (rule: CSSProperties & {
29
+ [key: string]: string;
30
+ }) => RuleValue;
31
+ /**
32
+ * 根据选择器和 CSS 规则,创建一个 CSS 规则块字符串
33
+ * @param selector CSS 选择器字符串
34
+ * @param rule CSS 规则,类型为`RuleValue`的字符串
35
+ * @returns 返回类型为`RuleBlockValue`的字符串,可以传入`css.at()`和`css.join()`
36
+ *
37
+ * @example
38
+ * css.selector(
39
+ * "#my-element",
40
+ * css.rule({
41
+ * color: "blue"
42
+ * })
43
+ * ) // -> "#my-element { color: blue; }"
44
+ */
45
+ export const selector: (selector: string, rule: RuleValue) => RuleBlockValue;
46
+ /**
47
+ * 根据 @ 规则和可选的 CSS 规则或规则块,创建一个 @ 规则块字符串
48
+ * @param identifier @ 规则,如 "@media (min-width: 768px)"
49
+ * @param rule 可选,类型为`RuleValue`的字符串,或类型为`SelectorValue`的字符串
50
+ * @returns 返回类型为`AtValue`的字符串,可以传入`css.join()`
51
+ *
52
+ * @example
53
+ * css.at(
54
+ * "@font-face",
55
+ * css.rule({
56
+ * scr: "..."
57
+ * })
58
+ * ) // -> "@font-face { scr: "..."; }"
59
+ *
60
+ * @example
61
+ * css.at(
62
+ * "@media (min-width: 768px)",
63
+ * css.selector(
64
+ * "#my-element",
65
+ * css.rule(...)
66
+ * )
67
+ * ) // -> "@media (min-width: 768px) { #my-element { ... } }"
68
+ */
69
+ export const at: (identifier: AtRules | (string & {}), rule?: RuleValue | RuleBlockValue) => AtValue;
70
+ /**
71
+ * 拼接 CSS 规则块和 @ 规则块,返回一个字符串
72
+ * @param rules CSS 规则块和 @ 规则块,类型为`RuleBlockValue`或`AtValue`的字符串
73
+ * @returns 返回标准的字符串
74
+ */
75
+ export const join: (...rules: (RuleBlockValue | AtValue)[]) => string;
76
+ export {};
77
+ }
@@ -1,3 +1,4 @@
1
1
  export * from "./string";
2
2
  export * from "./uri";
3
3
  export * from "./class";
4
+ export * from "./css";
@@ -1,3 +1,24 @@
1
- export declare namespace URI {
1
+ export declare namespace uri {
2
+ /**
3
+ * 拼接路径字符串:
4
+ * - 解析路径中的 `.` 和 `..`
5
+ * - 保留 URL 协议头 (如 `http://`) 和协议自适应的开头 (如 `//domain`)
6
+ * - 保留主动传入的连续斜杠 (如 `a//b`)
7
+ *
8
+ * @param path 若干个要拼接的路径片段
9
+ * @returns 拼接后的路径字符串
10
+ *
11
+ * @example
12
+ * // 基础拼接
13
+ * uri.join('/a/', 'b', '/c') // -> "/a/b/c"
14
+ *
15
+ * @example
16
+ * // 路径解析
17
+ * uri.join('/a/b/../c') // -> "/a/c"
18
+ *
19
+ * @example
20
+ * // 保留协议头
21
+ * uri.join("http://example.com", "a") // -> "http://example.com/a"
22
+ */
2
23
  const join: (...path: string[]) => string;
3
24
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ceale/util",
3
3
  "author": "Ceale",
4
- "version": "1.5.0",
4
+ "version": "1.7.0",
5
5
  "module": "index.ts",
6
6
  "type": "module",
7
7
  "main": "dist/esm/index.js",
@@ -29,5 +29,9 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "typescript": "^5"
32
+ },
33
+ "dependencies": {
34
+ "@types/vue": "^2.0.0",
35
+ "csstype": "^3.1.3"
32
36
  }
33
37
  }