# reduce-function-call

> Reduce function calls in a string, using a callback

Latest version **1.0.3** (published 2019-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install reduce-function-call
pnpm add reduce-function-call
yarn add reduce-function-call
bun add reduce-function-call
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2019-09-12 |
| First published | 2014-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | MoOx |
| Maintainers | moox |
| Keywords | string, reduce, replacement, function, call, eval, interpret |

## Links

- npm: https://www.npmjs.com/package/reduce-function-call
- Repository: https://github.com/MoOx/reduce-function-call
- Homepage: https://github.com/MoOx/reduce-function-call#readme
- Issues: https://github.com/MoOx/reduce-function-call/issues
- npm.io page: https://npm.io/package/reduce-function-call

## Dependencies (1)

- [balanced-match](https://npm.io/package/balanced-match.md) ^1.0.0

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2019-09-12
- 1.0.2 — 2016-11-28
- 1.0.1 — 2014-08-06
- 1.0.0 — 2014-08-06

## README

# reduce-function-call [![Build Status](https://travis-ci.org/MoOx/reduce-function-call.svg?branch=master)](https://travis-ci.org/MoOx/reduce-function-call)

> Reduce function calls in a string, using a callback

---

[Professionally supported reduce-function-call is now available](https://tidelift.com/subscription/pkg/npm-reduce-function-call?utm_source=npm-reduce-function-call&utm_medium=referral&utm_campaign=readme)

---

## Installation

```console
npm install reduce-function-call
```

## Usage

```js
var reduceFunctionCall = require("reduce-function-call")

reduceFunctionCall("foo(1)", "foo", function(body) {
  // body === "1"
  return parseInt(body, 10) + 1
})
// "2"

var nothingOrUpper = function(body, functionIdentifier) {
  // ignore empty value
  if (body === "") {
    return functionIdentifier + "()"
  }

  return body.toUpperCase()
}

reduceFunctionCall("bar()", "bar", nothingOrUpper)
// "bar()"

reduceFunctionCall("upper(baz)", "upper", nothingOrUpper)
// "BAZ"

reduceFunctionCall("math(math(2 + 2) * 4 + math(2 + 2)) and other things", "math", function(body, functionIdentifier, call) {
  try {
    return eval(body)
  }
  catch (e) {
    return call
  }
})
// "20 and other things"

reduceFunctionCall("sha bla blah() blaa bla() abla() aabla() blaaa()", /\b([a-z]?bla[a-z]?)\(/, function(body, functionIdentifier) {
  if (functionIdentifier === "bla") {
    return "ABRACADABRA"
  }
  return functionIdentifier.replace("bla", "!")
}
// "sha bla !h blaa ABRACADABRA a! aabla() blaaa()"
```

See [unit tests](test/index.js) for others examples.

## Contributing

Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.

```console
git clone https://github.com/MoOx/reduce-function-call.git
git checkout -b patch-1
npm install
npm test
```

---

## [Changelog](CHANGELOG.md)

## [License](LICENSE)

---

## Security contact information

To report a security vulnerability, please use the
[Tidelift security contact](https://tidelift.com/security). Tidelift will
coordinate the fix and disclosure.

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