@win2win/shared 1.0.125 → 1.0.126

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,7 @@
1
+ export interface DeserializeOptions {
2
+ context?: Record<string, any>;
3
+ run?: boolean;
4
+ useInvisibleContext?: boolean;
5
+ }
6
+ export declare function deserialize(stringFn?: string, options?: DeserializeOptions): any;
7
+ export declare function deserializeWithContext(stringFn?: string, options?: Pick<DeserializeOptions, "context" | "run">): any;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserialize = deserialize;
4
+ exports.deserializeWithContext = deserializeWithContext;
5
+ function deserialize(stringFn, options) {
6
+ const { context = {}, run = false, useInvisibleContext = false, } = options || {};
7
+ if (!stringFn || typeof stringFn !== "string")
8
+ return run ? null : () => null;
9
+ try {
10
+ const cleanedStringFn = stringFn.replace(/\/\/.*$/gm, "").trim();
11
+ const fn = new Function("context", `return (...args) => { with (context) { return (${cleanedStringFn})(${useInvisibleContext ? "" : "context,"} ...args) } }`);
12
+ const runableFn = fn(context);
13
+ return run ? runableFn() : runableFn;
14
+ }
15
+ catch (error) {
16
+ console.log(error);
17
+ return run ? null : () => null;
18
+ }
19
+ }
20
+ function deserializeWithContext(stringFn, options) {
21
+ return deserialize(stringFn, { ...options, useInvisibleContext: true });
22
+ }
@@ -0,0 +1,2 @@
1
+ export * from './formatters';
2
+ export * from './validators';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./formatters"), exports);
18
+ __exportStar(require("./validators"), exports);
@@ -0,0 +1 @@
1
+ export declare function isSerializedFunction(str?: any): boolean;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSerializedFunction = isSerializedFunction;
4
+ function isSerializedFunction(str) {
5
+ if (typeof str !== 'string')
6
+ return false;
7
+ if (!str || (!str.includes('=>') && !str.includes('function(')))
8
+ return false;
9
+ try {
10
+ new Function(`return (${str})`);
11
+ return true;
12
+ }
13
+ catch (err) {
14
+ return false;
15
+ }
16
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './enums';
2
- export * from './interfaces';
1
+ export * from "./enums";
2
+ export * from "./helpers";
3
+ export * from "./interfaces";
package/dist/index.js CHANGED
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./enums"), exports);
18
+ __exportStar(require("./helpers"), exports);
18
19
  __exportStar(require("./interfaces"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@win2win/shared",
3
- "version": "1.0.125",
3
+ "version": "1.0.126",
4
4
  "description": "Tipos, interfaces, funciones, constantes, clases y enums compartidos por todos los proyectos de Win2Win",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",