@nookuio/iframe 0.7.0 → 0.8.0

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.
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createClient = createClient;
7
- var _lodash = _interopRequireDefault(require("lodash"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
7
  function createClient(localCtx, options) {
10
8
  const {
11
9
  invoke,
@@ -31,7 +29,7 @@ function createClient(localCtx, options) {
31
29
  }
32
30
  const listenersCollection = /* @__PURE__ */new Map();
33
31
  handle(async request => {
34
- const value = _lodash.default.get(localCtx, request.key);
32
+ const value = get(localCtx, request.key);
35
33
  if (value === void 0) return {
36
34
  type: "response",
37
35
  id: request.id,
@@ -125,4 +123,17 @@ function createClient(localCtx, options) {
125
123
  }
126
124
  });
127
125
  return rootProxy;
126
+ }
127
+ function get(obj, path, defaultValue) {
128
+ if (!obj || typeof obj !== "object") return defaultValue;
129
+ const pathArray = Array.isArray(path) ? path : path.replace(/\[(\d+)]/g, ".$1").replace(/\["([^"]+)"\]/g, ".$1").replace(/\['([^']+)'\]/g, ".$1").split(".").filter(Boolean);
130
+ let result = obj;
131
+ for (const key of pathArray) {
132
+ if (result != null && typeof result === "object" && key in result) {
133
+ result = result[key];
134
+ } else {
135
+ return defaultValue;
136
+ }
137
+ }
138
+ return result;
128
139
  }
@@ -1,4 +1,3 @@
1
- import _ from "lodash";
2
1
  export function createClient(localCtx, options) {
3
2
  const { invoke, handle, emit, handleEvent, serialize: _serialize, deserialize: _deserialize } = options;
4
3
  function serialize(data) {
@@ -17,7 +16,7 @@ export function createClient(localCtx, options) {
17
16
  }
18
17
  const listenersCollection = /* @__PURE__ */ new Map();
19
18
  handle(async (request) => {
20
- const value = _.get(localCtx, request.key);
19
+ const value = get(localCtx, request.key);
21
20
  if (value === void 0)
22
21
  return {
23
22
  type: "response",
@@ -113,3 +112,16 @@ export function createClient(localCtx, options) {
113
112
  );
114
113
  return rootProxy;
115
114
  }
115
+ function get(obj, path, defaultValue) {
116
+ if (!obj || typeof obj !== "object") return defaultValue;
117
+ const pathArray = Array.isArray(path) ? path : path.replace(/\[(\d+)]/g, ".$1").replace(/\["([^"]+)"\]/g, ".$1").replace(/\['([^']+)'\]/g, ".$1").split(".").filter(Boolean);
118
+ let result = obj;
119
+ for (const key of pathArray) {
120
+ if (result != null && typeof result === "object" && key in result) {
121
+ result = result[key];
122
+ } else {
123
+ return defaultValue;
124
+ }
125
+ }
126
+ return result;
127
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nookuio/iframe",
3
3
  "description": "",
4
- "version": "0.7.0",
4
+ "version": "0.8.0",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "exports": {