@esfaenza/extensions 11.2.10 → 11.2.11

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.
@@ -1296,14 +1296,40 @@
1296
1296
  * @param {number} level Livello di ricorsione nel caso venga effettuato l'hash di un oggetto che contiene altri oggetti
1297
1297
  * @param {boolean} navigateFullDepth Indica se navigare l'oggetto per l'intera lunghezza. In caso contrario si ferma al secondo livello
1298
1298
  *
1299
- * @returns {string} md5 generato per l'oggetto in questione
1299
+ * @returns {string} Hash generato per l'oggetto in questione
1300
1300
  */
1301
- HashingService.prototype.hashObject = function (o, level, navigateFullDepth) {
1301
+ HashingService.prototype.hashObject = function (o, level, navigateFullDepth, precise) {
1302
1302
  if (level === void 0) { level = 0; }
1303
1303
  if (navigateFullDepth === void 0) { navigateFullDepth = false; }
1304
+ if (precise === void 0) { precise = false; }
1304
1305
  var strDef = this.stringify(o, level, navigateFullDepth);
1305
- var md5 = this.md5(strDef);
1306
- return md5;
1306
+ var hash = precise ? this.md5(strDef) : this.superSimpleHash(strDef);
1307
+ return hash;
1308
+ };
1309
+ /**
1310
+ * Hash più semplice e più veloce dell'md5, ma meno sicuro... vediamo come va
1311
+ *
1312
+ * @param {string} str Stringa di cui calcolare l'hash
1313
+ */
1314
+ HashingService.prototype.simpleHash = function (str) {
1315
+ var hash = 0;
1316
+ for (var i = 0; i < str.length; i++) {
1317
+ var char = str.charCodeAt(i);
1318
+ hash = (hash << 5) - hash + char;
1319
+ hash &= hash; // Convert to 32bit integer
1320
+ }
1321
+ return new Uint32Array([hash])[0].toString(36);
1322
+ };
1323
+ /**
1324
+ * Hash più semplice e più veloce dell'md5, ma meno sicuro... vediamo come va
1325
+ *
1326
+ * @param {string} str Stringa di cui calcolare l'hash
1327
+ */
1328
+ HashingService.prototype.superSimpleHash = function (str) {
1329
+ var h, i;
1330
+ for (i = 0, h = 0; i < str.length; i++)
1331
+ h = Math.imul(31, h) + str.charCodeAt(i) | 0;
1332
+ return h.toString();
1307
1333
  };
1308
1334
  /**
1309
1335
  * Genera una stringa che identifica univocamente l'oggetto in questione