Comparing version 0.2.1 to 0.3.0
@@ -11,26 +11,37 @@ 'use strict'; | ||
const parts = []; | ||
if (!str || typeof str !== "string") { | ||
return parts; | ||
} | ||
let buff = ""; | ||
let previusUpper = isUppercase(str[0]); | ||
let previousSplitter = splitters.includes(str[0]); | ||
let previusUpper = null; | ||
let previousSplitter = null; | ||
for (const char of str.split("")) { | ||
const isSplitter = splitters.includes(char); | ||
if (isSplitter) { | ||
if (isSplitter === true) { | ||
parts.push(buff); | ||
buff = ""; | ||
previusUpper = false; | ||
previousSplitter = true; | ||
} else if (!previousSplitter && !previusUpper && isUppercase(char)) { | ||
parts.push(buff); | ||
buff = char; | ||
previusUpper = true; | ||
previousSplitter = false; | ||
} else { | ||
buff += char; | ||
previusUpper = isUppercase(char); | ||
previousSplitter = isSplitter; | ||
previusUpper = null; | ||
continue; | ||
} | ||
const isUpper = isUppercase(char); | ||
if (previousSplitter === false) { | ||
if (previusUpper === false && isUpper === true) { | ||
parts.push(buff); | ||
buff = char; | ||
previusUpper = isUpper; | ||
continue; | ||
} | ||
if (previusUpper === true && isUpper === false && buff.length > 1) { | ||
const lastChar = buff[buff.length - 1]; | ||
parts.push(buff.substr(0, buff.length - 1)); | ||
buff = lastChar + char; | ||
previusUpper = isUpper; | ||
continue; | ||
} | ||
} | ||
buff += char; | ||
previusUpper = isUpper; | ||
previousSplitter = isSplitter; | ||
} | ||
if (buff) { | ||
parts.push(buff); | ||
} | ||
parts.push(buff); | ||
return parts; | ||
@@ -37,0 +48,0 @@ } |
{ | ||
"name": "scule", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "repository": "nuxt-contrib/scule", |
@@ -70,3 +70,3 @@ # 🧵 Scule | ||
- Splits string by the splitters provided (default: `['-', '_', '/', '.]`) | ||
- Splits when case changes from lower to upper (only rising edges) | ||
- Splits when case changes from lower to upper or upper to lower | ||
- Case is preserved in returned value | ||
@@ -73,0 +73,0 @@ - Is an irreversible function since splitters are omitted |
Sorry, the diff of this file is not supported yet
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
154
8995
6