@standardserver/shared 0.0.3 → 0.0.5

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/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
2
2
 
3
3
  declare const PACKAGE_NAME = "@standardserver/shared";
4
- declare const PACKAGE_VERSION = "0.0.3";
4
+ declare const PACKAGE_VERSION = "0.0.5";
5
5
  /**
6
6
  * Generates a unique symbol for the specified name within the package scope.
7
7
  * The symbol is globally registered using `Symbol.for` to ensure consistency across modules.
@@ -67,7 +67,15 @@ declare function stringifyJSON<T>(value: T | {
67
67
  */
68
68
  declare function isTypescriptObject(maybeObject: unknown): maybeObject is object;
69
69
 
70
- declare function getOrBind<T extends object, K extends PropertyKey>(target: T, property: K): K extends keyof T ? T[K] : unknown;
70
+ interface GetOrBindOptions {
71
+ /**
72
+ * Whether to bind the function to the target before returning it.
73
+ *
74
+ * @default true
75
+ */
76
+ bind?: boolean;
77
+ }
78
+ declare function getOrBind<T extends object, K extends PropertyKey>(target: T, property: K, { bind }?: GetOrBindOptions): K extends keyof T ? T[K] : unknown;
71
79
 
72
80
  interface AsyncIdQueueCloseOptions {
73
81
  id?: string;
@@ -106,4 +114,4 @@ declare function sleep(ms: number): Promise<void>;
106
114
  declare function tryDecodeURIComponent(value: string): string;
107
115
 
108
116
  export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
109
- export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn };
117
+ export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn, GetOrBindOptions };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
2
2
 
3
3
  declare const PACKAGE_NAME = "@standardserver/shared";
4
- declare const PACKAGE_VERSION = "0.0.3";
4
+ declare const PACKAGE_VERSION = "0.0.5";
5
5
  /**
6
6
  * Generates a unique symbol for the specified name within the package scope.
7
7
  * The symbol is globally registered using `Symbol.for` to ensure consistency across modules.
@@ -67,7 +67,15 @@ declare function stringifyJSON<T>(value: T | {
67
67
  */
68
68
  declare function isTypescriptObject(maybeObject: unknown): maybeObject is object;
69
69
 
70
- declare function getOrBind<T extends object, K extends PropertyKey>(target: T, property: K): K extends keyof T ? T[K] : unknown;
70
+ interface GetOrBindOptions {
71
+ /**
72
+ * Whether to bind the function to the target before returning it.
73
+ *
74
+ * @default true
75
+ */
76
+ bind?: boolean;
77
+ }
78
+ declare function getOrBind<T extends object, K extends PropertyKey>(target: T, property: K, { bind }?: GetOrBindOptions): K extends keyof T ? T[K] : unknown;
71
79
 
72
80
  interface AsyncIdQueueCloseOptions {
73
81
  id?: string;
@@ -106,4 +114,4 @@ declare function sleep(ms: number): Promise<void>;
106
114
  declare function tryDecodeURIComponent(value: string): string;
107
115
 
108
116
  export { AbortError, AsyncIdQueue, AsyncIteratorClass, PACKAGE_NAME, PACKAGE_VERSION, SequentialIdGenerator, getOrBind, getPackageSymbol, isAsyncIteratorObject, isTypescriptObject, parseEmptyableJSON, sequential, sleep, stringifyJSON, toArray, tryDecodeURIComponent };
109
- export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn };
117
+ export type { AsyncCleanupFn, AsyncIdQueueCloseOptions, AsyncIdQueueOptions, AsyncIteratorClassNextFn, GetOrBindOptions };
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ function toArray(value) {
3
3
  }
4
4
 
5
5
  const PACKAGE_NAME = "@standardserver/shared";
6
- const PACKAGE_VERSION = "0.0.3";
6
+ const PACKAGE_VERSION = "0.0.5";
7
7
  function getPackageSymbol(name) {
8
8
  return Symbol.for(`${PACKAGE_NAME}@${PACKAGE_VERSION}/${name}`);
9
9
  }
@@ -120,22 +120,19 @@ function isTypescriptObject(maybeObject) {
120
120
  }
121
121
 
122
122
  const GET_OR_BIND_CACHE = /* @__PURE__ */ new WeakMap();
123
- function getOrBind(target, property) {
123
+ function getOrBind(target, property, { bind = true } = {}) {
124
124
  const value = Reflect.get(target, property);
125
- if (typeof value !== "function") {
125
+ if (!bind || typeof value !== "function") {
126
126
  return value;
127
127
  }
128
- let cache = GET_OR_BIND_CACHE.get(target);
129
- if (!cache) {
130
- cache = /* @__PURE__ */ new WeakMap();
131
- GET_OR_BIND_CACHE.set(target, cache);
128
+ let targetCache = GET_OR_BIND_CACHE.get(value);
129
+ if (!targetCache) {
130
+ GET_OR_BIND_CACHE.set(value, targetCache = /* @__PURE__ */ new WeakMap());
132
131
  }
133
- const cached = cache.get(value);
134
- if (cached) {
135
- return cached;
132
+ let bound = targetCache.get(target);
133
+ if (!bound) {
134
+ targetCache.set(target, bound = value.bind(target));
136
135
  }
137
- const bound = value.bind(target);
138
- cache.set(value, bound);
139
136
  return bound;
140
137
  }
141
138
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@standardserver/shared",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "license": "MIT",
6
6
  "homepage": "https://standardserver.dev",
7
7
  "repository": {