UNPKG

nope-js-node

Version:

NoPE Runtime for Nodejs. For Browser-Support please use nope-browser

31 lines (30 loc) 918 B
"use strict"; /** * @module hash * @author M.Karkowski * @email M.Karkowski@zema.de * * Helper module to generate `hashs` of different type of objects. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.generateHash = void 0; const jsonMethods_1 = require("./jsonMethods"); /** * Function to generate a Hash * @param obj the Object, that should be hashed */ function generateHash(obj) { // Convert the object to String const str = typeof obj === "string" ? obj : (0, jsonMethods_1.stringifyWithFunctions)(obj); // Define Vars. let hash = 0, i, chr; if (str.length === 0) return hash.toString(); for (i = 0; i < str.length; i++) { chr = str.charCodeAt(i); hash = (hash << 5) - hash + chr; hash |= 0; // Convert to 32bit integer } return hash.toString(); } exports.generateHash = generateHash;