sharp 0.34.4 → 0.34.5-rc.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.
- package/install/build.js +38 -0
- package/install/check.js +7 -34
- package/lib/channel.js +6 -6
- package/lib/colour.js +12 -9
- package/lib/composite.js +8 -8
- package/lib/constructor.js +11 -7
- package/lib/index.d.ts +3 -1
- package/lib/index.js +4 -4
- package/lib/input.js +12 -14
- package/lib/is.js +19 -45
- package/lib/libvips.js +25 -23
- package/lib/operation.js +9 -11
- package/lib/output.js +26 -15
- package/lib/resize.js +5 -5
- package/lib/sharp.js +7 -8
- package/lib/utility.js +9 -9
- package/package.json +47 -59
- package/src/common.cc +11 -7
- package/src/common.h +9 -6
- package/src/metadata.cc +15 -11
- package/src/metadata.h +5 -2
- package/src/operations.cc +6 -4
- package/src/operations.h +5 -2
- package/src/pipeline.cc +35 -34
- package/src/pipeline.h +9 -3
- package/src/sharp.cc +10 -8
- package/src/stats.cc +8 -5
- package/src/stats.h +6 -3
- package/src/utilities.cc +8 -6
- package/src/utilities.h +4 -2
package/install/build.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
Copyright 2013 Lovell Fuller and others.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
useGlobalLibvips,
|
|
8
|
+
globalLibvipsVersion,
|
|
9
|
+
log,
|
|
10
|
+
spawnRebuild,
|
|
11
|
+
} = require('../lib/libvips');
|
|
12
|
+
|
|
13
|
+
log('Attempting to build from source via node-gyp');
|
|
14
|
+
log('See https://sharp.pixelplumbing.com/install#building-from-source');
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const addonApi = require('node-addon-api');
|
|
18
|
+
log(`Found node-addon-api ${addonApi.version || ''}`);
|
|
19
|
+
} catch (_err) {
|
|
20
|
+
log('Please add node-addon-api to your dependencies');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const gyp = require('node-gyp');
|
|
25
|
+
log(`Found node-gyp ${gyp().version}`);
|
|
26
|
+
} catch (_err) {
|
|
27
|
+
log('Please add node-gyp to your dependencies');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (useGlobalLibvips(log)) {
|
|
32
|
+
log(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const status = spawnRebuild();
|
|
36
|
+
if (status !== 0) {
|
|
37
|
+
process.exit(status);
|
|
38
|
+
}
|
package/install/check.js
CHANGED
|
@@ -1,39 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*!
|
|
2
|
+
Copyright 2013 Lovell Fuller and others.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
try {
|
|
7
|
-
const { useGlobalLibvips
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
log(msg);
|
|
11
|
-
log('Attempting to build from source via node-gyp');
|
|
12
|
-
try {
|
|
13
|
-
const addonApi = require('node-addon-api');
|
|
14
|
-
log(`Found node-addon-api ${addonApi.version || ''}`);
|
|
15
|
-
} catch (err) {
|
|
16
|
-
log('Please add node-addon-api to your dependencies');
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
const gyp = require('node-gyp');
|
|
21
|
-
log(`Found node-gyp ${gyp().version}`);
|
|
22
|
-
} catch (err) {
|
|
23
|
-
log('Please add node-gyp to your dependencies');
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
log('See https://sharp.pixelplumbing.com/install#building-from-source');
|
|
27
|
-
const status = spawnRebuild();
|
|
28
|
-
if (status !== 0) {
|
|
29
|
-
process.exit(status);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if (useGlobalLibvips(log)) {
|
|
34
|
-
buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
|
|
35
|
-
} else if (process.env.npm_config_build_from_source) {
|
|
36
|
-
buildFromSource('Detected --build-from-source flag');
|
|
7
|
+
const { useGlobalLibvips } = require('../lib/libvips');
|
|
8
|
+
if (useGlobalLibvips() || process.env.npm_config_build_from_source) {
|
|
9
|
+
process.exit(1);
|
|
37
10
|
}
|
|
38
11
|
} catch (err) {
|
|
39
12
|
const summary = err.message.split(/\n/).slice(0, 1);
|
package/lib/channel.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*!
|
|
2
|
+
Copyright 2013 Lovell Fuller and others.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
const is = require('./is');
|
|
7
7
|
|
|
@@ -18,7 +18,7 @@ const bool = {
|
|
|
18
18
|
/**
|
|
19
19
|
* Remove alpha channels, if any. This is a no-op if the image does not have an alpha channel.
|
|
20
20
|
*
|
|
21
|
-
* See also {@link /api-operation
|
|
21
|
+
* See also {@link /api-operation/#flatten flatten}.
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
24
|
* sharp('rgba.png')
|
|
@@ -163,7 +163,7 @@ function bandbool (boolOp) {
|
|
|
163
163
|
* @module Sharp
|
|
164
164
|
* @private
|
|
165
165
|
*/
|
|
166
|
-
module.exports =
|
|
166
|
+
module.exports = (Sharp) => {
|
|
167
167
|
Object.assign(Sharp.prototype, {
|
|
168
168
|
// Public instance functions
|
|
169
169
|
removeAlpha,
|
package/lib/colour.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*!
|
|
2
|
+
Copyright 2013 Lovell Fuller and others.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
const color = require('@img/colour');
|
|
7
7
|
const is = require('./is');
|
|
@@ -69,7 +69,7 @@ function grayscale (grayscale) {
|
|
|
69
69
|
*
|
|
70
70
|
* The input image will be converted to the provided colourspace at the start of the pipeline.
|
|
71
71
|
* All operations will use this colourspace before converting to the output colourspace,
|
|
72
|
-
* as defined by {@link #tocolourspace
|
|
72
|
+
* as defined by {@link #tocolourspace toColourspace}.
|
|
73
73
|
*
|
|
74
74
|
* @since 0.29.0
|
|
75
75
|
*
|
|
@@ -80,7 +80,7 @@ function grayscale (grayscale) {
|
|
|
80
80
|
* .toColourspace('srgb')
|
|
81
81
|
* .toFile('16bpc-pipeline-to-8bpc-output.png')
|
|
82
82
|
*
|
|
83
|
-
* @param {string} [colourspace] - pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://
|
|
83
|
+
* @param {string} [colourspace] - pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://www.libvips.org/API/current/enum.Interpretation.html)
|
|
84
84
|
* @returns {Sharp}
|
|
85
85
|
* @throws {Error} Invalid parameters
|
|
86
86
|
*/
|
|
@@ -112,7 +112,7 @@ function pipelineColorspace (colorspace) {
|
|
|
112
112
|
* .toColourspace('rgb16')
|
|
113
113
|
* .toFile('16-bpp.png')
|
|
114
114
|
*
|
|
115
|
-
* @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://
|
|
115
|
+
* @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://www.libvips.org/API/current/enum.Interpretation.html)
|
|
116
116
|
* @returns {Sharp}
|
|
117
117
|
* @throws {Error} Invalid parameters
|
|
118
118
|
*/
|
|
@@ -141,7 +141,10 @@ function toColorspace (colorspace) {
|
|
|
141
141
|
* @throws {Error} Invalid value
|
|
142
142
|
*/
|
|
143
143
|
function _getBackgroundColourOption (value) {
|
|
144
|
-
if (
|
|
144
|
+
if (
|
|
145
|
+
is.object(value) ||
|
|
146
|
+
(is.string(value) && value.length >= 3 && value.length <= 200)
|
|
147
|
+
) {
|
|
145
148
|
const colour = color(value);
|
|
146
149
|
return [
|
|
147
150
|
colour.red(),
|
|
@@ -172,7 +175,7 @@ function _setBackgroundColourOption (key, value) {
|
|
|
172
175
|
* @module Sharp
|
|
173
176
|
* @private
|
|
174
177
|
*/
|
|
175
|
-
module.exports =
|
|
178
|
+
module.exports = (Sharp) => {
|
|
176
179
|
Object.assign(Sharp.prototype, {
|
|
177
180
|
// Public
|
|
178
181
|
tint,
|
package/lib/composite.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*!
|
|
2
|
+
Copyright 2013 Lovell Fuller and others.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
const is = require('./is');
|
|
7
7
|
|
|
@@ -56,7 +56,7 @@ const blend = {
|
|
|
56
56
|
* `hard-light`, `soft-light`, `difference`, `exclusion`.
|
|
57
57
|
*
|
|
58
58
|
* More information about blend modes can be found at
|
|
59
|
-
* https://www.libvips.org/API/current/
|
|
59
|
+
* https://www.libvips.org/API/current/enum.BlendMode.html
|
|
60
60
|
* and https://www.cairographics.org/operators/
|
|
61
61
|
*
|
|
62
62
|
* @since 0.22.0
|
|
@@ -123,8 +123,8 @@ const blend = {
|
|
|
123
123
|
* @param {Number} [images[].raw.height]
|
|
124
124
|
* @param {Number} [images[].raw.channels]
|
|
125
125
|
* @param {boolean} [images[].animated=false] - Set to `true` to read all frames/pages of an animated image.
|
|
126
|
-
* @param {string} [images[].failOn='warning'] - @see {@link /api-constructor
|
|
127
|
-
* @param {number|boolean} [images[].limitInputPixels=268402689] - @see {@link /api-constructor
|
|
126
|
+
* @param {string} [images[].failOn='warning'] - @see {@link /api-constructor/ constructor parameters}
|
|
127
|
+
* @param {number|boolean} [images[].limitInputPixels=268402689] - @see {@link /api-constructor/ constructor parameters}
|
|
128
128
|
* @returns {Sharp}
|
|
129
129
|
* @throws {Error} Invalid parameters
|
|
130
130
|
*/
|
|
@@ -206,7 +206,7 @@ function composite (images) {
|
|
|
206
206
|
* @module Sharp
|
|
207
207
|
* @private
|
|
208
208
|
*/
|
|
209
|
-
module.exports =
|
|
209
|
+
module.exports = (Sharp) => {
|
|
210
210
|
Sharp.prototype.composite = composite;
|
|
211
211
|
Sharp.blend = blend;
|
|
212
212
|
};
|
package/lib/constructor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*!
|
|
2
|
+
Copyright 2013 Lovell Fuller and others.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
const util = require('node:util');
|
|
7
7
|
const stream = require('node:stream');
|
|
@@ -12,6 +12,10 @@ require('./sharp');
|
|
|
12
12
|
// Use NODE_DEBUG=sharp to enable libvips warnings
|
|
13
13
|
const debuglog = util.debuglog('sharp');
|
|
14
14
|
|
|
15
|
+
const queueListener = (queueLength) => {
|
|
16
|
+
Sharp.queue.emit('change', queueLength);
|
|
17
|
+
};
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
20
|
* Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
|
17
21
|
*
|
|
@@ -205,6 +209,7 @@ const debuglog = util.debuglog('sharp');
|
|
|
205
209
|
* @throws {Error} Invalid parameters
|
|
206
210
|
*/
|
|
207
211
|
const Sharp = function (input, options) {
|
|
212
|
+
// biome-ignore lint/complexity/noArguments: constructor factory
|
|
208
213
|
if (arguments.length === 1 && !is.defined(input)) {
|
|
209
214
|
throw new Error('Invalid input');
|
|
210
215
|
}
|
|
@@ -353,6 +358,7 @@ const Sharp = function (input, options) {
|
|
|
353
358
|
gifProgressive: false,
|
|
354
359
|
tiffQuality: 80,
|
|
355
360
|
tiffCompression: 'jpeg',
|
|
361
|
+
tiffBigtiff: false,
|
|
356
362
|
tiffPredictor: 'horizontal',
|
|
357
363
|
tiffPyramid: false,
|
|
358
364
|
tiffMiniswhite: false,
|
|
@@ -396,9 +402,7 @@ const Sharp = function (input, options) {
|
|
|
396
402
|
debuglog(warning);
|
|
397
403
|
},
|
|
398
404
|
// Function to notify of queue length changes
|
|
399
|
-
queueListener
|
|
400
|
-
Sharp.queue.emit('change', queueLength);
|
|
401
|
-
}
|
|
405
|
+
queueListener
|
|
402
406
|
};
|
|
403
407
|
this.options.input = this._createInputDescriptor(input, options, { allowStream: true });
|
|
404
408
|
return this;
|
package/lib/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
/// <reference types="node" />
|
|
29
29
|
|
|
30
|
-
import { Duplex } from 'stream';
|
|
30
|
+
import type { Duplex } from 'node:stream';
|
|
31
31
|
|
|
32
32
|
//#region Constructor functions
|
|
33
33
|
|
|
@@ -1460,6 +1460,8 @@ declare namespace sharp {
|
|
|
1460
1460
|
quality?: number | undefined;
|
|
1461
1461
|
/** Compression options: none, jpeg, deflate, packbits, ccittfax4, lzw, webp, zstd, jp2k (optional, default 'jpeg') */
|
|
1462
1462
|
compression?: string | undefined;
|
|
1463
|
+
/** Use BigTIFF variant (has no effect when compression is none) (optional, default false) */
|
|
1464
|
+
bigtiff?: boolean | undefined;
|
|
1463
1465
|
/** Compression predictor options: none, horizontal, float (optional, default 'horizontal') */
|
|
1464
1466
|
predictor?: string | undefined;
|
|
1465
1467
|
/** Write an image pyramid (optional, default false) */
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*!
|
|
2
|
+
Copyright 2013 Lovell Fuller and others.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
const Sharp = require('./constructor');
|
|
7
7
|
require('./input')(Sharp);
|
package/lib/input.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*!
|
|
2
|
+
Copyright 2013 Lovell Fuller and others.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
const is = require('./is');
|
|
7
7
|
const sharp = require('./sharp');
|
|
@@ -54,7 +54,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|
|
54
54
|
const inputDescriptor = {
|
|
55
55
|
autoOrient: false,
|
|
56
56
|
failOn: 'warning',
|
|
57
|
-
limitInputPixels:
|
|
57
|
+
limitInputPixels: 0x3FFF ** 2,
|
|
58
58
|
ignoreIcc: false,
|
|
59
59
|
unlimited: false,
|
|
60
60
|
sequentialRead: true
|
|
@@ -150,7 +150,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|
|
150
150
|
if (is.defined(inputOptions.limitInputPixels)) {
|
|
151
151
|
if (is.bool(inputOptions.limitInputPixels)) {
|
|
152
152
|
inputDescriptor.limitInputPixels = inputOptions.limitInputPixels
|
|
153
|
-
?
|
|
153
|
+
? 0x3FFF ** 2
|
|
154
154
|
: 0;
|
|
155
155
|
} else if (is.integer(inputOptions.limitInputPixels) && is.inRange(inputOptions.limitInputPixels, 0, Number.MAX_SAFE_INTEGER)) {
|
|
156
156
|
inputDescriptor.limitInputPixels = inputOptions.limitInputPixels;
|
|
@@ -513,7 +513,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
515
|
} else if (is.defined(inputOptions)) {
|
|
516
|
-
throw new Error(
|
|
516
|
+
throw new Error(`Invalid input options ${inputOptions}`);
|
|
517
517
|
}
|
|
518
518
|
return inputDescriptor;
|
|
519
519
|
}
|
|
@@ -525,10 +525,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|
|
525
525
|
* @param {string} encoding - unused
|
|
526
526
|
* @param {Function} callback
|
|
527
527
|
*/
|
|
528
|
-
function _write (chunk,
|
|
529
|
-
/* istanbul ignore else */
|
|
528
|
+
function _write (chunk, _encoding, callback) {
|
|
530
529
|
if (Array.isArray(this.options.input.buffer)) {
|
|
531
|
-
/* istanbul ignore else */
|
|
532
530
|
if (is.buffer(chunk)) {
|
|
533
531
|
if (this.options.input.buffer.length === 0) {
|
|
534
532
|
this.on('finish', () => {
|
|
@@ -572,7 +570,7 @@ function _isStreamInput () {
|
|
|
572
570
|
* such as resize or rotate.
|
|
573
571
|
*
|
|
574
572
|
* Dimensions in the response will respect the `page` and `pages` properties of the
|
|
575
|
-
* {@link /api-constructor
|
|
573
|
+
* {@link /api-constructor/ constructor parameters}.
|
|
576
574
|
*
|
|
577
575
|
* A `Promise` is returned when `callback` is not provided.
|
|
578
576
|
*
|
|
@@ -580,9 +578,9 @@ function _isStreamInput () {
|
|
|
580
578
|
* - `size`: Total size of image in bytes, for Stream and Buffer input only
|
|
581
579
|
* - `width`: Number of pixels wide (EXIF orientation is not taken into consideration, see example below)
|
|
582
580
|
* - `height`: Number of pixels high (EXIF orientation is not taken into consideration, see example below)
|
|
583
|
-
* - `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://www.libvips.org/API/current/
|
|
581
|
+
* - `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://www.libvips.org/API/current/enum.Interpretation.html)
|
|
584
582
|
* - `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
|
585
|
-
* - `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://www.libvips.org/API/current/
|
|
583
|
+
* - `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://www.libvips.org/API/current/enum.BandFormat.html)
|
|
586
584
|
* - `density`: Number of pixels per inch (DPI), if present
|
|
587
585
|
* - `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
|
588
586
|
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
|
@@ -794,7 +792,7 @@ function stats (callback) {
|
|
|
794
792
|
* @module Sharp
|
|
795
793
|
* @private
|
|
796
794
|
*/
|
|
797
|
-
module.exports =
|
|
795
|
+
module.exports = (Sharp) => {
|
|
798
796
|
Object.assign(Sharp.prototype, {
|
|
799
797
|
// Private
|
|
800
798
|
_inputOptionsFromObject,
|
package/lib/is.js
CHANGED
|
@@ -1,61 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*!
|
|
2
|
+
Copyright 2013 Lovell Fuller and others.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Is this value defined and not null?
|
|
8
8
|
* @private
|
|
9
9
|
*/
|
|
10
|
-
const defined =
|
|
11
|
-
return typeof val !== 'undefined' && val !== null;
|
|
12
|
-
};
|
|
10
|
+
const defined = (val) => typeof val !== 'undefined' && val !== null;
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* Is this value an object?
|
|
16
14
|
* @private
|
|
17
15
|
*/
|
|
18
|
-
const object =
|
|
19
|
-
return typeof val === 'object';
|
|
20
|
-
};
|
|
16
|
+
const object = (val) => typeof val === 'object';
|
|
21
17
|
|
|
22
18
|
/**
|
|
23
19
|
* Is this value a plain object?
|
|
24
20
|
* @private
|
|
25
21
|
*/
|
|
26
|
-
const plainObject =
|
|
27
|
-
return Object.prototype.toString.call(val) === '[object Object]';
|
|
28
|
-
};
|
|
22
|
+
const plainObject = (val) => Object.prototype.toString.call(val) === '[object Object]';
|
|
29
23
|
|
|
30
24
|
/**
|
|
31
25
|
* Is this value a function?
|
|
32
26
|
* @private
|
|
33
27
|
*/
|
|
34
|
-
const fn =
|
|
35
|
-
return typeof val === 'function';
|
|
36
|
-
};
|
|
28
|
+
const fn = (val) => typeof val === 'function';
|
|
37
29
|
|
|
38
30
|
/**
|
|
39
31
|
* Is this value a boolean?
|
|
40
32
|
* @private
|
|
41
33
|
*/
|
|
42
|
-
const bool =
|
|
43
|
-
return typeof val === 'boolean';
|
|
44
|
-
};
|
|
34
|
+
const bool = (val) => typeof val === 'boolean';
|
|
45
35
|
|
|
46
36
|
/**
|
|
47
37
|
* Is this value a Buffer object?
|
|
48
38
|
* @private
|
|
49
39
|
*/
|
|
50
|
-
const buffer =
|
|
51
|
-
return val instanceof Buffer;
|
|
52
|
-
};
|
|
40
|
+
const buffer = (val) => val instanceof Buffer;
|
|
53
41
|
|
|
54
42
|
/**
|
|
55
43
|
* Is this value a typed array object?. E.g. Uint8Array or Uint8ClampedArray?
|
|
56
44
|
* @private
|
|
57
45
|
*/
|
|
58
|
-
const typedArray =
|
|
46
|
+
const typedArray = (val) => {
|
|
59
47
|
if (defined(val)) {
|
|
60
48
|
switch (val.constructor) {
|
|
61
49
|
case Uint8Array:
|
|
@@ -78,49 +66,37 @@ const typedArray = function (val) {
|
|
|
78
66
|
* Is this value an ArrayBuffer object?
|
|
79
67
|
* @private
|
|
80
68
|
*/
|
|
81
|
-
const arrayBuffer =
|
|
82
|
-
return val instanceof ArrayBuffer;
|
|
83
|
-
};
|
|
69
|
+
const arrayBuffer = (val) => val instanceof ArrayBuffer;
|
|
84
70
|
|
|
85
71
|
/**
|
|
86
72
|
* Is this value a non-empty string?
|
|
87
73
|
* @private
|
|
88
74
|
*/
|
|
89
|
-
const string =
|
|
90
|
-
return typeof val === 'string' && val.length > 0;
|
|
91
|
-
};
|
|
75
|
+
const string = (val) => typeof val === 'string' && val.length > 0;
|
|
92
76
|
|
|
93
77
|
/**
|
|
94
78
|
* Is this value a real number?
|
|
95
79
|
* @private
|
|
96
80
|
*/
|
|
97
|
-
const number =
|
|
98
|
-
return typeof val === 'number' && !Number.isNaN(val);
|
|
99
|
-
};
|
|
81
|
+
const number = (val) => typeof val === 'number' && !Number.isNaN(val);
|
|
100
82
|
|
|
101
83
|
/**
|
|
102
84
|
* Is this value an integer?
|
|
103
85
|
* @private
|
|
104
86
|
*/
|
|
105
|
-
const integer =
|
|
106
|
-
return Number.isInteger(val);
|
|
107
|
-
};
|
|
87
|
+
const integer = (val) => Number.isInteger(val);
|
|
108
88
|
|
|
109
89
|
/**
|
|
110
90
|
* Is this value within an inclusive given range?
|
|
111
91
|
* @private
|
|
112
92
|
*/
|
|
113
|
-
const inRange =
|
|
114
|
-
return val >= min && val <= max;
|
|
115
|
-
};
|
|
93
|
+
const inRange = (val, min, max) => val >= min && val <= max;
|
|
116
94
|
|
|
117
95
|
/**
|
|
118
96
|
* Is this value within the elements of an array?
|
|
119
97
|
* @private
|
|
120
98
|
*/
|
|
121
|
-
const inArray =
|
|
122
|
-
return list.includes(val);
|
|
123
|
-
};
|
|
99
|
+
const inArray = (val, list) => list.includes(val);
|
|
124
100
|
|
|
125
101
|
/**
|
|
126
102
|
* Create an Error with a message relating to an invalid parameter.
|
|
@@ -131,11 +107,9 @@ const inArray = function (val, list) {
|
|
|
131
107
|
* @returns {Error} Containing the formatted message.
|
|
132
108
|
* @private
|
|
133
109
|
*/
|
|
134
|
-
const invalidParameterError =
|
|
135
|
-
return new Error(
|
|
110
|
+
const invalidParameterError = (name, expected, actual) => new Error(
|
|
136
111
|
`Expected ${expected} for ${name} but received ${actual} of type ${typeof actual}`
|
|
137
112
|
);
|
|
138
|
-
};
|
|
139
113
|
|
|
140
114
|
/**
|
|
141
115
|
* Ensures an Error from C++ contains a JS stack.
|
|
@@ -145,7 +119,7 @@ const invalidParameterError = function (name, expected, actual) {
|
|
|
145
119
|
* @returns {Error} Error with message and stack.
|
|
146
120
|
* @private
|
|
147
121
|
*/
|
|
148
|
-
const nativeError =
|
|
122
|
+
const nativeError = (native, context) => {
|
|
149
123
|
context.message = native.message;
|
|
150
124
|
return context;
|
|
151
125
|
};
|