@esfaenza/extensions 11.2.8 → 11.2.12

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.
@@ -1268,8 +1268,11 @@
1268
1268
  /**
1269
1269
  * Blacklist dei tipi da ignorare quando si effettua l'hashing degli oggetti
1270
1270
  */
1271
- this.ObjectHashingBlacklist = ["NgForm", "ElementRef", "ExtensionsService", "ToastrService", "LocaleService", "AppState", "Router", "ActivatedRoute", "HTTPService", "Location",
1272
- "CanvasComponent", "ModalDirective", "ChangeDetectorRef", "DateService", "EventEmitter", "ViewRef_", "Subscriber", "ItemLocalization"];
1271
+ this.objBlacklist = {
1272
+ "NgForm": true, "ElementRef": true, "ExtensionsService": true, "ToastrService": true, "LocaleService": true, "AppState": true, "Router": true,
1273
+ "ActivatedRoute": true, "HTTPService": true, "Location": true, "CanvasComponent": true, "ModalDirective": true, "ChangeDetectorRef": true,
1274
+ "DateService": true, "EventEmitter": true, "ViewRef_": true, "Subscriber": true, "ItemLocalization": true
1275
+ };
1273
1276
  /**
1274
1277
  * Array dei possibili valori di un simbolo esadecimale
1275
1278
  */
@@ -1293,14 +1296,34 @@
1293
1296
  * @param {number} level Livello di ricorsione nel caso venga effettuato l'hash di un oggetto che contiene altri oggetti
1294
1297
  * @param {boolean} navigateFullDepth Indica se navigare l'oggetto per l'intera lunghezza. In caso contrario si ferma al secondo livello
1295
1298
  *
1296
- * @returns {string} md5 generato per l'oggetto in questione
1299
+ * @returns {string} Hash generato per l'oggetto in questione
1297
1300
  */
1298
- HashingService.prototype.hashObject = function (o, level, navigateFullDepth) {
1301
+ HashingService.prototype.hashObject = function (o, level, navigateFullDepth, precise) {
1299
1302
  if (level === void 0) { level = 0; }
1300
1303
  if (navigateFullDepth === void 0) { navigateFullDepth = false; }
1304
+ if (precise === void 0) { precise = false; }
1301
1305
  var strDef = this.stringify(o, level, navigateFullDepth);
1302
- var md5 = this.md5(strDef);
1303
- return md5;
1306
+ var hash = precise ? this.md5(strDef) : this.simpleHash(strDef);
1307
+ return hash;
1308
+ };
1309
+ /**
1310
+ * Hash più semplice e più veloce dell'md5, ma meno sicuro
1311
+ *
1312
+ * Vedi https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
1313
+ *
1314
+ * @param {string} str Stringa di cui calcolare l'hash
1315
+ */
1316
+ HashingService.prototype.simpleHash = function (str, seed) {
1317
+ if (seed === void 0) { seed = 0; }
1318
+ var h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
1319
+ for (var i = 0, ch = void 0; i < str.length; i++) {
1320
+ ch = str.charCodeAt(i);
1321
+ h1 = Math.imul(h1 ^ ch, 2654435761);
1322
+ h2 = Math.imul(h2 ^ ch, 1597334677);
1323
+ }
1324
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
1325
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
1326
+ return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString();
1304
1327
  };
1305
1328
  /**
1306
1329
  * Genera una stringa che identifica univocamente l'oggetto in questione
@@ -1318,14 +1341,14 @@
1318
1341
  if (o === false)
1319
1342
  return "f";
1320
1343
  if (o instanceof Date)
1321
- return "d:" + o.toString();
1344
+ return 'd:' + o.valueOf().toString();
1322
1345
  i = typeof o;
1323
1346
  if (i === "string")
1324
- return "s:" + o.replace(/([\\\\;])/g, "\\$1");
1347
+ return "s:" + o;
1325
1348
  if (i === "number")
1326
1349
  return "n:" + o;
1327
1350
  if (o instanceof Function)
1328
- return "m:" + o.toString().replace(/([\\\\;])/g, "\\$1");
1351
+ return "m:" + o.toString();
1329
1352
  if (o instanceof Array) {
1330
1353
  r = [];
1331
1354
  for (i = 0; i < o.length; i++) {
@@ -1339,7 +1362,7 @@
1339
1362
  //Se è oggetto, escludo tutti quelli di sistema/inutili
1340
1363
  if (o) {
1341
1364
  var name = o.__proto__.constructor.name;
1342
- if (this.ObjectHashingBlacklist.indexOf(name) == -1) {
1365
+ if (!this.objBlacklist[name]) {
1343
1366
  for (i in o) {
1344
1367
  if (o.hasOwnProperty(i) && (level <= 2 || navigateFullDepth)) {
1345
1368
  var res = this.stringify(o[i], level + 1, navigateFullDepth);