# sugarize

> Sugarize method calls

Latest version **1.2.2** (published 2018-10-30) · MIT license · 0 weekly downloads

## Install

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

## 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.2.2 |
| Published | 2018-10-30 |
| First published | 2018-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | elcoosp |
| Maintainers | elcoosp |
| Keywords | js, sugar, method, proxy |

## Links

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

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.2.2 (latest) — 2018-10-30
- 1.2.1 — 2018-05-21
- 1.2.0 — 2018-05-19
- 1.1.0 — 2018-05-16
- 1.0.4 — 2018-05-10

## README

# Sugarize

[![Greenkeeper badge](https://badges.greenkeeper.io/elcoosp/sugarize.svg)](https://greenkeeper.io/)
[![Build Status](https://travis-ci.org/elcoosp/sugarize.svg?branch=master)](https://travis-ci.org/elcoosp/sugarize)
[![codecov](https://codecov.io/gh/elcoosp/sugarize/branch/master/graph/badge.svg)](https://codecov.io/gh/elcoosp/sugarize)

Sugarize method calls instead of creating functions specially for piping.

## Install

`npm i -S sugarize`

## Basic usage

```javascript
const { sugarizeSlow, sugarize } = require('sugarize')

const pipe = (...fns) => a => fns.reduce((acc, f) => f(acc), a)

const [up, low, rep] = sugarizeSlow('toUpperCase', 'toLowerCase', 'repeat')
const a = pipe(
	up(),
	low(),
	rep(3)
)('str')
a // ​​​​​strstrstr​​​​​

const [upper, lower] = sugarize('toUpperCase', 'toLowerCase')
const b = pipe(
	upper,
	lower
)('str')
b // str

const c = pipe(...sugarize('toUpperCase', 'toLowerCase'))('str')
c // str
```

This works with any custom method, since the sugar function return a new function ready to call the given method with arguments (in the case of the sugarSlow version).

```javascript
const doThing = sugarSlow('doThing')
const makeBar = sugar('makeBar')
const obj = {
  doing: undefined,
  making: undefined,
  doThing(something) {
    this.doing = `Doing ${something}`
    return this
  },
  makeBar() {
    this.making = 'Making bar'
    return this
  }
}

pipe(doThing('sport'), makeBar)(obj)
//​​​ { doing: 'Doing sport',​​​​​
​​​​​// making: 'Making bar',​​​​​
​​​​​// doThing: [λ: doThing],​​​​​
​​​​​// makeBar: [λ: makeBar] }​​​​​
```

## Or with proxy version

This version produce exactly the same result but use a proxy behind, so it is not safe to use for production purpose.

```javascript
const { proxiedSugarizeSlow, proxiedSugarize } = require('sugarize')

const { toUpperCase, toLowerCase } = proxiedSugarize // Just extract the method call you need
const a = pipe(
	toUpperCase,
	toLowerCase
)('str')
// str

const { map, repeat, toUpperCase, join } = proxiedSugarizeSlow
const a = pipe(
	map(repeat(2)),
	join(''),
	toUpperCase()
)(['s', 't', 'r'])
// SSTTRR
```

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