Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kayle-normalise

Normalise human-readable text to a machine-readable format.

Converts special characters to their closest match (by appearance).

Usage

Install the package:

npm install kayle-normalise

Import 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"

Options

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 to true.
  • replacePunctuation: Whether to replace punctuation with an empty string. Defaults to true.
  • removeWhitespace: all to remove all whitespace, some to remove unnecessary whitespace, none to keep all whitespace. Defaults to all.
  • additionalMappings: Additional mappings to be used in the normalisation process. Defaults to {}.

Tests

bun test

About

Normalise human-readable text to a machine-readable format.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages