Skip to the content.

Lower Case First

NPM version NPM downloads Bundle size License: MIT TypeScript

Transform text by making the first character lowercase while preserving the rest.

πŸš€ Features

πŸ“¦ Installation

# npm
npm install text-lower-case-first

# yarn
yarn add text-lower-case-first

# pnpm
pnpm add text-lower-case-first

# bun
bun add text-lower-case-first

🎯 Quick Start

import { lowerCaseFirst } from "text-lower-case-first";

console.log(lowerCaseFirst("Hello World")); // "hello World"
console.log(lowerCaseFirst("HELLO WORLD")); // "hELLO WORLD"
console.log(lowerCaseFirst("CamelCase")); // "camelCase"

πŸ“– Usage

import { lowerCaseFirst } from "text-lower-case-first";

console.log(lowerCaseFirst("Hello")); // "hello"

CommonJS

const { lowerCaseFirst } = require("text-lower-case-first");

console.log(lowerCaseFirst("Hello")); // "hello"

TypeScript

import { lowerCaseFirst } from "text-lower-case-first";

const result: string = lowerCaseFirst("Hello World");
console.log(result); // "hello World"

πŸ”„ Transformation Examples

Basic Transformations

import { lowerCaseFirst } from "text-lower-case-first";

// Simple cases
lowerCaseFirst("Hello"); // "hello"
lowerCaseFirst("hello"); // "hello"
lowerCaseFirst("HELLO"); // "hELLO"

// Multiple words
lowerCaseFirst("Hello World"); // "hello World"
lowerCaseFirst("HELLO WORLD"); // "hELLO WORLD"
lowerCaseFirst("hello world"); // "hello world"

// Programming cases
lowerCaseFirst("CamelCase"); // "camelCase"
lowerCaseFirst("PascalCase"); // "pascalCase"
lowerCaseFirst("Snake_case"); // "snake_case"
lowerCaseFirst("Kebab-case"); // "kebab-case"

Edge Cases

import { lowerCaseFirst } from "text-lower-case-first";

// Empty and single character
lowerCaseFirst(""); // ""
lowerCaseFirst("A"); // "a"
lowerCaseFirst("a"); // "a"

// Numbers and symbols
lowerCaseFirst("123hello"); // "123hello"
lowerCaseFirst("@Hello"); // "@Hello"
lowerCaseFirst("Hello123"); // "hello123"

// Unicode characters
lowerCaseFirst("Γ‘ice"); // "Γ±ice"
lowerCaseFirst("Über"); // "über"
lowerCaseFirst("CafΓ©"); // "cafΓ©"

🌍 Real-World Examples

Variable Name Conversion

import { lowerCaseFirst } from "text-lower-case-first";

// Convert PascalCase to camelCase
lowerCaseFirst("UserProfile"); // "userProfile"
lowerCaseFirst("DatabaseConnection"); // "databaseConnection"
lowerCaseFirst("ApiResponse"); // "apiResponse"
lowerCaseFirst("HttpClient"); // "httpClient"

JSON Property Processing

import { lowerCaseFirst } from "text-lower-case-first";

function convertObjectKeys(obj) {
  const converted = {};

  for (const [key, value] of Object.entries(obj)) {
    const newKey = lowerCaseFirst(key);
    converted[newKey] =
      typeof value === "object" && value !== null
        ? convertObjectKeys(value)
        : value;
  }

  return converted;
}

const apiResponse = {
  UserName: "john_doe",
  EmailAddress: "john@example.com",
  ProfileData: {
    FirstName: "John",
    LastName: "Doe",
    PhoneNumber: "123-456-7890",
  },
};

console.log(convertObjectKeys(apiResponse));
// {
//   userName: "john_doe",
//   emailAddress: "john@example.com",
//   profileData: {
//     firstName: "John",
//     lastName: "Doe",
//     phoneNumber: "123-456-7890"
//   }
// }

Class Method Generation

import { lowerCaseFirst } from "text-lower-case-first";

function createGetter(propertyName) {
  const methodName = `get${propertyName}`;
  return lowerCaseFirst(methodName);
}

function createSetter(propertyName) {
  const methodName = `set${propertyName}`;
  return lowerCaseFirst(methodName);
}

console.log(createGetter("UserName")); // "getUserName"
console.log(createSetter("EmailAddress")); // "setEmailAddress"
console.log(createGetter("IsActive")); // "getIsActive"

Form Field Processing

import { lowerCaseFirst } from "text-lower-case-first";

function processFormFields(fields) {
  const processed = {};

  fields.forEach((field) => {
    // Convert field names to camelCase
    const fieldName = lowerCaseFirst(field.Name || field.name);
    processed[fieldName] = {
      value: field.Value || field.value || "",
      required: field.Required || field.required || false,
      type: field.Type || field.type || "text",
    };
  });

  return processed;
}

const formFields = [
  { Name: "FirstName", Value: "John", Required: true, Type: "text" },
  { Name: "LastName", Value: "Doe", Required: true, Type: "text" },
  { Name: "EmailAddress", Value: "", Required: true, Type: "email" },
];

console.log(processFormFields(formFields));
// {
//   firstName: { value: "John", required: true, type: "text" },
//   lastName: { value: "Doe", required: true, type: "text" },
//   emailAddress: { value: "", required: true, type: "email" }
// }

API Response Normalization

import { lowerCaseFirst } from "text-lower-case-first";

function normalizeApiResponse(response) {
  if (Array.isArray(response)) {
    return response.map(normalizeApiResponse);
  }

  if (typeof response === "object" && response !== null) {
    const normalized = {};

    for (const [key, value] of Object.entries(response)) {
      const normalizedKey = lowerCaseFirst(key);
      normalized[normalizedKey] = normalizeApiResponse(value);
    }

    return normalized;
  }

  return response;
}

const apiData = {
  UserId: 123,
  UserName: "john_doe",
  ProfileInfo: {
    FirstName: "John",
    LastName: "Doe",
    ContactDetails: {
      EmailAddress: "john@example.com",
      PhoneNumber: "123-456-7890",
    },
  },
  Preferences: [
    { SettingName: "theme", SettingValue: "dark" },
    { SettingName: "language", SettingValue: "en" },
  ],
};

console.log(normalizeApiResponse(apiData));
// {
//   userId: 123,
//   userName: "john_doe",
//   profileInfo: {
//     firstName: "John",
//     lastName: "Doe",
//     contactDetails: {
//       emailAddress: "john@example.com",
//       phoneNumber: "123-456-7890"
//     }
//   },
//   preferences: [
//     { settingName: "theme", settingValue: "dark" },
//     { settingName: "language", settingValue: "en" }
//   ]
// }

Code Generation

import { lowerCaseFirst } from "text-lower-case-first";

class CodeGenerator {
  generateProperty(name, type = "string") {
    const propertyName = lowerCaseFirst(name);
    return `private ${propertyName}: ${type};`;
  }

  generateGetter(name, type = "string") {
    const propertyName = lowerCaseFirst(name);
    const methodName = `get${name}`;
    return `public ${lowerCaseFirst(methodName)}(): ${type} {
      return this.${propertyName};
    }`;
  }

  generateSetter(name, type = "string") {
    const propertyName = lowerCaseFirst(name);
    const methodName = `set${name}`;
    const paramName = lowerCaseFirst(name);
    return `public ${lowerCaseFirst(methodName)}(${paramName}: ${type}): void {
      this.${propertyName} = ${paramName};
    }`;
  }
}

const generator = new CodeGenerator();
console.log(generator.generateProperty("UserName"));
// "private userName: string;"

console.log(generator.generateGetter("UserName"));
// "public getUserName(): string {
//   return this.userName;
// }"

Configuration Processing

import { lowerCaseFirst } from "text-lower-case-first";

function processConfiguration(config) {
  const processed = {};

  for (const [section, settings] of Object.entries(config)) {
    const sectionName = lowerCaseFirst(section);
    processed[sectionName] = {};

    for (const [key, value] of Object.entries(settings)) {
      const settingName = lowerCaseFirst(key);
      processed[sectionName][settingName] = value;
    }
  }

  return processed;
}

const appConfig = {
  DatabaseSettings: {
    ConnectionString: "localhost:5432",
    MaxConnections: 100,
    TimeoutSeconds: 30,
  },
  ApiSettings: {
    BaseUrl: "https://api.example.com",
    ApiKey: "secret-key",
    RateLimitPerMinute: 1000,
  },
};

console.log(processConfiguration(appConfig));
// {
//   databaseSettings: {
//     connectionString: "localhost:5432",
//     maxConnections: 100,
//     timeoutSeconds: 30
//   },
//   apiSettings: {
//     baseUrl: "https://api.example.com",
//     apiKey: "secret-key",
//     rateLimitPerMinute: 1000
//   }
// }

πŸ“– API Reference

lowerCaseFirst(input)

Makes the first character of a string lowercase while preserving the rest.

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