Browse Source

feat(ts) migrate StringUtils to TS

dev0
Naman Jain 6 months ago
parent
commit
35af1d28aa
No account linked to committer's email address
1 changed files with 6 additions and 6 deletions
  1. 6
    6
      modules/util/StringUtils.ts

modules/util/StringUtils.js → modules/util/StringUtils.ts View File

@@ -2,17 +2,17 @@
2 2
  * Implements a simple hash code for a string (see
3 3
  * https://en.wikipedia.org/wiki/Java_hashCode()).
4 4
  *
5
- * @param {string} The string to return a hash of.
6
- * @return {Number} the integer hash code of the string.
5
+ * @param {string} string - The string to return a hash of.
6
+ * @return {number} the integer hash code of the string.
7 7
  */
8
-function integerHash(string) {
8
+function integerHash(string: string): number {
9 9
     if (!string) {
10 10
         return 0;
11 11
     }
12 12
 
13
-    let char, hash = 0, i;
13
+    let char: number, hash = 0;
14 14
 
15
-    for (i = 0; i < string.length; i++) {
15
+    for (let i = 0; i < string.length; i++) {
16 16
         char = string.charCodeAt(i);
17 17
         hash += char * Math.pow(31, string.length - 1 - i);
18 18
         hash = Math.abs(hash | 0); // eslint-disable-line no-bitwise
@@ -21,4 +21,4 @@ function integerHash(string) {
21 21
     return hash;
22 22
 }
23 23
 
24
-module.exports = { integerHash };
24
+export default integerHash;

Loading…
Cancel
Save