Coder Social home page Coder Social logo

remove-accents's Introduction

remove-accents

Removes the accents from a string, converting them to their corresponding non-accented ASCII characters.

npm install remove-accents

Unit tests

About

An easy to use solution for converting all accented characters to their corresponding non-accented ASCII characters.

Syntax

import removeAccents from 'remove-accents';

removeAccents(inputString)

Alternatively, you could use the CommonJS syntax to import it:

const removeAccents = require('remove-accents');

inputString

The string that you wish to remove accents from.

Usage

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

Methods

The exported function also has helper methods.

has

Determine if a string has any accented characters.

import removeAccents from 'remove-accents';

console.log(removeAccents.has('ÀÁÂÃÄÅ')); // true
console.log(removeAccents.has('ABC'));    // false

remove

Alias of removeAccents.

import removeAccents from 'remove-accents';

console.log(removeAccents.remove('ÀÁÂÃÄÅ')); // AAAAAA

License

MIT

remove-accents's People

Contributors

alorel avatar andreialecu avatar codeman99 avatar glebtv avatar gollenia avatar huy-vuong avatar jsnajdr avatar michaelkirk avatar soreine avatar tyxla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

remove-accents's Issues

accent not removed

The "hanging" accent is not removed from an s in the name below.

nicolaescu plopṣor c s
nicolaescu plopsor c s

Eszett

Hi, the Eszett character is incorrectly substituted for a single 's':

$ npm t

> [email protected] test /var/www/remove-accents
> tape test.js

TAP version 13
# remove accents from string
ok 1 should be equivalent
# do not modify non-accented strings
not ok 2 should be equivalent
  ---
    operator: deepEqual
    expected: |-
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789.,:;~`!@#$%^&*()-_=+[]{}\'"|\\<>?/ß'
    actual: |-
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789.,:;~`!@#$%^&*()-_=+[]{}\'"|\\<>?/s'
    at: Test.<anonymous> (/var/www/remove-accents/test.js:18:4)
    stack: |-
      Error: should be equivalent
          at Test.assert [as _assert] (/var/www/remove-accents/node_modules/tape/lib/test.js:212:54)
          at Test.bound [as _assert] (/var/www/remove-accents/node_modules/tape/lib/test.js:64:32)
          at Test.deepEqual.Test.deepEquals.Test.isEquivalent.Test.same (/var/www/remove-accents/node_modules/tape/lib/test.js:380:10)
          at Test.bound [as same] (/var/www/remove-accents/node_modules/tape/lib/test.js:64:32)
          at Test.<anonymous> (/var/www/remove-accents/test.js:18:4)
          at Test.bound [as _cb] (/var/www/remove-accents/node_modules/tape/lib/test.js:64:32)
          at Test.run (/var/www/remove-accents/node_modules/tape/lib/test.js:83:10)
          at Test.bound [as run] (/var/www/remove-accents/node_modules/tape/lib/test.js:64:32)
          at Immediate.next [as _onImmediate] (/var/www/remove-accents/node_modules/tape/lib/results.js:71:15)
          at processImmediate [as _immediateCallback] (timers.js:396:17)
  ...

1..2
# tests 2
# pass  1
# fail  1

The expected behaviour should be either:

  • convert 'ß' -> 'ss'
  • leave 'ß' as 'ß'

I looked through the code and was also surprised by the behaviour, maybe it is an artifact of the regular expression?

Node-REd?

Hello. How to use it with Node-REd ?
Thanks.
Marc.

Support "shaving" of accents

In some languages (like mine, Hungarian) we have long and short version of accents, so there is ö/ü and there is ő/ű - and for some use cases it is useful to have a function that replaces all long version with short ones (as they sound similar so one might misakenly use the other), while keeping some accents, like for é, because e sounds differently, so one would unliokely to use the wrong one.

This is what I would call "shaving" of accents. This would only applied to Latin characters. Could you support this? I presume you use some sort of charachter database to pick what accented chars to change so this would be a version of that. I'd be happy to help, test or discuss further. Thanks!

Better handling of non-string argument

Would like to be able to send any argument to removeAccents() and have more robust handling. I propose to simply return the sent in value if it's not a string. For example if I pass in undefined simply return undefined. If I pass in an object simply return the object. Don't attempt to call .toString().

Too many characters unhandled

Hey, we just experienced another issue where this library missed a character (this time it was ñ).

I highly recommend anyone who depends on it to simply do this:

function removeAccents(str) {
  return str.normalize('NFD').replace(/\p{Diacritic}/gu, '');
}

ES6 Solution?

Found this library while looking for a solution to this problem. Also discovered that ES6 can now do the following. I realise this library is 3 years old, so incase anyone else need a one line solution instead of another dependency.

"ÀÁÂÃÄÅ".normalize("NFD").replace(/[\u0300-\u036f]/g, "")
//outputs AAAAAA

Note the above method only works with accents, not none accented characters eg - Æ

The is no import

For the God's sake can somebody please share the import header :)

Doesn't seem to work

const removeAccents = require('remove-accents');

console.log(
	removeAccents('ÀÁÂÃÄÅ')
); // AAAAAA
console.log(
	removeAccents('Capture d’écran 2018-06-05 à 10.09.54.png')
); // Capture d’écran 2018-06-05 à 10.09.54.png

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.