blakeembrey / change-case

Convert strings between camelCase, PascalCase, Capital Case, snake_case and more
MIT License
2.27k stars 97 forks source link

Invalid or Unexpected Token on SUPPORTED LOCALES for change-case #290

Closed michael-lumley closed 2 years ago

michael-lumley commented 2 years ago

This segment of code from lower-case...

var SUPPORTED_LOCALE = {
    tr: {
        regexp: /\u0130|\u0049|\u0049\u0307/g,
        map: {
            İ: "\u0069",
            I: "\u0131",
            İ: "\u0069",
        },
    },
    az: {
        regexp: /\u0130/g,
        map: {
            İ: "\u0069",
            I: "\u0131",
            İ: "\u0069",
        },
    },
    lt: {
        regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g,
        map: {
            I: "\u0069\u0307",
            J: "\u006A\u0307",
            Į: "\u012F\u0307",
            Ì: "\u0069\u0307\u0300",
            Í: "\u0069\u0307\u0301",
            Ĩ: "\u0069\u0307\u0303",
        },
    },
};

Throws an Unexpected Token error for me on the "İ" character. I suspect it needs to be wrapped in "". My workaround for this is deleting all of the keys of SUPPORTED_LOCALE, such that SUPPORTED_LOCALE = {} which works, but gets overwritten with the original every time I update one of my packages. Would love to get this corrected...

blakeembrey commented 2 years ago

Seems like a duplicate of https://github.com/blakeembrey/change-case/issues/96? Since this works in a standard browser and tests I’m inclined to leave it as is.

michael-lumley commented 2 years ago

Unfortunately, this does not work for me in the browser...

image image

Latest chrome version...

image
michael-lumley commented 2 years ago

FWIW, I have confirmed that the fix is as simple as enclosing the characters in double quotes...

blakeembrey commented 2 years ago

Based on your screenshot that’s incorrect encoding and not related to this library. You can compare with the source code if you want, but it’s a different character entirely. You can also see the correct character in your original post.

blakeembrey commented 2 years ago

If you think it must use quotes you’ll have to file an issue with Prettier since it’s auto-formatted and the formatting removes the quotes.

michael-lumley commented 2 years ago

For posterity, this required importing the script with charset="UTF-8" in the import tag. See more here: https://stackoverflow.com/questions/49064060/unicode-characters-not-showed-when-bundling-and-deploying-react-app-with-webpack