MCPcopy Create free account
hub / github.com/scopsy/await-to-js

github.com/scopsy/await-to-js @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
3 symbols 10 edges 6 files 0 documented · 0% 13 cross-repo links updated 2y ago★ 3,3598 open issues

Browse by type

Functions 3 Types & classes 0
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

await-to-js

NPM version Downloads

Async await wrapper for easy error handling

Supported by:





    <a href="https://github.com/novuhq/novu">
        <img src="https://user-images.githubusercontent.com/8872447/165779274-22a190da-3284-487e-bd1e-14983df12cbb.png" width="200">
    </a>

The open-source notification infrastructure

Pre-requisites

You need to use Node 7.6 (or later) or an ES7 transpiler in order to use async/await functionality. You can use babel or typescript for that.

Install

npm i await-to-js --save

Usage

import to from 'await-to-js';
// If you use CommonJS (i.e NodeJS environment), it should be:
// const to = require('await-to-js').default;

async function asyncTaskWithCb(cb) {
     let err, user, savedTask, notification;

     [ err, user ] = await to(UserModel.findById(1));
     if(!user) return cb('No user found');

     [ err, savedTask ] = await to(TaskModel({userId: user.id, name: 'Demo Task'}));
     if(err) return cb('Error occurred while saving task');

    if(user.notificationsEnabled) {
       [ err ] = await to(NotificationService.sendNotification(user.id, 'Task Created'));
       if(err) return cb('Error while sending notification');
    }

    if(savedTask.assignedUser.id !== user.id) {
       [ err, notification ] = await to(NotificationService.sendNotification(savedTask.assignedUser.id, 'Task was created for you'));
       if(err) return cb('Error while sending notification');
    }

    cb(null, savedTask);
}

async function asyncFunctionWithThrow() {
  const [err, user] = await to(UserModel.findById(1));
  if (!user) throw new Error('User not found');

}

TypeScript usage

interface ServerResponse {
  test: number;
}

const p = Promise.resolve({test: 123});

const [err, data] = await to<ServerResponse>(p);
console.log(data.test);

License

MIT © Dima Grossman && Tomer Barnea

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 3

Languages

TypeScript100%

Modules by API surface

examples/example-1.js2 symbols
src/await-to-js.ts1 symbols

Dependencies from manifests, versioned

@types/jest21.1.0 · 1×
@types/node8.0.0 · 1×
colors1.1.2 · 1×
commitizen2.9.6 · 1×
coveralls2.13.1 · 1×
cross-env5.0.1 · 1×
cz-conventional-changelog2.0.0 · 1×
husky0.14.0 · 1×
jest21.0.0 · 1×
lint-staged4.0.0 · 1×
lodash.camelcase4.3.0 · 1×
prompt1.0.0 · 1×

For agents

$ claude mcp add await-to-js \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page