@powerlines/plugin-image-compression 0.2.289 → 0.2.291

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/README.md CHANGED
@@ -27,7 +27,7 @@ This package is part of the <b>🔌 Powerlines</b> monorepo. Powerlines is the "
27
27
 
28
28
  <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
29
29
 
30
- [![Version](https://img.shields.io/badge/version-0.2.283-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://stormsoftware.com/projects/powerlines)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/powerlines/release.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
30
+ [![Version](https://img.shields.io/badge/version-0.2.290-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://stormsoftware.com/projects/powerlines)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/powerlines/release.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
31
31
 
32
32
  <!-- prettier-ignore-start -->
33
33
  <!-- markdownlint-disable -->
@@ -58,21 +58,19 @@ A Powerlines plugin to use [Sharp](https://sharp.pixelplumbing.com) to optimize
58
58
 
59
59
  ## Table of Contents
60
60
 
61
- - [Powerlines - Image Compression Plugin](#powerlines---image-compression-plugin)
62
- - [Table of Contents](#table-of-contents)
63
- - [Installing](#installing)
64
- - [Reduced Package Size](#reduced-package-size)
65
- - [Development](#development)
66
- - [Building](#building)
67
- - [Running unit tests](#running-unit-tests)
68
- - [Linting](#linting)
69
- - [Storm Workspaces](#storm-workspaces)
70
- - [Roadmap](#roadmap)
71
- - [Support](#support)
72
- - [License](#license)
73
- - [Changelog](#changelog)
74
- - [Contributing](#contributing)
75
- - [Contributors](#contributors)
61
+ - [Installing](#installing)
62
+ - [Reduced Package Size](#reduced-package-size)
63
+ - [Development](#development)
64
+ - [Building](#building)
65
+ - [Running unit tests](#running-unit-tests)
66
+ - [Linting](#linting)
67
+ - [Storm Workspaces](#storm-workspaces)
68
+ - [Roadmap](#roadmap)
69
+ - [Support](#support)
70
+ - [License](#license)
71
+ - [Changelog](#changelog)
72
+ - [Contributing](#contributing)
73
+ - [Contributors](#contributors)
76
74
 
77
75
  <!-- END doctoc -->
78
76
 
@@ -1,4 +1,4 @@
1
- //#region rolldown:runtime
1
+ //#region \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -0,0 +1,3 @@
1
+ import "node:module";
2
+
3
+ export { };
package/dist/index.cjs CHANGED
@@ -1,13 +1,13 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
2
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
- const require_pretty_bytes = require('./node_modules/.pnpm/@stryke_string-format@0.17.3/node_modules/@stryke/string-format/dist/pretty-bytes.cjs');
4
- let __stryke_convert_to_array = require("@stryke/convert/to-array");
5
- let __stryke_fs_list_files = require("@stryke/fs/list-files");
6
- let __stryke_fs_read_file = require("@stryke/fs/read-file");
7
- let __stryke_fs_write_file = require("@stryke/fs/write-file");
8
- let __stryke_path_find = require("@stryke/path/find");
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let _stryke_convert_to_array = require("@stryke/convert/to-array");
4
+ let _stryke_fs_list_files = require("@stryke/fs/list-files");
5
+ let _stryke_fs_read_file = require("@stryke/fs/read-file");
6
+ let _stryke_fs_write_file = require("@stryke/fs/write-file");
7
+ let _stryke_path_find = require("@stryke/path/find");
8
+ let _stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
9
9
  let chalk = require("chalk");
10
- chalk = require_rolldown_runtime.__toESM(chalk);
10
+ chalk = require_runtime.__toESM(chalk);
11
11
  let node_buffer = require("node:buffer");
12
12
  let node_fs_promises = require("node:fs/promises");
13
13
  let powerlines_plugin_utils = require("powerlines/plugin-utils");
@@ -42,29 +42,29 @@ 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.replacePathTokens)(this, path)).filter(Boolean);
45
+ this.config.imageCompression.filter = (0, _stryke_convert_to_array.toArray)(this.config.imageCompression.filter).map((path) => (0, powerlines_plugin_utils.replacePathTokens)(this, path)).filter(Boolean);
46
46
  },
47
47
  async prepare() {
48
- await Promise.all((0, __stryke_convert_to_array.toArray)(this.config.imageCompression.filter).map(async (path) => {
49
- await Promise.all((await (0, __stryke_fs_list_files.listFiles)(path)).map(async (file) => {
48
+ await Promise.all((0, _stryke_convert_to_array.toArray)(this.config.imageCompression.filter).map(async (path) => {
49
+ await Promise.all((await (0, _stryke_fs_list_files.listFiles)(path)).map(async (file) => {
50
50
  const outputPath = this.config.imageCompression.outputPath ? (0, powerlines_plugin_utils.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;
54
- const extension = (0, __stryke_path_find.findFileExtensionSafe)(file).toLowerCase();
54
+ const extension = (0, _stryke_path_find.findFileExtensionSafe)(file).toLowerCase();
55
55
  if (!extension) {
56
56
  this.error(` ✘ Failed to optimize ${file} - Unable to determine file extension`);
57
57
  return;
58
58
  }
59
59
  if (extension === "svg") {
60
- const result = (0, svgo.optimize)(await (0, __stryke_fs_read_file.readFile)(file), {
60
+ const result = (0, svgo.optimize)(await (0, _stryke_fs_read_file.readFile)(file), {
61
61
  multipass: true,
62
62
  path: file,
63
63
  ...this.config.imageCompression.svg
64
64
  });
65
65
  if (result.data) {
66
66
  compressedSize = node_buffer.Buffer.byteLength(result.data, "utf8");
67
- await (0, __stryke_fs_write_file.writeFile)(outputPath, result.data);
67
+ await (0, _stryke_fs_write_file.writeFile)(outputPath, result.data);
68
68
  }
69
69
  } else {
70
70
  let image = await import("sharp").then((sharpModule) => sharpModule.default(file, { animated: extension === "gif" }));
@@ -108,14 +108,13 @@ 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
  }
115
115
  };
116
116
  };
117
- var src_default = plugin;
118
117
 
119
118
  //#endregion
120
- exports.default = src_default;
119
+ exports.default = plugin;
121
120
  exports.plugin = plugin;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { ImageCompressionPluginContext, ImageCompressionPluginOptions, ImageCompressionPluginResolvedConfig, ImageCompressionPluginUserConfig, __ΩImageCompressionPluginContext, __ΩImageCompressionPluginOptions, __ΩImageCompressionPluginResolvedConfig, __ΩImageCompressionPluginUserConfig } from "./types/plugin.cjs";
2
- import "./types/index.cjs";
3
2
  import { Plugin } from "powerlines";
4
3
 
5
4
  //#region src/index.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;IAmCwB,gBAAA,CAAA,EAID,6BAJC;EAAA;;;;AAgBxB;;;;;;AAIS,cAJI,MAIJ,EAAA,CAAA,iBAHU,6BAGV,GAH0C,6BAG1C,CAAA,CAAA,OAAA,CAAA,EADE,6BACF,EAAA,GAAN,MAAM,CAAC,QAAD,CAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;YAsCY,MAAA;IACR,gBAAA,GAAmB,6BAAA;EAAA;AAAA;;;;;;;;AAYvB;cAAa,MAAA,oBACM,6BAAA,GAAgC,6BAAA,EAEjD,OAAA,GAAS,6BAAA,KACR,MAAA,CAAO,QAAA"}
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { ImageCompressionPluginContext, ImageCompressionPluginOptions, ImageCompressionPluginResolvedConfig, ImageCompressionPluginUserConfig, __ΩImageCompressionPluginContext, __ΩImageCompressionPluginOptions, __ΩImageCompressionPluginResolvedConfig, __ΩImageCompressionPluginUserConfig } from "./types/plugin.mjs";
2
- import "./types/index.mjs";
3
2
  import { Plugin } from "powerlines";
4
3
 
5
4
  //#region src/index.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;IAmCwB,gBAAA,CAAA,EAID,6BAJC;EAAA;;;;AAgBxB;;;;;;AAIS,cAJI,MAIJ,EAAA,CAAA,iBAHU,6BAGV,GAH0C,6BAG1C,CAAA,CAAA,OAAA,CAAA,EADE,6BACF,EAAA,GAAN,MAAM,CAAC,QAAD,CAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;YAsCY,MAAA;IACR,gBAAA,GAAmB,6BAAA;EAAA;AAAA;;;;;;;;AAYvB;cAAa,MAAA,oBACM,6BAAA,GAAgC,6BAAA,EAEjD,OAAA,GAAS,6BAAA,KACR,MAAA,CAAO,QAAA"}
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { prettyBytes } from "./node_modules/.pnpm/@stryke_string-format@0.17.3/node_modules/@stryke/string-format/dist/pretty-bytes.mjs";
2
1
  import { toArray } from "@stryke/convert/to-array";
3
2
  import { listFiles } from "@stryke/fs/list-files";
4
3
  import { readFile } from "@stryke/fs/read-file";
5
4
  import { writeFile } from "@stryke/fs/write-file";
6
5
  import { findFileExtensionSafe } from "@stryke/path/find";
6
+ import { prettyBytes } from "@stryke/string-format/pretty-bytes";
7
7
  import chalk from "chalk";
8
8
  import { Buffer } from "node:buffer";
9
9
  import { stat } from "node:fs/promises";
@@ -111,8 +111,7 @@ const plugin = (options = {}) => {
111
111
  }
112
112
  };
113
113
  };
114
- var src_default = plugin;
115
114
 
116
115
  //#endregion
117
- export { src_default as default, plugin };
116
+ export { plugin as default, plugin };
118
117
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { listFiles } from \"@stryke/fs/list-files\";\nimport { readFile } from \"@stryke/fs/read-file\";\nimport { writeFile } from \"@stryke/fs/write-file\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { prettyBytes } from \"@stryke/string-format/pretty-bytes\";\nimport chalk from \"chalk\";\nimport { Buffer } from \"node:buffer\";\nimport { stat } from \"node:fs/promises\";\nimport type { Plugin } from \"powerlines\";\nimport { replacePathTokens } from \"powerlines/plugin-utils\";\nimport { optimize } from \"svgo\";\nimport {\n ImageCompressionPluginContext,\n ImageCompressionPluginOptions\n} from \"./types/plugin\";\n\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n imageCompression?: ImageCompressionPluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to optimize image assets used by the project.\n *\n * @see https://sharp.pixelplumbing.com\n *\n * @param options - The plugin options.\n * @returns A Powerlines plugin instance.\n */\nexport const plugin = <\n TContext extends ImageCompressionPluginContext = ImageCompressionPluginContext\n>(\n options: ImageCompressionPluginOptions = {}\n): Plugin<TContext> => {\n return {\n name: \"image-compression\",\n config() {\n return {\n imageCompression: {\n filter:\n \"{root}/**/*.{svg,jpg,jpeg,png,webp,avif,heif,gif,tiff,jp2,jxl}\",\n svg: {},\n jpeg: {},\n png: {},\n webp: {},\n avif: {},\n heif: {},\n tiff: {},\n jp2: {},\n jxl: {},\n ...options\n }\n };\n },\n async configResolved() {\n if (!this.config.imageCompression.filter) {\n throw new Error(\n \"ImageCompression plugin requires a filter or glob pattern to be specified in the configuration.\"\n );\n }\n\n this.config.imageCompression.filter = toArray(\n this.config.imageCompression.filter\n )\n .map(path => replacePathTokens(this, path))\n .filter(Boolean);\n },\n async prepare() {\n await Promise.all(\n toArray(this.config.imageCompression.filter).map(async path => {\n await Promise.all(\n (await listFiles(path)).map(async file => {\n const outputPath = this.config.imageCompression.outputPath\n ? replacePathTokens(\n this,\n this.config.imageCompression.outputPath\n ).replace(/\\{fileName\\}/g, file.split(\"/\").pop() || \"output\")\n : file;\n\n const start = performance.now();\n const originalSize = (await stat(file)).size;\n let compressedSize = 0;\n\n const extension = findFileExtensionSafe(file).toLowerCase();\n if (!extension) {\n this.error(\n ` ✘ Failed to optimize ${file} - Unable to determine file extension`\n );\n return;\n }\n\n if (extension === \"svg\") {\n const result = optimize(await readFile(file), {\n multipass: true,\n path: file,\n ...this.config.imageCompression.svg\n });\n if (result.data) {\n compressedSize = Buffer.byteLength(result.data, \"utf8\");\n await writeFile(outputPath, result.data);\n }\n } else {\n let image = await import(\"sharp\").then(sharpModule =>\n sharpModule.default(file, { animated: extension === \"gif\" })\n );\n\n switch (extension) {\n case \"jpeg\":\n case \"jpg\":\n image = image.jpeg(this.config.imageCompression.jpeg);\n break;\n case \"png\":\n image = image.png(this.config.imageCompression.png);\n break;\n case \"webp\":\n image = image.webp(this.config.imageCompression.webp);\n break;\n case \"avif\":\n image = image.avif(this.config.imageCompression.avif);\n break;\n case \"gif\":\n image = image.gif(this.config.imageCompression.gif);\n break;\n case \"heif\":\n image = image.heif(this.config.imageCompression.heif);\n break;\n case \"tiff\":\n image = image.tiff(this.config.imageCompression.tiff);\n break;\n case \"jp2\":\n image = image.jp2(this.config.imageCompression.jp2);\n break;\n case \"jxl\":\n image = image.jxl(this.config.imageCompression.jxl);\n break;\n }\n\n const result = await image.toFile(outputPath);\n compressedSize = result.size;\n }\n\n if (!compressedSize) {\n this.error(` ✘ Failed to optimize ${file} - No data returned`);\n return;\n }\n\n if (compressedSize >= originalSize) {\n this.error(\n ` ✘ Failed to optimize ${file} - Compression output was not smaller than the original`\n );\n return;\n }\n\n this.info(\n ` ✔ Successfully optimized ${\n file\n }: ${chalk.redBright(prettyBytes(originalSize))} -> ${chalk.greenBright(\n prettyBytes(compressedSize)\n )} (${chalk.green(\n (100 - (compressedSize / originalSize) * 100).toFixed(2)\n )}%) in ${(performance.now() - start).toFixed(2)} ms`\n );\n })\n );\n })\n );\n }\n };\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmDA,MAAa,UAGX,UAAyC,EAAE,KACtB;AACrB,QAAO;EACL,MAAM;EACN,SAAS;AACP,UAAO,EACL,kBAAkB;IAChB,QACE;IACF,KAAK,EAAE;IACP,MAAM,EAAE;IACR,KAAK,EAAE;IACP,MAAM,EAAE;IACR,MAAM,EAAE;IACR,MAAM,EAAE;IACR,MAAM,EAAE;IACR,KAAK,EAAE;IACP,KAAK,EAAE;IACP,GAAG;IACJ,EACF;;EAEH,MAAM,iBAAiB;AACrB,OAAI,CAAC,KAAK,OAAO,iBAAiB,OAChC,OAAM,IAAI,MACR,kGACD;AAGH,QAAK,OAAO,iBAAiB,SAAS,QACpC,KAAK,OAAO,iBAAiB,OAC9B,CACE,KAAI,SAAQ,kBAAkB,MAAM,KAAK,CAAC,CAC1C,OAAO,QAAQ;;EAEpB,MAAM,UAAU;AACd,SAAM,QAAQ,IACZ,QAAQ,KAAK,OAAO,iBAAiB,OAAO,CAAC,IAAI,OAAM,SAAQ;AAC7D,UAAM,QAAQ,KACX,MAAM,UAAU,KAAK,EAAE,IAAI,OAAM,SAAQ;KACxC,MAAM,aAAa,KAAK,OAAO,iBAAiB,aAC5C,kBACE,MACA,KAAK,OAAO,iBAAiB,WAC9B,CAAC,QAAQ,iBAAiB,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI,SAAS,GAC7D;KAEJ,MAAM,QAAQ,YAAY,KAAK;KAC/B,MAAM,gBAAgB,MAAM,KAAK,KAAK,EAAE;KACxC,IAAI,iBAAiB;KAErB,MAAM,YAAY,sBAAsB,KAAK,CAAC,aAAa;AAC3D,SAAI,CAAC,WAAW;AACd,WAAK,MACH,yBAAyB,KAAK,uCAC/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IAAI,MAAM,UAAU,YAAY,aAAa,CAAC,CAAC,MAAM,MAAM,YAC1D,YAAY,eAAe,CAC5B,CAAC,IAAI,MAAM,OACT,MAAO,iBAAiB,eAAgB,KAAK,QAAQ,EAAE,CACzD,CAAC,SAAS,YAAY,KAAK,GAAG,OAAO,QAAQ,EAAE,CAAC,KAClD;MACD,CACH;KACD,CACH;;EAEJ;;AAGH,kBAAe"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { listFiles } from \"@stryke/fs/list-files\";\nimport { readFile } from \"@stryke/fs/read-file\";\nimport { writeFile } from \"@stryke/fs/write-file\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { prettyBytes } from \"@stryke/string-format/pretty-bytes\";\nimport chalk from \"chalk\";\nimport { Buffer } from \"node:buffer\";\nimport { stat } from \"node:fs/promises\";\nimport type { Plugin } from \"powerlines\";\nimport { replacePathTokens } from \"powerlines/plugin-utils\";\nimport { optimize } from \"svgo\";\nimport {\n ImageCompressionPluginContext,\n ImageCompressionPluginOptions\n} from \"./types/plugin\";\n\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n imageCompression?: ImageCompressionPluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to optimize image assets used by the project.\n *\n * @see https://sharp.pixelplumbing.com\n *\n * @param options - The plugin options.\n * @returns A Powerlines plugin instance.\n */\nexport const plugin = <\n TContext extends ImageCompressionPluginContext = ImageCompressionPluginContext\n>(\n options: ImageCompressionPluginOptions = {}\n): Plugin<TContext> => {\n return {\n name: \"image-compression\",\n config() {\n return {\n imageCompression: {\n filter:\n \"{root}/**/*.{svg,jpg,jpeg,png,webp,avif,heif,gif,tiff,jp2,jxl}\",\n svg: {},\n jpeg: {},\n png: {},\n webp: {},\n avif: {},\n heif: {},\n tiff: {},\n jp2: {},\n jxl: {},\n ...options\n }\n };\n },\n async configResolved() {\n if (!this.config.imageCompression.filter) {\n throw new Error(\n \"ImageCompression plugin requires a filter or glob pattern to be specified in the configuration.\"\n );\n }\n\n this.config.imageCompression.filter = toArray(\n this.config.imageCompression.filter\n )\n .map(path => replacePathTokens(this, path))\n .filter(Boolean);\n },\n async prepare() {\n await Promise.all(\n toArray(this.config.imageCompression.filter).map(async path => {\n await Promise.all(\n (await listFiles(path)).map(async file => {\n const outputPath = this.config.imageCompression.outputPath\n ? replacePathTokens(\n this,\n this.config.imageCompression.outputPath\n ).replace(/\\{fileName\\}/g, file.split(\"/\").pop() || \"output\")\n : file;\n\n const start = performance.now();\n const originalSize = (await stat(file)).size;\n let compressedSize = 0;\n\n const extension = findFileExtensionSafe(file).toLowerCase();\n if (!extension) {\n this.error(\n ` ✘ Failed to optimize ${file} - Unable to determine file extension`\n );\n return;\n }\n\n if (extension === \"svg\") {\n const result = optimize(await readFile(file), {\n multipass: true,\n path: file,\n ...this.config.imageCompression.svg\n });\n if (result.data) {\n compressedSize = Buffer.byteLength(result.data, \"utf8\");\n await writeFile(outputPath, result.data);\n }\n } else {\n let image = await import(\"sharp\").then(sharpModule =>\n sharpModule.default(file, { animated: extension === \"gif\" })\n );\n\n switch (extension) {\n case \"jpeg\":\n case \"jpg\":\n image = image.jpeg(this.config.imageCompression.jpeg);\n break;\n case \"png\":\n image = image.png(this.config.imageCompression.png);\n break;\n case \"webp\":\n image = image.webp(this.config.imageCompression.webp);\n break;\n case \"avif\":\n image = image.avif(this.config.imageCompression.avif);\n break;\n case \"gif\":\n image = image.gif(this.config.imageCompression.gif);\n break;\n case \"heif\":\n image = image.heif(this.config.imageCompression.heif);\n break;\n case \"tiff\":\n image = image.tiff(this.config.imageCompression.tiff);\n break;\n case \"jp2\":\n image = image.jp2(this.config.imageCompression.jp2);\n break;\n case \"jxl\":\n image = image.jxl(this.config.imageCompression.jxl);\n break;\n }\n\n const result = await image.toFile(outputPath);\n compressedSize = result.size;\n }\n\n if (!compressedSize) {\n this.error(` ✘ Failed to optimize ${file} - No data returned`);\n return;\n }\n\n if (compressedSize >= originalSize) {\n this.error(\n ` ✘ Failed to optimize ${file} - Compression output was not smaller than the original`\n );\n return;\n }\n\n this.info(\n ` ✔ Successfully optimized ${\n file\n }: ${chalk.redBright(prettyBytes(originalSize))} -> ${chalk.greenBright(\n prettyBytes(compressedSize)\n )} (${chalk.green(\n (100 - (compressedSize / originalSize) * 100).toFixed(2)\n )}%) in ${(performance.now() - start).toFixed(2)} ms`\n );\n })\n );\n })\n );\n }\n };\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmDA,MAAa,UAGX,UAAyC,EAAE,KACtB;AACrB,QAAO;EACL,MAAM;EACN,SAAS;AACP,UAAO,EACL,kBAAkB;IAChB,QACE;IACF,KAAK,EAAE;IACP,MAAM,EAAE;IACR,KAAK,EAAE;IACP,MAAM,EAAE;IACR,MAAM,EAAE;IACR,MAAM,EAAE;IACR,MAAM,EAAE;IACR,KAAK,EAAE;IACP,KAAK,EAAE;IACP,GAAG;IACJ,EACF;;EAEH,MAAM,iBAAiB;AACrB,OAAI,CAAC,KAAK,OAAO,iBAAiB,OAChC,OAAM,IAAI,MACR,kGACD;AAGH,QAAK,OAAO,iBAAiB,SAAS,QACpC,KAAK,OAAO,iBAAiB,OAC9B,CACE,KAAI,SAAQ,kBAAkB,MAAM,KAAK,CAAC,CAC1C,OAAO,QAAQ;;EAEpB,MAAM,UAAU;AACd,SAAM,QAAQ,IACZ,QAAQ,KAAK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;KAgBI,sDACc,uCACtB,wCACA,cAAc"}
1
+ {"version":3,"file":"plugin.d.cts","names":[],"sources":["../../src/types/plugin.ts"],"mappings":";;;;;UAgCiB,6BAAA;;AAAjB;;;;EAME,MAAA;EAuBM;;;;;;EAfN,UAAA;EAkDO;;;EA7CP,GAAA,GAAM,MAAA;EALN;;;EAUA,IAAA,GAAO,WAAA;EAAA;;;EAKP,GAAA,GAAM,UAAA;EAKA;;;EAAN,GAAA,GAAM,UAAA;EAUC;;;EALP,GAAA,GAAM,UAAA;EAeC;;;EAVP,IAAA,GAAO,WAAA;EAoBA;;;EAfP,GAAA,GAAM,UAAA;EAkB0C;;;EAbhD,IAAA,GAAO,WAAA;EAcP;;;EATA,IAAA,GAAO,WAAA;EAYQ;;;EAPf,IAAA,GAAO,WAAA;AAAA;AAAA,UAGQ,gCAAA,SAAyC,UAAA;EACxD,gBAAA,GAAmB,6BAAA;AAAA;AAAA,UAGJ,oCAAA,SAA6C,cAAA;EAC5D,gBAAA,EAAkB,IAAA,CAChB,6BAAA,mGAaA,QAAA,CACE,IAAA,CACE,6BAAA;AAAA;AAAA,KAgBI,6BAAA,yBACc,oCAAA,GACtB,oCAAA,IACA,aAAA,CAAc,eAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.mts","names":[],"sources":["../../src/types/plugin.ts"],"sourcesContent":[],"mappings":";;;;;UAgCiB,6BAAA;;AAAjB;;;;EAkCQ,MAAA,CAAA,EAAA,MAAA,GAAA,MAAA,EAAA;EAKA;;;;;;EAyBY,UAAA,CAAA,EAAA,MAAA;EAGH;AAIjB;;EACoB,GAAA,CAAA,EArDZ,MAqDY;EAgBZ;;;EAjBsD,IAAA,CAAA,EA/CrD,WA+CqD;EAAc;AAiC5E;;EAEI,GAAA,CAAA,EA7EI,UA6EJ;EACc;;;QAzEV;;;;QAKA;;;;SAKC;;;;QAKD;;;;SAKC;;;;SAKA;;;;SAKA;;UAGQ,gCAAA,SAAyC;qBACrC;;UAGJ,oCAAA,SAA6C;oBAC1C,KAChB,gIAaA,SACE,KACE;;KAgBI,sDACc,uCACtB,wCACA,cAAc"}
1
+ {"version":3,"file":"plugin.d.mts","names":[],"sources":["../../src/types/plugin.ts"],"mappings":";;;;;UAgCiB,6BAAA;;AAAjB;;;;EAME,MAAA;EAuBM;;;;;;EAfN,UAAA;EAkDO;;;EA7CP,GAAA,GAAM,MAAA;EALN;;;EAUA,IAAA,GAAO,WAAA;EAAA;;;EAKP,GAAA,GAAM,UAAA;EAKA;;;EAAN,GAAA,GAAM,UAAA;EAUC;;;EALP,GAAA,GAAM,UAAA;EAeC;;;EAVP,IAAA,GAAO,WAAA;EAoBA;;;EAfP,GAAA,GAAM,UAAA;EAkB0C;;;EAbhD,IAAA,GAAO,WAAA;EAcP;;;EATA,IAAA,GAAO,WAAA;EAYQ;;;EAPf,IAAA,GAAO,WAAA;AAAA;AAAA,UAGQ,gCAAA,SAAyC,UAAA;EACxD,gBAAA,GAAmB,6BAAA;AAAA;AAAA,UAGJ,oCAAA,SAA6C,cAAA;EAC5D,gBAAA,EAAkB,IAAA,CAChB,6BAAA,mGAaA,QAAA,CACE,IAAA,CACE,6BAAA;AAAA;AAAA,KAgBI,6BAAA,yBACc,oCAAA,GACtB,oCAAA,IACA,aAAA,CAAc,eAAA;AAAA"}
package/package.json CHANGED
@@ -1,18 +1,30 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-image-compression",
3
- "version": "0.2.289",
4
- "type": "module",
3
+ "version": "0.2.291",
4
+ "private": false,
5
5
  "description": "A Powerlines plugin to optimize images used by the project.",
6
+ "keywords": [
7
+ "sharp",
8
+ "svgo",
9
+ "powerlines",
10
+ "storm-software",
11
+ "powerlines-plugin"
12
+ ],
13
+ "homepage": "https://stormsoftware.com",
14
+ "bugs": {
15
+ "url": "https://stormsoftware.com/support",
16
+ "email": "support@stormsoftware.com"
17
+ },
6
18
  "repository": {
7
19
  "type": "github",
8
20
  "url": "https://github.com/storm-software/powerlines.git",
9
21
  "directory": "packages/plugin-image-compression"
10
22
  },
11
- "homepage": "https://stormsoftware.com",
12
- "bugs": {
13
- "url": "https://stormsoftware.com/support",
14
- "email": "support@stormsoftware.com"
23
+ "funding": {
24
+ "type": "github",
25
+ "url": "https://github.com/sponsors/storm-software"
15
26
  },
27
+ "license": "Apache-2.0",
16
28
  "author": {
17
29
  "name": "Storm Software",
18
30
  "email": "contact@stormsoftware.com",
@@ -32,14 +44,7 @@
32
44
  "url": "https://stormsoftware.com"
33
45
  }
34
46
  ],
35
- "funding": {
36
- "type": "github",
37
- "url": "https://github.com/sponsors/storm-software"
38
- },
39
- "license": "Apache-2.0",
40
- "private": false,
41
- "main": "./dist/index.cjs",
42
- "module": "./dist/index.mjs",
47
+ "type": "module",
43
48
  "exports": {
44
49
  ".": {
45
50
  "require": {
@@ -55,7 +60,7 @@
55
60
  "default": "./dist/index.mjs"
56
61
  }
57
62
  },
58
- "./*": "./*",
63
+ "./package.json": "./package.json",
59
64
  "./types": {
60
65
  "require": {
61
66
  "types": "./dist/types/index.d.cts",
@@ -85,32 +90,28 @@
85
90
  }
86
91
  }
87
92
  },
93
+ "main": "./dist/index.cjs",
94
+ "module": "./dist/index.mjs",
95
+ "types": "./dist/index.d.cts",
88
96
  "typings": "dist/index.d.mts",
89
97
  "files": ["dist/**/*"],
90
- "keywords": [
91
- "sharp",
92
- "svgo",
93
- "powerlines",
94
- "storm-software",
95
- "powerlines-plugin"
96
- ],
97
98
  "dependencies": {
98
99
  "@stryke/convert": "^0.6.53",
99
100
  "@stryke/fs": "^0.33.57",
100
101
  "@stryke/path": "^0.26.19",
102
+ "@stryke/string-format": "^0.17.3",
101
103
  "chalk": "5.6.2",
102
104
  "defu": "^6.1.4",
103
105
  "jiti": "^2.6.1",
104
- "powerlines": "^0.41.5",
106
+ "powerlines": "^0.41.7",
105
107
  "sharp": "^0.34.5",
106
108
  "svgo": "^4.0.1"
107
109
  },
108
110
  "devDependencies": {
109
- "@powerlines/plugin-plugin": "^0.12.291",
111
+ "@powerlines/plugin-plugin": "^0.12.293",
110
112
  "@storm-software/config": "^1.135.29",
111
113
  "@types/node": "^25.4.0"
112
114
  },
113
115
  "publishConfig": { "access": "public" },
114
- "types": "./dist/index.d.cts",
115
- "gitHead": "0ed0ad0cd6f440d1584ac705987ef985931161db"
116
+ "gitHead": "2fb48143904805988bac9bdbc04cdc4a35ff398b"
116
117
  }
@@ -1,128 +0,0 @@
1
-
2
- //#region ../../node_modules/.pnpm/@stryke+string-format@0.17.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;
@@ -1,128 +0,0 @@
1
- //#region ../../node_modules/.pnpm/@stryke+string-format@0.17.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 };
128
- //# sourceMappingURL=pretty-bytes.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pretty-bytes.mjs","names":[],"sources":["../../../../../../../../../../node_modules/.pnpm/@stryke+string-format@0.17.3/node_modules/@stryke/string-format/dist/pretty-bytes.mjs"],"sourcesContent":["//#region src/pretty-bytes.ts\nconst BYTE_UNITS = [\n\t\"B\",\n\t\"kB\",\n\t\"MB\",\n\t\"GB\",\n\t\"TB\",\n\t\"PB\",\n\t\"EB\",\n\t\"ZB\",\n\t\"YB\"\n];\nconst BIBYTE_UNITS = [\n\t\"B\",\n\t\"KiB\",\n\t\"MiB\",\n\t\"GiB\",\n\t\"TiB\",\n\t\"PiB\",\n\t\"EiB\",\n\t\"ZiB\",\n\t\"YiB\"\n];\nconst BIT_UNITS = [\n\t\"b\",\n\t\"kbit\",\n\t\"Mbit\",\n\t\"Gbit\",\n\t\"Tbit\",\n\t\"Pbit\",\n\t\"Ebit\",\n\t\"Zbit\",\n\t\"Ybit\"\n];\nconst BIBIT_UNITS = [\n\t\"b\",\n\t\"kibit\",\n\t\"Mibit\",\n\t\"Gibit\",\n\t\"Tibit\",\n\t\"Pibit\",\n\t\"Eibit\",\n\t\"Zibit\",\n\t\"Yibit\"\n];\n/**\n* Formats the given number using `Number#toLocaleString`.\n*\n* @remarks\n* - If locale is a string, the value is expected to be a locale-key (for example: `de`).\n* - If locale is true, the system default locale is used for translation.\n* - If no value for locale is specified, the number is returned unmodified.\n*\n* @param number - The number to format.\n* @param locale - The locale to use for formatting the number.\n* @param options - The options to use for formatting the number.\n* @returns The formatted number.\n*/\nconst toLocaleString = (number, locale, options = {}) => {\n\tlet result = number;\n\tlet _locale = locale;\n\tif (typeof _locale === \"string\") {\n\t\tif (!_locale) _locale = process.env.STORM_LOCALE || \"en-US\";\n\t\tif (Array.isArray(_locale)) result = number?.toLocaleString(_locale, options);\n\t} else if (_locale === true || options !== void 0) result = number?.toLocaleString(void 0, options);\n\treturn String(result);\n};\n/**\n* Convert bytes to a human readable string: `1337` → `1.34 kB`.\n*\n* @param number - The number to format.\n*\n* @example\n* ```ts\n* import { prettyBytes } from '@stryke/string-fns/pretty-bytes';\n*\n* prettyBytes(1337);\n* //=> '1.34 kB'\n*\n* prettyBytes(100);\n* //=> '100 B'\n*\n* // Display file size differences\n* prettyBytes(42, {signed: true});\n* //=> '+42 B'\n*\n* // Localized output using German locale\n* prettyBytes(1337, {locale: 'de'});\n* //=> '1,34 kB'\n* ```\n*\n* @param number - The number to format.\n* @param options - The options to use.\n* @returns The formatted string.\n*/\nfunction prettyBytes(number, options) {\n\tlet _number = number;\n\tif (!Number.isFinite(_number)) throw new TypeError(`Expected a finite number, got ${typeof _number}: ${_number}`);\n\tconst opts = {\n\t\tbits: false,\n\t\tbinary: false,\n\t\tspace: true,\n\t\t...options\n\t};\n\tconst UNITS = opts.bits ? opts.binary ? BIBIT_UNITS : BIT_UNITS : opts.binary ? BIBYTE_UNITS : BYTE_UNITS;\n\tconst separator = opts.space ? \" \" : \"\";\n\tif (opts.signed && _number === 0) return ` 0${separator}${UNITS[0]}`;\n\tconst isNegative = _number < 0;\n\tconst prefix = isNegative ? \"-\" : opts.signed ? \"+\" : \"\";\n\tif (isNegative) _number = -_number;\n\tlet localeOptions;\n\tif (opts.minimumFractionDigits !== void 0) localeOptions = { minimumFractionDigits: opts.minimumFractionDigits };\n\tif (opts.maximumFractionDigits !== void 0) localeOptions = {\n\t\tmaximumFractionDigits: opts.maximumFractionDigits,\n\t\t...localeOptions\n\t};\n\tif (_number < 1) return prefix + toLocaleString(_number, opts.locale, localeOptions) + separator + UNITS[0];\n\tconst exponent = Math.min(Math.floor(opts.binary ? Math.log(_number) / Math.log(1024) : Math.log10(_number) / 3), UNITS.length - 1);\n\t_number /= (opts.binary ? 1024 : 1e3) ** exponent;\n\tif (!localeOptions) _number = _number.toPrecision(3);\n\tconst numberString = toLocaleString(Number(_number), opts.locale, localeOptions);\n\tconst unit = UNITS[exponent];\n\treturn prefix + numberString + separator + unit;\n}\n\n//#endregion\nexport { prettyBytes, toLocaleString };\n//# sourceMappingURL=pretty-bytes.mjs.map"],"x_google_ignoreList":[0],"mappings":";AACA,MAAM,aAAa;CAClB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,MAAM,eAAe;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,MAAM,YAAY;CACjB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,MAAM,cAAc;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;;;;;;;;;AAcD,MAAM,kBAAkB,QAAQ,QAAQ,UAAU,EAAE,KAAK;CACxD,IAAI,SAAS;CACb,IAAI,UAAU;AACd,KAAI,OAAO,YAAY,UAAU;AAChC,MAAI,CAAC,QAAS,WAAU,QAAQ,IAAI,gBAAgB;AACpD,MAAI,MAAM,QAAQ,QAAQ,CAAE,UAAS,QAAQ,eAAe,SAAS,QAAQ;YACnE,YAAY,QAAQ,YAAY,KAAK,EAAG,UAAS,QAAQ,eAAe,KAAK,GAAG,QAAQ;AACnG,QAAO,OAAO,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BtB,SAAS,YAAY,QAAQ,SAAS;CACrC,IAAI,UAAU;AACd,KAAI,CAAC,OAAO,SAAS,QAAQ,CAAE,OAAM,IAAI,UAAU,iCAAiC,OAAO,QAAQ,IAAI,UAAU;CACjH,MAAM,OAAO;EACZ,MAAM;EACN,QAAQ;EACR,OAAO;EACP,GAAG;EACH;CACD,MAAM,QAAQ,KAAK,OAAO,KAAK,SAAS,cAAc,YAAY,KAAK,SAAS,eAAe;CAC/F,MAAM,YAAY,KAAK,QAAQ,MAAM;AACrC,KAAI,KAAK,UAAU,YAAY,EAAG,QAAO,KAAK,YAAY,MAAM;CAChE,MAAM,a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