Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
remove-accents
Advanced tools
Package description
The remove-accents npm package is designed to help developers remove accents and diacritics from strings. This can be particularly useful for creating cleaner, ASCII-only versions of text that originally contains special characters from various languages. It's commonly used in applications that need to standardize user input, generate slugs for URLs, or simply ensure compatibility with systems that do not support such characters.
Removing accents from a string
This feature allows you to remove all accents and diacritics from a given string, converting characters like 'À' to 'A', 'á' to 'a', etc. The code sample demonstrates how to use the package to convert a string containing various accented characters into its unaccented counterpart.
"use strict"; const removeAccents = require('remove-accents'); console.log(removeAccents('ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ'));
The diacritics package offers similar functionality to remove-accents, allowing for the removal or replacement of diacritics in strings. It provides a more extensive API for handling different use cases, including the ability to get information about specific diacritics.
Unidecode is another package that provides functionality to remove accents from strings, but it goes a step further by attempting to transliterate the string into ASCII. This means it not only removes diacritics but also tries to represent the original sound of the name as closely as possible in ASCII, making it more comprehensive for certain applications.
Readme
Removes the accents from a string, converting them to their corresponding non-accented ASCII characters.
npm install remove-accents
An easy to use solution for converting all accented characters to their corresponding non-accented ASCII characters.
import removeAccents from 'remove-accents';
removeAccents(inputString)
Alternatively, you could use the CommonJS syntax to import it:
const removeAccents = require('remove-accents');
The string that you wish to remove accents from.
Call removeAccents()
by passing the string you wish to remove accents from, and you will get the non-accented string as result.
const input = 'ÀÁÂÃÄÅ';
const output = removeAccents(input);
console.log(output); // AAAAAA
The exported function also has helper methods.
Determine if a string has any accented characters.
import removeAccents from 'remove-accents';
console.log(removeAccents.has('ÀÁÂÃÄÅ')); // true
console.log(removeAccents.has('ABC')); // false
Alias of removeAccents
.
import removeAccents from 'remove-accents';
console.log(removeAccents.remove('ÀÁÂÃÄÅ')); // AAAAAA
MIT
FAQs
Converting the accented characters to their corresponding non-accented ASCII characters.
The npm package remove-accents receives a total of 3,209,240 weekly downloads. As such, remove-accents popularity was classified as popular.
We found that remove-accents demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.