No Case
Transform text into no case format where words are lowercase and separated by spaces.
๐ Features
- Lightweight - Only ~450B minified + gzipped
- Type-safe - Full TypeScript support with comprehensive type definitions
- Zero dependencies - No external dependencies
- Tree-shakeable - ES modules support
- Universal - Works in browsers, Node.js, and serverless environments
- Well-tested - Comprehensive test suite with edge cases
- Customizable - Flexible options for advanced use cases
๐ฆ Installation
# npm
npm install text-no-case
# yarn
yarn add text-no-case
# pnpm
pnpm add text-no-case
# bun
bun add text-no-case
๐ฏ Quick Start
import { noCase } from "text-no-case";
console.log(noCase("hello world")); // "hello world"
console.log(noCase("userProfileData")); // "user profile data"
console.log(noCase("backgroundColor")); // "background color"
๐ Usage
ES Modules (Recommended)
import { noCase } from "text-no-case";
console.log(noCase("hello world")); // "hello world"
CommonJS
const { noCase } = require("text-no-case");
console.log(noCase("hello world")); // "hello world"
TypeScript
import { noCase, Options } from "text-no-case";
const result: string = noCase("hello world");
console.log(result); // "hello world"
๐ Transformation Examples
Basic Transformations
import { noCase } from "text-no-case";
// From different cases
noCase("hello world"); // "hello world"
noCase("Hello World"); // "hello world"
noCase("HELLO WORLD"); // "hello world"
noCase("camelCase"); // "camel case"
noCase("PascalCase"); // "pascal case"
noCase("snake_case"); // "snake case"
noCase("kebab-case"); // "kebab case"
noCase("dot.case"); // "dot case"
// Complex examples
noCase("XMLHttpRequest"); // "xml http request"
noCase("iPhone"); // "i phone"
noCase("version 1.2.3"); // "version 1 2 3"
noCase("userProfileData"); // "user profile data"
Advanced Options
import { noCase } from "text-no-case";
// Custom word splitting
noCase("XMLHttpRequest", {
splitRegexp: /([a-z])([A-Z])/g,
}); // "xml http request"
// Custom character stripping
noCase("hello@world.com", {
stripRegexp: /[@.]/g,
}); // "hello world com"
// Custom transformation function
noCase("api-v2-endpoint", {
transform: (word, index) => {
if (word === "api") return "api";
if (word === "v2") return "version 2";
return word.toLowerCase();
},
}); // "api version 2 endpoint"
๐ Real-World Examples
Search Query Processing
import { noCase } from "text-no-case";
// Normalize search queries
noCase("JavaScript"); // "java script"
noCase("ReactJS"); // "react js"
noCase("Node.js"); // "node js"
noCase("TypeScript"); // "type script"
noCase("MongoDB"); // "mongo db"
Content Processing
import { noCase } from "text-no-case";
// Process content for readability
noCase("userManagement"); // "user management"
noCase("dataVisualization"); // "data visualization"
noCase("apiIntegration"); // "api integration"
noCase("errorHandling"); // "error handling"
noCase("performanceOptimization"); // "performance optimization"
Tag Processing
import { noCase } from "text-no-case";
// Convert tags to readable format
const tags = [
"webDevelopment",
"machineLearning",
"dataScience",
"userExperience",
"projectManagement",
];
const readableTags = tags.map(noCase);
console.log(readableTags);
// [
// "web development",
// "machine learning",
// "data science",
// "user experience",
// "project management"
// ]
Form Label Generation
import { noCase } from "text-no-case";
function generateFormLabel(fieldName) {
return noCase(fieldName)
.split(" ")
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(" ");
}
console.log(generateFormLabel("firstName")); // "First Name"
console.log(generateFormLabel("emailAddress")); // "Email Address"
console.log(generateFormLabel("phoneNumber")); // "Phone Number"
URL Slug Preparation
import { noCase } from "text-no-case";
function prepareSlug(title) {
return noCase(title)
.replace(/\s+/g, "-")
.replace(/[^a-z0-9-]/g, "");
}
console.log(prepareSlug("Hello World!")); // "hello-world"
console.log(prepareSlug("JavaScript Tips & Tricks")); // "java-script-tips-tricks"
Text Analysis
import { noCase } from "text-no-case";
function analyzeText(text) {
const normalized = noCase(text);
const words = normalized.split(" ").filter((word) => word.length > 0);
return {
wordCount: words.length,
uniqueWords: [...new Set(words)].length,
averageWordLength:
words.reduce((sum, word) => sum + word.length, 0) / words.length,
};
}
console.log(analyzeText("userProfileData"));
// { wordCount: 3, uniqueWords: 3, averageWordLength: 4.67 }
Content Normalization
import { noCase } from "text-no-case";
function normalizeContent(content) {
return content
.split("\n")
.map((line) => line.trim())
.filter((line) => line.length > 0)
.map((line) => noCase(line))
.join(" ");
}
const content = `
userManagement
dataVisualization
apiIntegration
`;
console.log(normalizeContent(content));
// "user management data visualization api integration"
Keyword Extraction
import { noCase } from "text-no-case";
function extractKeywords(text, minLength = 3) {
const normalized = noCase(text);
const words = normalized.split(" ");
return words
.filter((word) => word.length >= minLength)
.filter((word, index, arr) => arr.indexOf(word) === index)
.sort();
}
console.log(extractKeywords("userProfileDataManagement"));
// ["data", "management", "profile", "user"]
๐ API Reference
noCase(input, options?)
Converts a string to no case format.
Parameters
input
(string
): The string to convertoptions
(Options
, optional): Configuration options
Returns
string
: The no case formatted string
Options
interface Options {
// Custom transform function for word processing
transform?: (word: string, index: number, words: string[]) => string;
// Regex to strip characters before processing
stripRegexp?: RegExp;
// Custom split function
split?: (value: string) => string[];
}
๐ง Advanced Configuration
Custom Word Splitting
import { noCase } from "text-no-case";
// Split on specific patterns
noCase("XMLHttpRequest", {
splitRegexp: /([a-z])([A-Z])/g,
}); // "xml http request"
// Split on numbers
noCase("user123data", {
splitRegexp: /([a-zA-Z])(\d)/g,
}); // "user 123 data"
Custom Character Stripping
import { noCase } from "text-no-case";
// Strip specific characters
noCase("hello@world.com", {
stripRegexp: /[@.]/g,
}); // "hello world com"
// Strip all non-alphanumeric
noCase("hello!@#world", {
stripRegexp: /[^a-zA-Z0-9]/g,
}); // "hello world"
Custom Transform Functions
import { noCase } from "text-no-case";
// Preserve certain words
noCase("xml-http-request", {
transform: (word, index) => {
const preserveWords = ["xml", "http", "api", "url"];
if (preserveWords.includes(word.toLowerCase())) {
return word.toLowerCase();
}
return word.toLowerCase();
},
}); // "xml http request"
// Custom business logic
noCase("user-v2-api", {
transform: (word, index) => {
if (word === "v2") return "version 2";
if (word === "api") return "api";
return word.toLowerCase();
},
}); // "user version 2 api"
๐ Bundle Size
This package is optimized for minimal bundle size:
- Minified: ~450B
- Gzipped: ~250B
- Tree-shakeable: Yes
- Side effects: None
๐ Browser Support
- Modern browsers: ES2015+ (Chrome 51+, Firefox 54+, Safari 10+)
- Node.js: 12+
- TypeScript: 4.0+
- Bundle formats: UMD, ESM, CommonJS
๐งช Testing
# Run tests
pnpm test
# Run tests in watch mode
pnpm test --watch
# Run tests with coverage
pnpm test --coverage
# Type checking
pnpm typecheck
# Linting
pnpm lint
๐ Related Packages
text-lower-case
- Convert to lowercasetext-sentence-case
- Convert to Sentence casetext-title-case
- Convert to Title Casetext-camel-case
- Convert to camelCasetext-case
- All case transformations in one package
๐ License
๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ Support
- ๐ง Email: selikhov.dmitrey@gmail.com
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ Documentation: Full Documentation
Made with โค๏ธ by Dmitry Selikhov