MCPcopy Create free account
hub / github.com/caike/jQuery-Simple-Timer / generateHash

Function generateHash

tests/qunit-2.9.2.js:279–296  ·  view source on GitHub ↗
(module, testName)

Source from the content-addressed store, hash-verified

277 // Based on Java's String.hashCode, a simple but not
278 // rigorously collision resistant hashing function
279 function generateHash(module, testName) {
280 var str = module + "\x1C" + testName;
281 var hash = 0;
282
283 for (var i = 0; i < str.length; i++) {
284 hash = (hash << 5) - hash + str.charCodeAt(i);
285 hash |= 0;
286 }
287
288 // Convert the possibly negative integer hash code into an 8 character hex string, which isn't
289 // strictly necessary but increases user understanding that the id is a SHA-like hash
290 var hex = (0x100000000 + hash).toString(16);
291 if (hex.length < 8) {
292 hex = "0000000" + hex;
293 }
294
295 return hex.slice(-8);
296 }
297
298 // Test for equality any JavaScript type.
299 // Authors: Philippe Rathé <prathe@gmail.com>, David Chan <david@troi.org>

Callers 3

createModuleFunction · 0.85
unitSamplerGeneratorFunction · 0.85
TestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected