# upsync

> ![UpSync](https://raw.githubusercontent.com/reverentgeek/upsync/master/upsync.png)

Latest version **0.1.3** (published 2017-02-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install upsync
pnpm add upsync
yarn add upsync
bun add upsync
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2017-02-25 |
| First published | 2017-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | David Neal |
| Maintainers | reverentgeek |

## Links

- npm: https://www.npmjs.com/package/upsync
- Repository: https://github.com/reverentgeek/upsync
- Homepage: https://github.com/reverentgeek/upsync#readme
- Issues: https://github.com/reverentgeek/upsync/issues
- npm.io page: https://npm.io/package/upsync

## Recent versions

- 0.1.3 (latest) — 2017-02-25
- 0.1.2 — 2017-02-25
- 0.1.1 — 2017-02-25
- 0.1.0 — 2017-02-25

## README

## UpSync: Callback -> Async/Await

![UpSync](https://raw.githubusercontent.com/reverentgeek/upsync/master/upsync.png)

> Note: This module is intended to be used with Node.js 7+ or other JavaScript engines/transpilers that have support for ES2017 async/await.

This project is more my personal tool for learning Node.js support for JavaScript ES2017 async/await.

I thought it would be a fun exercise to write my own utility that takes a traditional callback-style function, and returns it wrapped in an async function. This is similar to some of the callback-to-promise utilities that are in various libraries.

### Basic usage:

```javascript
const upsync = require( "upsync" );

// The old, callback way of doing things
function oldSchool( firstname, lastname, callback ) {
	const msg = `kicking it old school, eh ${ firstname } ${ lastname }?`;
	callback( null, msg );
}

// upsync that sucker
const asyncSchool = upsync( oldSchool );

// Let's use it
async function runThisThang() {
	const response = await asyncSchool( "Old", "Dawg" );
	console.log( response );
}

runThisThang();
```

### Same deal, but with fat arrows:

```javascript
const upsync = require( "upsync" );

// The old, callback way of doing things
const oldSchool = ( firstname, lastname, callback ) => {
	const msg = `kicking it old school, eh ${ firstname } ${ lastname }?`;
	callback( null, msg );
};

// upsync that sucker
const asyncSchool = upsync( oldSchool );

// Let's use it
const runThisThang = async () => {
	const response = await asyncSchool( "Old", "Dawg" );
	console.log( response );
}

runThisThang();
```

### Okay, here's a slightly more legitimate example

```javascript
const upsync = require( "upsync" );
const fs = require( "fs" );
const readFile = upsync( fs.readFile );

const readAndParseJsonFile = async filename => {
	try {
		const contents = await readFile( filename );
		return JSON.parse( contents );
	} catch( err ) {
		console.log( err );
		throw err;
	}
};

const main = async () => {
	try {
		const pkg = await readAndParseJsonFile( "./package.json" );
		console.log( pkg );
	} catch ( err ) {
		console.log( "error in main:", err );
	}
}

// async functions return a promise
main().then( () => {
	console.log( "finished!" );
} );
```

---
_Source: https://npm.io/package/upsync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
