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 🙏

© 2024 – Pkg Stats / Ryan Hefner

naming-style

v1.0.1

Published

One lightly library contains a series of methods for converting one string or text to different kind of naming style, such as camelCase, PascalCase, hyphen-case, CONSTANT_CASE, etc.

Downloads

5,635

Readme

naming-style

npm npm npm

中文

One lightly library contains a series of methods for converting one string or text to different kind of naming style, such as camelCase, PascalCase, hyphen-case, CONSTANT_CASE, etc.

Install

yarn add naming-style

or

npm i naming-style

Quick Start

import {
  style,
  camel,
  pascal,
  hyphen,
  constant,
  snake,
  underscore,
  setence,
} from 'naming-style';

style('iAm24YearsOld'); // Detect naming style of 'iAm24YearsOld'
// Output: 'camel'

style('--naming-style -loves you'); // Detect naming style of '--naming-style -loves you'
// Output: 'other'

camel('--naming-style -loves you'); // Convert to camel case
// Output: 'namingStyleLovesYou'

pascal('--naming-style -loves you'); // Convert to pascal case
// Output: 'NamingStyleLovesYou'

hyphen('--naming-style -loves you'); // Convert to hyphen case
// Output: 'naming-style-loves-you'

constant('--naming-style -loves you'); // Convert to constant case
// Output: 'NAMING_STYLE_LOVES_YOU'

snake('--naming-style -loves you'); // Convert to snake case
// Output: 'naming_style_loves_you'

sentence('--naming-style -loves you'); // Convert to sentence case
// Output: 'Naming-style loves you'

underscore('--naming-style -loves you'); // Convert to underscore case
// Output: '__naming_style__loves_you'

Features

1. Methods

  • This library provides 8 methods you can use:

    • style() is used to detect the naming-style of the input.
    • other 7 methods are used to convert the input to several naming styles.

2. Available styles for converting to

  • This library provides 7 naming styles you can convert to, including camel, pascal, hyphen, constant, snake, sentence and underscore.

  • The first 6 styles are the basic styles, which the last one underscore is derived from them.

Example:

camel       -->  'iAm24YearsOld'
pascal      -->  'IAm24YearsOld'
hyphen      -->  'i-am-24-years-old'
constant    -->  'I_AM_24_YEARS_OLD'
snake       -->  'i_am_24_years_old'
sentence    -->  'I am 24 years old'
underscore  -->  'i_am_24_years_old'

3. Basic methods are reversible by each other

  • If the input belongs to the basic styles, you can use corresponding methods of them to convert your text reversibly.

Example:

import { style, camel, snake } from 'naming-style';

const origin = 'i_am_24_years_old';

const namingStyle = style(origin);
console.log(namingStyle);
// 'snake'

const camelCase = camel(origin);
const snake_case = snake(camelCase);
const newCamelCase = camel(snake_case);

console.log(camelCase === newCamelCase);
// true

4. Other regular input

  • If the naming style of the input does not belong to any style from library, the result returned by the style method is 'other'.

Example:

import { style } from 'naming-style';

style('--naming-style -loves you');
// Output: 'other'