js-build-tools 3.0.0 → 3.0.1

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 (63) hide show
  1. package/dist/build.js +59 -59
  2. package/dist/bundle.js +12 -12
  3. package/dist/bundleLint.js +17 -17
  4. package/dist/bundleMinify.js +8 -8
  5. package/dist/copyFonts.js +8 -8
  6. package/dist/default.js +15 -15
  7. package/dist/distLint.js +17 -17
  8. package/dist/distMinify.js +8 -8
  9. package/dist/partials/addToReadme.js +13 -13
  10. package/dist/partials/beginWatcher.js +9 -9
  11. package/dist/partials/distFor.js +16 -16
  12. package/dist/partials/distForSrc.js +9 -9
  13. package/dist/partials/distSeries.js +19 -19
  14. package/dist/partials/imagesFor.js +27 -27
  15. package/dist/partials/readmeTemplate.js +11 -11
  16. package/dist/partials/runOnChange.js +27 -27
  17. package/dist/partials/sassFor.js +20 -20
  18. package/dist/partials/tsFor.js +20 -20
  19. package/dist/partials.js +34 -34
  20. package/dist/test-helpers/setUp.js +51 -51
  21. package/dist/testFull.js +17 -17
  22. package/dist/testHelpers.js +8 -8
  23. package/dist/testQuick.js +19 -19
  24. package/dist/utilities/dotGet.js +42 -42
  25. package/dist/utilities/dotNotate.js +50 -50
  26. package/dist/utilities/dotSet.js +36 -36
  27. package/dist/utilities/isObject.js +4 -4
  28. package/dist/utilities/strAfter.js +14 -0
  29. package/dist/utilities/strBefore.js +14 -0
  30. package/dist/watchTest.js +13 -13
  31. package/functions/utilities/dotGet.js +2 -2
  32. package/functions/utilities/dotSet.js +2 -2
  33. package/functions/utilities/strAfter.js +13 -0
  34. package/functions/utilities/strBefore.js +13 -0
  35. package/package.json +3 -3
  36. package/vendor/array-union/index.js +30 -30
  37. package/vendor/easy-transform-stream/index.js +54 -58
  38. package/vendor/globby/gitignore.js +96 -100
  39. package/vendor/globby/index.js +191 -195
  40. package/vendor/globby/stream-utils.js +57 -57
  41. package/vendor/globby/to-path.js +19 -19
  42. package/vendor/gulp-plugin-extras/index.js +42 -46
  43. package/vendor/gulp-plugin-extras/plugin-error.js +144 -144
  44. package/vendor/ignore/index.js +467 -467
  45. package/vendor/imagemin/index.js +90 -94
  46. package/vendor/imagemin-gifsicle/index.js +33 -37
  47. package/vendor/imagemin-mozjpeg/index.js +100 -104
  48. package/vendor/imagemin-mozjpeg/node_modules/execa/index.js +2 -6
  49. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/kill.js +2 -2
  50. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stream.js +2 -6
  51. package/vendor/imagemin-optipng/index.js +43 -43
  52. package/vendor/imagemin-svgo/index.js +26 -26
  53. package/vendor/is-jpg/index.js +11 -11
  54. package/vendor/junk/index.js +48 -48
  55. package/vendor/mozjpeg/index.js +8 -8
  56. package/vendor/mozjpeg/lib/index.js +17 -17
  57. package/vendor/mozjpeg/package.json +49 -50
  58. package/vendor/mozjpeg/vendor/cjpeg +0 -0
  59. package/vendor/mozjpeg/vendor/source/mozjpeg.tar.gz +0 -0
  60. package/vendor/p-pipe/index.js +22 -26
  61. package/vendor/plur/index.js +31 -31
  62. package/vendor/pretty-bytes/index.js +70 -70
  63. package/vendor/slash/index.js +11 -11
@@ -1,94 +1,90 @@
1
- async function exportImagemin () {
2
- "use strict";
3
-
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = imagemin;
8
- require("core-js/modules/esnext.async-iterator.filter.js");
9
- require("core-js/modules/esnext.async-iterator.map.js");
10
- require("core-js/modules/esnext.iterator.constructor.js");
11
- require("core-js/modules/esnext.iterator.filter.js");
12
- require("core-js/modules/esnext.iterator.map.js");
13
- require("core-js/modules/web.dom-collections.iterator.js");
14
- var _nodeBuffer = require("node:buffer");
15
- var _nodeFs = require("node:fs");
16
- var _nodeUtil = require("node:util");
17
- var _nodePath = _interopRequireDefault(require("node:path"));
18
- var _gracefulFs = _interopRequireDefault(require("graceful-fs"));
19
- var _fileType = _interopRequireDefault(require("file-type"));
20
- var _index = require("../globby/index.js");
21
- var _index2 = _interopRequireDefault(require("../p-pipe/index.js"));
22
- var _replaceExt = _interopRequireDefault(require("replace-ext"));
23
- var _index3 = _interopRequireDefault(require("../junk/index.js"));
24
- var _index4 = _interopRequireDefault(require("../slash/index.js"));
25
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
- const readFile = (0, _nodeUtil.promisify)(_gracefulFs.default.readFile);
27
- const writeFile = (0, _nodeUtil.promisify)(_gracefulFs.default.writeFile);
28
- const handleFile = async (sourcePath, _ref) => {
29
- let {
30
- destination,
31
- plugins = []
32
- } = _ref;
33
- if (plugins && !Array.isArray(plugins)) {
34
- throw new TypeError('The `plugins` option should be an `Array`');
35
- }
36
- let data = await readFile(sourcePath);
37
- data = await (plugins.length > 0 ? (0, _index2.default)(...plugins)(data) : data);
38
- const {
39
- ext
40
- } = (await _fileType.default.fromBuffer(data)) || {
41
- ext: _nodePath.default.extname(sourcePath)
42
- };
43
- let destinationPath = destination ? _nodePath.default.join(destination, _nodePath.default.basename(sourcePath)) : undefined;
44
- destinationPath = ext === 'webp' ? (0, _replaceExt.default)(destinationPath, '.webp') : destinationPath;
45
- const returnValue = {
46
- data,
47
- sourcePath,
48
- destinationPath
49
- };
50
- if (!destinationPath) {
51
- return returnValue;
52
- }
53
- await _nodeFs.promises.mkdir(_nodePath.default.dirname(returnValue.destinationPath), {
54
- recursive: true
55
- });
56
- await writeFile(returnValue.destinationPath, returnValue.data);
57
- return returnValue;
58
- };
59
- async function imagemin(input) {
60
- let {
61
- glob = true,
62
- ...options
63
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
64
- if (!Array.isArray(input)) {
65
- throw new TypeError("Expected an `Array`, got `".concat(typeof input, "`"));
66
- }
67
- const unixFilePaths = input.map(path => (0, _index4.default)(path));
68
- const filePaths = glob ? await (0, _index.globby)(unixFilePaths, {
69
- onlyFiles: true
70
- }) : input;
71
- return Promise.all(filePaths.filter(filePath => _index3.default.not(_nodePath.default.basename(filePath))).map(async filePath => {
72
- try {
73
- return await handleFile(filePath, options);
74
- } catch (error) {
75
- error.message = "Error occurred when handling file: ".concat(input, "\n\n").concat(error.stack);
76
- throw error;
77
- }
78
- }));
79
- }
80
- imagemin.buffer = async function (input) {
81
- let {
82
- plugins = []
83
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
84
- if (!_nodeBuffer.Buffer.isBuffer(input)) {
85
- throw new TypeError("Expected a `Buffer`, got `".concat(typeof input, "`"));
86
- }
87
- if (plugins.length === 0) {
88
- return input;
89
- }
90
- return (0, _index2.default)(...plugins)(input);
91
- };
92
- }
93
-
94
- exportImagemin()
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = imagemin;
7
+ require("core-js/modules/esnext.async-iterator.filter.js");
8
+ require("core-js/modules/esnext.async-iterator.map.js");
9
+ require("core-js/modules/esnext.iterator.constructor.js");
10
+ require("core-js/modules/esnext.iterator.filter.js");
11
+ require("core-js/modules/esnext.iterator.map.js");
12
+ require("core-js/modules/web.dom-collections.iterator.js");
13
+ var _nodeBuffer = require("node:buffer");
14
+ var _nodeFs = require("node:fs");
15
+ var _nodeUtil = require("node:util");
16
+ var _nodePath = _interopRequireDefault(require("node:path"));
17
+ var _gracefulFs = _interopRequireDefault(require("graceful-fs"));
18
+ var _fileType = _interopRequireDefault(require("file-type"));
19
+ var _index = require("../globby/index.js");
20
+ var _index2 = _interopRequireDefault(require("../p-pipe/index.js"));
21
+ var _replaceExt = _interopRequireDefault(require("replace-ext"));
22
+ var _index3 = _interopRequireDefault(require("../junk/index.js"));
23
+ var _index4 = _interopRequireDefault(require("../slash/index.js"));
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+ const readFile = (0, _nodeUtil.promisify)(_gracefulFs.default.readFile);
26
+ const writeFile = (0, _nodeUtil.promisify)(_gracefulFs.default.writeFile);
27
+ const handleFile = async (sourcePath, _ref) => {
28
+ let {
29
+ destination,
30
+ plugins = []
31
+ } = _ref;
32
+ if (plugins && !Array.isArray(plugins)) {
33
+ throw new TypeError('The `plugins` option should be an `Array`');
34
+ }
35
+ let data = await readFile(sourcePath);
36
+ data = await (plugins.length > 0 ? (0, _index2.default)(...plugins)(data) : data);
37
+ const {
38
+ ext
39
+ } = (await _fileType.default.fromBuffer(data)) || {
40
+ ext: _nodePath.default.extname(sourcePath)
41
+ };
42
+ let destinationPath = destination ? _nodePath.default.join(destination, _nodePath.default.basename(sourcePath)) : undefined;
43
+ destinationPath = ext === 'webp' ? (0, _replaceExt.default)(destinationPath, '.webp') : destinationPath;
44
+ const returnValue = {
45
+ data,
46
+ sourcePath,
47
+ destinationPath
48
+ };
49
+ if (!destinationPath) {
50
+ return returnValue;
51
+ }
52
+ await _nodeFs.promises.mkdir(_nodePath.default.dirname(returnValue.destinationPath), {
53
+ recursive: true
54
+ });
55
+ await writeFile(returnValue.destinationPath, returnValue.data);
56
+ return returnValue;
57
+ };
58
+ async function imagemin(input) {
59
+ let {
60
+ glob = true,
61
+ ...options
62
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
63
+ if (!Array.isArray(input)) {
64
+ throw new TypeError("Expected an `Array`, got `".concat(typeof input, "`"));
65
+ }
66
+ const unixFilePaths = input.map(path => (0, _index4.default)(path));
67
+ const filePaths = glob ? await (0, _index.globby)(unixFilePaths, {
68
+ onlyFiles: true
69
+ }) : input;
70
+ return Promise.all(filePaths.filter(filePath => _index3.default.not(_nodePath.default.basename(filePath))).map(async filePath => {
71
+ try {
72
+ return await handleFile(filePath, options);
73
+ } catch (error) {
74
+ error.message = "Error occurred when handling file: ".concat(input, "\n\n").concat(error.stack);
75
+ throw error;
76
+ }
77
+ }));
78
+ }
79
+ imagemin.buffer = async function (input) {
80
+ let {
81
+ plugins = []
82
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
83
+ if (!_nodeBuffer.Buffer.isBuffer(input)) {
84
+ throw new TypeError("Expected a `Buffer`, got `".concat(typeof input, "`"));
85
+ }
86
+ if (plugins.length === 0) {
87
+ return input;
88
+ }
89
+ return (0, _index2.default)(...plugins)(input);
90
+ };
@@ -1,37 +1,33 @@
1
- async function exportImageminGifsicle () {
2
- 'use strict';
3
-
4
- const execa = require('execa');
5
- const gifsicle = require('gifsicle');
6
- const isGif = require('is-gif');
7
- module.exports = function () {
8
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
9
- return async input => {
10
- if (!Buffer.isBuffer(input)) {
11
- throw new TypeError("Expected `input` to be of type `Buffer` but received type `".concat(typeof input, "`"));
12
- }
13
- if (!isGif(input)) {
14
- return input;
15
- }
16
- const args = ['--no-warnings', '--no-app-extensions'];
17
- if (options.interlaced) {
18
- args.push('--interlace');
19
- }
20
- if (options.optimizationLevel) {
21
- args.push("--optimize=".concat(options.optimizationLevel));
22
- }
23
- if (options.colors) {
24
- args.push("--colors=".concat(options.colors));
25
- }
26
- const {
27
- stdout
28
- } = await execa(gifsicle, args, {
29
- encoding: null,
30
- input
31
- });
32
- return stdout;
33
- };
34
- };
35
- }
36
-
37
- exportImageminGifsicle()
1
+ 'use strict';
2
+
3
+ const execa = require('execa');
4
+ const gifsicle = require('gifsicle');
5
+ const isGif = require('is-gif');
6
+ module.exports = function () {
7
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8
+ return async input => {
9
+ if (!Buffer.isBuffer(input)) {
10
+ throw new TypeError("Expected `input` to be of type `Buffer` but received type `".concat(typeof input, "`"));
11
+ }
12
+ if (!isGif(input)) {
13
+ return input;
14
+ }
15
+ const args = ['--no-warnings', '--no-app-extensions'];
16
+ if (options.interlaced) {
17
+ args.push('--interlace');
18
+ }
19
+ if (options.optimizationLevel) {
20
+ args.push("--optimize=".concat(options.optimizationLevel));
21
+ }
22
+ if (options.colors) {
23
+ args.push("--colors=".concat(options.colors));
24
+ }
25
+ const {
26
+ stdout
27
+ } = await execa(gifsicle, args, {
28
+ encoding: null,
29
+ input
30
+ });
31
+ return stdout;
32
+ };
33
+ };
@@ -1,104 +1,100 @@
1
- async function exportImageminMozjpeg () {
2
- "use strict";
3
-
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _nodeBuffer = require("node:buffer");
9
- var _index = require("./node_modules/execa/index.js");
10
- var _index2 = _interopRequireDefault(require("../is-jpg/index.js"));
11
- var _index3 = _interopRequireDefault(require("../mozjpeg/index.js"));
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- const imageminMozjpeg = options => async buffer => {
14
- options = {
15
- trellis: true,
16
- trellisDC: true,
17
- overshoot: true,
18
- ...options
19
- };
20
- if (!_nodeBuffer.Buffer.isBuffer(buffer)) {
21
- return Promise.reject(new TypeError('Expected a buffer'));
22
- }
23
- if (!(0, _index2.default)(buffer)) {
24
- return Promise.resolve(buffer);
25
- }
26
-
27
- // TODO: Remove these sometime far in the future
28
- if (options.fastcrush) {
29
- return Promise.reject(new Error('Option `fastcrush` was renamed to `fastCrush`'));
30
- }
31
- if (options.maxmemory) {
32
- return Promise.reject(new Error('Option `maxmemory` was renamed to `maxMemory`'));
33
- }
34
- if (options.notrellis) {
35
- return Promise.reject(new Error('Option `notrellis` was renamed to `trellis` and inverted'));
36
- }
37
- if (options.noovershoot) {
38
- return Promise.reject(new Error('Option `noovershoot` was renamed to `overshoot` and inverted'));
39
- }
40
- const args = [];
41
- if (typeof options.quality !== 'undefined') {
42
- args.push('-quality', options.quality);
43
- }
44
- if (options.progressive === false) {
45
- args.push('-baseline');
46
- }
47
- if (options.targa) {
48
- args.push('-targa');
49
- }
50
- if (options.revert) {
51
- args.push('-revert');
52
- }
53
- if (options.fastCrush) {
54
- args.push('-fastcrush');
55
- }
56
- if (typeof options.dcScanOpt !== 'undefined') {
57
- args.push('-dc-scan-opt', options.dcScanOpt);
58
- }
59
- if (!options.trellis) {
60
- args.push('-notrellis');
61
- }
62
- if (!options.trellisDC) {
63
- args.push('-notrellis-dc');
64
- }
65
- if (options.tune) {
66
- args.push("-tune-".concat(options.tune));
67
- }
68
- if (!options.overshoot) {
69
- args.push('-noovershoot');
70
- }
71
- if (options.arithmetic) {
72
- args.push('-arithmetic');
73
- }
74
- if (options.dct) {
75
- args.push('-dct', options.dct);
76
- }
77
- if (options.quantBaseline) {
78
- args.push('-quant-baseline', options.quantBaseline);
79
- }
80
- if (typeof options.quantTable !== 'undefined') {
81
- args.push('-quant-table', options.quantTable);
82
- }
83
- if (options.smooth) {
84
- args.push('-smooth', options.smooth);
85
- }
86
- if (options.maxMemory) {
87
- args.push('-maxmemory', options.maxMemory);
88
- }
89
- if (options.sample) {
90
- args.push('-sample', options.sample.join(','));
91
- }
92
- const {
93
- stdout
94
- } = await (0, _index.execa)(_index3.default, args, {
95
- encoding: null,
96
- input: buffer,
97
- maxBuffer: Number.POSITIVE_INFINITY
98
- });
99
- return stdout;
100
- };
101
- var _default = exports.default = imageminMozjpeg;
102
- }
103
-
104
- exportImageminMozjpeg()
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _nodeBuffer = require("node:buffer");
8
+ var _index = require("./node_modules/execa/index.js");
9
+ var _index2 = _interopRequireDefault(require("../is-jpg/index.js"));
10
+ var _index3 = _interopRequireDefault(require("../mozjpeg/index.js"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ const imageminMozjpeg = options => async buffer => {
13
+ options = {
14
+ trellis: true,
15
+ trellisDC: true,
16
+ overshoot: true,
17
+ ...options
18
+ };
19
+ if (!_nodeBuffer.Buffer.isBuffer(buffer)) {
20
+ return Promise.reject(new TypeError('Expected a buffer'));
21
+ }
22
+ if (!(0, _index2.default)(buffer)) {
23
+ return Promise.resolve(buffer);
24
+ }
25
+
26
+ // TODO: Remove these sometime far in the future
27
+ if (options.fastcrush) {
28
+ return Promise.reject(new Error('Option `fastcrush` was renamed to `fastCrush`'));
29
+ }
30
+ if (options.maxmemory) {
31
+ return Promise.reject(new Error('Option `maxmemory` was renamed to `maxMemory`'));
32
+ }
33
+ if (options.notrellis) {
34
+ return Promise.reject(new Error('Option `notrellis` was renamed to `trellis` and inverted'));
35
+ }
36
+ if (options.noovershoot) {
37
+ return Promise.reject(new Error('Option `noovershoot` was renamed to `overshoot` and inverted'));
38
+ }
39
+ const args = [];
40
+ if (typeof options.quality !== 'undefined') {
41
+ args.push('-quality', options.quality);
42
+ }
43
+ if (options.progressive === false) {
44
+ args.push('-baseline');
45
+ }
46
+ if (options.targa) {
47
+ args.push('-targa');
48
+ }
49
+ if (options.revert) {
50
+ args.push('-revert');
51
+ }
52
+ if (options.fastCrush) {
53
+ args.push('-fastcrush');
54
+ }
55
+ if (typeof options.dcScanOpt !== 'undefined') {
56
+ args.push('-dc-scan-opt', options.dcScanOpt);
57
+ }
58
+ if (!options.trellis) {
59
+ args.push('-notrellis');
60
+ }
61
+ if (!options.trellisDC) {
62
+ args.push('-notrellis-dc');
63
+ }
64
+ if (options.tune) {
65
+ args.push("-tune-".concat(options.tune));
66
+ }
67
+ if (!options.overshoot) {
68
+ args.push('-noovershoot');
69
+ }
70
+ if (options.arithmetic) {
71
+ args.push('-arithmetic');
72
+ }
73
+ if (options.dct) {
74
+ args.push('-dct', options.dct);
75
+ }
76
+ if (options.quantBaseline) {
77
+ args.push('-quant-baseline', options.quantBaseline);
78
+ }
79
+ if (typeof options.quantTable !== 'undefined') {
80
+ args.push('-quant-table', options.quantTable);
81
+ }
82
+ if (options.smooth) {
83
+ args.push('-smooth', options.smooth);
84
+ }
85
+ if (options.maxMemory) {
86
+ args.push('-maxmemory', options.maxMemory);
87
+ }
88
+ if (options.sample) {
89
+ args.push('-sample', options.sample.join(','));
90
+ }
91
+ const {
92
+ stdout
93
+ } = await (0, _index.execa)(_index3.default, args, {
94
+ encoding: null,
95
+ input: buffer,
96
+ maxBuffer: Number.POSITIVE_INFINITY
97
+ });
98
+ return stdout;
99
+ };
100
+ var _default = exports.default = imageminMozjpeg;
@@ -1,5 +1,4 @@
1
- async function exportExeca () {
2
- "use strict";
1
+ "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
@@ -258,7 +257,4 @@ function execaNode(scriptPath, args) {
258
257
  stdio,
259
258
  shell: false
260
259
  });
261
- }
262
- }
263
-
264
- exportExeca()
260
+ }
@@ -7,7 +7,7 @@ exports.validateTimeout = exports.spawnedKill = exports.spawnedCancel = exports.
7
7
  require("core-js/modules/es.promise.finally.js");
8
8
  require("core-js/modules/web.dom-collections.iterator.js");
9
9
  var _nodeOs = _interopRequireDefault(require("node:os"));
10
- var _signalExit = _interopRequireDefault(require("signal-exit"));
10
+ var _signalExit = require("signal-exit");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
12
  const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;
13
13
 
@@ -113,7 +113,7 @@ const setExitHandler = async (spawned, _ref5, timedPromise) => {
113
113
  if (!cleanup || detached) {
114
114
  return timedPromise;
115
115
  }
116
- const removeExitHandler = (0, _signalExit.default)(() => {
116
+ const removeExitHandler = (0, _signalExit.onExit)(() => {
117
117
  spawned.kill();
118
118
  });
119
119
  return timedPromise.finally(() => {
@@ -1,5 +1,4 @@
1
- async function exportLib () {
2
- "use strict";
1
+ "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
@@ -122,7 +121,4 @@ const validateInputSync = _ref5 => {
122
121
  throw new TypeError('The `input` option cannot be a stream in sync mode');
123
122
  }
124
123
  };
125
- exports.validateInputSync = validateInputSync;
126
- }
127
-
128
- exportLib()
124
+ exports.validateInputSync = validateInputSync;
@@ -1,44 +1,44 @@
1
- 'use strict';
2
-
3
- const execBuffer = require('exec-buffer');
4
- const isPng = require('is-png');
5
- const optipng = require('optipng-bin');
6
- module.exports = options => async buffer => {
7
- options = {
8
- optimizationLevel: 3,
9
- bitDepthReduction: true,
10
- colorTypeReduction: true,
11
- paletteReduction: true,
12
- interlaced: false,
13
- errorRecovery: true,
14
- ...options
15
- };
16
- if (!Buffer.isBuffer(buffer)) {
17
- throw new TypeError('Expected a buffer');
18
- }
19
- if (!isPng(buffer)) {
20
- return buffer;
21
- }
22
- const arguments_ = ['-strip', 'all', '-clobber', '-o', options.optimizationLevel, '-out', execBuffer.output];
23
- if (options.errorRecovery) {
24
- arguments_.push('-fix');
25
- }
26
- if (!options.bitDepthReduction) {
27
- arguments_.push('-nb');
28
- }
29
- if (typeof options.interlaced === 'boolean') {
30
- arguments_.push('-i', options.interlaced ? '1' : '0');
31
- }
32
- if (!options.colorTypeReduction) {
33
- arguments_.push('-nc');
34
- }
35
- if (!options.paletteReduction) {
36
- arguments_.push('-np');
37
- }
38
- arguments_.push(execBuffer.input);
39
- return execBuffer({
40
- input: buffer,
41
- bin: optipng,
42
- args: arguments_
43
- });
1
+ 'use strict';
2
+
3
+ const execBuffer = require('exec-buffer');
4
+ const isPng = require('is-png');
5
+ const optipng = require('optipng-bin');
6
+ module.exports = options => async buffer => {
7
+ options = {
8
+ optimizationLevel: 3,
9
+ bitDepthReduction: true,
10
+ colorTypeReduction: true,
11
+ paletteReduction: true,
12
+ interlaced: false,
13
+ errorRecovery: true,
14
+ ...options
15
+ };
16
+ if (!Buffer.isBuffer(buffer)) {
17
+ throw new TypeError('Expected a buffer');
18
+ }
19
+ if (!isPng(buffer)) {
20
+ return buffer;
21
+ }
22
+ const arguments_ = ['-strip', 'all', '-clobber', '-o', options.optimizationLevel, '-out', execBuffer.output];
23
+ if (options.errorRecovery) {
24
+ arguments_.push('-fix');
25
+ }
26
+ if (!options.bitDepthReduction) {
27
+ arguments_.push('-nb');
28
+ }
29
+ if (typeof options.interlaced === 'boolean') {
30
+ arguments_.push('-i', options.interlaced ? '1' : '0');
31
+ }
32
+ if (!options.colorTypeReduction) {
33
+ arguments_.push('-nc');
34
+ }
35
+ if (!options.paletteReduction) {
36
+ arguments_.push('-np');
37
+ }
38
+ arguments_.push(execBuffer.input);
39
+ return execBuffer({
40
+ input: buffer,
41
+ bin: optipng,
42
+ args: arguments_
43
+ });
44
44
  };