# jsonfork

> JSON fork-transforming tool

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

## Install

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

## 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-03-03 |
| First published | 2017-02-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | devebot |
| Maintainers | devebot |

## Links

- npm: https://www.npmjs.com/package/jsonfork
- npm.io page: https://npm.io/package/jsonfork

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^2.6.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.4.7
- [jsonbeat](https://npm.io/package/jsonbeat.md) ^0.2.0
- [jsonvalidator](https://npm.io/package/jsonvalidator.md) ^0.1.1

## Recent versions

- 0.1.3 (latest) — 2017-03-03
- 0.1.2 — 2017-02-20
- 0.1.1 — 2017-02-15

## README

# jsonfork

> JSON fork-transforming tool

## Install

```shell
npm install --save jsonfork
```

## Example

Define the `myfork`:

```javascript
var jsonfork = require('jsonfork');

var myfork = new jsonfork({
	name: 'Billing',
	source: {
		schema: {
			"type": "object",
			"properties": {
				"title": { "type": "string" },
				"fromTime": { "type": "string" },
				"toTime": { "type": "string" },
				"customerId": { "type": "string" },
				"items": {
					"type": "array",
					"items": {
						"type": "object",
						"properties": {
							"label": { "type": "string" },
							"price": { "type": "number" },
							"amount": { "type": "number" }
						},
						"required": ["label", "price", "amount"]
					}
				}
			}
		}
	},
	targets: [{
		name: 'Details',
		transform: function(data) {
			return {
				title: data.title + ' [' + data.customerId + ']',
				customerId: data.customerId,
				items: data.items
			}
		}
	},{
		name: 'Summary',
		transform: function(data) {
			var summary = data.items.reduce(function(sum, item) {
				sum.count += item.amount;
				sum.total += item.amount * item.price;
				return sum;
			}, { count: 0, total: 0 });
			return {
				title: data.title + ' [' + data.customerId + ']',
				customerId: data.customerId,
				count: summary.count,
				total: summary.total
			}
		},
		schema: {}
	}]
});

myfork.outlet('Details').on('result', function(result) {
	// save to database
	console.log('Details (from event): %s', JSON.stringify(result));
});

myfork.outlet('Details').on('defect', function(result) {
	// push error to log or enqueue
});

myfork.outlet('Summary').on('result', function(result) {
	// push to log or send back to webpage
	console.log('Summary (from event): %s', JSON.stringify(result));
});

myfork.outlet('Summary').on('defect', function(result) {
	// push error to log or enqueue
});
```

Use the `myfork`:

```javascript
var output = myfork.pushSync({
	title: 'JsonFork Billing',
	customerId: 'hello.com',
	items: [
		{ label: 'Item#1', price: 15, amount: 2 },
		{ label: 'Item#2', price: 17, amount: 3 }
	]
});

console.log('Output: %s', JSON.stringify(output, null, 2));
```

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