@orpc/shared 0.0.0-next.b2e67f7 → 0.0.0-next.b36125c
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.js +40 -0
- package/dist/src/function.d.ts +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/iterator.d.ts +2 -0
- package/dist/src/json.d.ts +3 -0
- package/dist/src/object.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -48,6 +48,9 @@ function isObject(value2) {
|
|
|
48
48
|
const proto = Object.getPrototypeOf(value2);
|
|
49
49
|
return proto === Object.prototype || !proto || !proto.constructor;
|
|
50
50
|
}
|
|
51
|
+
function isTypescriptObject(value2) {
|
|
52
|
+
return !!value2 && (typeof value2 === "object" || typeof value2 === "function");
|
|
53
|
+
}
|
|
51
54
|
|
|
52
55
|
// src/error.ts
|
|
53
56
|
function toError(error) {
|
|
@@ -68,6 +71,19 @@ function toError(error) {
|
|
|
68
71
|
return new Error("Unknown error", { cause: error });
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
// src/function.ts
|
|
75
|
+
function once(fn) {
|
|
76
|
+
let cached;
|
|
77
|
+
return () => {
|
|
78
|
+
if (cached) {
|
|
79
|
+
return cached.result;
|
|
80
|
+
}
|
|
81
|
+
const result = fn();
|
|
82
|
+
cached = { result };
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
71
87
|
// src/interceptor.ts
|
|
72
88
|
function onStart(callback) {
|
|
73
89
|
return async (options, ...rest) => {
|
|
@@ -122,6 +138,25 @@ async function intercept(interceptors, options, main) {
|
|
|
122
138
|
return await next(options);
|
|
123
139
|
}
|
|
124
140
|
|
|
141
|
+
// src/iterator.ts
|
|
142
|
+
function isAsyncIteratorObject(maybe) {
|
|
143
|
+
if (!maybe || typeof maybe !== "object") {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/json.ts
|
|
150
|
+
function parseEmptyableJSON(text) {
|
|
151
|
+
if (!text) {
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
return JSON.parse(text);
|
|
155
|
+
}
|
|
156
|
+
function stringifyJSON(value2) {
|
|
157
|
+
return JSON.stringify(value2);
|
|
158
|
+
}
|
|
159
|
+
|
|
125
160
|
// src/value.ts
|
|
126
161
|
function value(value2, ...args) {
|
|
127
162
|
if (typeof value2 === "function") {
|
|
@@ -138,7 +173,9 @@ export {
|
|
|
138
173
|
group,
|
|
139
174
|
guard,
|
|
140
175
|
intercept,
|
|
176
|
+
isAsyncIteratorObject,
|
|
141
177
|
isObject,
|
|
178
|
+
isTypescriptObject,
|
|
142
179
|
mapEntries,
|
|
143
180
|
mapValues,
|
|
144
181
|
omit,
|
|
@@ -146,8 +183,11 @@ export {
|
|
|
146
183
|
onFinish,
|
|
147
184
|
onStart,
|
|
148
185
|
onSuccess,
|
|
186
|
+
once,
|
|
187
|
+
parseEmptyableJSON,
|
|
149
188
|
retry,
|
|
150
189
|
set,
|
|
190
|
+
stringifyJSON,
|
|
151
191
|
toError,
|
|
152
192
|
trim,
|
|
153
193
|
value
|
package/dist/src/function.d.ts
CHANGED
package/dist/src/index.d.ts
CHANGED
package/dist/src/object.d.ts
CHANGED
|
@@ -9,4 +9,8 @@ export declare function findDeepMatches(check: (value: unknown) => boolean, payl
|
|
|
9
9
|
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
10
10
|
*/
|
|
11
11
|
export declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Check if the value satisfy a `object` type in typescript
|
|
14
|
+
*/
|
|
15
|
+
export declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
|
|
12
16
|
//# sourceMappingURL=object.d.ts.map
|