# scpp

> Micro functions to execute asynchronous functions synchronously or in parallel.

Latest version **1.0.5** (published 2018-09-30) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2018-09-30 |
| First published | 2017-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Edgars Mjasņiokovs |
| Maintainers | mjasnikovs |
| Keywords | sync, parallel, async, small, fast |

## Links

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

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2018-09-30
- 1.0.4 — 2017-03-21
- 1.0.3 — 2017-03-21
- 1.0.2 — 2017-03-21
- 1.0.0 — 2017-03-21

## README

![scpp](/logo.png)

###### Forget about bloated libraries, promises, function generators and embrace callbacks.

# Why scpp?
* Small (1 file, 20 lines of code, no dependency's)
* Fast (Faster then async.js)
* Tested in production

## Install or copy/paste code

```JavaScript
npm install --save scpp

const {sync, parallel} = require('scpp')

or 

import {sync, parallel} from 'scpp'
``` 

#### sync minification
```javaScript 
const sync = (l,c) => (function $(l,c,i,r){l[i]((e,d)=>l[++i]&&!e?$(l,c,i,d):c(e,d),r)})(l,c,0)
```

#### parallel minification
```javaScript 
const parallel = (l,c) => {let t=l.length,x=1;l.forEach((v,k)=>v((e,d)=>{l[k]=d;return(--t!==0&&x===1&&!e)===true||--x||c(e,l)}))}
```

# How to use sync
Sync accepts 2 arguments
* array, with functions to execute synchronously
```JavaScript 
[Function, Function, Function]
```
* callback function, which is executed after all functions in array have finished executing, or any of functions returns error
```JavaScript 
(error, result) => {
	if (error) {
		return new Error(error)
	}
	console.log(result)
}
```

#### Sync example
```JavaScript
sync([
	// Function always shod return callback
	// return callback(ERROR, VALUE passing down)
	// if ERROR is not null, synchronously execution will stop and error value is returned.
	callback => {
		console.log('First!')
		return callback(null, 'Secound!')
	},
	// Only one value can be passed down (Which can contain multiple values inside, doh)
	(callback, previously) => {
		console.log(previously) // Secound!
		return callback(null, 'Third!')
	}
], (err, result) => {
	// err = null, result = 'Third!'
	if (err) {return new Error(err)}
	console.log(result)
})
```

# How to use parallel
Parallel accepts 2 arguments
* array, with functions to execute in parallel
```JavaScript 
[Function, Function, Function]
```
* callback function, which is executed after all functions in array have finished executing, or any of functions returns error
```JavaScript 
(error, result) => {
	if (error) {
		return new Error(error)
	}
	console.log(result)
}
```

#### Parallel example
```JavaScript
parallel([
	// Function always shod return callback
	// return callback(ERROR)
	// if ERROR is not null, parallel execution will stop and error value is returned.
	callback => {
		return callback(null, 'First!')
	},
	// No value can be passed down in parallel execution
	callback => {
		return callback(null, 'Second!')
	},
	callback => {
		return callback(null, 'Third!')
	}
// err = null, result = ['First!', 'Second!', 'Third!']
// result is array, contains all values from parallel execution, in proper order.
], (err, [first, second, third]) => {
	if (err) {return new Error(err)}
	console.log(first) // First!
	console.log(second) // Second!
	console.log(third) // Third!
})

```

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