short-hash-ts
Advanced tools
Comparing version 1.0.1 to 1.0.2
"use strict"; | ||
module.exports = require('./shorthash'); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var shorthash_1 = require("./shorthash"); | ||
exports.default = shorthash_1.default; |
@@ -1,7 +0,9 @@ | ||
declare function bitwiseHash(string: string): number; | ||
declare function convertBinaryHash(number: number, binary: number): string; | ||
/** | ||
* We needed the last element's char to replace the negative sign, which is why we chose 61 binary. | ||
* কেন 61 বাইনারি চয়ন করুন, কারণ বিয়োগ চিহ্নটি প্রতিস্থাপন করার জন্য আমাদের শেষ উপাদান char প্রয়োজন | ||
*/ | ||
declare function unique(string: string): string; | ||
export default class Shorthash { | ||
static bitwiseHash(string: string): number; | ||
static convertBinaryHash(number: number, binary: number): string; | ||
/** | ||
* We needed the last element's char to replace the negative sign, which is why we chose 61 binary. | ||
* কেন 61 বাইনারি চয়ন করুন, কারণ বিয়োগ চিহ্নটি প্রতিস্থাপন করার জন্য আমাদের শেষ উপাদান char প্রয়োজন | ||
*/ | ||
static unique(string: string): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* | ||
@@ -10,49 +11,54 @@ The MIT license allows for the unrestricted distribution of shorthash-ts. | ||
*/ | ||
exports.unique = unique; | ||
// this function is an imitation of Reference One | ||
//এই ফাংশন একটি রেফারেন্স এক অনুকরণ | ||
function bitwiseHash(string) { | ||
var length_of_hash = 0; | ||
if (string.length == 0) | ||
var Shorthash = /** @class */ (function () { | ||
function Shorthash() { | ||
} | ||
// this function is an imitation of Reference One | ||
//এই ফাংশন একটি রেফারেন্স এক অনুকরণ | ||
Shorthash.bitwiseHash = function (string) { | ||
var length_of_hash = 0; | ||
if (string.length == 0) | ||
return length_of_hash; | ||
for (var i = 0; i < string.length; i++) { | ||
var ch = string.charCodeAt(i); | ||
length_of_hash = (length_of_hash << 5) - length_of_hash + ch; | ||
length_of_hash = length_of_hash & length_of_hash; // Convert to 32bit number | ||
} | ||
return length_of_hash; | ||
for (var i = 0; i < string.length; i++) { | ||
var ch = string.charCodeAt(i); | ||
length_of_hash = (length_of_hash << 5) - length_of_hash + ch; | ||
length_of_hash = length_of_hash & length_of_hash; // Convert to 32bit number | ||
} | ||
return length_of_hash; | ||
} | ||
// create a 62-byte maximum bespoke binary from a binary. | ||
//বাইনারি থেকে একটি নতুন কাস্টমাইজড বাইনারি তৈরি করুন, সর্বোচ্চ আকার হল 62 | ||
function convertBinaryHash(number, binary) { | ||
binary = binary || 62; | ||
var result = ''; | ||
var newNum; | ||
var stack = []; | ||
var minus_sign = number < 0 ? '-' : ''; | ||
function table(newNum) { | ||
var t = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
return t[newNum]; | ||
} | ||
number = Math.abs(number); | ||
while (number >= binary) { | ||
newNum = number % binary; | ||
number = Math.floor(number / binary); | ||
stack.push(table(newNum)); | ||
} | ||
if (number > 0) { | ||
stack.push(table(number)); | ||
} | ||
for (var i = stack.length - 1; i >= 0; i--) { | ||
result += stack[i]; | ||
} | ||
return minus_sign + result; | ||
} | ||
/** | ||
* We needed the last element's char to replace the negative sign, which is why we chose 61 binary. | ||
* কেন 61 বাইনারি চয়ন করুন, কারণ বিয়োগ চিহ্নটি প্রতিস্থাপন করার জন্য আমাদের শেষ উপাদান char প্রয়োজন | ||
*/ | ||
function unique(string) { | ||
var id = convertBinaryHash(bitwiseHash(string), 61); | ||
return id.replace('-', 'Z'); | ||
} | ||
}; | ||
// create a 62-byte maximum bespoke binary from a binary. | ||
//বাইনারি থেকে একটি নতুন কাস্টমাইজড বাইনারি তৈরি করুন, সর্বোচ্চ আকার হল 62 | ||
Shorthash.convertBinaryHash = function (number, binary) { | ||
binary = binary || 62; | ||
var result = ''; | ||
var newNum; | ||
var stack = []; | ||
var minus_sign = number < 0 ? '-' : ''; | ||
function table(newNum) { | ||
var t = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
return t[newNum]; | ||
} | ||
number = Math.abs(number); | ||
while (number >= binary) { | ||
newNum = number % binary; | ||
number = Math.floor(number / binary); | ||
stack.push(table(newNum)); | ||
} | ||
if (number > 0) { | ||
stack.push(table(number)); | ||
} | ||
for (var i = stack.length - 1; i >= 0; i--) { | ||
result += stack[i]; | ||
} | ||
return minus_sign + result; | ||
}; | ||
/** | ||
* We needed the last element's char to replace the negative sign, which is why we chose 61 binary. | ||
* কেন 61 বাইনারি চয়ন করুন, কারণ বিয়োগ চিহ্নটি প্রতিস্থাপন করার জন্য আমাদের শেষ উপাদান char প্রয়োজন | ||
*/ | ||
Shorthash.unique = function (string) { | ||
var id = Shorthash.convertBinaryHash(Shorthash.bitwiseHash(string), 61); | ||
return id.replace('-', 'Z'); | ||
}; | ||
return Shorthash; | ||
}()); | ||
exports.default = Shorthash; |
{ | ||
"name": "short-hash-ts", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Get a quick hash that uses the well-liked Bernstein \"times 33\" hash method and delivers a hex string.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6365
76