# humanization

> To err is human

Latest version **6.3.1** (published 2019-10-27) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 35/100 (D)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.3.1 |
| Published | 2019-10-27 |
| First published | 2019-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 45.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | dzucconi |
| Maintainers | dzuc |

## Links

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

## Dependencies (2)

- [seedrandom](https://npm.io/package/seedrandom.md) ^3.0.1
- [@types/seedrandom](https://npm.io/package/@types/seedrandom.md) ^2.4.28

## Recent versions

- 6.3.1 (latest) — 2019-10-27
- 6.3.0 — 2019-10-07
- 6.2.2 — 2019-10-02
- 6.2.1 — 2019-09-23
- 6.2.0 — 2019-08-31
- 6.1.0 — 2019-08-31
- 6.0.0 — 2019-08-29
- 5.0.0 — 2019-08-29
- 4.0.0 — 2019-08-27
- 3.0.0 — 2019-08-22
- 2.1.0 — 2019-08-21
- 2.0.0 — 2019-07-04
- 1.0.1 — 2019-07-03
- 1.0.0 — 2019-07-02
- 0.0.0-development — 2019-07-02

## README

# humanization

[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![npm](https://img.shields.io/npm/v/humanization)](https://www.npmjs.com/package/humanization) [![Build Status](https://travis-ci.org/dzucconi/humanization.svg?branch=master)](https://travis-ci.org/dzucconi/humanization)

`humanization` is a library that seeks to simulate human patterns of mistakes when typing text. It can serve as a kind of ergonomic layer for automated chatbots to make them feel more human.

## Getting started

```javascript
import { humanize } from "humanization";

humanize("All their equipment and instruments are alive.").toString();
// => "All thei5 eqjipmetn and insfrmuents rAe alIve."
```

```javascript
import {
  humanize,
  mistakes,
  process,
  isProcessedWord,
  ProcessedCharacter,
  Applicable
} from "humanization";

const [thx] = process("thx");
const print = (input: ProcessedCharacter[]) =>
  input.map(({ source }) => source).join("");

const thanks = (input: Applicable): Applicable => {
  // Only re-write words that match 'thanks':
  if (isProcessedWord(input) && /thanks/i.test(print(input))) {
    return [
      // Replace entire word with "thx"
      ...thx,
      // Leaves punctuation intact
      ...input.filter(processedCharacter =>
        /[,.?!\-]/.test(processedCharacter.source)
      )
    ];
  }

  return input;
};

humanize("hey thanks so much!", {
  seed: "1234",
  mistakes: [
    // Mistakes are applied in order from top to bottom
    { apply: mistakes.capitalize, probability: 0.5 },
    { apply: thanks, probability: 1 },
    {
      apply: input =>
        mistakes.repeat(input, {
          "!": 1,
          x: 1
        }),
      probability: 1
    }
  ]
}).toString();
// => "hEY thxxxxxxxxx SO mUCh!!!"
```

## Development

- `yarn install`
- `yarn watch`

### Testing

- `yarn test` or `yarn test --watch`

### Building

- `yarn compile`

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