or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lowercase-keys

Lowercase the keys of an object

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lowercase-keys@3.0.x

To install, run

npx @tessl/cli install tessl/npm-lowercase-keys@3.0.0

index.mddocs/

Lowercase Keys

Lowercase Keys is a utility function that creates a new object with all keys converted to lowercase while preserving the original values. It's designed as a lightweight, zero-dependency utility for data normalization and consistent key formatting.

Package Information

  • Package Name: lowercase-keys
  • Package Type: npm
  • Language: JavaScript (ES modules) with TypeScript definitions
  • Installation: npm install lowercase-keys

Core Imports

import lowercaseKeys from 'lowercase-keys';

Note: This package is ES modules only and requires Node.js 12.20.0+.

Basic Usage

import lowercaseKeys from 'lowercase-keys';

// Basic transformation
const result = lowercaseKeys({FOO: true, bAr: false});
console.log(result);
// => {foo: true, bar: false}

// With mixed case keys
const data = lowercaseKeys({
  UserName: 'alice',
  EMAIL_ADDRESS: 'alice@example.com',
  isActive: true
});
console.log(data);
// => {username: 'alice', email_address: 'alice@example.com', isactive: true}

Capabilities

Object Key Transformation

Converts all keys of an object to lowercase while preserving the original values and their types.

/**
 * Lowercase the keys of an object.
 * @param {Record<string, T>} object - The input object whose keys should be lowercased
 * @returns {Record<string, T>} A new object with the keys lowercased
 */
function lowercaseKeys<T>(object: Record<string, T>): Record<string, T>;

Parameters:

  • object (Record<string, T>): Input object with string keys and values of any type

Returns:

  • Record<string, T>: New object with all keys converted to lowercase, values unchanged

Behavior:

  • Creates a new object (does not modify the original)
  • Converts all keys to lowercase using JavaScript's String.toLowerCase()
  • Preserves all original values and their types exactly
  • Maintains object property order (ES2015+ environments)

Usage Examples:

// Simple object transformation
const config = lowercaseKeys({
  API_KEY: 'abc123',
  Database_URL: 'localhost:5432',
  debug: true
});
// => {api_key: 'abc123', database_url: 'localhost:5432', debug: true}

// Works with any value types
const mixed = lowercaseKeys({
  Count: 42,
  Items: ['a', 'b', 'c'],
  Settings: { enabled: true },
  Handler: function() { return 'hello'; }
});
// => {count: 42, items: ['a', 'b', 'c'], settings: { enabled: true }, handler: function() { return 'hello'; }}

// Empty object
const empty = lowercaseKeys({});
// => {}

TypeScript Support:

The function is fully typed with generic type preservation:

// Type is preserved through transformation
const typed: Record<string, number> = lowercaseKeys({FOO: 1, BAR: 2});
// typed has type Record<string, number>

// Works with interface types
interface User {
  name: string;
  age: number;
}

const users: Record<string, User> = lowercaseKeys({
  'USER_1': { name: 'Alice', age: 25 },
  'USER_2': { name: 'Bob', age: 30 }
});
// users has type Record<string, User>