@pi-r/tinify 0.12.5 → 0.13.0

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 (2) hide show
  1. package/index.js +10 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -6,11 +6,12 @@ const { errorMessage, isPlainObject, parseExpires } = require('@e-mc/types');
6
6
  const CACHE_APIKEY = {};
7
7
  const withinRange = (value = 0) => value > Date.now();
8
8
  function compress(options = {}) {
9
- let apiKey = options.apiKey, proxy = options.proxy, expires = options.expires;
9
+ let apiKey = options.apiKey, preserve = options.preserve, proxy = options.proxy, expires = options.expires;
10
10
  if (!apiKey && isPlainObject(this?.module)) {
11
11
  const settings = this.module.tinify;
12
12
  if (settings) {
13
13
  apiKey ||= settings.api_key;
14
+ preserve ||= settings.preserve;
14
15
  proxy ??= settings.proxy;
15
16
  expires ??= settings.expires;
16
17
  }
@@ -27,7 +28,14 @@ function compress(options = {}) {
27
28
  tinify.proxy = proxy ||= '';
28
29
  const cacheKey = apiKey + proxy;
29
30
  const sendData = () => {
30
- tinify.fromBuffer(data).toBuffer((err, result) => {
31
+ const request = tinify.fromBuffer(data);
32
+ if (Array.isArray(preserve)) {
33
+ request.preserve(...preserve);
34
+ }
35
+ else if (preserve) {
36
+ request.preserve(preserve);
37
+ }
38
+ request.toBuffer((err, result) => {
31
39
  if (result) {
32
40
  resolve(result);
33
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/tinify",
3
- "version": "0.12.5",
3
+ "version": "0.13.0",
4
4
  "description": "TinyPNG compress function for E-mc.",
5
5
  "main": "index.js",
6
6
  "repository": {