# @pelevesque/sum-digits

> Sums the digits in a string with a powerful substrings->digits feature.

Latest version **0.0.10** (published 2020-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pelevesque/sum-digits
pnpm add @pelevesque/sum-digits
yarn add @pelevesque/sum-digits
bun add @pelevesque/sum-digits
```

## 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.0.10 |
| Published | 2020-02-11 |
| First published | 2019-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=9.0.0 |
| Dependencies | 2 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Pierre-Emmanuel Lévesque |
| Maintainers | pelevesque |
| Keywords | math, sum, digits |

## Links

- npm: https://www.npmjs.com/package/@pelevesque/sum-digits
- Repository: https://github.com/pelevesque/sum-digits
- Homepage: https://github.com/pelevesque/sum-digits#readme
- Issues: https://github.com/pelevesque/sum-digits/issues
- npm.io page: https://npm.io/package/@pelevesque/sum-digits

## Dependencies (2)

- [isobject](https://npm.io/package/isobject.md) ^4.0.0
- [string-occurrence](https://npm.io/package/string-occurrence.md) ^1.2.0

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 0.0.10 (latest) — 2020-02-11
- 0.0.9 — 2019-07-22
- 0.0.8 — 2019-06-29
- 0.0.7 — 2019-06-21
- 0.0.6 — 2019-06-18
- 0.0.5 — 2019-06-17
- 0.0.4 — 2019-06-17
- 0.0.3 — 2019-06-17
- 0.0.2 — 2019-06-02
- 0.0.1 — 2019-06-01

## README

[![Build Status](https://travis-ci.org/pelevesque/sum-digits.svg?branch=master)](https://travis-ci.org/pelevesque/sum-digits)
[![Coverage Status](https://coveralls.io/repos/github/pelevesque/sum-digits/badge.svg?branch=master)](https://coveralls.io/github/pelevesque/sum-digits?branch=master)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

# sum-digits

Sums the digits in a string with a powerful substrings->digits feature.

## Node Repository

https://www.npmjs.com/package/@pelevesque/sum-digits

## Installation

`npm install @pelevesque/sum-digits`

## Tests

Command                      | Description
---------------------------- | ------------
`npm test` or `npm run test` | All Tests Below
`npm run cover`              | Standard Style
`npm run standard`           | Coverage
`npm run unit`               | Unit Tests

## Usage

### Parameters

```js
str     (required)
options (optional) default = { substringsToDigits = null, sumPlainDigits = true }
```

### Examples

```js
const sumDigits = require('@pelevesque/sum-digits')
```

```js
// normal summing
sumDigits('1234') // 10
```

```js
// ignores non numeric characters
sumDigits('1a2!3_4.') // 10
```

```js
// you can provide a hash table of substrings to digits
const substringsToDigits = { a: 1, b: 2, c: 3 }
sumDigits('1a2b3ca', { substringsToDigits: substringsToDigits }) // 13
```

```js
// substrings can be of any length
const substringsToDigits = { '1p': 1000, panama: 100, nam: 10, 2: 1 }
sumDigits('1panama2', { substringsToDigits: substringsToDigits }) // 1114
```

```js
// you can bypass plain digit summing and only use substringsToDigits summing
const substringsToDigits = { '1p': 1000, panama: 100, nam: 10, 2: 1 }
sumDigits('1panama2', { substringsToDigits: substringsToDigits, sumPlainDigits: false}) // 1111
```

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