Skip to the content.

Lower Case

NPM version NPM downloads Bundle size License: MIT TypeScript

Transform text to lowercase format - all characters converted to lowercase.

πŸš€ Features

πŸ“¦ 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

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

Returns

πŸ“Š Bundle Size

This package is optimized for minimal bundle size:

🌍 Browser Support

πŸ§ͺ 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

πŸ“œ License

MIT Β© Dmitry Selikhov

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ†˜ Support


Made with ❀️ by Dmitry Selikhov