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
import { humanize } from "humanization";
humanize("All their equipment and instruments are alive.").toString();
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 => {
if (isProcessedWord(input) && /thanks/i.test(print(input))) {
return [
...thx,
...input.filter(processedCharacter =>
/[,.?!\-]/.test(processedCharacter.source)
)
];
}
return input;
};
humanize("hey thanks so much!", {
seed: "1234",
mistakes: [
{ apply: mistakes.capitalize, probability: 0.5 },
{ apply: thanks, probability: 1 },
{
apply: input =>
mistakes.repeat(input, {
"!": 1,
x: 1
}),
probability: 1
}
]
}).toString();
Development
Testing
yarn test
or yarn test --watch
Building