npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

text-dot-case

v1.2.9

Published

Convert into a lower case text with a period between words

Readme

Dot Case

NPM version NPM downloads Bundle size License: MIT TypeScript

Transform text into dot.case format where words are lowercase and separated by dots.

🚀 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-dot-case

# yarn
yarn add text-dot-case

# pnpm
pnpm add text-dot-case

# bun
bun add text-dot-case

🎯 Quick Start

import { dotCase } from "text-dot-case";

console.log(dotCase("hello world")); // "hello.world"
console.log(dotCase("userProfileData")); // "user.profile.data"
console.log(dotCase("backgroundColor")); // "background.color"

📖 Usage

ES Modules (Recommended)

import { dotCase } from "text-dot-case";

console.log(dotCase("Hello World")); // "hello.world"

CommonJS

const { dotCase } = require("text-dot-case");

console.log(dotCase("Hello World")); // "hello.world"

TypeScript

import { dotCase, Options } from "text-dot-case";

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

🔄 Transformation Examples

Basic Transformations

import { dotCase } from "text-dot-case";

// From different cases
dotCase("Hello World"); // "hello.world"
dotCase("helloWorld"); // "hello.world"
dotCase("HelloWorld"); // "hello.world"
dotCase("hello_world"); // "hello.world"
dotCase("hello-world"); // "hello.world"
dotCase("HELLO_WORLD"); // "hello.world"
dotCase("CONSTANT_CASE"); // "constant.case"

// Complex examples
dotCase("XMLParser"); // "xml.parser"
dotCase("iPhone6Plus"); // "i.phone6.plus"
dotCase("HTML5Canvas"); // "html5.canvas"
dotCase("getUserID"); // "get.user.id"

Advanced Options

import { dotCase } from "text-dot-case";

// Custom word splitting
dotCase("XMLHttpRequest", {
  splitRegexp: /([a-z])([A-Z])/g,
}); // "xml.http.request"

// Custom character stripping
dotCase("[email protected]", {
  stripRegexp: /[@]/g,
}); // "hello.world.com"

// Custom transformation function
dotCase("API-v2-endpoint", {
  transform: (word, index) => {
    if (word === "API") return "api";
    if (word === "v2") return "v2";
    return word.toLowerCase();
  },
}); // "api.v2.endpoint"

🌍 Real-World Examples

Object Property Names

import { dotCase } from "text-dot-case";

// API response normalization
const apiResponse = {
  "First Name": "John",
  Last_Name: "Doe",
  emailAddress: "[email protected]",
  phoneNumber: "+1234567890",
};

const normalized = Object.keys(apiResponse).reduce((acc, key) => {
  acc[dotCase(key)] = apiResponse[key];
  return acc;
}, {});

console.log(normalized);
// {
//   "first.name": "John",
//   "last.name": "Doe",
//   "email.address": "[email protected]",
//   "phone.number": "+1234567890"
// }

Configuration Keys

import { dotCase } from "text-dot-case";

// Environment variables to config
dotCase("DATABASE_HOST"); // "database.host"
dotCase("apiSecretKey"); // "api.secret.key"
dotCase("maxRetryAttempts"); // "max.retry.attempts"
dotCase("REDIS_CONNECTION"); // "redis.connection"
dotCase("jwtTokenExpiry"); // "jwt.token.expiry"

File and Module Names

import { dotCase } from "text-dot-case";

// Component naming
dotCase("UserProfile"); // "user.profile"
dotCase("ShoppingCart"); // "shopping.cart"
dotCase("PaymentGateway"); // "payment.gateway"
dotCase("AuthMiddleware"); // "auth.middleware"
dotCase("EmailValidator"); // "email.validator"

Method and Function Names

import { dotCase } from "text-dot-case";

// Class methods to dot notation
dotCase("getUserById"); // "get.user.by.id"
dotCase("calculateTotalPrice"); // "calculate.total.price"
dotCase("validateEmailAddress"); // "validate.email.address"
dotCase("processPaymentData"); // "process.payment.data"
dotCase("generateAccessToken"); // "generate.access.token"

Database and Schema Mapping

import { dotCase } from "text-dot-case";

// Transform form data for nested objects
function normalizeFormData(formData) {
  const normalized = {};

  for (const [key, value] of Object.entries(formData)) {
    normalized[dotCase(key)] = value;
  }

  return normalized;
}

const form = {
  firstName: "John",
  lastName: "Doe",
  emailAddress: "[email protected]",
  billingAddress: "123 Main St",
  shippingAddress: "456 Oak Ave",
};

console.log(normalizeFormData(form));
// {
//   "first.name": "John",
//   "last.name": "Doe",
//   "email.address": "[email protected]",
//   "billing.address": "123 Main St",
//   "shipping.address": "456 Oak Ave"
// }

Constants and Enums

import { dotCase } from "text-dot-case";

// Transform constants
dotCase("MAX_FILE_SIZE"); // "max.file.size"
dotCase("DEFAULT_TIMEOUT"); // "default.timeout"
dotCase("ERROR_MESSAGES"); // "error.messages"
dotCase("HTTP_STATUS_CODES"); // "http.status.codes"
dotCase("VALIDATION_RULES"); // "validation.rules"

📖 API Reference

dotCase(input, options?)

Converts a string to dot.case.

Parameters

  • input (string): The string to convert
  • options (Options, optional): Configuration options

Returns

  • string: The dot.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 { dotCase } from "text-dot-case";

// Split on specific patterns
dotCase("XMLHttpRequest", {
  splitRegexp: /([a-z])([A-Z])/g,
}); // "xml.http.request"

// Split on numbers
dotCase("user123data", {
  splitRegexp: /([a-zA-Z])(\d)/g,
}); // "user.123.data"

Custom Character Stripping

import { dotCase } from "text-dot-case";

// Strip specific characters
dotCase("[email protected]", {
  stripRegexp: /[@]/g,
}); // "hello.world.com"

// Strip all non-alphanumeric except dots
dotCase("hello!@#world", {
  stripRegexp: /[^a-zA-Z0-9.]/g,
}); // "hello.world"

Custom Transform Functions

import { dotCase } from "text-dot-case";

// Preserve specific formatting
dotCase("XML-HTTP-Request", {
  transform: (word, index) => {
    const acronyms = ["xml", "http", "api", "url"];
    if (acronyms.includes(word.toLowerCase())) {
      return word.toLowerCase();
    }
    return word.toLowerCase();
  },
}); // "xml.http.request"

// Custom business logic
dotCase("UserV2API", {
  transform: (word, index) => {
    if (word === "V2") return "v2";
    if (word === "API") return "api";
    return word.toLowerCase();
  },
}); // "user.v2.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

📜 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