@guanghechen/filepart 1.0.0-alpha.7 → 1.0.1
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.
- package/lib/cjs/index.cjs +6 -16
- package/lib/esm/index.mjs +2 -13
- package/lib/types/index.d.ts +1 -0
- package/package.json +6 -8
package/lib/cjs/index.cjs
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var invariant = require('@guanghechen/invariant');
|
|
3
4
|
var filepart_types = require('@guanghechen/filepart.types');
|
|
4
5
|
|
|
5
|
-
const isProduction = process.env['NODE_ENV'] === 'production';
|
|
6
|
-
const prefix = 'Invariant failed';
|
|
7
|
-
function invariant(condition, message) {
|
|
8
|
-
if (condition)
|
|
9
|
-
return;
|
|
10
|
-
if (isProduction)
|
|
11
|
-
throw new Error(prefix);
|
|
12
|
-
if (message == null)
|
|
13
|
-
throw new Error(prefix + ': ');
|
|
14
|
-
throw new Error(prefix + ': ' + (message instanceof Function ? message() : message));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
6
|
function* calcFilePartItemsBySize(fileSize, partSize) {
|
|
18
7
|
if (fileSize <= 0) {
|
|
19
8
|
yield { sid: 1, start: 0, end: 0 };
|
|
@@ -23,9 +12,9 @@ function* calcFilePartItemsBySize(fileSize, partSize) {
|
|
|
23
12
|
yield { sid: 1, start: 0, end: fileSize };
|
|
24
13
|
return;
|
|
25
14
|
}
|
|
26
|
-
invariant(partSize >= 1 && Number.isInteger(partSize), 'Part size should be a positive integer!');
|
|
15
|
+
invariant.invariant(partSize >= 1 && Number.isInteger(partSize), 'Part size should be a positive integer!');
|
|
27
16
|
const partTotal = Math.ceil(fileSize / partSize);
|
|
28
|
-
invariant(partTotal > 0, 'Part size is too small!');
|
|
17
|
+
invariant.invariant(partTotal > 0, 'Part size is too small!');
|
|
29
18
|
for (let i = 0; i < partTotal; ++i) {
|
|
30
19
|
const part = {
|
|
31
20
|
sid: i + 1,
|
|
@@ -36,7 +25,7 @@ function* calcFilePartItemsBySize(fileSize, partSize) {
|
|
|
36
25
|
}
|
|
37
26
|
}
|
|
38
27
|
function* calcFilePartItemsByCount(fileSize, partTotal) {
|
|
39
|
-
invariant(partTotal >= 1 && Number.isInteger(partTotal), 'Total of part should be a positive integer!');
|
|
28
|
+
invariant.invariant(partTotal >= 1 && Number.isInteger(partTotal), 'Total of part should be a positive integer!');
|
|
40
29
|
if (fileSize <= 0) {
|
|
41
30
|
yield { sid: 1, start: 0, end: 0 };
|
|
42
31
|
return;
|
|
@@ -46,7 +35,7 @@ function* calcFilePartItemsByCount(fileSize, partTotal) {
|
|
|
46
35
|
return;
|
|
47
36
|
}
|
|
48
37
|
const partSize = Math.ceil(fileSize / partTotal);
|
|
49
|
-
invariant(partSize > 0, 'Part size is too small!');
|
|
38
|
+
invariant.invariant(partSize > 0, 'Part size is too small!');
|
|
50
39
|
for (let i = 0; i < partTotal; ++i) {
|
|
51
40
|
const part = {
|
|
52
41
|
sid: i + 1,
|
|
@@ -95,3 +84,4 @@ Object.keys(filepart_types).forEach(function (k) {
|
|
|
95
84
|
get: function () { return filepart_types[k]; }
|
|
96
85
|
});
|
|
97
86
|
});
|
|
87
|
+
//# sourceMappingURL=index.cjs.map
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
import '
|
|
1
|
+
import { invariant } from '@guanghechen/invariant';
|
|
2
2
|
export * from '@guanghechen/filepart.types';
|
|
3
3
|
|
|
4
|
-
const isProduction = process.env['NODE_ENV'] === 'production';
|
|
5
|
-
const prefix = 'Invariant failed';
|
|
6
|
-
function invariant(condition, message) {
|
|
7
|
-
if (condition)
|
|
8
|
-
return;
|
|
9
|
-
if (isProduction)
|
|
10
|
-
throw new Error(prefix);
|
|
11
|
-
if (message == null)
|
|
12
|
-
throw new Error(prefix + ': ');
|
|
13
|
-
throw new Error(prefix + ': ' + (message instanceof Function ? message() : message));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
4
|
function* calcFilePartItemsBySize(fileSize, partSize) {
|
|
17
5
|
if (fileSize <= 0) {
|
|
18
6
|
yield { sid: 1, start: 0, end: 0 };
|
|
@@ -85,3 +73,4 @@ function* calcFilePartNamesByCount(partTotal, partCodePrefix) {
|
|
|
85
73
|
}
|
|
86
74
|
|
|
87
75
|
export { calcFilePartItemsByCount, calcFilePartItemsBySize, calcFilePartNames, calcFilePartNamesByCount };
|
|
76
|
+
//# sourceMappingURL=index.mjs.map
|
package/lib/types/index.d.ts
CHANGED
|
@@ -28,3 +28,4 @@ declare function calcFilePartNames(parts: ReadonlyArray<Pick<IFilePartItem, 'sid
|
|
|
28
28
|
declare function calcFilePartNamesByCount(partTotal: number, partCodePrefix: string): IterableIterator<string>;
|
|
29
29
|
|
|
30
30
|
export { calcFilePartItemsByCount, calcFilePartItemsBySize, calcFilePartNames, calcFilePartNamesByCount };
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guanghechen/filepart",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "File helper",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "guanghechen",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/guanghechen/sora/tree/@guanghechen/filepart@1.0.0
|
|
11
|
+
"url": "https://github.com/guanghechen/sora/tree/@guanghechen/filepart@1.0.0",
|
|
12
12
|
"directory": "packages/filepart"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/filepart@1.0.0
|
|
14
|
+
"homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/filepart@1.0.0/packages/filepart#readme",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"file helper",
|
|
17
17
|
"split file",
|
|
@@ -40,10 +40,8 @@
|
|
|
40
40
|
"README.md"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@guanghechen/filepart.types": "^1.0.
|
|
43
|
+
"@guanghechen/filepart.types": "^1.0.1",
|
|
44
|
+
"@guanghechen/invariant": "^6.0.2"
|
|
44
45
|
},
|
|
45
|
-
"
|
|
46
|
-
"@guanghechen/internal": "^1.0.0-alpha.0"
|
|
47
|
-
},
|
|
48
|
-
"gitHead": "61841206a2ca8060c0f47a32b9aa177b318f7c2e"
|
|
46
|
+
"gitHead": "e4d3bb66f61d6bf0a771d6c805dc1eb1ea31361d"
|
|
49
47
|
}
|