Skip to content

Commit 09ed44a

Browse files
committed
refactor: use typescript
1 parent 82796e1 commit 09ed44a

File tree

18 files changed

+270
-212
lines changed

18 files changed

+270
-212
lines changed

.commitlintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
rules: {
3+
'type-enum': [
4+
2,
5+
'always',
6+
['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test', 'wip'],
7+
],
8+
},
9+
};

.eslintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"project": "./tsconfig.ci.json"
5+
},
6+
"plugins": ["@typescript-eslint"],
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/eslint-recommended",
10+
"plugin:@typescript-eslint/recommended",
11+
"prettier",
12+
"prettier/@typescript-eslint"
13+
]
14+
}

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: ['https://paypal.me/hustcc', 'https://atool.vip']

.gitignore

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1-
.project
2-
.settings
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
38

4-
node_modules/*
9+
# Sys
10+
.DS_STORE
11+
.idea
512

13+
# Node
14+
node_modules/
15+
16+
# Build
17+
dist
18+
lib
19+
20+
# Test
21+
coverage

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"bracketSpacing": true,
6+
"printWidth": 120,
7+
"arrowParens": "always"
8+
}

.travis.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
language: node_js
22
node_js:
3-
- "4.4.4"
4-
- "0.12"
3+
- "8"
4+
- "9"
5+
- "10"
6+
- "11"
7+
- "12"
8+
addons:
9+
apt:
10+
packages:
11+
- xvfb
12+
install:
13+
- export DISPLAY=':99.0'
14+
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
15+
- npm install
16+
script:
17+
- npm run ci
18+
after_success:
19+
- npm run coveralls

LICENSE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
The MIT License (MIT)
1+
MIT License
22

3-
Copyright (c) 2016 Hust.cc
3+
Copyright (c) 2019 hustcc
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

__tests__/index.spec.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import fileSize from '../src';
2+
3+
describe('fileSize.js', () => {
4+
let bytes, i, unit;
5+
const jedec = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
6+
const si = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
7+
8+
test('jedec', () => {
9+
// test `bytes`, default spec `jedec`
10+
bytes = 1.98765;
11+
12+
for (i = 0; i < jedec.length; i++) {
13+
unit = jedec[i];
14+
expect(fileSize(bytes)).toBe('2.0 ' + unit + 'b'); // default fixed = 1
15+
expect(fileSize(bytes, undefined, 'jedec')).toBe('2.0 ' + unit + 'b'); // default fixed = 1
16+
expect(fileSize(bytes, 2, 'not_exist_spec')).toBe('1.99 ' + unit + 'b'); // default spec = 'jedec'
17+
18+
expect(fileSize(bytes, 4)).toBe('1.9876 ' + unit + 'b'); // test fixed = 3
19+
bytes *= 1024;
20+
}
21+
});
22+
23+
test('si', () => {
24+
// test spec `si`
25+
bytes = 1.23456;
26+
for (i = 0; i < si.length; i++) {
27+
unit = si[i];
28+
expect(fileSize(bytes, undefined, 'si')).toBe('1.2 ' + unit + 'b');
29+
30+
expect(fileSize(bytes, 4, 'si')).toBe('1.2346 ' + unit + 'b'); // test fixed = 3
31+
bytes *= 1000;
32+
}
33+
});
34+
35+
test('iec', () => {
36+
// test spec `iec`
37+
bytes = 1.98765;
38+
const iec = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'];
39+
for (i = 0; i < iec.length; i++) {
40+
unit = iec[i];
41+
expect(fileSize(bytes, undefined, 'iec')).toBe('2.0 ' + unit + 'b');
42+
43+
expect(fileSize(bytes, 3, 'iec')).toBe('1.988 ' + unit + 'b'); // test fixed = 3
44+
bytes *= 1024;
45+
}
46+
});
47+
48+
test('other', () => {
49+
// test negative
50+
bytes = -1.98765;
51+
for (i = 0; i < jedec.length; i++) {
52+
unit = jedec[i];
53+
expect(fileSize(bytes)).toBe('2.0 ' + unit + 'b'); // default fixed = 1
54+
expect(fileSize(bytes, undefined, 'jedec')).toBe('2.0 ' + unit + 'b'); // default fixed = 1
55+
expect(fileSize(bytes, 2, 'not_exist_spec')).toBe('1.99 ' + unit + 'b'); // default spec = 'jedec'
56+
57+
expect(fileSize(bytes, 4)).toBe('1.9876 ' + unit + 'b'); // test fixed = 3
58+
bytes *= 1024;
59+
}
60+
// bytes
61+
expect(fileSize(123456)).toBe('120.6 Kb');
62+
// fixed
63+
expect(fileSize(123456, 0)).toBe('121 Kb');
64+
expect(fileSize(123456, 4)).toBe('120.5625 Kb');
65+
// spec, jedec / iec / si
66+
expect(fileSize(123456, 2, 'iec')).toBe('120.56 Kib');
67+
expect(fileSize(123456, 0, 'si')).toBe('123 kb');
68+
});
69+
});

dist/filesize.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

dist/filesize.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)