Ctor single arg: allow plain object, reject null/undefined

Thank you @kub1x
This commit is contained in:
Lovell Fuller
2017-05-06 19:03:14 +01:00
parent 39a21787b7
commit c41d755441
14 changed files with 104 additions and 79 deletions

View File

@@ -5,6 +5,7 @@ const util = require('util');
const stream = require('stream');
const events = require('events');
const semver = require('semver');
const is = require('./is');
const sharp = require('../build/Release/sharp.node');
// Versioning
@@ -59,7 +60,7 @@ const debuglog = util.debuglog('sharp');
*
* @example
* // Create a blank 300x200 PNG image of semi-transluent red pixels
* sharp(null, {
* sharp({
* create: {
* width: 300,
* height: 200,
@@ -74,7 +75,7 @@ const debuglog = util.debuglog('sharp');
* @param {(Buffer|String)} [input] - if present, can be
* a Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or
* a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
* JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when null or undefined.
* JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
* @param {Object} [options] - if present, is an Object with optional attributes.
* @param {Number} [options.density=72] - integral number representing the DPI for vector images.
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
@@ -90,6 +91,9 @@ const debuglog = util.debuglog('sharp');
* @throws {Error} Invalid parameters
*/
const Sharp = function (input, options) {
if (arguments.length === 1 && !is.defined(input)) {
throw new Error('Invalid input');
}
if (!(this instanceof Sharp)) {
return new Sharp(input, options);
}