@powerlines/plugin-image-compression 0.2.170 → 0.2.172

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 (21) hide show
  1. package/dist/index.cjs +5 -5
  2. package/dist/index.d.mts +1 -1
  3. package/dist/index.mjs +2 -2
  4. package/dist/powerlines/src/plugin-utils/paths.cjs +36 -0
  5. package/dist/powerlines/src/plugin-utils/paths.mjs +35 -0
  6. package/dist/types/plugin.d.mts +3 -3
  7. package/package.json +4 -4
  8. package/dist/node_modules/.pnpm/@stryke_string-format@0.13.4/node_modules/@stryke/string-format/dist/pretty-bytes.cjs +0 -128
  9. package/dist/node_modules/.pnpm/@stryke_string-format@0.13.4/node_modules/@stryke/string-format/dist/pretty-bytes.mjs +0 -127
  10. /package/dist/{packages/powerlines → powerlines}/src/internal/helpers/hooks.d.mts +0 -0
  11. /package/dist/{packages/powerlines → powerlines}/src/types/api.d.mts +0 -0
  12. /package/dist/{packages/powerlines → powerlines}/src/types/build.d.mts +0 -0
  13. /package/dist/{packages/powerlines → powerlines}/src/types/commands.d.mts +0 -0
  14. /package/dist/{packages/powerlines → powerlines}/src/types/config.d.mts +0 -0
  15. /package/dist/{packages/powerlines → powerlines}/src/types/context.d.mts +0 -0
  16. /package/dist/{packages/powerlines → powerlines}/src/types/fs.d.mts +0 -0
  17. /package/dist/{packages/powerlines → powerlines}/src/types/hooks.d.mts +0 -0
  18. /package/dist/{packages/powerlines → powerlines}/src/types/plugin.d.mts +0 -0
  19. /package/dist/{packages/powerlines → powerlines}/src/types/resolved.d.mts +0 -0
  20. /package/dist/{packages/powerlines → powerlines}/src/types/tsconfig.d.mts +0 -0
  21. /package/dist/{packages/powerlines → powerlines}/src/types/unplugin.d.mts +0 -0
package/dist/index.cjs CHANGED
@@ -1,16 +1,16 @@
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.4/node_modules/@stryke/string-format/dist/pretty-bytes.cjs');
3
+ const require_paths = require('./powerlines/src/plugin-utils/paths.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");
7
7
  let __stryke_fs_write_file = require("@stryke/fs/write-file");
8
8
  let __stryke_path_find = require("@stryke/path/find");
9
+ let __stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
9
10
  let chalk = require("chalk");
10
11
  chalk = require_rolldown_runtime.__toESM(chalk);
11
12
  let node_buffer = require("node:buffer");
12
13
  let node_fs_promises = require("node:fs/promises");
13
- let powerlines_plugin_utils_paths = require("powerlines/plugin-utils/paths");
14
14
  let svgo = require("svgo");
15
15
 
16
16
  //#region src/index.ts
@@ -42,12 +42,12 @@ const plugin = (options = {}) => {
42
42
  },
43
43
  async configResolved() {
44
44
  if (!this.config.imageCompression.filter) throw new Error("ImageCompression plugin requires a filter or glob pattern to be specified in the configuration.");
45
- this.config.imageCompression.filter = (0, __stryke_convert_to_array.toArray)(this.config.imageCompression.filter).map((path) => (0, powerlines_plugin_utils_paths.replacePathTokens)(this, path)).filter(Boolean);
45
+ this.config.imageCompression.filter = (0, __stryke_convert_to_array.toArray)(this.config.imageCompression.filter).map((path) => require_paths.replacePathTokens(this, path)).filter(Boolean);
46
46
  },
47
47
  async prepare() {
48
48
  await Promise.all((0, __stryke_convert_to_array.toArray)(this.config.imageCompression.filter).map(async (path) => {
49
49
  await Promise.all((await (0, __stryke_fs_list_files.listFiles)(path)).map(async (file) => {
50
- const outputPath = this.config.imageCompression.outputPath ? (0, powerlines_plugin_utils_paths.replacePathTokens)(this, this.config.imageCompression.outputPath).replace(/\{fileName\}/g, file.split("/").pop() || "output") : file;
50
+ const outputPath = this.config.imageCompression.outputPath ? require_paths.replacePathTokens(this, this.config.imageCompression.outputPath).replace(/\{fileName\}/g, file.split("/").pop() || "output") : file;
51
51
  const start = performance.now();
52
52
  const originalSize = (await (0, node_fs_promises.stat)(file)).size;
53
53
  let compressedSize = 0;
@@ -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.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`);
111
+ this.info(` ✔ Successfully optimized ${file}: ${chalk.default.redBright((0, __stryke_string_format_pretty_bytes.prettyBytes)(originalSize))} -> ${chalk.default.greenBright((0, __stryke_string_format_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.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Plugin } from "./packages/powerlines/src/types/plugin.mjs";
1
+ import { Plugin } from "./powerlines/src/types/plugin.mjs";
2
2
  import { ImageCompressionPluginContext, ImageCompressionPluginOptions, ImageCompressionPluginResolvedConfig, ImageCompressionPluginUserConfig, __ΩImageCompressionPluginContext, __ΩImageCompressionPluginOptions, __ΩImageCompressionPluginResolvedConfig, __ΩImageCompressionPluginUserConfig } from "./types/plugin.mjs";
3
3
  import "./types/index.mjs";
4
4
 
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
- import { prettyBytes } from "./node_modules/.pnpm/@stryke_string-format@0.13.4/node_modules/@stryke/string-format/dist/pretty-bytes.mjs";
1
+ import { replacePathTokens } from "./powerlines/src/plugin-utils/paths.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";
5
5
  import { writeFile } from "@stryke/fs/write-file";
6
6
  import { findFileExtensionSafe } from "@stryke/path/find";
7
+ import { prettyBytes } from "@stryke/string-format/pretty-bytes";
7
8
  import chalk from "chalk";
8
9
  import { Buffer } from "node:buffer";
9
10
  import { stat } from "node:fs/promises";
10
- import { replacePathTokens } from "powerlines/plugin-utils/paths";
11
11
  import { optimize } from "svgo";
12
12
 
13
13
  //#region src/index.ts
@@ -0,0 +1,36 @@
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let __stryke_path_replace = require("@stryke/path/replace");
3
+
4
+ //#region ../powerlines/src/plugin-utils/paths.ts
5
+ /**
6
+ * Replaces tokens in the given path string with their corresponding values from the context.
7
+ *
8
+ * @remarks
9
+ * The following tokens are supported:
10
+ * - `{workspaceRoot}` - The root directory of the workspace.
11
+ * - `{root}` - The root directory of the project (same as `{projectRoot}`).
12
+ * - `{projectRoot}` - The root directory of the project (same as `{root}`).
13
+ * - `{sourceRoot}` - The source root directory of the project (usually `./src`).
14
+ * - `{powerlinesPath}` - The directory where Powerlines is installed.
15
+ * - `{cachePath}` - The environment's directory for cached files.
16
+ * - `{dataPath}` - The environment's directory for data files.
17
+ * - `{logPath}` - The environment's directory for log files.
18
+ * - `{tempPath}` - The environment's directory for temporary files.
19
+ * - `{configPath}` - The environment's directory for configuration files.
20
+ * - `{outputPath}` - The configured output directory for the project.
21
+ * - `{buildPath}` - The configured distribution directory for the project.
22
+ * - `{artifactsPath}` - The configured directory for build artifacts.
23
+ * - `{builtinPath}` - The configured directory for generated built-in plugins.
24
+ * - `{entryPath}` - The configured directory for generated entry files.
25
+ *
26
+ * @param context - The context containing the values for the path tokens.
27
+ * @param path - The path string with tokens to replace.
28
+ * @returns The path string with tokens replaced by their corresponding values from the context.
29
+ */
30
+ function replacePathTokens(context, path) {
31
+ if (!path) return path;
32
+ return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.projectRoot).replaceAll("{projectRoot}", context.config.projectRoot).replaceAll("{sourceRoot}", context.config.sourceRoot).replaceAll("{powerlinesPath}", context.powerlinesPath).replaceAll("{cachePath}", context.cachePath).replaceAll("{dataPath}", context.dataPath).replaceAll("{logPath}", context.envPaths.log).replaceAll("{tempPath}", context.envPaths.temp).replaceAll("{configPath}", context.envPaths.config).replaceAll("{outputPath}", context.config.output.outputPath).replaceAll("{buildPath}", context.config.output.buildPath).replaceAll("{artifactsPath}", (0, __stryke_path_replace.replacePath)(context.artifactsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{builtinPath}", (0, __stryke_path_replace.replacePath)(context.builtinsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{entryPath}", (0, __stryke_path_replace.replacePath)(context.entryPath, context.workspaceConfig.workspaceRoot));
33
+ }
34
+
35
+ //#endregion
36
+ exports.replacePathTokens = replacePathTokens;
@@ -0,0 +1,35 @@
1
+ import { replacePath } from "@stryke/path/replace";
2
+
3
+ //#region ../powerlines/src/plugin-utils/paths.ts
4
+ /**
5
+ * Replaces tokens in the given path string with their corresponding values from the context.
6
+ *
7
+ * @remarks
8
+ * The following tokens are supported:
9
+ * - `{workspaceRoot}` - The root directory of the workspace.
10
+ * - `{root}` - The root directory of the project (same as `{projectRoot}`).
11
+ * - `{projectRoot}` - The root directory of the project (same as `{root}`).
12
+ * - `{sourceRoot}` - The source root directory of the project (usually `./src`).
13
+ * - `{powerlinesPath}` - The directory where Powerlines is installed.
14
+ * - `{cachePath}` - The environment's directory for cached files.
15
+ * - `{dataPath}` - The environment's directory for data files.
16
+ * - `{logPath}` - The environment's directory for log files.
17
+ * - `{tempPath}` - The environment's directory for temporary files.
18
+ * - `{configPath}` - The environment's directory for configuration files.
19
+ * - `{outputPath}` - The configured output directory for the project.
20
+ * - `{buildPath}` - The configured distribution directory for the project.
21
+ * - `{artifactsPath}` - The configured directory for build artifacts.
22
+ * - `{builtinPath}` - The configured directory for generated built-in plugins.
23
+ * - `{entryPath}` - The configured directory for generated entry files.
24
+ *
25
+ * @param context - The context containing the values for the path tokens.
26
+ * @param path - The path string with tokens to replace.
27
+ * @returns The path string with tokens replaced by their corresponding values from the context.
28
+ */
29
+ function replacePathTokens(context, path) {
30
+ if (!path) return path;
31
+ return path.replaceAll("{workspaceRoot}", context.workspaceConfig.workspaceRoot).replaceAll("{root}", context.config.projectRoot).replaceAll("{projectRoot}", context.config.projectRoot).replaceAll("{sourceRoot}", context.config.sourceRoot).replaceAll("{powerlinesPath}", context.powerlinesPath).replaceAll("{cachePath}", context.cachePath).replaceAll("{dataPath}", context.dataPath).replaceAll("{logPath}", context.envPaths.log).replaceAll("{tempPath}", context.envPaths.temp).replaceAll("{configPath}", context.envPaths.config).replaceAll("{outputPath}", context.config.output.outputPath).replaceAll("{buildPath}", context.config.output.buildPath).replaceAll("{artifactsPath}", replacePath(context.artifactsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{builtinPath}", replacePath(context.builtinsPath, context.workspaceConfig.workspaceRoot)).replaceAll("{entryPath}", replacePath(context.entryPath, context.workspaceConfig.workspaceRoot));
32
+ }
33
+
34
+ //#endregion
35
+ export { replacePathTokens };
@@ -1,6 +1,6 @@
1
- import { UserConfig } from "../packages/powerlines/src/types/config.mjs";
2
- import { ResolvedConfig } from "../packages/powerlines/src/types/resolved.mjs";
3
- import { PluginContext } from "../packages/powerlines/src/types/context.mjs";
1
+ import { UserConfig } from "../powerlines/src/types/config.mjs";
2
+ import { ResolvedConfig } from "../powerlines/src/types/resolved.mjs";
3
+ import { PluginContext } from "../powerlines/src/types/context.mjs";
4
4
  import { Config } from "svgo";
5
5
  import { AvifOptions, GifOptions, HeifOptions, Jp2Options, JpegOptions, JxlOptions, PngOptions, TiffOptions, WebpOptions } from "sharp";
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-image-compression",
3
- "version": "0.2.170",
3
+ "version": "0.2.172",
4
4
  "type": "module",
5
5
  "description": "A Powerlines plugin to optimize images used by the project.",
6
6
  "repository": {
@@ -129,15 +129,15 @@
129
129
  "chalk": "5.6.2",
130
130
  "defu": "^6.1.4",
131
131
  "jiti": "^2.6.1",
132
- "powerlines": "^0.37.94",
132
+ "powerlines": "^0.37.95",
133
133
  "sharp": "^0.34.5",
134
134
  "svgo": "^4.0.0"
135
135
  },
136
136
  "devDependencies": {
137
- "@powerlines/plugin-plugin": "^0.12.172",
137
+ "@powerlines/plugin-plugin": "^0.12.174",
138
138
  "@storm-software/config": "^1.135.1",
139
139
  "@types/node": "^24.10.9"
140
140
  },
141
141
  "publishConfig": { "access": "public" },
142
- "gitHead": "e15a429ae1117158920d049de10328041eaf8895"
142
+ "gitHead": "2852dab8ff7cad2d1aa4a44d7fd2479d62f65d47"
143
143
  }
@@ -1,128 +0,0 @@
1
-
2
- //#region ../../node_modules/.pnpm/@stryke+string-format@0.13.4/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;
@@ -1,127 +0,0 @@
1
- //#region ../../node_modules/.pnpm/@stryke+string-format@0.13.4/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 };