guoguo-converbyte 1.2.0 → 1.2.2

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.
Files changed (3) hide show
  1. package/exec.js +7 -0
  2. package/index.js +9 -24
  3. package/package.json +4 -1
package/exec.js ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ const converbyte = require('./index.js');
3
+
4
+ const bytes = process.argv[2];
5
+ const type = process.argv[3];
6
+
7
+ console.log(converbyte(bytes, type));
package/index.js CHANGED
@@ -1,26 +1,11 @@
1
- // 使用第三方包
2
- /*
3
- 1. 先找是否存在内置模块 lodash
4
- 2. 再从当前目录中的 node_modules 里面找 lodash
5
- 3. 如果没有,会从上级目录的 node_modules 里面找 lodash, 一直向上找
6
- 4. 最后会找全局 node_modules
1
+ /**
2
+ * 计算机容量单位转换
3
+ * @params number bytes 字节数
4
+ * @params number type 0:不转回 1:KB 2:MB 3:GB 4:TB 默认值是0
5
+ * @return number 转换之后的结果
6
+ */
7
+ const coverByte = (bytes, type=0) => bytes / (1024 ** type);
7
8
 
8
- */
9
- const _ = require('lodash');
10
- // commonJS引入
11
- const chalk = require('chalk');
12
- // ES6引入
13
- // import chalk from 'chalk';
14
- const uniq = require('uniq');
15
- // const converbyte = require('converbyte');
16
9
 
17
-
18
- const arr = [1,2,3,4,5,6,7,8,9,10,11];
19
- console.log(_.chunk(arr, 3));
20
-
21
- console.log(chalk.red('高小乐一口水喝掉一个太平洋!'));
22
- console.log(chalk.bgRed('高小乐吃了一顿饭!'));
23
-
24
- console.log(uniq([10,20,30,40,50,40,30,30,20]));
25
-
26
- // console.log(converbyte(3445454545, 3).toFixed(2) + 'GB');
10
+ // CommonJS模块规范暴露数据
11
+ module.exports = coverByte;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guoguo-converbyte",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -8,5 +8,8 @@
8
8
  "main": "index.js",
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "bin": {
13
+ "bytec": "exec.js"
11
14
  }
12
15
  }