case-anything
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -5,2 +5,7 @@ 'use strict'; | ||
// Latin-1 Supplement | ||
// upper case ranges | ||
// [À-ÖØ-ß] | ||
// lower case ranges | ||
// [à-öø-ÿ] | ||
/** | ||
@@ -13,3 +18,3 @@ * A string.match function that will return an array of "string parts" | ||
function splitOnSpecialChars(string) { | ||
return string.match(/^[a-z]+|[A-Z][a-z]+|[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g); | ||
return string.match(/^[a-zà-öø-ÿ]+|[A-ZÀ-ÖØ-ß][a-zà-öø-ÿ]+|[a-zà-öø-ÿ]+|[0-9]+|[A-ZÀ-ÖØ-ß]+(?![a-zà-öø-ÿ])/g); | ||
} | ||
@@ -26,3 +31,3 @@ /** | ||
var parts = target.includes(' ') ? target.split(' ').filter(Boolean) : splitOnSpecialChars(target); | ||
return noSpecialChars ? parts.map(function (part) { return part.replace(/[^a-zA-Z0-9]/g, ''); }) : parts; | ||
return noSpecialChars ? parts.map(function (part) { return part.replace(/[^a-zA-ZØßø0-9]/g, ''); }) : parts; | ||
} | ||
@@ -29,0 +34,0 @@ /** |
@@ -0,1 +1,6 @@ | ||
// Latin-1 Supplement | ||
// upper case ranges | ||
// [À-ÖØ-ß] | ||
// lower case ranges | ||
// [à-öø-ÿ] | ||
/** | ||
@@ -8,3 +13,3 @@ * A string.match function that will return an array of "string parts" | ||
function splitOnSpecialChars(string) { | ||
return string.match(/^[a-z]+|[A-Z][a-z]+|[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g); | ||
return string.match(/^[a-zà-öø-ÿ]+|[A-ZÀ-ÖØ-ß][a-zà-öø-ÿ]+|[a-zà-öø-ÿ]+|[0-9]+|[A-ZÀ-ÖØ-ß]+(?![a-zà-öø-ÿ])/g); | ||
} | ||
@@ -21,3 +26,3 @@ /** | ||
var parts = target.includes(' ') ? target.split(' ').filter(Boolean) : splitOnSpecialChars(target); | ||
return noSpecialChars ? parts.map(function (part) { return part.replace(/[^a-zA-Z0-9]/g, ''); }) : parts; | ||
return noSpecialChars ? parts.map(function (part) { return part.replace(/[^a-zA-ZØßø0-9]/g, ''); }) : parts; | ||
} | ||
@@ -24,0 +29,0 @@ /** |
{ | ||
"name": "case-anything", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "description": "camelCase, kebab-case, PascalCase... a simple integration with nano package size. (SMALL footprint!)", |
@@ -32,14 +32,14 @@ # Case anything 🐫 | ||
const testString = 'PonytaVaporeon_poliwrath-BUTTERFREE' | ||
const str = 'PonytaVaporeon_poliwrath-BUTTERFREE' | ||
// or any variant on this | ||
camelCase(testString) === 'ponytaVaporeonPoliwrathButterfree' | ||
camelCase(str) === 'ponytaVaporeonPoliwrathButterfree' | ||
pascalCase(testString) === 'PonytaVaporeonPoliwrathButterfree' | ||
pascalCase(str) === 'PonytaVaporeonPoliwrathButterfree' | ||
kebabCase(testString) === 'ponyta-vaporeon-poliwrath-butterfree' | ||
kebabCase(str) === 'ponyta-vaporeon-poliwrath-butterfree' | ||
snakeCase(testString) === 'ponyta_vaporeon_poliwrath_butterfree' | ||
snakeCase(str) === 'ponyta_vaporeon_poliwrath_butterfree' | ||
constantCase(testString) === 'PONYTA_VAPOREON_POLIWRATH_BUTTERFREE' | ||
constantCase(str) === 'PONYTA_VAPOREON_POLIWRATH_BUTTERFREE' | ||
``` | ||
@@ -52,7 +52,7 @@ | ||
const testString = 'PonytaVaporeon_poliwrath-BUTTERFREE' | ||
const str = 'PonytaVaporeon_poliwrath-BUTTERFREE' | ||
spaceCase(testString) === 'Ponyta Vaporeon poliwrath BUTTERFREE' | ||
spaceCase(str) === 'Ponyta Vaporeon poliwrath BUTTERFREE' | ||
pathCase(testString) === 'Ponyta/Vaporeon/poliwrath/BUTTERFREE' | ||
pathCase(str) === 'Ponyta/Vaporeon/poliwrath/BUTTERFREE' | ||
``` | ||
@@ -65,7 +65,7 @@ | ||
const testString = 'PonytaVaporeon_poliwrath-BUTTERFREE' | ||
const str = 'PonytaVaporeon_poliwrath-BUTTERFREE' | ||
upperCase(testString) === 'PONYTA VAPOREON POLIWRATH BUTTERFREE' | ||
lowerCase(testString) === 'ponyta vaporeon poliwrath butterfree' | ||
capitalCase(testString) === 'Ponyta Vaporeon Poliwrath Butterfree' | ||
upperCase(str) === 'PONYTA VAPOREON POLIWRATH BUTTERFREE' | ||
lowerCase(str) === 'ponyta vaporeon poliwrath butterfree' | ||
capitalCase(str) === 'Ponyta Vaporeon Poliwrath Butterfree' | ||
``` | ||
@@ -81,17 +81,17 @@ | ||
```js | ||
const testString = "listen I'm O.K.!" | ||
const str = "listen I'm O.K.!" | ||
// splits on spaces & removes special characters | ||
camelCase(listenImOK) === 'listenImOk' | ||
pascalCase(listenImOK) === 'ListenImOk' | ||
kebabCase(listenImOK) === 'listen-im-ok' | ||
snakeCase(listenImOK) === 'listen_im_ok' | ||
constantCase(listenImOK) === 'LISTEN_IM_OK' | ||
camelCase(str) === 'listenImOk' | ||
pascalCase(str) === 'ListenImOk' | ||
kebabCase(str) === 'listen-im-ok' | ||
snakeCase(str) === 'listen_im_ok' | ||
constantCase(str) === 'LISTEN_IM_OK' | ||
// splits on spaces & keeps special characters | ||
spaceCase(listenImOK) === "listen I'm O.K.!" | ||
pathCase(listenImOK) === "listen/I'm/O.K.!" | ||
lowerCase(listenImOK) === "listen i'm o.k.!" | ||
upperCase(listenImOK) === "LISTEN I'M O.K.!" | ||
capitalCase(listenImOK) === "Listen I'm O.k.!" | ||
spaceCase(str) === "listen I'm O.K.!" | ||
pathCase(str) === "listen/I'm/O.K.!" | ||
lowerCase(str) === "listen i'm o.k.!" | ||
upperCase(str) === "LISTEN I'M O.K.!" | ||
capitalCase(str) === "Listen I'm O.k.!" | ||
``` | ||
@@ -102,12 +102,28 @@ <!-- prettier-ignore-end --> | ||
### When special alphabet is involved | ||
### When special characters are involved | ||
Currently what keeps the package small is the fact that I use a simple regex to find all the parts in a string: | ||
I have extended regular alphabet with the most common "Latin-1 Supplement" special characters. | ||
- `/^[a-z]+|[A-Z][a-z]+|[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g` | ||
The coolest thing about this library is that it will **"convert" special characters into regular alphabet** for the cases used as variable names! 😎 | ||
That means that alphabet letters like é, ç, ü, ī and many others aren't compatible. | ||
<!-- prettier-ignore-start --> | ||
```js | ||
const str = 'Çâfé Ågård' | ||
If there is a simple way to include these via unicode ranges in the regex, please feel free to open a PR or issue! | ||
// CONVERTS special characters: | ||
camelCase(str) === 'cafeAgard' | ||
pascalCase(str) === 'CafeAgard' | ||
kebabCase(str) === 'cafe-agard' | ||
snakeCase(str) === 'cafe_agard' | ||
constantCase(str) === 'CAFE_AGARD' | ||
// DOES NOT convert special characters: | ||
spaceCase(str) === "Çâfé Ågård" | ||
pathCase(str) === "Çâfé/Ågård" | ||
lowerCase(str) === "çâfé ågård" | ||
upperCase(str) === "ÇÂFÉ ÅGÅRD" | ||
capitalCase(str) === "Çâfé Ågård" | ||
``` | ||
<!-- prettier-ignore-end --> | ||
## Package size | ||
@@ -114,0 +130,0 @@ |
@@ -0,1 +1,7 @@ | ||
// Latin-1 Supplement | ||
// upper case ranges | ||
// [À-ÖØ-ß] | ||
// lower case ranges | ||
// [à-öø-ÿ] | ||
/** | ||
@@ -8,3 +14,3 @@ * A string.match function that will return an array of "string parts" | ||
export function splitOnSpecialChars (string: string): any[] { | ||
return string.match(/^[a-z]+|[A-Z][a-z]+|[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g) | ||
return string.match(/^[a-zà-öø-ÿ]+|[A-ZÀ-ÖØ-ß][a-zà-öø-ÿ]+|[a-zà-öø-ÿ]+|[0-9]+|[A-ZÀ-ÖØ-ß]+(?![a-zà-öø-ÿ])/g) | ||
} | ||
@@ -21,3 +27,3 @@ | ||
const parts = target.includes(' ') ? target.split(' ').filter(Boolean) : splitOnSpecialChars(target) | ||
return noSpecialChars ? parts.map(part => part.replace(/[^a-zA-Z0-9]/g, '')) : parts | ||
return noSpecialChars ? parts.map(part => part.replace(/[^a-zA-ZØßø0-9]/g, '')) : parts | ||
} | ||
@@ -24,0 +30,0 @@ |
@@ -15,2 +15,3 @@ import test from 'ava' | ||
// a bunch of different combinations | ||
const tests = [ | ||
@@ -26,3 +27,2 @@ 'ponytaVaporeonPOLIWRATH_ButterfreeA', | ||
// 1 | ||
test('camelCase', t => { | ||
@@ -76,3 +76,3 @@ tests.forEach(w => { t.is(camelCase(w), 'ponytaVaporeonPoliwrathButterfreeA') }) // prettier-ignore | ||
// 2 | ||
// single capital | ||
const QTableA = 'QTableA' | ||
@@ -91,3 +91,3 @@ | ||
// 3 | ||
// spaces & non alphabet characters | ||
const ImaMIB101OK = "I'm a M.I.B. 101 OK?" | ||
@@ -106,3 +106,3 @@ | ||
// 4 | ||
// spaces & non alphabet characters | ||
const listenImOK = "listen I'm O.K.!" | ||
@@ -121,3 +121,3 @@ | ||
// 5 | ||
// double spacing | ||
const doubleRainbow = 'Double Rainbow' | ||
@@ -135,1 +135,31 @@ | ||
test("capitalCase Double Rainbow", t => { t.is(capitalCase(doubleRainbow), "Double Rainbow") }) // prettier-ignore | ||
const n = (str: string) => str.normalize() | ||
// special characters with Canonical Composition: | ||
const specialCharsNFC = `Ågård î garçons Çafé château voilà ñoël été l'aïeul Ågård ÀÖØß àöøÿ` | ||
test("camelCase specialChars NFC", t => { t.is(n(camelCase(specialCharsNFC)), n(`agardIGarconsCafeChateauVoilaNoelEteLaieulAgardAoøßAoøy`)) }) // prettier-ignore | ||
test("pascalCase specialChars NFC", t => { t.is(n(pascalCase(specialCharsNFC)), n(`AgardIGarconsCafeChateauVoilaNoelEteLaieulAgardAoøßAoøy`)) }) // prettier-ignore | ||
test("kebabCase specialChars NFC", t => { t.is(n(kebabCase(specialCharsNFC)), n(`agard-i-garcons-cafe-chateau-voila-noel-ete-laieul-agard-aoøß-aoøy`)) }) // prettier-ignore | ||
test("snakeCase specialChars NFC", t => { t.is(n(snakeCase(specialCharsNFC)), n(`agard_i_garcons_cafe_chateau_voila_noel_ete_laieul_agard_aoøß_aoøy`)) }) // prettier-ignore | ||
test("constantCase specialChars NFC", t => { t.is(n(constantCase(specialCharsNFC)), n(`AGARD_I_GARCONS_CAFE_CHATEAU_VOILA_NOEL_ETE_LAIEUL_AGARD_AOØSS_AOØY`)) }) // prettier-ignore | ||
test("spaceCase specialChars NFC", t => { t.is(n(spaceCase(specialCharsNFC)), n(`Ågård î garçons Çafé château voilà ñoël été l'aïeul Ågård ÀÖØß àöøÿ`)) }) // prettier-ignore | ||
test("pathCase specialChars NFC", t => { t.is(n(pathCase(specialCharsNFC)), n(`Ågård/î/garçons/Çafé/château/voilà/ñoël/été/l'aïeul/Ågård/ÀÖØß/àöøÿ`)) }) // prettier-ignore | ||
test("lowerCase specialChars NFC", t => { t.is(n(lowerCase(specialCharsNFC)), n(`ågård î garçons çafé château voilà ñoël été l'aïeul ågård àöøß àöøÿ`)) }) // prettier-ignore | ||
test("upperCase specialChars NFC", t => { t.is(n(upperCase(specialCharsNFC)), n(`ÅGÅRD Î GARÇONS ÇAFÉ CHÂTEAU VOILÀ ÑOËL ÉTÉ L'AÏEUL ÅGÅRD ÀÖØSS ÀÖØŸ`)) }) // prettier-ignore | ||
test("capitalCase specialChars NFC", t => { t.is(n(capitalCase(specialCharsNFC)), n(`Ågård Î Garçons Çafé Château Voilà Ñoël Été L'aïeul Ågård Àöøß Àöøÿ`)) }) // prettier-ignore | ||
// special characters with Canonical Decomposition: | ||
const specialCharsNFD = `Ågård î garçons Çafé château voilà ñoël été l'aïeul Ågård ÀÖØß àöøÿ` | ||
test("camelCase specialChars NFD", t => { t.is(n(camelCase(specialCharsNFD)), n(`agardIGarconsCafeChateauVoilaNoelEteLaieulAgardAoøßAoøy`)) }) // prettier-ignore | ||
test("pascalCase specialChars NFD", t => { t.is(n(pascalCase(specialCharsNFD)), n(`AgardIGarconsCafeChateauVoilaNoelEteLaieulAgardAoøßAoøy`)) }) // prettier-ignore | ||
test("kebabCase specialChars NFD", t => { t.is(n(kebabCase(specialCharsNFD)), n(`agard-i-garcons-cafe-chateau-voila-noel-ete-laieul-agard-aoøß-aoøy`)) }) // prettier-ignore | ||
test("snakeCase specialChars NFD", t => { t.is(n(snakeCase(specialCharsNFD)), n(`agard_i_garcons_cafe_chateau_voila_noel_ete_laieul_agard_aoøß_aoøy`)) }) // prettier-ignore | ||
test("constantCase specialChars NFD", t => { t.is(n(constantCase(specialCharsNFD)), n(`AGARD_I_GARCONS_CAFE_CHATEAU_VOILA_NOEL_ETE_LAIEUL_AGARD_AOØSS_AOØY`)) }) // prettier-ignore | ||
test("spaceCase specialChars NFD", t => { t.is(n(spaceCase(specialCharsNFD)), n(`Ågård î garçons Çafé château voilà ñoël été l'aïeul Ågård ÀÖØß àöøÿ`)) }) // prettier-ignore | ||
test("pathCase specialChars NFD", t => { t.is(n(pathCase(specialCharsNFD)), n(`Ågård/î/garçons/Çafé/château/voilà/ñoël/été/l'aïeul/Ågård/ÀÖØß/àöøÿ`)) }) // prettier-ignore | ||
test("lowerCase specialChars NFD", t => { t.is(n(lowerCase(specialCharsNFD)), n(`ågård î garçons çafé château voilà ñoël été l'aïeul ågård àöøß àöøÿ`)) }) // prettier-ignore | ||
test("upperCase specialChars NFD", t => { t.is(n(upperCase(specialCharsNFD)), n(`ÅGÅRD Î GARÇONS ÇAFÉ CHÂTEAU VOILÀ ÑOËL ÉTÉ L'AÏEUL ÅGÅRD ÀÖØSS ÀÖØŸ`)) }) // prettier-ignore | ||
test("capitalCase specialChars NFD", t => { t.is(n(capitalCase(specialCharsNFD)), n(`Ågård Î Garçons Çafé Château Voilà Ñoël Été L'aïeul Ågård Àöøß Àöøÿ`)) }) // prettier-ignore |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37890
811
146