2.2.8 • Published 6 years ago

custom-translate v2.2.8

Weekly downloads
555
License
ISC
Repository
github
Last release
6 years ago

custom-translate

Downloads Version Travis

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:

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:

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.

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:

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.

translator.regexTrans(text, dictionary, 'i');
2.2.8

6 years ago

2.2.7

6 years ago

2.2.6

6 years ago

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.6

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.3.7

7 years ago

1.3.6

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago