Normalise human-readable text to a machine-readable format.
Converts special characters to their closest match (by appearance).
Install the package:
npm install kayle-normaliseImport the package:
import { normalise } from "kayle-normalise";Use the normalise function:
const normalised = normalise("Hello, world!");
console.log(normalised); // "hello world"
const hello = normalise("ⓗⓔⓛⓛⓞ");
console.log(hello); // "hello"You can pass an options object to the normalise function to customise the behaviour:
const normalised = normalise("Hell0, w🌍rld!", {
replaceNumbers: false,
replacePunctuation: true,
removeWhitespace: "some",
additionalMappings: {
"🌍": "o",
},
});
console.log(normalised); // "hell0 world"Available options:
replaceNumbers: Whether to replace numbers with their corresponding letters (0->o, 1->i, 3->e, 5->s). Defaults totrue.replacePunctuation: Whether to replace punctuation with an empty string. Defaults totrue.removeWhitespace:allto remove all whitespace,someto remove unnecessary whitespace,noneto keep all whitespace. Defaults toall.additionalMappings: Additional mappings to be used in the normalisation process. Defaults to{}.
bun test