@omnific/utils 0.5.0 → 0.6.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.
@@ -0,0 +1,23 @@
1
+ /** 发射器订阅者。 */
2
+ export type EmitterListener<T> = (value: T) => void;
3
+ /** 提供订阅能力的对象。 */
4
+ export interface Subscribable<T = void> {
5
+ /** 订阅变化,返回取消订阅函数。 */
6
+ readonly subscribe: (listener: EmitterListener<T>) => () => void;
7
+ }
8
+ /** 单通道变更发射器。 */
9
+ export interface Emitter<T = void> extends Subscribable<T> {
10
+ /** 通知所有订阅者。 */
11
+ readonly emit: (value: T) => void;
12
+ }
13
+ /**
14
+ * 创建单通道变更发射器。
15
+ *
16
+ * 只负责保存订阅者并在 `emit` 时逐个触发,不包含状态与通知时机。
17
+ *
18
+ * @example
19
+ * const emitter = createEmitter<string>();
20
+ * const unsubscribe = emitter.subscribe(value => console.log(value));
21
+ * emitter.emit('ready');
22
+ */
23
+ export declare const createEmitter: <T = void>() => Emitter<T>;
@@ -0,0 +1,28 @@
1
+ // createEmitter.ts
2
+ /**
3
+ * 创建单通道变更发射器。
4
+ *
5
+ * 只负责保存订阅者并在 `emit` 时逐个触发,不包含状态与通知时机。
6
+ *
7
+ * @example
8
+ * const emitter = createEmitter<string>();
9
+ * const unsubscribe = emitter.subscribe(value => console.log(value));
10
+ * emitter.emit('ready');
11
+ */
12
+ const createEmitter = () => {
13
+ const listeners = /* @__PURE__ */ new Set();
14
+ const subscribe = (listener) => {
15
+ listeners.add(listener);
16
+ return () => {
17
+ listeners.delete(listener);
18
+ };
19
+ };
20
+ const emit = (value) => {
21
+ for (const listener of listeners) listener(value);
22
+ };
23
+ return {
24
+ subscribe,
25
+ emit
26
+ };
27
+ };
28
+ export { createEmitter };
package/dist/main.d.ts CHANGED
@@ -4,11 +4,13 @@ import { isArrayEmpty } from "./isArrayEmpty.js";
4
4
  import { isBoolean } from "./isBoolean.js";
5
5
  import { isBlob } from "./isBlob.js";
6
6
  import { ChainedFunction, createChainedFunction } from "./createChainedFunction.js";
7
+ import { Emitter, EmitterListener, Subscribable, createEmitter } from "./createEmitter.js";
7
8
  import { DebounceOptions, DebouncedFunction, debounce } from "./debounce.js";
8
9
  import { isFunction } from "./isFunction.js";
9
10
  import hasValue from "./hasValue.js";
10
11
  import { isFormData } from "./isFormData.js";
11
12
  import { isNil } from "./isNil.js";
13
+ import { noop } from "./noop.js";
12
14
  import { isNumber } from "./isNumber.js";
13
15
  import { isPlainObject } from "./isPlainObject.js";
14
16
  import { isString } from "./isString.js";
@@ -26,4 +28,4 @@ import { isSymbol } from "./isSymbol.js";
26
28
  import { ThrottleOptions, ThrottledFunction, throttle } from "./throttle.js";
27
29
  import resolveValue from "./resolveValue.js";
28
30
  import { uniqueId } from "./uniqueId.js";
29
- export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type QueryInput, type QueryParameters, type QueryValue, type ThrottleOptions, type ThrottledFunction, buildURL, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, kebabCase, parseJson, resolveValue, throttle, uniqueId };
31
+ export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type Emitter, type EmitterListener, type QueryInput, type QueryParameters, type QueryValue, type Subscribable, type ThrottleOptions, type ThrottledFunction, buildURL, createChainedFunction, createEmitter, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, kebabCase, noop, parseJson, resolveValue, throttle, uniqueId };
package/dist/main.js CHANGED
@@ -4,11 +4,13 @@ import { isArrayEmpty } from "./isArrayEmpty.js";
4
4
  import { isBoolean } from "./isBoolean.js";
5
5
  import { isBlob } from "./isBlob.js";
6
6
  import { createChainedFunction } from "./createChainedFunction.js";
7
+ import { createEmitter } from "./createEmitter.js";
7
8
  import { debounce } from "./debounce.js";
8
9
  import { isFunction } from "./isFunction.js";
9
10
  import hasValue from "./hasValue.js";
10
11
  import { isFormData } from "./isFormData.js";
11
12
  import { isNil } from "./isNil.js";
13
+ import { noop } from "./noop.js";
12
14
  import { isNumber } from "./isNumber.js";
13
15
  import { isPlainObject } from "./isPlainObject.js";
14
16
  import { isString } from "./isString.js";
@@ -26,4 +28,4 @@ import { isSymbol } from "./isSymbol.js";
26
28
  import { throttle } from "./throttle.js";
27
29
  import resolveValue from "./resolveValue.js";
28
30
  import { uniqueId } from "./uniqueId.js";
29
- export { buildURL, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, kebabCase, parseJson, resolveValue, throttle, uniqueId };
31
+ export { buildURL, createChainedFunction, createEmitter, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, kebabCase, noop, parseJson, resolveValue, throttle, uniqueId };
package/dist/noop.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 不执行任何操作的空函数。
3
+ */
4
+ export declare const noop: () => void;
package/dist/noop.js ADDED
@@ -0,0 +1,6 @@
1
+ // noop.ts
2
+ /**
3
+ * 不执行任何操作的空函数。
4
+ */
5
+ const noop = () => {};
6
+ export { noop };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnific/utils",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Shared utilities for Omnific packages",
5
5
  "license": "MIT",
6
6
  "type": "module",