@bbn/bbn 1.0.242 → 1.0.243

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.
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Makes a hash out of anything
3
- * @param {[*]} args
3
+ * @param {*} value
4
+ * @param {Function} fn
5
+ * @param {Number} [depth=null]
6
+ * @param {Number} [level=0]
7
+ * @param {WeakSet} [visited=null]
4
8
  * @returns {String}
5
9
  */
6
- export default function treatForHash(value: any, fn: any, depth?: any, level?: number): any;
10
+ export default function treatForHash(value: any, fn: any, depth?: any, level?: number, visited?: any): any;
@@ -2,12 +2,20 @@ import isDom from '../type/isDom.js';
2
2
  import isCp from '../type/isCp.js';
3
3
  /**
4
4
  * Makes a hash out of anything
5
- * @param {[*]} args
5
+ * @param {*} value
6
+ * @param {Function} fn
7
+ * @param {Number} [depth=null]
8
+ * @param {Number} [level=0]
9
+ * @param {WeakSet} [visited=null]
6
10
  * @returns {String}
7
11
  */
8
- export default function treatForHash(value, fn, depth, level) {
12
+ export default function treatForHash(value, fn, depth, level, visited) {
9
13
  if (depth === void 0) { depth = null; }
10
14
  if (level === void 0) { level = 0; }
15
+ if (visited === void 0) { visited = null; }
16
+ if (!level) {
17
+ visited = new WeakSet();
18
+ }
11
19
  if (value === undefined) {
12
20
  value = "__BBN_UNDEFINED__";
13
21
  }
@@ -47,29 +55,31 @@ export default function treatForHash(value, fn, depth, level) {
47
55
  }
48
56
  }
49
57
  else if (bbn.fn.isArray(value)) {
50
- if (depth && (depth < level)) {
58
+ if (visited.has(value) || (depth && (depth < level))) {
51
59
  value = "__BBN_ARRAY__" + value.constructor.toString();
52
60
  }
53
61
  else {
62
+ visited.add(value);
54
63
  var st = '';
55
64
  for (var i = 0; i < value.length; i++) {
56
- st += "__BBN_ITEM" + i.toString() + "__" + fn(value[i], fn, level + 1, depth);
65
+ st += "__BBN_ITEM" + i.toString() + "__" + fn(value[i], fn, depth, level + 1, visited);
57
66
  }
58
67
  value = "__BBN_ARRAY__" + st;
59
68
  }
60
69
  }
61
70
  else if (typeof value === 'object') {
62
- if (depth && (depth < level)) {
71
+ if (visited.has(value) || (depth && (depth < level))) {
63
72
  value = "__BBN_OBJECT__" + value.constructor.toString();
64
73
  }
65
74
  else {
75
+ visited.add(value);
66
76
  var st = '';
67
77
  for (var n in value) {
68
78
  var idx = n;
69
79
  if (typeof idx !== 'string') {
70
- idx = fn(idx);
80
+ idx = fn(idx, fn, 1, 1);
71
81
  }
72
- st += "__BBN_PROP_" + idx + "__" + fn(value[n], fn, level + 1, depth);
82
+ st += "__BBN_PROP_" + idx + "__" + fn(value[n], fn, depth, level + 1, visited);
73
83
  }
74
84
  value = "__BBN_OBJECT__" + st;
75
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "1.0.242",
3
+ "version": "1.0.243",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",