triangle-utils 1.4.11 → 1.4.12
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/src/UtilsMisc.d.ts +2 -0
- package/dist/src/UtilsMisc.js +12 -0
- package/package.json +1 -1
- package/src/UtilsMisc.ts +13 -0
- package/tsconfig.json +1 -1
package/dist/src/UtilsMisc.d.ts
CHANGED
|
@@ -28,5 +28,7 @@ export declare class UtilsMisc {
|
|
|
28
28
|
chunk_index: [number, number];
|
|
29
29
|
chunk_text: string;
|
|
30
30
|
}[];
|
|
31
|
+
static instantiate<T>(constructor: new (x: any) => T, x: any): T | undefined;
|
|
32
|
+
static instantiator<T>(constructor: new (x: any) => T): (x: any) => T | undefined;
|
|
31
33
|
}
|
|
32
34
|
export {};
|
package/dist/src/UtilsMisc.js
CHANGED
|
@@ -153,4 +153,16 @@ export class UtilsMisc {
|
|
|
153
153
|
chunk_text: text.substring(...chunk_index)
|
|
154
154
|
}));
|
|
155
155
|
}
|
|
156
|
+
static instantiate(constructor, x) {
|
|
157
|
+
try {
|
|
158
|
+
const instance = new constructor(x);
|
|
159
|
+
return instance;
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
static instantiator(constructor) {
|
|
166
|
+
return (x) => UtilsMisc.instantiate(constructor, x);
|
|
167
|
+
}
|
|
156
168
|
}
|
package/package.json
CHANGED
package/src/UtilsMisc.ts
CHANGED
|
@@ -185,4 +185,17 @@ export class UtilsMisc {
|
|
|
185
185
|
}))
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
static instantiate<T>(constructor : new (x : any) => T, x : any) : T | undefined {
|
|
189
|
+
try {
|
|
190
|
+
const instance = new constructor(x)
|
|
191
|
+
return instance
|
|
192
|
+
} catch (error) {
|
|
193
|
+
return undefined
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
static instantiator<T>(constructor : new (x : any) => T) : (x : any) => T | undefined {
|
|
198
|
+
return (x : any) => UtilsMisc.instantiate(constructor, x)
|
|
199
|
+
}
|
|
200
|
+
|
|
188
201
|
}
|
package/tsconfig.json
CHANGED