New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

use-title-case

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-title-case

A React hook to properly capitalize titles using Vercel's title library

latest
Source
npmnpm
Version
0.1.5
Version published
Maintainers
1
Created
Source

useTitleCase()


Quality

npm

React Title Case is a simple React Hook that provides a callback for Vercel's title library, which correctly capitalizes strings as per The Chicago Manual of Style.

Installation

# Using pnpm
pnpm add use-title-case

# Using yarn
yarn add use-title-case

# Using npm
npm install use-title-case

Usage

Hook

import { useTitleCase } from "use-title-case";

export const YourSnazzyComponent = () => {
  const title = useTitleCase();

  return (
    <div>
      <h1>{title("i Am An INCorrectly capitAlized TITLE")}</h1>
    </div>
  );
};
// The <h1/ > element's text will be rendered as "I am an Incorrectly Capitalized Title"

Component

import { TitleCase } from "use-title-case";

export const YourSnazzyComponent = () => {
  return (
    <div>
      <h1>
        <TitleCase>i Am An INCorrectly capitAlized TITLE</TitleCase>
      </h1>
    </div>
  );
};
// The <h1/ > element's text will be rendered as "I am an Incorrectly Capitalized Title"

Overrides

React Title Case comes with some (primarily networking/infrastructure-focused) built-in overrides. However, you can add override strings in multiple ways, as needed:

Per-Hook

import { useTitleCase } from "use-title-case";

export const YourSnazzyComponent = () => {
  const title = useTitleCase({ overrides: ["TITLE"] });

  return (
    <div>
      <h1>{title("i Am An INCorrectly capitAlized TITLE")}</h1>
    </div>
  );
};
// The <h1/ > element's text will be rendered as "I am an Incorrectly Capitalized TITLE"

Environment Variables

# As a comma-separated list:
export USER_OVERRIDES="INCorrectly,TITLE"

# As a JSON array:
export USER_OVERRIDES="[INCorrectly,TITLE]"

# This will also work:
export USER_OVERRIDES='["INCorrectly","TITLE"]'

Context Provider

import { TitleCaseProvider, useTitleCase } from "use-title-case";

export const YourSnazzyComponent = () => {
  const title = useTitleCase();

  return (
    <div>
      <h1>{title("i Am An INCorrectly capitAlized TITLE")}</h1>
    </div>
  );
};

export const App = () => {
  return (
    <TitleCaseProvider overrides={["INCorrectly", "TITLE"]}>
      <YourSnazzyComponent />
    </TitleCaseProvider>
  );
};
// The <h1/ > element's text will be rendered as "I am an INCorrectly Capitalized TITLE"

Options

PropertyTypeDefaultDescription
overridesstring[]See hereProvide an array of strings that should not be capitalized
useBuiltInsbooleantrueSet to false if you don't want to use the default overrides.

License

FAQs

Package last updated on 04 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts