gm icon indicating copy to clipboard operation
gm copied to clipboard

Add support for promises

Open ajmas opened this issue 4 years ago • 0 comments

Looking at the docs and trying to use the project, it would seem there is no promise support.

Would this be something that could be of interest to add support for, and would contributions for this be welcome?

As an example of resulting usage change, with this:

before

gm('/path/to/my/img.jpg')
  .resize(240, 240)
  .noProfile()
  .write('/path/to/resize.png', function (err) {
    if (!err) console.log('done');
  });

after

try {
  await gm('/path/to/my/img.jpg')
    .resize(240, 240)
    .noProfile()
    .write('/path/to/resize.png');

  console.log('done');
} catch (err) {
  console.log(err);
}

For backwards compatibility, if a callback is provided then that is used, so something like:

if (callback) {
  callback(undefined, value);
} else {
  return value;
}

ajmas avatar Jun 30 '21 11:06 ajmas