topkat-utils 1.3.7 → 1.3.8

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.
@@ -441,4 +441,20 @@ export function mergeObjectArrays<T extends Record<string, any[]>>(obj: T) {
441
441
  }
442
442
 
443
443
  export const keys = objKeys
444
- export const entries = objEntries
444
+ export const entries = objEntries
445
+
446
+
447
+
448
+ /** A Helper to create JavascriptProxies, will add __isProxy and toJSON helper to prevent error when logging the proxy and to be able to check if the object is proxyfied */
449
+ export function createProxy<T extends Record<string, any>>(obj: T, optn: {
450
+ getter: Required<ProxyHandler<T>>['get'],
451
+ jsonRepresentation?: (obj: T) => string
452
+ }) {
453
+ return new Proxy(obj, {
454
+ get(target, prop, receiver) {
455
+ if (prop === '__isProxy') return true
456
+ else if (prop === 'toJSON') return optn?.jsonRepresentation?.(target) || '[TopkatUtils Proxy]'
457
+ return optn.getter(target, prop, receiver)
458
+ }
459
+ })
460
+ }