浏览代码

feat(ts) migrate StringUtils to TS

dev0
Naman Jain 6 个月前
父节点
当前提交
35af1d28aa
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 6 次插入6 次删除
  1. 6
    6
      modules/util/StringUtils.ts

modules/util/StringUtils.js → modules/util/StringUtils.ts 查看文件

2
  * Implements a simple hash code for a string (see
2
  * Implements a simple hash code for a string (see
3
  * https://en.wikipedia.org/wiki/Java_hashCode()).
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
     if (!string) {
9
     if (!string) {
10
         return 0;
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
         char = string.charCodeAt(i);
16
         char = string.charCodeAt(i);
17
         hash += char * Math.pow(31, string.length - 1 - i);
17
         hash += char * Math.pow(31, string.length - 1 - i);
18
         hash = Math.abs(hash | 0); // eslint-disable-line no-bitwise
18
         hash = Math.abs(hash | 0); // eslint-disable-line no-bitwise
21
     return hash;
21
     return hash;
22
 }
22
 }
23
 
23
 
24
-module.exports = { integerHash };
24
+export default integerHash;

正在加载...
取消
保存