# custom-translate

> A simple module for replacing words, letters, or patterns in a string with others.

Latest version **2.2.9** (published 2025-10-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install custom-translate
pnpm add custom-translate
yarn add custom-translate
bun add custom-translate
```

## Health

**Score 55/100 (C)** — status: stable.

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

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.2.9 |
| Published | 2025-10-04 |
| First published | 2017-04-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | lilyissillyyy |
| Maintainers | lilyissillyyy |
| Keywords | translate, translator |

## Links

- npm: https://www.npmjs.com/package/custom-translate
- Repository: https://github.com/lilyissillyyy/custom-translate
- Homepage: https://github.com/lilyissillyyy/custom-translate#readme
- Issues: https://github.com/lilyissillyyy/custom-translate/issues
- npm.io page: https://npm.io/package/custom-translate

## Alternatives

- [ext-list](https://npm.io/package/ext-list.md) — 6.3M weekly downloads
- [@lexical/selection](https://npm.io/package/@lexical/selection.md) — 3.8M weekly downloads
- [@lexical/text](https://npm.io/package/@lexical/text.md) — 3.6M weekly downloads
- [@lexical/clipboard](https://npm.io/package/@lexical/clipboard.md) — 3.0M weekly downloads
- [@tiptap/extension-mention](https://npm.io/package/@tiptap/extension-mention.md) — 3.0M weekly downloads

## Recent versions

- 2.2.9 (latest) — 2025-10-04
- 2.2.8 — 2018-10-08
- 2.2.7 — 2018-09-10
- 2.2.6 — 2018-08-20
- 2.2.5 — 2018-08-20
- 2.2.4 — 2018-04-04
- 2.2.3 — 2018-02-26
- 2.2.2 — 2017-12-07
- 2.2.1 — 2017-12-07
- 2.2.0 — 2017-12-07
- 2.1.1 — 2017-10-07
- 2.1.0 — 2017-10-07
- 2.0.6 — 2017-10-05
- 2.0.5 — 2017-10-03
- 2.0.4 — 2017-10-03
- … 21 more at https://npm.io/package/custom-translate/versions

## README

# custom-translate
[![Downloads](https://img.shields.io/npm/dt/custom-translate.svg?maxAge=3600)](https://www.npmjs.com/package/custom-translate)
[![Version](https://img.shields.io/npm/v/custom-translate.svg?maxAge=3600)](https://www.npmjs.com/package/custom-translate)

custom-translate is a simple module for translating certain words, letters, or
patterns in a string with others. Usage is simple:

## wordTrans
wordTrans takes an object of words and changes them into others. For example:
```js
const translator = require('custom-translate');

const text = 'I have a cow that goes moo.';
const dictionary = {
	cow: 'cat',
	moo: 'meow'
};

translator.wordTrans(text, dictionary);
```
Output will be: `I have a cat that goes meow.`

`wordTrans` automatically ignores casing, all instances of the word, regardless
of case, will be replaced.

Casing of the first letter will be matched, so if `cow` happened to be `Cow` in
the `text` variable, the result would be `I have a Cat that goes meow.`.

## letterTrans
letterTrans takes an object of letters (or symbols) and changes them into
others. For example:
```js
const translator = require('custom-translate');

const text = 'I like cheese.';
const dictionary = {
	c: '!',
	I: 'S'
};

translator.letterTrans(text, dictionary);
```

Output will be: `S like !heese`

Unlike `wordTrans`, `letterTrans` does not ignore casing by default.

You can also specify what to join the string back together with. This defaults
to `''` for `letterTrans` and `' '` for `wordTrans`.

```js
translator.letterTrans(text, dictionary, ' ');
translator.wordTrans(text, dictionary, ', ');
```

## regexTrans
regexTrans takes an object with Regular Expressions (as strings) as the keys and
what they are to be replaced with as the values. They will be replaced in order.
For example:
```js
const translator = require('custom-translate');

const text = 'ABC abc 123';
const dictionary = {
	'ABCD?': 'EFG',
	'123': '456'
};

translator.regexTrans(text, dictionary);
```

Output will be: `EFG EFG 456`

You can also change the flags to use during replacements. This defaults to `gi`.

```js
translator.regexTrans(text, dictionary, 'i');
```

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