šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

degenerator

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

degenerator

Compiles sync functions into async generator functions

5.0.1
latest
Source
npm
Version published
Weekly downloads
11M
4.94%
Maintainers
1
Weekly downloads
Ā 
Created

What is degenerator?

The 'degenerator' npm package is a tool that allows you to convert asynchronous functions using callbacks into functions that return Promises. It is particularly useful for adapting older, callback-style codebases to modern Promise-based patterns or async/await syntax in JavaScript.

What are degenerator's main functionalities?

Converting callback-based functions to Promises

This feature allows you to wrap a traditional callback-based function, such as 'fs.readFile', into a function that returns a Promise. This makes it easier to work with asynchronous code using 'then' and 'catch' methods or async/await syntax.

const degenerator = require('degenerator');
const fs = require('fs');

const readFilePromise = degenerator(fs.readFile, { callback: true });

readFilePromise('example.txt', 'utf8').then(contents => {
  console.log(contents);
}).catch(error => {
  console.error('Error reading file:', error);
});

Other packages similar to degenerator

FAQs

Package last updated on 19 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts