GithubHelp home page GithubHelp logo

torvalamo / pmod Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 9 KB

Get node modules with functions that return promises if you don't give them a callback. Otherwise works as before.

JavaScript 100.00%

pmod's Introduction

pmod

Get your node modules with functions that return promises if you don't give them a callback.

If you request a module that is not supported, it will give you the default module instead.

These modules are currently supported: child_process, cluster, crypto, dgram, dns, fs, http, http2, https, inspector, net, realine, stream, timers, tls, zlib

PS: Currently not all functions are tested. But should work in theory. :-D

Install

npm install pmod --save

Use

const fs = require('pmod').fs;

fs.readFile('myfile', 'utf8').then(data => {
	// do stuff with data
	console.log(data);
}).catch(err => {
	// do stuff with err
	console.log(err);
});

The functions work as normal as well!

const fs = require('pmod').fs;

fs.readFile('myfile', 'utf8', (err, data) => {
	if (err) {
		// do stuff with err
		console.log(err);
	} else {
		// do stuff with data
		console.log(data);
	}
});

Module classes

Classes inside of modules have their prototype functions also modified.

This means that you can use promises in their async versions.

const fs = require('pmod').fs;

let stream = fs.createWriteStream('myfile'); // returns a fs.WriteStream object

stream.write('test')
	.then(() => stream.write('next'))
	.then(() => stream.write('last'))
	.then(() => stream.end())
	.catch(err => console.log(err));

Known issues

There may be some class methods that have been forgotten, simply due to the fact that inherited class methods aren't usually listed in the node documentation.

Please create an issue and/or a pull request on github if that is the case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.