Skip to the content.

No Case

NPM version NPM downloads Bundle size License: MIT TypeScript

Transform text into no case format where words are lowercase and separated by spaces.

๐Ÿš€ Features

๐Ÿ“ฆ Installation

# npm
npm install text-no-case

# yarn
yarn add text-no-case

# pnpm
pnpm add text-no-case

# bun
bun add text-no-case

๐ŸŽฏ Quick Start

import { noCase } from "text-no-case";

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

๐Ÿ“– Usage

import { noCase } from "text-no-case";

console.log(noCase("hello world")); // "hello world"

CommonJS

const { noCase } = require("text-no-case");

console.log(noCase("hello world")); // "hello world"

TypeScript

import { noCase, Options } from "text-no-case";

const result: string = noCase("hello world");
console.log(result); // "hello world"

๐Ÿ”„ Transformation Examples

Basic Transformations

import { noCase } from "text-no-case";

// From different cases
noCase("hello world"); // "hello world"
noCase("Hello World"); // "hello world"
noCase("HELLO WORLD"); // "hello world"
noCase("camelCase"); // "camel case"
noCase("PascalCase"); // "pascal case"
noCase("snake_case"); // "snake case"
noCase("kebab-case"); // "kebab case"
noCase("dot.case"); // "dot case"

// Complex examples
noCase("XMLHttpRequest"); // "xml http request"
noCase("iPhone"); // "i phone"
noCase("version 1.2.3"); // "version 1 2 3"
noCase("userProfileData"); // "user profile data"

Advanced Options

import { noCase } from "text-no-case";

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

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

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

๐ŸŒ Real-World Examples

Search Query Processing

import { noCase } from "text-no-case";

// Normalize search queries
noCase("JavaScript"); // "java script"
noCase("ReactJS"); // "react js"
noCase("Node.js"); // "node js"
noCase("TypeScript"); // "type script"
noCase("MongoDB"); // "mongo db"

Content Processing

import { noCase } from "text-no-case";

// Process content for readability
noCase("userManagement"); // "user management"
noCase("dataVisualization"); // "data visualization"
noCase("apiIntegration"); // "api integration"
noCase("errorHandling"); // "error handling"
noCase("performanceOptimization"); // "performance optimization"

Tag Processing

import { noCase } from "text-no-case";

// Convert tags to readable format
const tags = [
  "webDevelopment",
  "machineLearning",
  "dataScience",
  "userExperience",
  "projectManagement",
];

const readableTags = tags.map(noCase);
console.log(readableTags);
// [
//   "web development",
//   "machine learning",
//   "data science",
//   "user experience",
//   "project management"
// ]

Form Label Generation

import { noCase } from "text-no-case";

function generateFormLabel(fieldName) {
  return noCase(fieldName)
    .split(" ")
    .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
    .join(" ");
}

console.log(generateFormLabel("firstName")); // "First Name"
console.log(generateFormLabel("emailAddress")); // "Email Address"
console.log(generateFormLabel("phoneNumber")); // "Phone Number"

URL Slug Preparation

import { noCase } from "text-no-case";

function prepareSlug(title) {
  return noCase(title)
    .replace(/\s+/g, "-")
    .replace(/[^a-z0-9-]/g, "");
}

console.log(prepareSlug("Hello World!")); // "hello-world"
console.log(prepareSlug("JavaScript Tips & Tricks")); // "java-script-tips-tricks"

Text Analysis

import { noCase } from "text-no-case";

function analyzeText(text) {
  const normalized = noCase(text);
  const words = normalized.split(" ").filter((word) => word.length > 0);

  return {
    wordCount: words.length,
    uniqueWords: [...new Set(words)].length,
    averageWordLength:
      words.reduce((sum, word) => sum + word.length, 0) / words.length,
  };
}

console.log(analyzeText("userProfileData"));
// { wordCount: 3, uniqueWords: 3, averageWordLength: 4.67 }

Content Normalization

import { noCase } from "text-no-case";

function normalizeContent(content) {
  return content
    .split("\n")
    .map((line) => line.trim())
    .filter((line) => line.length > 0)
    .map((line) => noCase(line))
    .join(" ");
}

const content = `
  userManagement
  dataVisualization
  apiIntegration
`;

console.log(normalizeContent(content));
// "user management data visualization api integration"

Keyword Extraction

import { noCase } from "text-no-case";

function extractKeywords(text, minLength = 3) {
  const normalized = noCase(text);
  const words = normalized.split(" ");

  return words
    .filter((word) => word.length >= minLength)
    .filter((word, index, arr) => arr.indexOf(word) === index)
    .sort();
}

console.log(extractKeywords("userProfileDataManagement"));
// ["data", "management", "profile", "user"]

๐Ÿ“– API Reference

noCase(input, options?)

Converts a string to no case format.

Parameters

Returns

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 { noCase } from "text-no-case";

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

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

Custom Character Stripping

import { noCase } from "text-no-case";

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

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

Custom Transform Functions

import { noCase } from "text-no-case";

// Preserve certain words
noCase("xml-http-request", {
  transform: (word, index) => {
    const preserveWords = ["xml", "http", "api", "url"];
    if (preserveWords.includes(word.toLowerCase())) {
      return word.toLowerCase();
    }
    return word.toLowerCase();
  },
}); // "xml http request"

// Custom business logic
noCase("user-v2-api", {
  transform: (word, index) => {
    if (word === "v2") return "version 2";
    if (word === "api") return "api";
    return word.toLowerCase();
  },
}); // "user version 2 api"

๐Ÿ“Š 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