mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
95 lines
1.5 KiB
JavaScript
95 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Is this value defined and not null?
|
|
* @private
|
|
*/
|
|
const defined = function (val) {
|
|
return typeof val !== 'undefined' && val !== null;
|
|
};
|
|
|
|
/**
|
|
* Is this value an object?
|
|
* @private
|
|
*/
|
|
const object = function (val) {
|
|
return typeof val === 'object';
|
|
};
|
|
|
|
/**
|
|
* Is this value a function?
|
|
* @private
|
|
*/
|
|
const fn = function (val) {
|
|
return typeof val === 'function';
|
|
};
|
|
|
|
/**
|
|
* Is this value a boolean?
|
|
* @private
|
|
*/
|
|
const bool = function (val) {
|
|
return typeof val === 'boolean';
|
|
};
|
|
|
|
/**
|
|
* Is this value a Buffer object?
|
|
* @private
|
|
*/
|
|
const buffer = function (val) {
|
|
return object(val) && val instanceof Buffer;
|
|
};
|
|
|
|
/**
|
|
* Is this value a non-empty string?
|
|
* @private
|
|
*/
|
|
const string = function (val) {
|
|
return typeof val === 'string' && val.length > 0;
|
|
};
|
|
|
|
/**
|
|
* Is this value a real number?
|
|
* @private
|
|
*/
|
|
const number = function (val) {
|
|
return typeof val === 'number' && !Number.isNaN(val);
|
|
};
|
|
|
|
/**
|
|
* Is this value an integer?
|
|
* @private
|
|
*/
|
|
const integer = function (val) {
|
|
return number(val) && val % 1 === 0;
|
|
};
|
|
|
|
/**
|
|
* Is this value within an inclusive given range?
|
|
* @private
|
|
*/
|
|
const inRange = function (val, min, max) {
|
|
return val >= min && val <= max;
|
|
};
|
|
|
|
/**
|
|
* Is this value within the elements of an array?
|
|
* @private
|
|
*/
|
|
const inArray = function (val, list) {
|
|
return list.indexOf(val) !== -1;
|
|
};
|
|
|
|
module.exports = {
|
|
defined: defined,
|
|
object: object,
|
|
fn: fn,
|
|
bool: bool,
|
|
buffer: buffer,
|
|
string: string,
|
|
number: number,
|
|
integer: integer,
|
|
inRange: inRange,
|
|
inArray: inArray
|
|
};
|