arcadible 0.1.25 → 0.1.27

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/package.json CHANGED
@@ -61,5 +61,5 @@
61
61
  "license": "Apache-2.0",
62
62
  "main": "./src/cli/index.js",
63
63
  "name": "arcadible",
64
- "version": "0.1.25"
64
+ "version": "0.1.27"
65
65
  }
package/src/phrase.js CHANGED
@@ -2,13 +2,8 @@
2
2
 
3
3
  // [import]
4
4
 
5
- const bytes = require("./util/bytes");
6
5
  const cfgproduct = require("./config/product");
7
6
 
8
- // [use]
9
-
10
- const formatBytes = bytes.formatBytes;
11
-
12
7
  // [declare]
13
8
 
14
9
  const TOOL = cfgproduct.tool;
@@ -130,7 +125,7 @@ const imageHeightMin = function (height) {
130
125
  // [function]
131
126
 
132
127
  const imageSizeMax = function (size) {
133
- return `Image size must not exceed: ${formatBytes(size)}`;
128
+ return `Image size must not exceed: ${size}`;
134
129
  };
135
130
 
136
131
  // [function]
@@ -340,7 +335,7 @@ const videoInvalid = function () {
340
335
  // [function]
341
336
 
342
337
  const videoSizeMax = function (size) {
343
- return `Video size must not exceed: ${formatBytes(size)}`;
338
+ return `Video size must not exceed: ${size}`;
344
339
  };
345
340
 
346
341
  // [function]
@@ -199,7 +199,7 @@ const zBannerVideo = function (root) {
199
199
 
200
200
  const zBio = function () {
201
201
  const field = "bio";
202
- return z.optional(zText(field, { max: 30 * 5, min: 1 }));
202
+ return z.optional(zText(field, { max: 30 * 6, min: 1 }));
203
203
  };
204
204
 
205
205
  // [function]
package/src/util/bytes.js CHANGED
@@ -3,19 +3,20 @@
3
3
  // [import]
4
4
 
5
5
  const phrase = require("../phrase");
6
+ const size = require("./size");
6
7
 
7
8
  // [function]
8
9
 
9
10
  const formatBytes = function (bytes) {
10
11
  switch (true) {
11
- case bytes < 1024:
12
- return phrase.sizeB(bytes);
13
- case bytes < 1024 ** 2:
14
- return phrase.sizeKb((bytes / 1024).toFixed(1));
15
- case bytes < 1024 ** 3:
16
- return phrase.sizeMb((bytes / 1024 / 1024).toFixed(1));
12
+ case bytes >= size.gb(1):
13
+ return phrase.sizeGb(size.toGb(bytes).toFixed(1));
14
+ case bytes >= size.mb(1):
15
+ return phrase.sizeMb(size.toMb(bytes).toFixed(1));
16
+ case bytes >= size.kb(1):
17
+ return phrase.sizeKb(size.toKb(bytes).toFixed(1));
17
18
  default:
18
- return phrase.sizeGb((bytes / 1024 / 1024 / 1024).toFixed(1));
19
+ return phrase.sizeB(size.toB(bytes));
19
20
  }
20
21
  };
21
22
 
package/src/util/image.js CHANGED
@@ -11,12 +11,14 @@ const imageSize = require("image-size").imageSize;
11
11
 
12
12
  // [import]
13
13
 
14
+ const bytes = require("./bytes");
14
15
  const cfgimage = require("../config/image");
15
16
  const phrase = require("../phrase");
16
17
 
17
18
  // [use]
18
19
 
19
20
  const extname = path.extname;
21
+ const formatBytes = bytes.formatBytes;
20
22
  const readFileSync = fs.readFileSync; // eslint-disable-line no-sync
21
23
  const statSync = fs.statSync; // eslint-disable-line no-sync
22
24
 
@@ -51,7 +53,7 @@ const checkSize = function (file, maxSize) {
51
53
 
52
54
  const checkPng = function (file, { aspect, maxSize, minHeight, minWidth }) {
53
55
  if (!checkSize(file, maxSize)) {
54
- return [phrase.imageSizeMax(maxSize)];
56
+ return [phrase.imageSizeMax(formatBytes(maxSize))];
55
57
  }
56
58
  const buffer = readFileSync(file);
57
59
  const { height, width } = imageSize(buffer);
@@ -71,7 +73,7 @@ const checkPng = function (file, { aspect, maxSize, minHeight, minWidth }) {
71
73
 
72
74
  const checkSvg = function (file, { maxSize }) {
73
75
  if (!checkSize(file, maxSize)) {
74
- return [phrase.imageSizeMax(maxSize)];
76
+ return [phrase.imageSizeMax(formatBytes(maxSize))];
75
77
  }
76
78
  return [];
77
79
  };
package/src/util/size.js CHANGED
@@ -2,28 +2,52 @@
2
2
 
3
3
  // [function]
4
4
 
5
- const b = function (value) {
6
- return value;
5
+ const b = function (bytes) {
6
+ return bytes;
7
7
  };
8
8
 
9
9
  // [function]
10
10
 
11
- const kb = function (value) {
12
- return b(value * 1024);
11
+ const kb = function (bytes) {
12
+ return b(bytes * 1024);
13
13
  };
14
14
 
15
15
  // [function]
16
16
 
17
- const mb = function (value) {
18
- return kb(value * 1024);
17
+ const mb = function (bytes) {
18
+ return kb(bytes * 1024);
19
19
  };
20
20
 
21
21
  // [function]
22
22
 
23
- const gb = function (value) {
24
- return mb(value * 1024);
23
+ const gb = function (bytes) {
24
+ return mb(bytes * 1024);
25
+ };
26
+
27
+ // [function]
28
+
29
+ const toB = function (bytes) {
30
+ return bytes;
31
+ };
32
+
33
+ // [function]
34
+
35
+ const toKb = function (bytes) {
36
+ return toB(bytes / 1024);
37
+ };
38
+
39
+ // [function]
40
+
41
+ const toMb = function (bytes) {
42
+ return toKb(bytes / 1024);
43
+ };
44
+
45
+ // [function]
46
+
47
+ const toGb = function (bytes) {
48
+ return toMb(bytes / 1024);
25
49
  };
26
50
 
27
51
  // [export]
28
52
 
29
- module.exports = { b, gb, kb, mb };
53
+ module.exports = { b, gb, kb, mb, toB, toGb, toKb, toMb };
package/src/util/video.js CHANGED
@@ -11,12 +11,14 @@ const fs = require("fs-extra");
11
11
 
12
12
  // [import]
13
13
 
14
+ const bytes = require("./bytes");
14
15
  const cfgvideo = require("../config/video");
15
16
  const phrase = require("../phrase");
16
17
 
17
18
  // [use]
18
19
 
19
20
  const extname = path.extname;
21
+ const formatBytes = bytes.formatBytes;
20
22
  const readFileSync = fs.readFileSync; // eslint-disable-line no-sync
21
23
  const statSync = fs.statSync; // eslint-disable-line no-sync
22
24
 
@@ -92,7 +94,7 @@ const checkMp4 = function (
92
94
  { aspect, maxDuration, maxSize, minDuration, minHeight, minWidth },
93
95
  ) {
94
96
  if (!checkSize(file, maxSize)) {
95
- return [phrase.videoSizeMax(maxSize)];
97
+ return [phrase.videoSizeMax(formatBytes(maxSize))];
96
98
  }
97
99
  let video = null;
98
100
  try {