@powerlines/plugin-image-compression 0.2.119 → 0.2.121

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/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
- const require_pretty_bytes = require('./node_modules/.pnpm/@stryke_string-format@0.13.1/node_modules/@stryke/string-format/dist/pretty-bytes.cjs');
3
+ const require_pretty_bytes = require('./node_modules/.pnpm/@stryke_string-format@0.13.3/node_modules/@stryke/string-format/dist/pretty-bytes.cjs');
4
4
  let __stryke_convert_to_array = require("@stryke/convert/to-array");
5
5
  let __stryke_fs_list_files = require("@stryke/fs/list-files");
6
6
  let __stryke_fs_read_file = require("@stryke/fs/read-file");
@@ -108,7 +108,7 @@ const plugin = (options = {}) => {
108
108
  this.error(` ✘ Failed to optimize ${file} - Compression output was not smaller than the original`);
109
109
  return;
110
110
  }
111
- this.info(` ✔ Successfully optimized ${file}: ${chalk.default.redBright(require_pretty_bytes.a(originalSize))} -> ${chalk.default.greenBright(require_pretty_bytes.a(compressedSize))} (${chalk.default.green((100 - compressedSize / originalSize * 100).toFixed(2))}%) in ${(performance.now() - start).toFixed(2)} ms`);
111
+ this.info(` ✔ Successfully optimized ${file}: ${chalk.default.redBright(require_pretty_bytes.prettyBytes(originalSize))} -> ${chalk.default.greenBright(require_pretty_bytes.prettyBytes(compressedSize))} (${chalk.default.green((100 - compressedSize / originalSize * 100).toFixed(2))}%) in ${(performance.now() - start).toFixed(2)} ms`);
112
112
  }));
113
113
  }));
114
114
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a } from "./node_modules/.pnpm/@stryke_string-format@0.13.1/node_modules/@stryke/string-format/dist/pretty-bytes.mjs";
1
+ import { prettyBytes } from "./node_modules/.pnpm/@stryke_string-format@0.13.3/node_modules/@stryke/string-format/dist/pretty-bytes.mjs";
2
2
  import { toArray } from "@stryke/convert/to-array";
3
3
  import { listFiles } from "@stryke/fs/list-files";
4
4
  import { readFile } from "@stryke/fs/read-file";
@@ -105,7 +105,7 @@ const plugin = (options = {}) => {
105
105
  this.error(` ✘ Failed to optimize ${file} - Compression output was not smaller than the original`);
106
106
  return;
107
107
  }
108
- this.info(` ✔ Successfully optimized ${file}: ${chalk.redBright(a(originalSize))} -> ${chalk.greenBright(a(compressedSize))} (${chalk.green((100 - compressedSize / originalSize * 100).toFixed(2))}%) in ${(performance.now() - start).toFixed(2)} ms`);
108
+ this.info(` ✔ Successfully optimized ${file}: ${chalk.redBright(prettyBytes(originalSize))} -> ${chalk.greenBright(prettyBytes(compressedSize))} (${chalk.green((100 - compressedSize / originalSize * 100).toFixed(2))}%) in ${(performance.now() - start).toFixed(2)} ms`);
109
109
  }));
110
110
  }));
111
111
  }
@@ -0,0 +1,128 @@
1
+
2
+ //#region ../../node_modules/.pnpm/@stryke+string-format@0.13.3/node_modules/@stryke/string-format/dist/pretty-bytes.mjs
3
+ const BYTE_UNITS = [
4
+ "B",
5
+ "kB",
6
+ "MB",
7
+ "GB",
8
+ "TB",
9
+ "PB",
10
+ "EB",
11
+ "ZB",
12
+ "YB"
13
+ ];
14
+ const BIBYTE_UNITS = [
15
+ "B",
16
+ "KiB",
17
+ "MiB",
18
+ "GiB",
19
+ "TiB",
20
+ "PiB",
21
+ "EiB",
22
+ "ZiB",
23
+ "YiB"
24
+ ];
25
+ const BIT_UNITS = [
26
+ "b",
27
+ "kbit",
28
+ "Mbit",
29
+ "Gbit",
30
+ "Tbit",
31
+ "Pbit",
32
+ "Ebit",
33
+ "Zbit",
34
+ "Ybit"
35
+ ];
36
+ const BIBIT_UNITS = [
37
+ "b",
38
+ "kibit",
39
+ "Mibit",
40
+ "Gibit",
41
+ "Tibit",
42
+ "Pibit",
43
+ "Eibit",
44
+ "Zibit",
45
+ "Yibit"
46
+ ];
47
+ /**
48
+ * Formats the given number using `Number#toLocaleString`.
49
+ *
50
+ * @remarks
51
+ * - If locale is a string, the value is expected to be a locale-key (for example: `de`).
52
+ * - If locale is true, the system default locale is used for translation.
53
+ * - If no value for locale is specified, the number is returned unmodified.
54
+ *
55
+ * @param number - The number to format.
56
+ * @param locale - The locale to use for formatting the number.
57
+ * @param options - The options to use for formatting the number.
58
+ * @returns The formatted number.
59
+ */
60
+ const toLocaleString = (number, locale, options = {}) => {
61
+ let result = number;
62
+ let _locale = locale;
63
+ if (typeof _locale === "string") {
64
+ if (!_locale) _locale = process.env.STORM_LOCALE || "en-US";
65
+ if (Array.isArray(_locale)) result = number?.toLocaleString(_locale, options);
66
+ } else if (_locale === true || options !== void 0) result = number?.toLocaleString(void 0, options);
67
+ return String(result);
68
+ };
69
+ /**
70
+ * Convert bytes to a human readable string: `1337` → `1.34 kB`.
71
+ *
72
+ * @param number - The number to format.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * import { prettyBytes } from '@stryke/string-fns/pretty-bytes';
77
+ *
78
+ * prettyBytes(1337);
79
+ * //=> '1.34 kB'
80
+ *
81
+ * prettyBytes(100);
82
+ * //=> '100 B'
83
+ *
84
+ * // Display file size differences
85
+ * prettyBytes(42, {signed: true});
86
+ * //=> '+42 B'
87
+ *
88
+ * // Localized output using German locale
89
+ * prettyBytes(1337, {locale: 'de'});
90
+ * //=> '1,34 kB'
91
+ * ```
92
+ *
93
+ * @param number - The number to format.
94
+ * @param options - The options to use.
95
+ * @returns The formatted string.
96
+ */
97
+ function prettyBytes(number, options) {
98
+ let _number = number;
99
+ if (!Number.isFinite(_number)) throw new TypeError(`Expected a finite number, got ${typeof _number}: ${_number}`);
100
+ const opts = {
101
+ bits: false,
102
+ binary: false,
103
+ space: true,
104
+ ...options
105
+ };
106
+ const UNITS = opts.bits ? opts.binary ? BIBIT_UNITS : BIT_UNITS : opts.binary ? BIBYTE_UNITS : BYTE_UNITS;
107
+ const separator = opts.space ? " " : "";
108
+ if (opts.signed && _number === 0) return ` 0${separator}${UNITS[0]}`;
109
+ const isNegative = _number < 0;
110
+ const prefix = isNegative ? "-" : opts.signed ? "+" : "";
111
+ if (isNegative) _number = -_number;
112
+ let localeOptions;
113
+ if (opts.minimumFractionDigits !== void 0) localeOptions = { minimumFractionDigits: opts.minimumFractionDigits };
114
+ if (opts.maximumFractionDigits !== void 0) localeOptions = {
115
+ maximumFractionDigits: opts.maximumFractionDigits,
116
+ ...localeOptions
117
+ };
118
+ if (_number < 1) return prefix + toLocaleString(_number, opts.locale, localeOptions) + separator + UNITS[0];
119
+ const exponent = Math.min(Math.floor(opts.binary ? Math.log(_number) / Math.log(1024) : Math.log10(_number) / 3), UNITS.length - 1);
120
+ _number /= (opts.binary ? 1024 : 1e3) ** exponent;
121
+ if (!localeOptions) _number = _number.toPrecision(3);
122
+ const numberString = toLocaleString(Number(_number), opts.locale, localeOptions);
123
+ const unit = UNITS[exponent];
124
+ return prefix + numberString + separator + unit;
125
+ }
126
+
127
+ //#endregion
128
+ exports.prettyBytes = prettyBytes;
@@ -0,0 +1,127 @@
1
+ //#region ../../node_modules/.pnpm/@stryke+string-format@0.13.3/node_modules/@stryke/string-format/dist/pretty-bytes.mjs
2
+ const BYTE_UNITS = [
3
+ "B",
4
+ "kB",
5
+ "MB",
6
+ "GB",
7
+ "TB",
8
+ "PB",
9
+ "EB",
10
+ "ZB",
11
+ "YB"
12
+ ];
13
+ const BIBYTE_UNITS = [
14
+ "B",
15
+ "KiB",
16
+ "MiB",
17
+ "GiB",
18
+ "TiB",
19
+ "PiB",
20
+ "EiB",
21
+ "ZiB",
22
+ "YiB"
23
+ ];
24
+ const BIT_UNITS = [
25
+ "b",
26
+ "kbit",
27
+ "Mbit",
28
+ "Gbit",
29
+ "Tbit",
30
+ "Pbit",
31
+ "Ebit",
32
+ "Zbit",
33
+ "Ybit"
34
+ ];
35
+ const BIBIT_UNITS = [
36
+ "b",
37
+ "kibit",
38
+ "Mibit",
39
+ "Gibit",
40
+ "Tibit",
41
+ "Pibit",
42
+ "Eibit",
43
+ "Zibit",
44
+ "Yibit"
45
+ ];
46
+ /**
47
+ * Formats the given number using `Number#toLocaleString`.
48
+ *
49
+ * @remarks
50
+ * - If locale is a string, the value is expected to be a locale-key (for example: `de`).
51
+ * - If locale is true, the system default locale is used for translation.
52
+ * - If no value for locale is specified, the number is returned unmodified.
53
+ *
54
+ * @param number - The number to format.
55
+ * @param locale - The locale to use for formatting the number.
56
+ * @param options - The options to use for formatting the number.
57
+ * @returns The formatted number.
58
+ */
59
+ const toLocaleString = (number, locale, options = {}) => {
60
+ let result = number;
61
+ let _locale = locale;
62
+ if (typeof _locale === "string") {
63
+ if (!_locale) _locale = process.env.STORM_LOCALE || "en-US";
64
+ if (Array.isArray(_locale)) result = number?.toLocaleString(_locale, options);
65
+ } else if (_locale === true || options !== void 0) result = number?.toLocaleString(void 0, options);
66
+ return String(result);
67
+ };
68
+ /**
69
+ * Convert bytes to a human readable string: `1337` → `1.34 kB`.
70
+ *
71
+ * @param number - The number to format.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { prettyBytes } from '@stryke/string-fns/pretty-bytes';
76
+ *
77
+ * prettyBytes(1337);
78
+ * //=> '1.34 kB'
79
+ *
80
+ * prettyBytes(100);
81
+ * //=> '100 B'
82
+ *
83
+ * // Display file size differences
84
+ * prettyBytes(42, {signed: true});
85
+ * //=> '+42 B'
86
+ *
87
+ * // Localized output using German locale
88
+ * prettyBytes(1337, {locale: 'de'});
89
+ * //=> '1,34 kB'
90
+ * ```
91
+ *
92
+ * @param number - The number to format.
93
+ * @param options - The options to use.
94
+ * @returns The formatted string.
95
+ */
96
+ function prettyBytes(number, options) {
97
+ let _number = number;
98
+ if (!Number.isFinite(_number)) throw new TypeError(`Expected a finite number, got ${typeof _number}: ${_number}`);
99
+ const opts = {
100
+ bits: false,
101
+ binary: false,
102
+ space: true,
103
+ ...options
104
+ };
105
+ const UNITS = opts.bits ? opts.binary ? BIBIT_UNITS : BIT_UNITS : opts.binary ? BIBYTE_UNITS : BYTE_UNITS;
106
+ const separator = opts.space ? " " : "";
107
+ if (opts.signed && _number === 0) return ` 0${separator}${UNITS[0]}`;
108
+ const isNegative = _number < 0;
109
+ const prefix = isNegative ? "-" : opts.signed ? "+" : "";
110
+ if (isNegative) _number = -_number;
111
+ let localeOptions;
112
+ if (opts.minimumFractionDigits !== void 0) localeOptions = { minimumFractionDigits: opts.minimumFractionDigits };
113
+ if (opts.maximumFractionDigits !== void 0) localeOptions = {
114
+ maximumFractionDigits: opts.maximumFractionDigits,
115
+ ...localeOptions
116
+ };
117
+ if (_number < 1) return prefix + toLocaleString(_number, opts.locale, localeOptions) + separator + UNITS[0];
118
+ const exponent = Math.min(Math.floor(opts.binary ? Math.log(_number) / Math.log(1024) : Math.log10(_number) / 3), UNITS.length - 1);
119
+ _number /= (opts.binary ? 1024 : 1e3) ** exponent;
120
+ if (!localeOptions) _number = _number.toPrecision(3);
121
+ const numberString = toLocaleString(Number(_number), opts.locale, localeOptions);
122
+ const unit = UNITS[exponent];
123
+ return prefix + numberString + separator + unit;
124
+ }
125
+
126
+ //#endregion
127
+ export { prettyBytes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-image-compression",
3
- "version": "0.2.119",
3
+ "version": "0.2.121",
4
4
  "type": "module",
5
5
  "description": "A Powerlines plugin to optimize images used by the project.",
6
6
  "repository": {
@@ -123,21 +123,21 @@
123
123
  "powerlines-plugin"
124
124
  ],
125
125
  "dependencies": {
126
- "@stryke/convert": "^0.6.32",
127
- "@stryke/fs": "^0.33.30",
128
- "@stryke/path": "^0.24.3",
126
+ "@stryke/convert": "^0.6.34",
127
+ "@stryke/fs": "^0.33.35",
128
+ "@stryke/path": "^0.25.3",
129
129
  "chalk": "5.6.2",
130
130
  "defu": "^6.1.4",
131
131
  "jiti": "^2.6.1",
132
- "powerlines": "^0.37.44",
132
+ "powerlines": "^0.37.46",
133
133
  "sharp": "^0.34.5",
134
134
  "svgo": "^4.0.0"
135
135
  },
136
136
  "devDependencies": {
137
- "@powerlines/plugin-plugin": "^0.12.122",
137
+ "@powerlines/plugin-plugin": "^0.12.124",
138
138
  "@storm-software/config": "^1.135.0",
139
139
  "@types/node": "^24.10.9"
140
140
  },
141
141
  "publishConfig": { "access": "public" },
142
- "gitHead": "e4860aa4ebc657acfef8a8f2399108f0badc520c"
142
+ "gitHead": "032b11dbd79e039303ebe2942ed230ea8956ece1"
143
143
  }
@@ -1,71 +0,0 @@
1
-
2
- //#region ../../node_modules/.pnpm/@stryke+string-format@0.13.1/node_modules/@stryke/string-format/dist/pretty-bytes.mjs
3
- const e = [
4
- `B`,
5
- `kB`,
6
- `MB`,
7
- `GB`,
8
- `TB`,
9
- `PB`,
10
- `EB`,
11
- `ZB`,
12
- `YB`
13
- ], t = [
14
- `B`,
15
- `KiB`,
16
- `MiB`,
17
- `GiB`,
18
- `TiB`,
19
- `PiB`,
20
- `EiB`,
21
- `ZiB`,
22
- `YiB`
23
- ], n = [
24
- `b`,
25
- `kbit`,
26
- `Mbit`,
27
- `Gbit`,
28
- `Tbit`,
29
- `Pbit`,
30
- `Ebit`,
31
- `Zbit`,
32
- `Ybit`
33
- ], r = [
34
- `b`,
35
- `kibit`,
36
- `Mibit`,
37
- `Gibit`,
38
- `Tibit`,
39
- `Pibit`,
40
- `Eibit`,
41
- `Zibit`,
42
- `Yibit`
43
- ], i = (e$1, t$1, n$1 = {}) => {
44
- let r$1 = e$1, i$1 = t$1;
45
- return typeof i$1 == `string` ? (i$1 ||= process.env.STORM_LOCALE || `en-US`, Array.isArray(i$1) && (r$1 = e$1?.toLocaleString(i$1, n$1))) : (i$1 === !0 || n$1 !== void 0) && (r$1 = e$1?.toLocaleString(void 0, n$1)), String(r$1);
46
- };
47
- function a(a$1, o) {
48
- let s = a$1;
49
- if (!Number.isFinite(s)) throw TypeError(`Expected a finite number, got ${typeof s}: ${s}`);
50
- let c = {
51
- bits: !1,
52
- binary: !1,
53
- space: !0,
54
- ...o
55
- }, l = c.bits ? c.binary ? r : n : c.binary ? t : e, u = c.space ? ` ` : ``;
56
- if (c.signed && s === 0) return ` 0${u}${l[0]}`;
57
- let d = s < 0, f = d ? `-` : c.signed ? `+` : ``;
58
- d && (s = -s);
59
- let p;
60
- if (c.minimumFractionDigits !== void 0 && (p = { minimumFractionDigits: c.minimumFractionDigits }), c.maximumFractionDigits !== void 0 && (p = {
61
- maximumFractionDigits: c.maximumFractionDigits,
62
- ...p
63
- }), s < 1) return f + i(s, c.locale, p) + u + l[0];
64
- let m = Math.min(Math.floor(c.binary ? Math.log(s) / Math.log(1024) : Math.log10(s) / 3), l.length - 1);
65
- s /= (c.binary ? 1024 : 1e3) ** m, p || (s = s.toPrecision(3));
66
- let h = i(Number(s), c.locale, p), g = l[m];
67
- return f + h + u + g;
68
- }
69
-
70
- //#endregion
71
- exports.a = a;
@@ -1,70 +0,0 @@
1
- //#region ../../node_modules/.pnpm/@stryke+string-format@0.13.1/node_modules/@stryke/string-format/dist/pretty-bytes.mjs
2
- const e = [
3
- `B`,
4
- `kB`,
5
- `MB`,
6
- `GB`,
7
- `TB`,
8
- `PB`,
9
- `EB`,
10
- `ZB`,
11
- `YB`
12
- ], t = [
13
- `B`,
14
- `KiB`,
15
- `MiB`,
16
- `GiB`,
17
- `TiB`,
18
- `PiB`,
19
- `EiB`,
20
- `ZiB`,
21
- `YiB`
22
- ], n = [
23
- `b`,
24
- `kbit`,
25
- `Mbit`,
26
- `Gbit`,
27
- `Tbit`,
28
- `Pbit`,
29
- `Ebit`,
30
- `Zbit`,
31
- `Ybit`
32
- ], r = [
33
- `b`,
34
- `kibit`,
35
- `Mibit`,
36
- `Gibit`,
37
- `Tibit`,
38
- `Pibit`,
39
- `Eibit`,
40
- `Zibit`,
41
- `Yibit`
42
- ], i = (e$1, t$1, n$1 = {}) => {
43
- let r$1 = e$1, i$1 = t$1;
44
- return typeof i$1 == `string` ? (i$1 ||= process.env.STORM_LOCALE || `en-US`, Array.isArray(i$1) && (r$1 = e$1?.toLocaleString(i$1, n$1))) : (i$1 === !0 || n$1 !== void 0) && (r$1 = e$1?.toLocaleString(void 0, n$1)), String(r$1);
45
- };
46
- function a(a$1, o) {
47
- let s = a$1;
48
- if (!Number.isFinite(s)) throw TypeError(`Expected a finite number, got ${typeof s}: ${s}`);
49
- let c = {
50
- bits: !1,
51
- binary: !1,
52
- space: !0,
53
- ...o
54
- }, l = c.bits ? c.binary ? r : n : c.binary ? t : e, u = c.space ? ` ` : ``;
55
- if (c.signed && s === 0) return ` 0${u}${l[0]}`;
56
- let d = s < 0, f = d ? `-` : c.signed ? `+` : ``;
57
- d && (s = -s);
58
- let p;
59
- if (c.minimumFractionDigits !== void 0 && (p = { minimumFractionDigits: c.minimumFractionDigits }), c.maximumFractionDigits !== void 0 && (p = {
60
- maximumFractionDigits: c.maximumFractionDigits,
61
- ...p
62
- }), s < 1) return f + i(s, c.locale, p) + u + l[0];
63
- let m = Math.min(Math.floor(c.binary ? Math.log(s) / Math.log(1024) : Math.log10(s) / 3), l.length - 1);
64
- s /= (c.binary ? 1024 : 1e3) ** m, p || (s = s.toPrecision(3));
65
- let h = i(Number(s), c.locale, p), g = l[m];
66
- return f + h + u + g;
67
- }
68
-
69
- //#endregion
70
- export { a };