Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

case-anything

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

case-anything - npm Package Compare versions

Comparing version 2.1.13 to 3.0.0

dist/core.d.ts

231

dist/index.d.ts

@@ -1,230 +0,1 @@

/**
* # 🐪 camelCase
* converts a string to camelCase
* - first lowercase then all capitalised
* - *strips away* special characters by default
*
* @example
* camelCase('$catDog') === 'catDog'
* @example
* camelCase('$catDog', { keepSpecialCharacters: true }) === '$catDog'
*/
declare function camelCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 🐫 PascalCase
* converts a string to PascalCase (also called UpperCamelCase)
* - all capitalised
* - *strips away* special characters by default
*
* @example
* pascalCase('$catDog') === 'CatDog'
* @example
* pascalCase('$catDog', { keepSpecialCharacters: true }) === '$CatDog'
*/
declare function pascalCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 🐫 UpperCamelCase
* converts a string to UpperCamelCase (also called PascalCase)
* - all capitalised
* - *strips away* special characters by default
*
* @example
* upperCamelCase('$catDog') === 'CatDog'
* @example
* upperCamelCase('$catDog', { keepSpecialCharacters: true }) === '$CatDog'
*/
declare const upperCamelCase: typeof pascalCase;
/**
* # 🥙 kebab-case
* converts a string to kebab-case
* - hyphenated lowercase
* - *strips away* special characters by default
*
* @example
* kebabCase('$catDog') === 'cat-dog'
* @example
* kebabCase('$catDog', { keepSpecialCharacters: true }) === '$cat-dog'
*/
declare function kebabCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 🐍 snake_case
* converts a string to snake_case
* - underscored lowercase
* - *strips away* special characters by default
*
* @example
* snakeCase('$catDog') === 'cat_dog'
* @example
* snakeCase('$catDog', { keepSpecialCharacters: true }) === '$cat_dog'
*/
declare function snakeCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 📣 CONSTANT_CASE
* converts a string to CONSTANT_CASE
* - underscored uppercase
* - *strips away* special characters by default
*
* @example
* constantCase('$catDog') === 'CAT_DOG'
* @example
* constantCase('$catDog', { keepSpecialCharacters: true }) === '$CAT_DOG'
*/
declare function constantCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 🚂 Train-Case
* converts strings to Train-Case
* - hyphenated & capitalised
* - *strips away* special characters by default
*
* @example
* trainCase('$catDog') === 'Cat-Dog'
* @example
* trainCase('$catDog', { keepSpecialCharacters: true }) === '$Cat-Dog'
*/
declare function trainCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 🕊 Ada_Case
* converts a string to Ada_Case
* - underscored & capitalised
* - *strips away* special characters by default
*
* @example
* adaCase('$catDog') === 'Cat_Dog'
* @example
* adaCase('$catDog', { keepSpecialCharacters: true }) === '$Cat_Dog'
*/
declare function adaCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 👔 COBOL-CASE
* converts a string to COBOL-CASE
* - hyphenated uppercase
* - *strips away* special characters by default
*
* @example
* cobolCase('$catDog') === 'CAT-DOG'
* @example
* cobolCase('$catDog', { keepSpecialCharacters: true }) === '$CAT-DOG'
*/
declare function cobolCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 📍 Dot.notation
* converts a string to dot.notation
* - adds dots, does not change casing
* - *strips away* special characters by default
*
* @example
* dotNotation('$catDog') === 'cat.Dog'
* @example
* dotNotation('$catDog', { keepSpecialCharacters: true }) === '$cat.Dog'
*/
declare function dotNotation(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 📂 Path/case
* converts a string to path/case
* - adds slashes, does not change casing
* - *keeps* special characters by default
*
* @example
* pathCase('$catDog') === '$cat/Dog'
* @example
* pathCase('$catDog', { keepSpecialCharacters: false }) === 'cat/Dog'
*/
declare function pathCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 🛰 Space case
* converts a string to space case
* - adds spaces, does not change casing
* - *keeps* special characters by default
*
* @example
* spaceCase('$catDog') === '$cat Dog'
* @example
* spaceCase('$catDog', { keepSpecialCharacters: false }) === 'cat Dog'
*/
declare function spaceCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 🏛 Capital Case
* converts a string to Capital Case
* - capitalizes words and adds spaces
* - *keeps* special characters by default
*
* @example
* capitalCase('$catDog') === '$Cat Dog'
* @example
* capitalCase('$catDog', { keepSpecialCharacters: false }) === 'Cat Dog'
*
* ⟪ if you do not want to add spaces, use `pascalCase()` ⟫
*/
declare function capitalCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 🔡 lower case
* converts a string to lower case
* - makes words lowercase and adds spaces
* - *keeps* special characters by default
*
* @example
* lowerCase('$catDog') === '$cat dog'
* @example
* lowerCase('$catDog', { keepSpecialCharacters: false }) === 'cat dog'
*
* ⟪ if you do not want to add spaces, use the native JS `toLowerCase()` ⟫
*/
declare function lowerCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
/**
* # 🔠 UPPER CASE
* converts a string to UPPER CASE
* - makes words upper case and adds spaces
* - *keeps* special characters by default
*
* @example
* upperCase('$catDog') === '$CAT DOG'
* @example
* upperCase('$catDog', { keepSpecialCharacters: false }) === 'CAT DOG'
*
* ⟪ if you do not want to add spaces, use the native JS `toUpperCase()` ⟫
*/
declare function upperCase(string: string, options?: {
keepSpecialCharacters?: boolean;
keep?: string[];
}): string;
export { adaCase, camelCase, capitalCase, cobolCase, constantCase, dotNotation, kebabCase, lowerCase, pascalCase, pathCase, snakeCase, spaceCase, trainCase, upperCamelCase, upperCase };
export { adaCase, camelCase, capitalCase, cobolCase, constantCase, dotNotation, kebabCase, lowerCase, pascalCase, pathCase, snakeCase, spaceCase, trainCase, upperCamelCase, upperCase, } from './core.js';

@@ -1,117 +0,1 @@

const magicSplit = /^[a-zà-öø-ÿ]+|[A-ZÀ-ÖØ-ß][a-zà-öø-ÿ]+|[a-zà-öø-ÿ]+|[0-9]+|[A-ZÀ-ÖØ-ß]+(?![a-zà-öø-ÿ])/g;
const spaceSplit = /\S+/g;
function getPartsAndIndexes(string, splitRegex) {
const result = { parts: [], prefixes: [] };
const matches = string.matchAll(splitRegex);
let lastWordEndIndex = 0;
for (const match of matches) {
if (typeof match.index !== "number")
continue;
const word = match[0];
result.parts.push(word);
const prefix = string.slice(lastWordEndIndex, match.index).trim();
result.prefixes.push(prefix);
lastWordEndIndex = match.index + word.length;
}
const tail = string.slice(lastWordEndIndex).trim();
if (tail) {
result.parts.push("");
result.prefixes.push(tail);
}
return result;
}
function splitAndPrefix(string, options) {
const { keepSpecialCharacters = false, keep, prefix = "" } = options || {};
const normalString = string.trim().normalize("NFC");
const hasSpaces = normalString.includes(" ");
const split = hasSpaces ? spaceSplit : magicSplit;
const partsAndIndexes = getPartsAndIndexes(normalString, split);
return partsAndIndexes.parts.map((_part, i) => {
let foundPrefix = partsAndIndexes.prefixes[i] || "";
let part = _part;
if (keepSpecialCharacters === false) {
if (keep) {
part = part.normalize("NFD").replace(new RegExp(`[^a-zA-Z\xD8\xDF\xF80-9${keep.join("")}]`, "g"), "");
}
if (!keep) {
part = part.normalize("NFD").replace(/[^a-zA-ZØßø0-9]/g, "");
foundPrefix = "";
}
}
if (keep) {
foundPrefix = foundPrefix.replace(new RegExp(`[^${keep.join("")}]`, "g"), "");
}
if (i === 0) {
return foundPrefix + part;
}
if (!foundPrefix && !part)
return "";
if (!hasSpaces) {
return (foundPrefix || prefix) + part;
}
if (!foundPrefix && prefix.match(/\s/)) {
return " " + part;
}
return (foundPrefix || prefix) + part;
}).filter(Boolean);
}
function capitaliseWord(string) {
const match = string.matchAll(magicSplit).next().value;
const firstLetterIndex = match ? match.index : 0;
return string.slice(0, firstLetterIndex + 1).toUpperCase() + string.slice(firstLetterIndex + 1).toLowerCase();
}
function camelCase(string, options) {
return splitAndPrefix(string, options).reduce((result, word, index) => {
return index === 0 || !(word[0] || "").match(magicSplit) ? result + word.toLowerCase() : result + capitaliseWord(word);
}, "");
}
function pascalCase(string, options) {
return splitAndPrefix(string, options).reduce((result, word) => {
return result + capitaliseWord(word);
}, "");
}
const upperCamelCase = pascalCase;
function kebabCase(string, options) {
return splitAndPrefix(string, { ...options, prefix: "-" }).join("").toLowerCase();
}
function snakeCase(string, options) {
return splitAndPrefix(string, { ...options, prefix: "_" }).join("").toLowerCase();
}
function constantCase(string, options) {
return splitAndPrefix(string, { ...options, prefix: "_" }).join("").toUpperCase();
}
function trainCase(string, options) {
return splitAndPrefix(string, { ...options, prefix: "-" }).map((word) => capitaliseWord(word)).join("");
}
function adaCase(string, options) {
return splitAndPrefix(string, { ...options, prefix: "_" }).map((part) => capitaliseWord(part)).join("");
}
function cobolCase(string, options) {
return splitAndPrefix(string, { ...options, prefix: "-" }).join("").toUpperCase();
}
function dotNotation(string, options) {
return splitAndPrefix(string, { ...options, prefix: "." }).join("");
}
function pathCase(string, options = { keepSpecialCharacters: true }) {
return splitAndPrefix(string, options).reduce((result, word, i) => {
const prefix = i === 0 || word[0] === "/" ? "" : "/";
return result + prefix + word;
}, "");
}
function spaceCase(string, options = { keepSpecialCharacters: true }) {
return splitAndPrefix(string, { ...options, prefix: " " }).join("");
}
function capitalCase(string, options = { keepSpecialCharacters: true }) {
return splitAndPrefix(string, { ...options, prefix: " " }).reduce((result, word) => {
return result + capitaliseWord(word);
}, "");
}
function lowerCase(string, options = { keepSpecialCharacters: true }) {
return splitAndPrefix(string, { ...options, prefix: " " }).join("").toLowerCase();
}
function upperCase(string, options = { keepSpecialCharacters: true }) {
return splitAndPrefix(string, { ...options, prefix: " " }).join("").toUpperCase();
}
export { adaCase, camelCase, capitalCase, cobolCase, constantCase, dotNotation, kebabCase, lowerCase, pascalCase, pathCase, snakeCase, spaceCase, trainCase, upperCamelCase, upperCase };
export { adaCase, camelCase, capitalCase, cobolCase, constantCase, dotNotation, kebabCase, lowerCase, pascalCase, pathCase, snakeCase, spaceCase, trainCase, upperCamelCase, upperCase, } from './core.js';
{
"name": "case-anything",
"version": "2.1.13",
"version": "3.0.0",
"description": "camelCase, kebab-case, PascalCase... a simple integration with nano package size. (SMALL footprint!)",
"type": "module",
"sideEffects": false,
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"main": "./dist/index.js",
"exports": {

@@ -22,33 +19,21 @@ ".": {

},
"files": [
"dist"
],
"engines": {
"node": ">=12.13"
"node": ">=18"
},
"scripts": {
"lint": "tsc --noEmit && eslint ./src --ext .ts",
"lint": "tsc --noEmit && eslint ./src",
"test": "vitest run",
"build": "rollup -c ./rollup.config.js",
"release": "npm run lint && del dist && npm run build && np"
"build": "del-cli dist && tsc",
"release": "npm run lint && npm run build && np"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"del-cli": "^5.0.0",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-tree-shaking": "^1.10.0",
"np": "^7.7.0",
"prettier": "^2.8.8",
"rollup": "^3.23.0",
"rollup-plugin-dts": "^5.3.0",
"rollup-plugin-esbuild": "^5.0.0",
"typescript": "^4.9.5",
"vitest": "^0.31.0"
"del-cli": "^5.1.0",
"np": "^10.0.5",
"vitest": "^1.6.0",
"@cycraft/eslint": "^0.3.0",
"@cycraft/tsconfig": "^0.1.2"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mesqueeb/case-anything.git"
},
"files": [
"dist"
],
"keywords": [

@@ -77,40 +62,11 @@ "change-case",

],
"author": "Luca Ban - Mesqueeb",
"author": "Luca Ban - Mesqueeb (https://cycraft.co)",
"funding": "https://github.com/sponsors/mesqueeb",
"license": "MIT",
"bugs": {
"url": "https://github.com/mesqueeb/case-anything/issues"
"repository": {
"type": "git",
"url": "https://github.com/mesqueeb/case-anything.git"
},
"homepage": "https://github.com/mesqueeb/case-anything#readme",
"np": {
"yarn": false,
"branch": "production"
},
"eslintConfig": {
"ignorePatterns": [
"node_modules",
"dist",
"scripts",
"test"
],
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"tree-shaking"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"tree-shaking/no-side-effects-in-initialization": "error",
"@typescript-eslint/ban-ts-comment": "off"
}
}
"bugs": "https://github.com/mesqueeb/case-anything/issues"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc