@unicom-cloud/utils 0.1.19 → 0.1.20

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.
@@ -0,0 +1,31 @@
1
+ function i() {
2
+ const t = [];
3
+ for (let e = 127744; e <= 129791; e++)
4
+ if (!(e >= 55296 && e <= 57343))
5
+ try {
6
+ const n = String.fromCodePoint(e);
7
+ o(n) && t.push({
8
+ emoji: n,
9
+ code: e.toString(16).toUpperCase().padStart(4, "0"),
10
+ name: r(n)
11
+ });
12
+ } catch {
13
+ }
14
+ return t;
15
+ }
16
+ function r(t) {
17
+ try {
18
+ const n = new Intl.Segmenter("en", { granularity: "grapheme" }).segment(t);
19
+ return Array.from(n)[0]?.segment || t;
20
+ } catch {
21
+ return t;
22
+ }
23
+ }
24
+ function o(t) {
25
+ return /\p{Emoji}/u.test(t);
26
+ }
27
+ export {
28
+ i as getEmojiList,
29
+ r as getEmojiName,
30
+ o as isEmoji
31
+ };
package/constant/index.js CHANGED
@@ -2,27 +2,29 @@ import * as o from "./address.js";
2
2
  import * as t from "./chineseCharacters.js";
3
3
  import * as a from "./constellations.js";
4
4
  import * as r from "./domain.js";
5
- import * as s from "./identity.js";
6
- import * as e from "./keyboardCode.js";
7
- import * as n from "./licensePlate.js";
8
- import * as m from "./name.js";
5
+ import * as s from "./emoji.js";
6
+ import * as e from "./identity.js";
7
+ import * as n from "./keyboardCode.js";
8
+ import * as m from "./licensePlate.js";
9
+ import * as i from "./name.js";
9
10
  import * as p from "./platform.js";
10
- import * as i from "./protocol.js";
11
- import * as c from "./ui.js";
12
- const _ = window.matchMedia(
11
+ import * as c from "./protocol.js";
12
+ import * as _ from "./ui.js";
13
+ const f = window.matchMedia(
13
14
  "(prefers-color-scheme: dark)"
14
15
  );
15
16
  export {
16
- _ as MATCH_MEDIA_PREFERS_COLOR_SCHEME_DARK,
17
+ f as MATCH_MEDIA_PREFERS_COLOR_SCHEME_DARK,
17
18
  t as chineseCharacters,
18
19
  a as constellations,
19
20
  o as date,
20
21
  r as domain,
21
- s as identity,
22
- e as keyboardCode,
23
- n as licensePlate,
24
- m as name,
22
+ s as emoji,
23
+ e as identity,
24
+ n as keyboardCode,
25
+ m as licensePlate,
26
+ i as name,
25
27
  p as platform,
26
- i as protocol,
27
- c as ui
28
+ c as protocol,
29
+ _ as ui
28
30
  };
@@ -1,19 +1,20 @@
1
- const i = navigator.userAgent.toLowerCase(), t = window.__wxjs_environment === "miniprogram" || !!window.wx?.getSystemInfoSync, a = /micromessenger/i.test(i), r = /dingtalk/i.test(i), c = /alipay|aliapp/i.test(i), n = /ipad|iphone|ipod/i.test(i), e = /android/i.test(i), w = /openharmony/i.test(i), s = /macintosh|mac os x/i.test(i), d = n || s, m = /windows|win32|win64|wow64/i.test(
1
+ const i = navigator.userAgent.toLowerCase(), s = window.__wxjs_environment === "miniprogram" || !!window.wx?.getSystemInfoSync, a = /micromessenger/i.test(i), r = /dingtalk/i.test(i), w = /alipay|aliapp/i.test(i), n = /ipad|iphone|ipod/i.test(i), e = /android/i.test(i), c = /openharmony/i.test(i), t = /macintosh|mac os x/i.test(i), d = n || t, m = /windows|win32|win64|wow64/i.test(
2
2
  i
3
3
  ), l = (n || e || /windows phone|blackberry|mobile|webos|iemobile|opera (mini|mobi)/i.test(
4
4
  i
5
- )) && ("ontouchend" in document || "ontouchend" in window), p = ["fullscreen", "standalone", "minimal-ui"].some((o) => window.matchMedia(`(display-mode: ${o})`).matches) || window.navigator.standalone === !0;
5
+ )) && ("ontouchend" in document || "ontouchend" in window), p = ["fullscreen", "standalone", "minimal-ui"].some((o) => window.matchMedia(`(display-mode: ${o})`).matches) || window.navigator.standalone === !0, g = !!(typeof window < "u" && window.document && window.document.createElement);
6
6
  export {
7
- c as isAlipayBrowser,
7
+ w as isAlipayBrowser,
8
8
  e as isAndroidOS,
9
9
  d as isAppleDevice,
10
+ g as isBrowser,
10
11
  r as isDingtalkBrowser,
11
- w as isHarmony,
12
+ c as isHarmony,
12
13
  n as isIOS_OS,
13
- s as isMacOS,
14
+ t as isMacOS,
14
15
  l as isMobileDevice,
15
16
  p as isPWA,
16
17
  a as isWeChatBrowser,
17
- t as isWeChatMiniProgram,
18
+ s as isWeChatMiniProgram,
18
19
  m as isWindowsOS
19
20
  };
package/constant.js CHANGED
@@ -2,13 +2,14 @@ import * as o from "./constant/address.js";
2
2
  import * as t from "./constant/chineseCharacters.js";
3
3
  import * as a from "./constant/constellations.js";
4
4
  import * as r from "./constant/domain.js";
5
- import * as s from "./constant/identity.js";
6
- import * as e from "./constant/keyboardCode.js";
7
- import * as n from "./constant/licensePlate.js";
8
- import * as m from "./constant/name.js";
9
- import * as p from "./constant/platform.js";
10
- import * as i from "./constant/protocol.js";
11
- import * as c from "./constant/ui.js";
5
+ import * as s from "./constant/emoji.js";
6
+ import * as e from "./constant/identity.js";
7
+ import * as n from "./constant/keyboardCode.js";
8
+ import * as m from "./constant/licensePlate.js";
9
+ import * as p from "./constant/name.js";
10
+ import * as i from "./constant/platform.js";
11
+ import * as c from "./constant/protocol.js";
12
+ import * as _ from "./constant/ui.js";
12
13
  import { MATCH_MEDIA_PREFERS_COLOR_SCHEME_DARK as l } from "./constant/index.js";
13
14
  export {
14
15
  l as MATCH_MEDIA_PREFERS_COLOR_SCHEME_DARK,
@@ -16,11 +17,12 @@ export {
16
17
  a as constellations,
17
18
  o as date,
18
19
  r as domain,
19
- s as identity,
20
- e as keyboardCode,
21
- n as licensePlate,
22
- m as name,
23
- p as platform,
24
- i as protocol,
25
- c as ui
20
+ s as emoji,
21
+ e as identity,
22
+ n as keyboardCode,
23
+ m as licensePlate,
24
+ p as name,
25
+ i as platform,
26
+ c as protocol,
27
+ _ as ui
26
28
  };
@@ -0,0 +1,4 @@
1
+ import { Emitter as r } from "./src/index.js";
2
+ export {
3
+ r as default
4
+ };
@@ -0,0 +1,95 @@
1
+ class a {
2
+ constructor(e = /* @__PURE__ */ new Map()) {
3
+ this.all = e;
4
+ }
5
+ /**
6
+ * 为指定类型注册一个事件处理函数
7
+ * @param type 要监听的事件类型
8
+ * @param handler 响应事件时要调用的函数
9
+ */
10
+ on(e, t) {
11
+ if (typeof t != "function") throw new Error(`${String(e)}: handler 必须为函数`);
12
+ const l = this.all.get(e) || /* @__PURE__ */ new Set();
13
+ l.add(t), this.all.set(e, l);
14
+ }
15
+ /**
16
+ * 为指定类型注册一个事件处理函数(只首次调用起作用,之后将被移除)
17
+ * @param type 要监听的事件类型
18
+ * @param handler 响应事件时要调用的函数
19
+ */
20
+ once(e, t) {
21
+ const l = (...s) => {
22
+ t(...s), this.off(e, l);
23
+ };
24
+ this.on(e, l);
25
+ }
26
+ /**
27
+ * 移除指定类型的事件处理函数
28
+ * 如果省略 `handler` 参数,则移除该类型的所有处理函数
29
+ * @param type 要移除处理函数的事件类型
30
+ * @param handler 要移除的处理函数
31
+ */
32
+ off(e, t) {
33
+ const l = this.all.get(e);
34
+ l && (t ? l.delete(t) : l.clear(), l.size || this.offAll(e));
35
+ }
36
+ /**
37
+ * 移除指定类型的所有事件处理函数
38
+ * 如果省略 `type` 参数,则移除所有处理函数
39
+ * @param type 要移除处理函数的事件类型
40
+ */
41
+ offAll(e) {
42
+ e ? this.all.delete(e) : this.all.clear();
43
+ }
44
+ /**
45
+ * 调用指定类型的所有处理函数
46
+ * @param type 要触发的事件类型
47
+ * @param args 传递给处理函数的参数
48
+ */
49
+ emit(e, ...t) {
50
+ const l = this.all.get(e);
51
+ if (!l) return;
52
+ const s = Array.from(l);
53
+ for (const r of s)
54
+ r(...t);
55
+ }
56
+ /**
57
+ * 获取指定类型的事件处理函数数量
58
+ * @param type 事件类型
59
+ * @returns 处理函数数量
60
+ */
61
+ getHandlerCount(e) {
62
+ return this.all.get(e)?.size ?? 0;
63
+ }
64
+ /**
65
+ * 检查指定类型是否有事件处理函数
66
+ * @param type 事件类型
67
+ * @returns 是否存在处理函数
68
+ */
69
+ hasHandlers(e) {
70
+ return this.getHandlerCount(e) > 0;
71
+ }
72
+ /**
73
+ * 获取所有已注册的事件类型
74
+ * @returns 事件类型数组
75
+ */
76
+ getEventTypes() {
77
+ return Array.from(this.all.keys());
78
+ }
79
+ /**
80
+ * 清空所有事件监听器
81
+ */
82
+ clear() {
83
+ this.offAll();
84
+ }
85
+ /**
86
+ * 销毁实例,释放资源
87
+ */
88
+ destroy() {
89
+ this.clear(), this.all = /* @__PURE__ */ new Map();
90
+ }
91
+ }
92
+ export {
93
+ a as Emitter,
94
+ a as default
95
+ };
package/emitter.js ADDED
@@ -0,0 +1,4 @@
1
+ import { Emitter as r } from "./emitter/src/index.js";
2
+ export {
3
+ r as default
4
+ };
package/index.js CHANGED
@@ -14,15 +14,15 @@ import { default as k, getContentDispositionFromHeader as y, getContentDispositi
14
14
  import { splitCookiesString as D } from "./cookie/index.js";
15
15
  import { default as S } from "./decimal/decimal.js";
16
16
  import { default as j } from "./diff/src/diff.js";
17
- import { fileToURL as L } from "./file/fileToURL.js";
18
- import { saveAs as P } from "./file/saveAs.js";
17
+ import { Emitter as L } from "./emitter/src/index.js";
18
+ import { fileToURL as P } from "./file/fileToURL.js";
19
+ import { saveAs as E } from "./file/saveAs.js";
19
20
  import * as f from "./filesize/src/constants.js";
20
- import { filesize as K, partial as R } from "./filesize/src/filesize.js";
21
- import { default as W } from "./invariant/index.js";
22
- import { default as q } from "./js-cookie/src/api.js";
21
+ import { filesize as R, partial as U } from "./filesize/src/filesize.js";
22
+ import { default as $ } from "./invariant/index.js";
23
+ import { default as w } from "./js-cookie/src/api.js";
23
24
  import * as n from "./lunar/lib/index.js";
24
- import { default as B } from "./md5/index.js";
25
- import { default as G } from "./mitt/src/index.js";
25
+ import { default as G } from "./md5/index.js";
26
26
  import { default as J } from "./normalize-wheel/index.js";
27
27
  import { default as O } from "./number-to-chinese/index.js";
28
28
  import { default as V } from "./nzh/nzh.js";
@@ -42,25 +42,25 @@ export {
42
42
  e as date,
43
43
  S as decimal,
44
44
  j as diff,
45
- L as fileToURL,
46
- K as filesize,
45
+ L as emitter,
46
+ P as fileToURL,
47
+ R as filesize,
47
48
  f as filesizeConstants,
48
49
  y as getContentDispositionFromHeader,
49
50
  T as getContentDispositionParametersFilenameFromHeader,
50
51
  g as getContentDispositionParametersFromHeader,
51
- W as invariant,
52
+ $ as invariant,
52
53
  r as is,
53
- q as jsCookie,
54
+ w as jsCookie,
54
55
  t as math,
55
- B as md5,
56
- G as mitt,
56
+ G as md5,
57
57
  J as normalizeWheel,
58
58
  O as numberToChinese,
59
59
  V as nzh,
60
60
  Y as objectKeysSort,
61
- R as partial,
61
+ U as partial,
62
62
  oo as pinyin,
63
- P as saveAs,
63
+ E as saveAs,
64
64
  ro as screenfull,
65
65
  a as snapdom,
66
66
  D as splitCookiesString,
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@unicom-cloud/utils","version":"0.1.19","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/index.d.ts","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
1
+ {"name":"@unicom-cloud/utils","version":"0.1.20","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/index.d.ts","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
@@ -0,0 +1,7 @@
1
+ export function getEmojiList(): {
2
+ emoji: string;
3
+ code: string;
4
+ name: any;
5
+ }[];
6
+ export function getEmojiName(emoji: any): any;
7
+ export function isEmoji(char: any): boolean;
@@ -2,6 +2,7 @@ export * as date from "./address";
2
2
  export * as chineseCharacters from "./chineseCharacters";
3
3
  export * as constellations from "./constellations";
4
4
  export * as domain from "./domain";
5
+ export * as emoji from "./emoji";
5
6
  export * as identity from "./identity";
6
7
  export * as keyboardCode from "./keyboardCode";
7
8
  export * as licensePlate from "./licensePlate";
@@ -10,3 +10,4 @@ export const isAppleDevice: boolean;
10
10
  export const isWindowsOS: boolean;
11
11
  export const isMobileDevice: boolean;
12
12
  export const isPWA: boolean;
13
+ export const isBrowser: boolean;
@@ -0,0 +1,73 @@
1
+ export type EventType = string | symbol;
2
+ export type Handler = (...args: unknown[]) => void;
3
+ export interface EmitterInterface {
4
+ on(type: EventType, handler: Handler): void;
5
+ once(type: EventType, handler: Handler): void;
6
+ off(type: EventType, handler?: Handler): void;
7
+ offAll(type?: EventType): void;
8
+ emit(type: EventType, ...args: unknown[]): void;
9
+ }
10
+ /**
11
+ * Emitter: 类式事件发射器 / 发布-订阅模式实现
12
+ */
13
+ export declare class Emitter implements EmitterInterface {
14
+ private all;
15
+ constructor(all?: typeof this.all);
16
+ /**
17
+ * 为指定类型注册一个事件处理函数
18
+ * @param type 要监听的事件类型
19
+ * @param handler 响应事件时要调用的函数
20
+ */
21
+ on(type: EventType, handler: Handler): void;
22
+ /**
23
+ * 为指定类型注册一个事件处理函数(只首次调用起作用,之后将被移除)
24
+ * @param type 要监听的事件类型
25
+ * @param handler 响应事件时要调用的函数
26
+ */
27
+ once(type: EventType, handler: Handler): void;
28
+ /**
29
+ * 移除指定类型的事件处理函数
30
+ * 如果省略 `handler` 参数,则移除该类型的所有处理函数
31
+ * @param type 要移除处理函数的事件类型
32
+ * @param handler 要移除的处理函数
33
+ */
34
+ off(type: EventType, handler?: Handler): void;
35
+ /**
36
+ * 移除指定类型的所有事件处理函数
37
+ * 如果省略 `type` 参数,则移除所有处理函数
38
+ * @param type 要移除处理函数的事件类型
39
+ */
40
+ offAll(type?: EventType): void;
41
+ /**
42
+ * 调用指定类型的所有处理函数
43
+ * @param type 要触发的事件类型
44
+ * @param args 传递给处理函数的参数
45
+ */
46
+ emit(type: EventType, ...args: unknown[]): void;
47
+ /**
48
+ * 获取指定类型的事件处理函数数量
49
+ * @param type 事件类型
50
+ * @returns 处理函数数量
51
+ */
52
+ getHandlerCount(type: EventType): number;
53
+ /**
54
+ * 检查指定类型是否有事件处理函数
55
+ * @param type 事件类型
56
+ * @returns 是否存在处理函数
57
+ */
58
+ hasHandlers(type: EventType): boolean;
59
+ /**
60
+ * 获取所有已注册的事件类型
61
+ * @returns 事件类型数组
62
+ */
63
+ getEventTypes(): EventType[];
64
+ /**
65
+ * 清空所有事件监听器
66
+ */
67
+ clear(): void;
68
+ /**
69
+ * 销毁实例,释放资源
70
+ */
71
+ destroy(): void;
72
+ }
73
+ export default Emitter;
package/types/index.d.ts CHANGED
@@ -12,11 +12,11 @@ export { default as className } from "./class-name";
12
12
  export { default as clipboardCopy } from "./clipboard-copy";
13
13
  export { default as decimal } from "./decimal";
14
14
  export { default as diff } from "./diff";
15
+ export { default as emitter } from "./emitter";
15
16
  export { default as invariant } from "./invariant";
16
17
  export { default as jsCookie } from "./js-cookie";
17
18
  export { default as Lunar } from "./lunar";
18
19
  export { default as md5 } from "./md5";
19
- export { default as mitt } from "./mitt";
20
20
  export { default as normalizeWheel } from "./normalize-wheel";
21
21
  export { default as numberToChinese } from "./number-to-chinese";
22
22
  export { default as nzh } from "./nzh";
package/mitt/index.js DELETED
@@ -1,4 +0,0 @@
1
- import { default as o } from "./src/index.js";
2
- export {
3
- o as default
4
- };
package/mitt/src/index.js DELETED
@@ -1,31 +0,0 @@
1
- function l(o = /* @__PURE__ */ new Map()) {
2
- function f(e, t) {
3
- if (typeof t != "function") throw new Error(`${String(e)}: handler 必须为函数`);
4
- const n = o.get(e) || /* @__PURE__ */ new Set();
5
- n.add(t), o.set(e, n);
6
- }
7
- function c(e, t) {
8
- const n = (...r) => {
9
- t(...r), s(e, n);
10
- };
11
- f(e, n);
12
- }
13
- function s(e, t) {
14
- const n = o.get(e);
15
- n && (t ? n.delete(t) : n.clear(), n.size || i(e));
16
- }
17
- function i(e) {
18
- e ? o.delete(e) : o.clear();
19
- }
20
- function u(e, ...t) {
21
- const n = o.get(e);
22
- if (!n) return;
23
- const r = Array.from(n);
24
- for (const d of r)
25
- d(...t);
26
- }
27
- return { on: f, once: c, off: s, offAll: i, emit: u };
28
- }
29
- export {
30
- l as default
31
- };
package/mitt.js DELETED
@@ -1,4 +0,0 @@
1
- import { default as o } from "./mitt/src/index.js";
2
- export {
3
- o as default
4
- };
@@ -1,15 +0,0 @@
1
- export type EventType = string | symbol;
2
- export type Handler = (...args: unknown[]) => void;
3
- export interface Emitter {
4
- on(type: EventType, handler: Handler): void;
5
- once(type: EventType, handler: Handler): void;
6
- off(type: EventType, handler?: Handler): void;
7
- offAll(type?: EventType): void;
8
- emit(type: EventType, ...args: unknown[]): void;
9
- }
10
- /**
11
- * Mitt: 函数式事件发射器 / 发布-订阅模式实现
12
- * @name mitt
13
- * @returns {Emitter}
14
- */
15
- export default function mitt(all?: Map<EventType, Set<Handler>>): Emitter;
File without changes