@zzclub/z-cli 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,334 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs";
3
+ import chalk from "chalk";
4
+ import { translate } from "../translate-api/index.js";
5
+ import { readJsonFile } from "../utils/file.js";
6
+ import { writeFileContent, getLocalConfig } from "../utils/common.js";
7
+ import ora from "ora";
8
+ // const { log } = require("../utils/common");
9
+
10
+ // let config: { translate: any } = await getLocalConfig();
11
+ // const translateConfig = config.translate;
12
+ const translateCmd = {
13
+ name: "translate",
14
+ description: "中译英功能,支持批量和单个文件翻译",
15
+ // options: ['-l, --language <language>', '转换为什么语言, 支持[zh]和[en]', 'en'],
16
+ options: [
17
+ {
18
+ flags: "-l, --language <language>",
19
+ description: "目前只支持从中文到英文",
20
+ defaultValue: "en",
21
+ },
22
+ {
23
+ flags: "-f, --file <file>",
24
+ description: "转换文件的路径",
25
+ defaultValue: null,
26
+ },
27
+ {
28
+ flags: "-d, --dir <dirpath>",
29
+ description: "转换文件夹的路径",
30
+ defaultValue: null,
31
+ },
32
+ ],
33
+ action: async (option) => {
34
+ let filePath = option.file;
35
+ let dirPath = option.dir;
36
+
37
+ if (!filePath && !dirPath) {
38
+ process.exit(1);
39
+ }
40
+ let file_spinner = ora();
41
+ let config = await getLocalConfig();
42
+ const translateConfig = config.translate;
43
+ if (!translateConfig.account.appId || !translateConfig.account.key) {
44
+ file_spinner.fail("请先设置appId和key后再使用翻译功能");
45
+ process.exit(1);
46
+ }
47
+ // 有文件夹路径时忽略文件
48
+ if (dirPath) {
49
+ dirPath = path.resolve(process.cwd(), dirPath);
50
+ let stat;
51
+ try {
52
+ stat = fs.statSync(dirPath);
53
+ } catch (err) {
54
+ file_spinner.fail(`${chalk.red(dirPath)}不存在!`);
55
+ return;
56
+ }
57
+
58
+ if (!stat.isDirectory()) {
59
+ file_spinner.fail(`${chalk.red(dirPath)}不是一个文件夹!`);
60
+ return;
61
+ } else {
62
+ let filePaths = [];
63
+ file_spinner.succeed(`开始检索${chalk.red(dirPath)}`);
64
+
65
+ getAllFilePaths(translateConfig, dirPath, filePaths);
66
+
67
+ // log.success(`共找到${chalk.red(filePaths.length)}个要翻译的文件`);
68
+ if (filePaths.length) {
69
+ file_spinner.succeed(
70
+ `共找到${chalk.red(filePaths.length)}个要翻译的文件`
71
+ );
72
+ file_spinner.start();
73
+ await execWorkerSync(filePaths, 0);
74
+ file_spinner.stop();
75
+ } else {
76
+ // log.success(`Exit`);
77
+ file_spinner.warn(
78
+ `共找到${chalk.red(filePaths.length)}个要翻译的文件`
79
+ );
80
+ }
81
+ }
82
+ } else {
83
+ file_spinner.succeed(`正在翻译${chalk.yellowBright(filePath)}`);
84
+ file_spinner.start();
85
+ let file_content = await readAndTranslateFileContent(filePath);
86
+ let fileName = path.basename(filePath);
87
+ let dirPath = path.dirname(filePath);
88
+ let newFileName =
89
+ fileName.split(".")[0] +
90
+ `-${option.language}.` +
91
+ fileName.split(".")[1];
92
+ let newFilePath = dirPath + "/" + newFileName;
93
+ writeFileContent(newFilePath, file_content, (spinner, isOk) => {
94
+ if (isOk) {
95
+ spinner.succeed("翻译结束");
96
+ } else {
97
+ spinner.fail("翻译失败!");
98
+ }
99
+
100
+ file_spinner.stop();
101
+ });
102
+ }
103
+ },
104
+ };
105
+
106
+ /**
107
+ * 递归处理i18n配置对象
108
+ * @param config i18n配置js 一般为langs文件下的js文件
109
+ * @description 把js对象处理成 [ { keys: ['common', 'title'], value: '要翻译的值'} ] 每个要翻译的中文为一个item keys表示他在对象里的位置
110
+ */
111
+ function parseConfigs(config) {
112
+ let words = [];
113
+
114
+ parseConfig(config, null);
115
+ function parseConfig(config, curItem) {
116
+ let keys = Object.keys(config);
117
+ keys.forEach((key) => {
118
+ let item = {
119
+ keys: curItem ? curItem.keys.concat([key]) : [key],
120
+ value: config[key],
121
+ };
122
+ // 对象的value为string时则为要翻译的值
123
+ if (typeof item.value === "string") {
124
+ words.push(item);
125
+ } else {
126
+ parseConfig(item.value, item);
127
+ }
128
+ });
129
+ }
130
+ return words;
131
+ }
132
+
133
+ /**
134
+ * 把所有要翻译的词分组 每秒有查询次数限制
135
+ * @param words 处理好的数据
136
+ * @param limitLength 每秒查几个词
137
+ * @returns {*[]} 处理后的二维数组
138
+ */
139
+ function limitWords(words, limitLength = 7) {
140
+ let wordsLimit = [];
141
+ if (words.length < limitLength) {
142
+ return [words];
143
+ } else {
144
+ for (let i = 0; i < words.length; i += limitLength) {
145
+ wordsLimit.push(words.slice(i, i + limitLength));
146
+ }
147
+ return wordsLimit;
148
+ }
149
+ }
150
+
151
+ /**
152
+ * 调用翻译功能
153
+ * @param limitedWords 分组后的word数据
154
+ * @param cb 全部翻译结束后的回调函数
155
+ */
156
+ function startTranslate(limitedWords, cb) {
157
+ let curIndex = 0;
158
+ let timer = null;
159
+ timer = setInterval(() => {
160
+ if (curIndex >= limitedWords.length) {
161
+ clearInterval(timer);
162
+ cb && cb();
163
+ } else {
164
+ limitedWords[curIndex].forEach(async (word) => {
165
+ let res = await translate({
166
+ query: word.value,
167
+ from: "zh",
168
+ to: "en",
169
+ }).catch((err) => {
170
+ console.log(err);
171
+ });
172
+
173
+ let translate_result = res.trans_result
174
+ ? res.trans_result[0].dst
175
+ : word.value;
176
+ word.value = translate_result;
177
+ });
178
+ curIndex++;
179
+ }
180
+ }, 1000);
181
+ }
182
+
183
+ /**
184
+ * 组装翻译后的数据结构
185
+ * @param words
186
+ * @param obj
187
+ */
188
+ function setTranslatedObj(words, obj) {
189
+ words.forEach((item) => {
190
+ item.keys.forEach((key, index) => {
191
+ if (index === 0 && item.keys.length > 1) {
192
+ if (!obj[key]) obj[key] = {};
193
+ } else if (index < item.keys.length - 1) {
194
+ // a.b.c
195
+ let _key = item.keys.slice(0, index + 1).join(".");
196
+ let flag = false;
197
+ eval(`flag = !!!obj.${_key}`);
198
+ if (flag) eval(`obj.${_key} = {}`);
199
+ } else {
200
+ let _key = item.keys.slice(0, index + 1).join(".");
201
+ eval(`obj.${_key} = "${item.value}"`);
202
+ }
203
+ });
204
+ });
205
+ }
206
+ function unquoteKeys(json) {
207
+ return json.replace(/"(\\[^]|[^\\"])*"\s*:?/g, function (match) {
208
+ if (/:$/.test(match)) {
209
+ return match.replace(/^"|"(?=\s*:$)/g, "");
210
+ } else {
211
+ return match;
212
+ }
213
+ });
214
+ }
215
+ /**
216
+ * 读取并翻译文本内容
217
+ * @param filePath 文件地址
218
+ * @param cb 翻译后的回调
219
+ * @return 翻译后的文本
220
+ */
221
+ function readAndTranslateFileContent(filePath, cb = () => {}) {
222
+ return new Promise((resolve, reject) => {
223
+ fs.readFile(filePath, { encoding: "utf8" }, (err, data) => {
224
+ if (err) {
225
+ // log.error("读取文件失败");
226
+ reject();
227
+ } else {
228
+ let jsonObj;
229
+ let fileData = data.toString();
230
+ let startIndex = fileData.indexOf("{");
231
+ let endIndex = fileData.lastIndexOf("}");
232
+ let jsonStr = fileData.slice(
233
+ startIndex,
234
+ endIndex === fileData.length ? endIndex : endIndex + 1
235
+ );
236
+ try {
237
+ // 当成js执行
238
+ eval("jsonObj = " + jsonStr);
239
+ } catch (err) {
240
+ jsonObj = null;
241
+ // log.error("文件解析失败");
242
+ reject();
243
+ }
244
+
245
+ if (jsonObj) {
246
+ let obj = {};
247
+ let words = parseConfigs(jsonObj);
248
+ let limitedWords = limitWords(words, 7);
249
+ // log.on(`正在翻译${chalk.yellow(filePath)}`);
250
+ startTranslate(limitedWords, () => {
251
+ let words_result = limitedWords.flat(1);
252
+ setTranslatedObj(words_result, obj);
253
+ let file_result =
254
+ `export default ` + unquoteKeys(JSON.stringify(obj, null, 2));
255
+ resolve(file_result);
256
+ });
257
+ }
258
+ }
259
+ });
260
+ });
261
+ }
262
+
263
+ /**
264
+ * 获取所有需要处理的文件路径+目标路径
265
+ * @param dirPath 从指定的目录地址开始查找
266
+ * @param filePaths 一个空数组,用来接收结果
267
+ */
268
+ function getAllFilePaths(translateConfig, dirPath, filePaths) {
269
+ let files = fs.readdirSync(dirPath);
270
+ files.forEach((file) => {
271
+ let filePath = path.join(dirPath, file);
272
+ let stats = fs.statSync(filePath);
273
+ // 是否是文件夹
274
+ let isDir = stats.isDirectory();
275
+ if (isDir) {
276
+ if (file === translateConfig.sourceDirName) {
277
+ // 找到目标文件夹, 获取所有文件
278
+ let files = fs.readdirSync(filePath);
279
+ files.forEach((file) => {
280
+ let jsPath = path.join(filePath, file);
281
+ let targetPath = path.join(dirPath, translateConfig.targetDirName);
282
+ filePaths.push({
283
+ sourcePath: jsPath,
284
+ targetPath,
285
+ });
286
+ });
287
+ } else if (!translateConfig.ignoreFiles.includes(file)) {
288
+ getAllFilePaths(translateConfig, filePath, filePaths);
289
+ }
290
+ }
291
+ });
292
+ }
293
+
294
+ /**
295
+ * 同步执行所有翻译操作
296
+ * 因为每秒请求数有限制, 异步请求会超过最大并发数
297
+ * @param files 所有要翻译的文件
298
+ * @param index 当前进行到的index
299
+ */
300
+ async function execWorkerSync(files, index = 0) {
301
+ let fileItem = files[index];
302
+ let file_content = await readAndTranslateFileContent(fileItem.sourcePath);
303
+ let fileName = path.basename(fileItem.sourcePath);
304
+ let newFilePath = fileItem.targetPath + "/" + fileName;
305
+ let exist = fs.existsSync(fileItem.targetPath);
306
+ // 自动创建不存在的目录
307
+ if (!exist) {
308
+ try {
309
+ // log.on(`创建文件夹${chalk.yellow(fileItem.targetPath)}`);
310
+ fs.mkdirSync(fileItem.targetPath);
311
+ } catch (error) {
312
+ // log.error(`创建文件夹${chalk.red(fileItem.targetPath)}失败`);
313
+ process.exit(1);
314
+ }
315
+ }
316
+ writeFileContent(newFilePath, file_content, async (spinner, isOk) => {
317
+ if (isOk) {
318
+ spinner.succeed(`${newFilePath}已翻译`);
319
+ } else {
320
+ spinner.fail(`${newFilePath}翻译失败`);
321
+ }
322
+ index++;
323
+ if (index < files.length) {
324
+ spinner.start();
325
+ await execWorkerSync(files, index);
326
+ spinner.stop();
327
+ } else {
328
+ spinner.stop();
329
+ spinner.succeed("翻译完毕");
330
+ }
331
+ });
332
+ }
333
+
334
+ export { translateCmd };
@@ -0,0 +1,16 @@
1
+ {
2
+ "translate": {
3
+ "sourceDirName": "zh-CN",
4
+ "targetDirName": "en-US",
5
+ "ignoreFiles": [
6
+ "node_modules"
7
+ ],
8
+ "account": {
9
+ "appId": "",
10
+ "key": ""
11
+ }
12
+ },
13
+ "editableConfig": [
14
+ "translate"
15
+ ]
16
+ }
package/src/index.js ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ // const pkg = require("./package.json");
4
+ import { registerCommand, initProgram } from "./command/index.js";
5
+ import { translateCmd } from "./command/translate.js";
6
+ import { configCmd } from "./command/config.js";
7
+ import { setCmd } from "./command/set.js";
8
+ import { tinyCmd } from "./command/tiny.js";
9
+ import { picgoCmd } from "./command/picgo.js";
10
+ import { checkUpdate } from './utils/common.js'
11
+
12
+ const program = new Command();
13
+
14
+ initProgram(program, async () => {
15
+ await checkUpdate()
16
+ registerCommand(program, translateCmd);
17
+
18
+ registerCommand(program, setCmd);
19
+
20
+ registerCommand(program, configCmd);
21
+
22
+ registerCommand(program, tinyCmd);
23
+ registerCommand(program, picgoCmd);
24
+
25
+ program.parse(process.argv);
26
+ });
@@ -0,0 +1,47 @@
1
+ import { MD5 } from "./md5.js";
2
+ import path from "path";
3
+ import { readJsonFile } from "../utils/file.js";
4
+ import axios from "axios";
5
+ import { dirname } from "node:path"
6
+ import { fileURLToPath } from "node:url"
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+ let salt = new Date().getTime();
11
+ let appid, key;
12
+ async function genUser() {
13
+ let config = await readJsonFile(path.resolve(__dirname, "../config.json"));
14
+ let translateConfig = config.translate;
15
+ appid = translateConfig.account.appId; // appid
16
+ key = translateConfig.account.key; // 密钥
17
+ }
18
+ function genSign(options) {
19
+ let str1 = appid + options.query + salt + key;
20
+ let sign = MD5(str1);
21
+ return sign;
22
+ }
23
+
24
+ export async function translate(options) {
25
+ await genUser();
26
+ return new Promise((resolve, reject) => {
27
+ axios({
28
+ url: "http://api.fanyi.baidu.com/api/trans/vip/translate",
29
+ method: "get",
30
+ params: {
31
+ q: options.query,
32
+ appid: appid,
33
+ salt: salt,
34
+ from: options.from,
35
+ to: options.to,
36
+ sign: genSign(options),
37
+ },
38
+ })
39
+ .then((res) => {
40
+ resolve(res.data);
41
+ })
42
+ .catch((err) => {
43
+ reject("翻译失败");
44
+ })
45
+ .finally(() => {});
46
+ });
47
+ }
@@ -0,0 +1,231 @@
1
+ var MD5 = function (string) {
2
+ function RotateLeft(lValue, iShiftBits) {
3
+ return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
4
+ }
5
+
6
+ function AddUnsigned(lX, lY) {
7
+ var lX4, lY4, lX8, lY8, lResult;
8
+ lX8 = lX & 0x80000000;
9
+ lY8 = lY & 0x80000000;
10
+ lX4 = lX & 0x40000000;
11
+ lY4 = lY & 0x40000000;
12
+ lResult = (lX & 0x3fffffff) + (lY & 0x3fffffff);
13
+ if (lX4 & lY4) {
14
+ return lResult ^ 0x80000000 ^ lX8 ^ lY8;
15
+ }
16
+ if (lX4 | lY4) {
17
+ if (lResult & 0x40000000) {
18
+ return lResult ^ 0xc0000000 ^ lX8 ^ lY8;
19
+ } else {
20
+ return lResult ^ 0x40000000 ^ lX8 ^ lY8;
21
+ }
22
+ } else {
23
+ return lResult ^ lX8 ^ lY8;
24
+ }
25
+ }
26
+
27
+ function F(x, y, z) {
28
+ return (x & y) | (~x & z);
29
+ }
30
+ function G(x, y, z) {
31
+ return (x & z) | (y & ~z);
32
+ }
33
+ function H(x, y, z) {
34
+ return x ^ y ^ z;
35
+ }
36
+ function I(x, y, z) {
37
+ return y ^ (x | ~z);
38
+ }
39
+
40
+ function FF(a, b, c, d, x, s, ac) {
41
+ a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
42
+ return AddUnsigned(RotateLeft(a, s), b);
43
+ }
44
+
45
+ function GG(a, b, c, d, x, s, ac) {
46
+ a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
47
+ return AddUnsigned(RotateLeft(a, s), b);
48
+ }
49
+
50
+ function HH(a, b, c, d, x, s, ac) {
51
+ a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
52
+ return AddUnsigned(RotateLeft(a, s), b);
53
+ }
54
+
55
+ function II(a, b, c, d, x, s, ac) {
56
+ a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
57
+ return AddUnsigned(RotateLeft(a, s), b);
58
+ }
59
+
60
+ function ConvertToWordArray(string) {
61
+ var lWordCount;
62
+ var lMessageLength = string.length;
63
+ var lNumberOfWords_temp1 = lMessageLength + 8;
64
+ var lNumberOfWords_temp2 =
65
+ (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
66
+ var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
67
+ var lWordArray = Array(lNumberOfWords - 1);
68
+ var lBytePosition = 0;
69
+ var lByteCount = 0;
70
+ while (lByteCount < lMessageLength) {
71
+ lWordCount = (lByteCount - (lByteCount % 4)) / 4;
72
+ lBytePosition = (lByteCount % 4) * 8;
73
+ lWordArray[lWordCount] =
74
+ lWordArray[lWordCount] |
75
+ (string.charCodeAt(lByteCount) << lBytePosition);
76
+ lByteCount++;
77
+ }
78
+ lWordCount = (lByteCount - (lByteCount % 4)) / 4;
79
+ lBytePosition = (lByteCount % 4) * 8;
80
+ lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
81
+ lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
82
+ lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
83
+ return lWordArray;
84
+ }
85
+
86
+ function WordToHex(lValue) {
87
+ var WordToHexValue = "",
88
+ WordToHexValue_temp = "",
89
+ lByte,
90
+ lCount;
91
+ for (lCount = 0; lCount <= 3; lCount++) {
92
+ lByte = (lValue >>> (lCount * 8)) & 255;
93
+ WordToHexValue_temp = "0" + lByte.toString(16);
94
+ WordToHexValue =
95
+ WordToHexValue +
96
+ WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
97
+ }
98
+ return WordToHexValue;
99
+ }
100
+
101
+ function Utf8Encode(string) {
102
+ string = string.replace(/\r\n/g, "\n");
103
+ var utftext = "";
104
+
105
+ for (var n = 0; n < string.length; n++) {
106
+ var c = string.charCodeAt(n);
107
+
108
+ if (c < 128) {
109
+ utftext += String.fromCharCode(c);
110
+ } else if (c > 127 && c < 2048) {
111
+ utftext += String.fromCharCode((c >> 6) | 192);
112
+ utftext += String.fromCharCode((c & 63) | 128);
113
+ } else {
114
+ utftext += String.fromCharCode((c >> 12) | 224);
115
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
116
+ utftext += String.fromCharCode((c & 63) | 128);
117
+ }
118
+ }
119
+
120
+ return utftext;
121
+ }
122
+
123
+ var x = Array();
124
+ var k, AA, BB, CC, DD, a, b, c, d;
125
+ var S11 = 7,
126
+ S12 = 12,
127
+ S13 = 17,
128
+ S14 = 22;
129
+ var S21 = 5,
130
+ S22 = 9,
131
+ S23 = 14,
132
+ S24 = 20;
133
+ var S31 = 4,
134
+ S32 = 11,
135
+ S33 = 16,
136
+ S34 = 23;
137
+ var S41 = 6,
138
+ S42 = 10,
139
+ S43 = 15,
140
+ S44 = 21;
141
+
142
+ string = Utf8Encode(string);
143
+
144
+ x = ConvertToWordArray(string);
145
+
146
+ a = 0x67452301;
147
+ b = 0xefcdab89;
148
+ c = 0x98badcfe;
149
+ d = 0x10325476;
150
+
151
+ for (k = 0; k < x.length; k += 16) {
152
+ AA = a;
153
+ BB = b;
154
+ CC = c;
155
+ DD = d;
156
+ a = FF(a, b, c, d, x[k + 0], S11, 0xd76aa478);
157
+ d = FF(d, a, b, c, x[k + 1], S12, 0xe8c7b756);
158
+ c = FF(c, d, a, b, x[k + 2], S13, 0x242070db);
159
+ b = FF(b, c, d, a, x[k + 3], S14, 0xc1bdceee);
160
+ a = FF(a, b, c, d, x[k + 4], S11, 0xf57c0faf);
161
+ d = FF(d, a, b, c, x[k + 5], S12, 0x4787c62a);
162
+ c = FF(c, d, a, b, x[k + 6], S13, 0xa8304613);
163
+ b = FF(b, c, d, a, x[k + 7], S14, 0xfd469501);
164
+ a = FF(a, b, c, d, x[k + 8], S11, 0x698098d8);
165
+ d = FF(d, a, b, c, x[k + 9], S12, 0x8b44f7af);
166
+ c = FF(c, d, a, b, x[k + 10], S13, 0xffff5bb1);
167
+ b = FF(b, c, d, a, x[k + 11], S14, 0x895cd7be);
168
+ a = FF(a, b, c, d, x[k + 12], S11, 0x6b901122);
169
+ d = FF(d, a, b, c, x[k + 13], S12, 0xfd987193);
170
+ c = FF(c, d, a, b, x[k + 14], S13, 0xa679438e);
171
+ b = FF(b, c, d, a, x[k + 15], S14, 0x49b40821);
172
+ a = GG(a, b, c, d, x[k + 1], S21, 0xf61e2562);
173
+ d = GG(d, a, b, c, x[k + 6], S22, 0xc040b340);
174
+ c = GG(c, d, a, b, x[k + 11], S23, 0x265e5a51);
175
+ b = GG(b, c, d, a, x[k + 0], S24, 0xe9b6c7aa);
176
+ a = GG(a, b, c, d, x[k + 5], S21, 0xd62f105d);
177
+ d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
178
+ c = GG(c, d, a, b, x[k + 15], S23, 0xd8a1e681);
179
+ b = GG(b, c, d, a, x[k + 4], S24, 0xe7d3fbc8);
180
+ a = GG(a, b, c, d, x[k + 9], S21, 0x21e1cde6);
181
+ d = GG(d, a, b, c, x[k + 14], S22, 0xc33707d6);
182
+ c = GG(c, d, a, b, x[k + 3], S23, 0xf4d50d87);
183
+ b = GG(b, c, d, a, x[k + 8], S24, 0x455a14ed);
184
+ a = GG(a, b, c, d, x[k + 13], S21, 0xa9e3e905);
185
+ d = GG(d, a, b, c, x[k + 2], S22, 0xfcefa3f8);
186
+ c = GG(c, d, a, b, x[k + 7], S23, 0x676f02d9);
187
+ b = GG(b, c, d, a, x[k + 12], S24, 0x8d2a4c8a);
188
+ a = HH(a, b, c, d, x[k + 5], S31, 0xfffa3942);
189
+ d = HH(d, a, b, c, x[k + 8], S32, 0x8771f681);
190
+ c = HH(c, d, a, b, x[k + 11], S33, 0x6d9d6122);
191
+ b = HH(b, c, d, a, x[k + 14], S34, 0xfde5380c);
192
+ a = HH(a, b, c, d, x[k + 1], S31, 0xa4beea44);
193
+ d = HH(d, a, b, c, x[k + 4], S32, 0x4bdecfa9);
194
+ c = HH(c, d, a, b, x[k + 7], S33, 0xf6bb4b60);
195
+ b = HH(b, c, d, a, x[k + 10], S34, 0xbebfbc70);
196
+ a = HH(a, b, c, d, x[k + 13], S31, 0x289b7ec6);
197
+ d = HH(d, a, b, c, x[k + 0], S32, 0xeaa127fa);
198
+ c = HH(c, d, a, b, x[k + 3], S33, 0xd4ef3085);
199
+ b = HH(b, c, d, a, x[k + 6], S34, 0x4881d05);
200
+ a = HH(a, b, c, d, x[k + 9], S31, 0xd9d4d039);
201
+ d = HH(d, a, b, c, x[k + 12], S32, 0xe6db99e5);
202
+ c = HH(c, d, a, b, x[k + 15], S33, 0x1fa27cf8);
203
+ b = HH(b, c, d, a, x[k + 2], S34, 0xc4ac5665);
204
+ a = II(a, b, c, d, x[k + 0], S41, 0xf4292244);
205
+ d = II(d, a, b, c, x[k + 7], S42, 0x432aff97);
206
+ c = II(c, d, a, b, x[k + 14], S43, 0xab9423a7);
207
+ b = II(b, c, d, a, x[k + 5], S44, 0xfc93a039);
208
+ a = II(a, b, c, d, x[k + 12], S41, 0x655b59c3);
209
+ d = II(d, a, b, c, x[k + 3], S42, 0x8f0ccc92);
210
+ c = II(c, d, a, b, x[k + 10], S43, 0xffeff47d);
211
+ b = II(b, c, d, a, x[k + 1], S44, 0x85845dd1);
212
+ a = II(a, b, c, d, x[k + 8], S41, 0x6fa87e4f);
213
+ d = II(d, a, b, c, x[k + 15], S42, 0xfe2ce6e0);
214
+ c = II(c, d, a, b, x[k + 6], S43, 0xa3014314);
215
+ b = II(b, c, d, a, x[k + 13], S44, 0x4e0811a1);
216
+ a = II(a, b, c, d, x[k + 4], S41, 0xf7537e82);
217
+ d = II(d, a, b, c, x[k + 11], S42, 0xbd3af235);
218
+ c = II(c, d, a, b, x[k + 2], S43, 0x2ad7d2bb);
219
+ b = II(b, c, d, a, x[k + 9], S44, 0xeb86d391);
220
+ a = AddUnsigned(a, AA);
221
+ b = AddUnsigned(b, BB);
222
+ c = AddUnsigned(c, CC);
223
+ d = AddUnsigned(d, DD);
224
+ }
225
+
226
+ var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);
227
+
228
+ return temp.toLowerCase();
229
+ };
230
+
231
+ export { MD5 };