# texting-squirrel

> Module to format texts with variables and functions. It supports multiple dictionaries.

Latest version **1.1.0** (published 2022-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install texting-squirrel
pnpm add texting-squirrel
yarn add texting-squirrel
bun add texting-squirrel
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-07-29 |
| First published | 2018-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 0 |
| Unpacked size | 426.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Lukas Macuda |
| Maintainers | zabkwak |
| Keywords | text, formatting |

## Links

- npm: https://www.npmjs.com/package/texting-squirrel
- Repository: https://github.com/zabkwak/texting-squirrel
- Homepage: https://zabkwak.github.io/texting-squirrel/
- Issues: https://github.com/zabkwak/texting-squirrel/issues
- npm.io page: https://npm.io/package/texting-squirrel

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-07-29
- 1.0.1 — 2020-01-24
- 1.0.0 — 2020-01-17
- 0.1.5 — 2019-11-18
- 0.1.4 — 2018-09-10
- 0.1.3 — 2018-09-10
- 0.1.2 — 2018-02-27
- 0.1.1 — 2018-02-23
- 0.1.0 — 2018-02-22

## README

# Texting Squirrel
Module to format texts with variables and functions. It supports multiple dictionaries.

## Installation
```bash
$ npm install texting-squirrel
```

## Usage
```javascript
import Text from 'texting-squirrel';

console.log(Text.format('Hi, {0}!', 'developer')); // will output Hi, developer!

Text.addDictionary('test', { module_name: 'Texting Squirrel' });
Text.setDictionary('test');

console.log(Text.get('module_name')); // will output Texting Squirrel
console.log(Text.format('I am using {module_name} module')); // will output I am using Texting Squirrel module
```

### Mode
The text module can be set in two modes `production` or `dev` with `setMode` method. In the `dev` mode warnings are logged in console and if the text is not found in dictionary the key is returned instead of empty string.

## Text functions
Functions can be registered to the module. The texts can be updated with those functions.

### count(index, a, b, c)
| Param | Type | Description |
| --- | --- | --- |
| index | <code>number</code> | Index in the args of the format function |
| a | <code>string</code> | Text which will be returned if the value is equal to `1` |
| b | <code>string</code> | Text which will be returned if the value is equal to `2`, `3` or `4` |
| c | <code>string</code> | Text which will be returned if the value is equal to `0` or bigger than `4` |

### gender(index, a, b, c)
| Param | Type | Description |
| --- | --- | --- |
| index | <code>number</code> | Index in the args of the format function |
| a | <code>string</code> | Text which will be returned if the value is equal to `male` | 
| b | <code>string</code> | Text which will be returned if the value is equal to `female` |
| c | <code>string</code> | Text which will be returned if the value is not defined or something else than `male` or `female` |

```javascript
import Text from 'texting-squirrel';

console.log(Text.format('{count(0, script, scripts, scripts)}', 5)); // will output 5 scripts
console.log(Text.format('{gender(0, He, She, He/She)} codes', 'female')); // will output She codes
```

### Custom functions
Custom functions can be registered and called

```javascript
Text.addFunction('date', () => new Date().toISOString());
console.log(Text.format('{date()}')); // will output [actual date in iso format]
```

## Docs
Checkout the documentation [here](https://zabkwak.github.io/texting-squirrel/).

## TODO
- passing JSON in the text -> every text in braces is cleared

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