IonicaBizau / image-to-ascii

:floppy_disk: A Node.js module that converts images to ASCII art.
http://ionicabizau.net/blog/16
MIT License
1.58k stars 106 forks source link

Promise support #65

Closed Richienb closed 4 years ago

Richienb commented 4 years ago

It would be nice if image-to-ascii supported returning promises.

rmlzy commented 4 years ago
  async _convert(imgPath) {
    return new Promise((resolve, reject) => {
      imageToAscii(imgPath, { colored: false }, (err, converted) => {
        if (err) {
          reject(err);
          return;
        }
        resolve(converted);
      });
    });
  }

You can wrap it yourself

Richienb commented 4 years ago

@rmlzy Or I could use pify:

const pify = require("pify")
const imageToAscii = pify(require("image-to-ascii"))
rmlzy commented 4 years ago

@Richienb Nice!

IonicaBizau commented 4 years ago

You can use util.promisify for now. Maybe in a future version Promises will be added. Contributions are welcome.