Lower Case
Transform text to lowercase format - all characters converted to lowercase.
π Features
- Lightweight - Only ~200B 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
π¦ Installation
# npm
npm install text-lower-case
# yarn
yarn add text-lower-case
# pnpm
pnpm add text-lower-case
# bun
bun add text-lower-case
π― Quick Start
import { lowerCase } from "text-lower-case";
console.log(lowerCase("HELLO WORLD")); // "hello world"
console.log(lowerCase("CamelCase")); // "camelcase"
console.log(lowerCase("KEBAB-CASE")); // "kebab-case"
π Usage
ES Modules (Recommended)
import { lowerCase } from "text-lower-case";
console.log(lowerCase("HELLO")); // "hello"
CommonJS
const { lowerCase } = require("text-lower-case");
console.log(lowerCase("HELLO")); // "hello"
TypeScript
import { lowerCase } from "text-lower-case";
const result: string = lowerCase("HELLO WORLD");
console.log(result); // "hello world"
π Transformation Examples
Basic Transformations
import { lowerCase } from "text-lower-case";
// Simple cases
lowerCase("HELLO"); // "hello"
lowerCase("WORLD"); // "world"
lowerCase("Hello World"); // "hello world"
// Mixed case
lowerCase("hELLo WoRLD"); // "hello world"
lowerCase("CamelCase"); // "camelcase"
lowerCase("PascalCase"); // "pascalcase"
// Programming cases
lowerCase("SNAKE_CASE"); // "snake_case"
lowerCase("KEBAB-CASE"); // "kebab-case"
lowerCase("DOT.CASE"); // "dot.case"
Edge Cases
import { lowerCase } from "text-lower-case";
// Empty and single character
lowerCase(""); // ""
lowerCase("A"); // "a"
lowerCase("a"); // "a"
// Numbers and symbols
lowerCase("HELLO123"); // "hello123"
lowerCase("TEST@EMAIL.COM"); // "test@email.com"
lowerCase("USER-123"); // "user-123"
// Unicode characters
lowerCase("CAFΓ"); // "cafΓ©"
lowerCase("NAΓVE"); // "naΓ―ve"
lowerCase("RΓSUMΓ"); // "rΓ©sumΓ©"
π Real-World Examples
Email and Username Processing
import { lowerCase } from "text-lower-case";
// Email normalization
lowerCase("USER@EXAMPLE.COM"); // "user@example.com"
lowerCase("John.Doe@Gmail.Com"); // "john.doe@gmail.com"
lowerCase("ADMIN@COMPANY.ORG"); // "admin@company.org"
// Username normalization
lowerCase("JohnDoe123"); // "johndoe123"
lowerCase("ADMIN_USER"); // "admin_user"
lowerCase("Guest-User"); // "guest-user"
URL and Domain Processing
import { lowerCase } from "text-lower-case";
// Domain normalization
lowerCase("EXAMPLE.COM"); // "example.com"
lowerCase("API.GitHub.Com"); // "api.github.com"
lowerCase("SUB.DOMAIN.ORG"); // "sub.domain.org"
// Protocol normalization
lowerCase("HTTPS"); // "https"
lowerCase("HTTP"); // "http"
lowerCase("FTP"); // "ftp"
Search and Filtering
import { lowerCase } from "text-lower-case";
function searchItems(items, query) {
const normalizedQuery = lowerCase(query);
return items.filter(
(item) =>
lowerCase(item.name).includes(normalizedQuery) ||
lowerCase(item.description).includes(normalizedQuery),
);
}
const products = [
{ name: "iPhone 15", description: "Latest Apple smartphone" },
{ name: "Samsung Galaxy", description: "Android flagship device" },
{ name: "Google Pixel", description: "Pure Android experience" },
];
console.log(searchItems(products, "APPLE"));
// [{ name: "iPhone 15", description: "Latest Apple smartphone" }]
Form Data Processing
import { lowerCase } from "text-lower-case";
function normalizeFormData(formData) {
const normalized = {};
for (const [key, value] of Object.entries(formData)) {
if (typeof value === "string") {
// Normalize email fields
if (key.toLowerCase().includes("email")) {
normalized[key] = lowerCase(value.trim());
}
// Normalize username fields
else if (key.toLowerCase().includes("username")) {
normalized[key] = lowerCase(value.trim());
} else {
normalized[key] = value;
}
} else {
normalized[key] = value;
}
}
return normalized;
}
const formData = {
email: " USER@EXAMPLE.COM ",
username: "JOHNDOE123",
firstName: "John",
lastName: "Doe",
};
console.log(normalizeFormData(formData));
// {
// email: "user@example.com",
// username: "johndoe123",
// firstName: "John",
// lastName: "Doe"
// }
Database Query Normalization
import { lowerCase } from "text-lower-case";
class UserRepository {
async findByEmail(email) {
const normalizedEmail = lowerCase(email.trim());
return await this.db.users.findOne({
email: normalizedEmail,
});
}
async findByUsername(username) {
const normalizedUsername = lowerCase(username.trim());
return await this.db.users.findOne({
username: normalizedUsername,
});
}
async searchUsers(query) {
const normalizedQuery = lowerCase(query);
return await this.db.users.find({
$or: [
{ email: { $regex: normalizedQuery, $options: "i" } },
{ username: { $regex: normalizedQuery, $options: "i" } },
],
});
}
}
Configuration Management
import { lowerCase } from "text-lower-case";
function parseEnvironmentVariables(env) {
const config = {};
for (const [key, value] of Object.entries(env)) {
// Normalize boolean values
if (typeof value === "string") {
const lowerValue = lowerCase(value);
if (lowerValue === "true" || lowerValue === "false") {
config[key] = lowerValue === "true";
}
// Normalize protocol values
else if (key.toLowerCase().includes("protocol")) {
config[key] = lowerValue;
}
// Normalize host values
else if (key.toLowerCase().includes("host")) {
config[key] = lowerValue;
} else {
config[key] = value;
}
} else {
config[key] = value;
}
}
return config;
}
const env = {
NODE_ENV: "PRODUCTION",
DATABASE_HOST: "LOCALHOST",
USE_SSL: "TRUE",
PROTOCOL: "HTTPS",
};
console.log(parseEnvironmentVariables(env));
// {
// NODE_ENV: "PRODUCTION",
// DATABASE_HOST: "localhost",
// USE_SSL: true,
// PROTOCOL: "https"
// }
Text Processing Pipeline
import { lowerCase } from "text-lower-case";
class TextNormalizer {
constructor() {
this.processors = [];
}
addTrim() {
this.processors.push((text) => text.trim());
return this;
}
addLowerCase() {
this.processors.push(lowerCase);
return this;
}
addRemoveExtraSpaces() {
this.processors.push((text) => text.replace(/\s+/g, " "));
return this;
}
process(text) {
return this.processors.reduce(
(result, processor) => processor(result),
text,
);
}
}
const normalizer = new TextNormalizer()
.addTrim()
.addLowerCase()
.addRemoveExtraSpaces();
console.log(normalizer.process(" HELLO WORLD ")); // "hello world"
API Response Processing
import { lowerCase } from "text-lower-case";
function normalizeApiResponse(response) {
if (response.data && Array.isArray(response.data)) {
response.data = response.data.map((item) => {
if (item.email) {
item.email = lowerCase(item.email);
}
if (item.username) {
item.username = lowerCase(item.username);
}
if (item.status) {
item.status = lowerCase(item.status);
}
return item;
});
}
return response;
}
const apiResponse = {
success: true,
data: [
{ id: 1, email: "USER@EXAMPLE.COM", username: "JOHNDOE", status: "ACTIVE" },
{
id: 2,
email: "ADMIN@COMPANY.ORG",
username: "ADMIN",
status: "INACTIVE",
},
],
};
console.log(normalizeApiResponse(apiResponse));
// {
// success: true,
// data: [
// { id: 1, email: "user@example.com", username: "johndoe", status: "active" },
// { id: 2, email: "admin@company.org", username: "admin", status: "inactive" }
// ]
// }
π API Reference
lowerCase(input)
Converts a string to lowercase format.
Parameters
input
(string
): The string to transform
Returns
string
: The string converted to lowercase
π Bundle Size
This package is optimized for minimal bundle size:
- Minified: ~200B
- Gzipped: ~150B
- 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-upper-case
- Convert to UPPERCASEtext-lower-case-first
- Make first character lowercasetext-sentence-case
- Convert to Sentence casetext-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