@bbn/bbn 1.0.241 → 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,7 +1,5 @@
1
- import isDom from '../type/isDom.js';
2
- import isCp from '../type/isCp.js';
3
- import circularReplacer from '../object/circularReplacer.js';
4
1
  import simpleHash from './simpleHash.js';
2
+ import treatForHash from './treatForHash.js';
5
3
  /**
6
4
  * Makes a hash out of anything
7
5
  * @param {[*]} args
@@ -14,31 +12,13 @@ export default function hash() {
14
12
  }
15
13
  //log(obj);
16
14
  var st = "";
15
+ var depth = null;
16
+ if ((args.length === 2) && (typeof args[1] === 'number')) {
17
+ depth = args[1];
18
+ args = [args[0]];
19
+ }
17
20
  for (var i in args) {
18
- var value = args[i];
19
- if (value === undefined) {
20
- value = "__BBN_UNDEFINED__";
21
- }
22
- else if (![undefined, Object, Array, null].includes(value === null || value === void 0 ? void 0 : value.constructor)) {
23
- if (isDom(value)) {
24
- if (value.bbnId) {
25
- value =
26
- "__BBN_DOM__" + value.tagName + "/" + value.bbnId + value.bbnHash;
27
- }
28
- else {
29
- value = "__BBN_DOM__" + value.tagName + "/" + value.className;
30
- }
31
- }
32
- else if (isCp(value)) {
33
- value = "__BBN_CP__" + value.$options.name + "/" + value.$cid;
34
- }
35
- }
36
- try {
37
- st += JSON.stringify(value, circularReplacer());
38
- }
39
- catch (e) {
40
- st += ".";
41
- }
21
+ st += treatForHash(args[i], treatForHash, depth);
42
22
  }
43
23
  return simpleHash(st);
44
24
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Makes a hash out of anything
3
+ * @param {*} value
4
+ * @param {Function} fn
5
+ * @param {Number} [depth=null]
6
+ * @param {Number} [level=0]
7
+ * @param {WeakSet} [visited=null]
8
+ * @returns {String}
9
+ */
10
+ export default function treatForHash(value: any, fn: any, depth?: any, level?: number, visited?: any): any;
@@ -0,0 +1,89 @@
1
+ import isDom from '../type/isDom.js';
2
+ import isCp from '../type/isCp.js';
3
+ /**
4
+ * Makes a hash out of anything
5
+ * @param {*} value
6
+ * @param {Function} fn
7
+ * @param {Number} [depth=null]
8
+ * @param {Number} [level=0]
9
+ * @param {WeakSet} [visited=null]
10
+ * @returns {String}
11
+ */
12
+ export default function treatForHash(value, fn, depth, level, visited) {
13
+ if (depth === void 0) { depth = null; }
14
+ if (level === void 0) { level = 0; }
15
+ if (visited === void 0) { visited = null; }
16
+ if (!level) {
17
+ visited = new WeakSet();
18
+ }
19
+ if (value === undefined) {
20
+ value = "__BBN_UNDEFINED__";
21
+ }
22
+ else if (value === null) {
23
+ value = "__BBN_NULL__";
24
+ }
25
+ else if (typeof value === 'function') {
26
+ value = "__BBN_FUNCTION__" + value.toString();
27
+ }
28
+ else if (typeof value === 'symbol') {
29
+ value = "__BBN_SYMBOL__" + value.toString();
30
+ }
31
+ else if (typeof value === 'string') {
32
+ value = "__BBN_STRING__" + value;
33
+ }
34
+ else if (typeof value === 'number') {
35
+ value = "__BBN_NUMBER__" + value.toString();
36
+ }
37
+ else if (typeof value === 'boolean') {
38
+ value = "__BBN_BOOLEAN__" + value.toString();
39
+ }
40
+ else if (![undefined, Object, Array, null].includes(value === null || value === void 0 ? void 0 : value.constructor)) {
41
+ if (isDom(value)) {
42
+ if (value.bbnId) {
43
+ value =
44
+ "__BBN_DOM__" + value.tagName + "/" + value.bbnId + value.bbnHash;
45
+ }
46
+ else {
47
+ value = "__BBN_DOM__" + value.tagName + "/" + value.className;
48
+ }
49
+ }
50
+ else if (isCp(value)) {
51
+ value = "__BBN_CP__" + value.$options.name + "/" + value.$cid;
52
+ }
53
+ else {
54
+ value = "__BBN_OBJECT__" + value.constructor.toString();
55
+ }
56
+ }
57
+ else if (bbn.fn.isArray(value)) {
58
+ if (visited.has(value) || (depth && (depth < level))) {
59
+ value = "__BBN_ARRAY__" + value.constructor.toString();
60
+ }
61
+ else {
62
+ visited.add(value);
63
+ var st = '';
64
+ for (var i = 0; i < value.length; i++) {
65
+ st += "__BBN_ITEM" + i.toString() + "__" + fn(value[i], fn, depth, level + 1, visited);
66
+ }
67
+ value = "__BBN_ARRAY__" + st;
68
+ }
69
+ }
70
+ else if (typeof value === 'object') {
71
+ if (visited.has(value) || (depth && (depth < level))) {
72
+ value = "__BBN_OBJECT__" + value.constructor.toString();
73
+ }
74
+ else {
75
+ visited.add(value);
76
+ var st = '';
77
+ for (var n in value) {
78
+ var idx = n;
79
+ if (typeof idx !== 'string') {
80
+ idx = fn(idx, fn, 1, 1);
81
+ }
82
+ st += "__BBN_PROP_" + idx + "__" + fn(value[n], fn, depth, level + 1, visited);
83
+ }
84
+ value = "__BBN_OBJECT__" + st;
85
+ }
86
+ }
87
+ return value;
88
+ }
89
+ ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "1.0.241",
3
+ "version": "1.0.243",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",