Browse Source

const replace let

Paul 6 years ago
parent
commit
58139adac4
1 changed files with 10 additions and 8 deletions
  1. 10
    8
      src/utils.ts

+ 10
- 8
src/utils.ts View File

12
   );
12
   );
13
 
13
 
14
   public static crc32(str: string): number {
14
   public static crc32(str: string): number {
15
-    let crcTable = window.crcTable || (window.crcTable = Utils.makeCRCTable());
15
+    const crcTable =
16
+      window.crcTable || (window.crcTable = Utils.makeCRCTable());
16
     let crc = 0 ^ -1;
17
     let crc = 0 ^ -1;
17
 
18
 
18
     for (let i = 0; i < str.length; i++) {
19
     for (let i = 0; i < str.length; i++) {
29
       return String.fromCharCode.apply(null, new Uint8Array(buf));
30
       return String.fromCharCode.apply(null, new Uint8Array(buf));
30
     }
31
     }
31
 
32
 
32
-    let bufView = new Uint8Array(buf);
33
-    let len = bufView.length;
34
-    let byteStr = new Array(len);
33
+    const bufView = new Uint8Array(buf);
34
+    const len = bufView.length;
35
+    const byteStr = new Array(len);
35
 
36
 
36
     for (let i = 0; i < len; i++) {
37
     for (let i = 0; i < len; i++) {
37
       byteStr[i] = String.fromCharCode.call(null, bufView[i]);
38
       byteStr[i] = String.fromCharCode.call(null, bufView[i]);
42
 
43
 
43
   // 字符串转为 ArrayBuffer 对象,参数为字符串
44
   // 字符串转为 ArrayBuffer 对象,参数为字符串
44
   public static str2ab(str: string): ArrayBuffer {
45
   public static str2ab(str: string): ArrayBuffer {
45
-    let buf = new ArrayBuffer(str.length); // 每个字符占用2个字节
46
-    let bufView = new Uint8Array(buf);
46
+    const buf = new ArrayBuffer(str.length); // 每个字符占用2个字节
47
+    const bufView = new Uint8Array(buf);
47
 
48
 
48
     for (let i = 0, strLen = str.length; i < strLen; i++) {
49
     for (let i = 0, strLen = str.length; i < strLen; i++) {
49
       bufView[i] = str.charCodeAt(i);
50
       bufView[i] = str.charCodeAt(i);
79
 
80
 
80
   // 字节数组转换为base64编码
81
   // 字节数组转换为base64编码
81
   public static binToBase64(bitString: string): string {
82
   public static binToBase64(bitString: string): string {
83
+    const tail = bitString.length % 6;
84
+    const bitStringTemp1 = bitString.substr(0, bitString.length - tail);
85
+
82
     let result = '';
86
     let result = '';
83
-    let tail = bitString.length % 6;
84
-    let bitStringTemp1 = bitString.substr(0, bitString.length - tail);
85
     let bitStringTemp2 = bitString.substr(bitString.length - tail, tail);
87
     let bitStringTemp2 = bitString.substr(bitString.length - tail, tail);
86
 
88
 
87
     for (let i = 0; i < bitStringTemp1.length; i += 6) {
89
     for (let i = 0; i < bitStringTemp1.length; i += 6) {