initial commit
This commit is contained in:
77
node_modules/scule/dist/index.cjs
generated
vendored
Normal file
77
node_modules/scule/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
const NUMBER_CHAR_RE = /\d/;
|
||||
const STR_SPLITTERS = ["-", "_", "/", "."];
|
||||
function isUppercase(char = "") {
|
||||
if (NUMBER_CHAR_RE.test(char)) {
|
||||
return void 0;
|
||||
}
|
||||
return char.toUpperCase() === char;
|
||||
}
|
||||
function splitByCase(string_, separators) {
|
||||
const splitters = separators ?? STR_SPLITTERS;
|
||||
const parts = [];
|
||||
if (!string_ || typeof string_ !== "string") {
|
||||
return parts;
|
||||
}
|
||||
let buff = "";
|
||||
let previousUpper;
|
||||
let previousSplitter;
|
||||
for (const char of string_) {
|
||||
const isSplitter = splitters.includes(char);
|
||||
if (isSplitter === true) {
|
||||
parts.push(buff);
|
||||
buff = "";
|
||||
previousUpper = void 0;
|
||||
continue;
|
||||
}
|
||||
const isUpper = isUppercase(char);
|
||||
if (previousSplitter === false) {
|
||||
if (previousUpper === false && isUpper === true) {
|
||||
parts.push(buff);
|
||||
buff = char;
|
||||
previousUpper = isUpper;
|
||||
continue;
|
||||
}
|
||||
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
||||
const lastChar = buff[buff.length - 1];
|
||||
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
||||
buff = lastChar + char;
|
||||
previousUpper = isUpper;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
buff += char;
|
||||
previousUpper = isUpper;
|
||||
previousSplitter = isSplitter;
|
||||
}
|
||||
parts.push(buff);
|
||||
return parts;
|
||||
}
|
||||
function upperFirst(string_) {
|
||||
return !string_ ? "" : string_[0].toUpperCase() + string_.slice(1);
|
||||
}
|
||||
function lowerFirst(string_) {
|
||||
return !string_ ? "" : string_[0].toLowerCase() + string_.slice(1);
|
||||
}
|
||||
function pascalCase(string_) {
|
||||
return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => upperFirst(p)).join("");
|
||||
}
|
||||
function camelCase(string_) {
|
||||
return lowerFirst(pascalCase(string_));
|
||||
}
|
||||
function kebabCase(string_, joiner) {
|
||||
return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => p.toLowerCase()).join(joiner ?? "-");
|
||||
}
|
||||
function snakeCase(string_) {
|
||||
return kebabCase(string_, "_");
|
||||
}
|
||||
|
||||
exports.camelCase = camelCase;
|
||||
exports.isUppercase = isUppercase;
|
||||
exports.kebabCase = kebabCase;
|
||||
exports.lowerFirst = lowerFirst;
|
||||
exports.pascalCase = pascalCase;
|
||||
exports.snakeCase = snakeCase;
|
||||
exports.splitByCase = splitByCase;
|
||||
exports.upperFirst = upperFirst;
|
||||
Reference in New Issue
Block a user