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

@calmdownval/casey

v1.1.2

Published

case detector & convertor library

Downloads

5

Readme

Casey

This module uses the ES modules feature and requires Node v8.15.0+. Please refer to Node's documentation to read more on how to enable this functionality in your environment.

A case detection + conversion library.

Installation

npm i --save @calmdownval/casey

Usage

detect(phrase: string): Case | null

Detects case in the phrase and returns a value from the Case enum if successfully identified, returns null otherwise.

import { detect, Case } from '@calmdownval/casey';

if (detect('thisIsCamelCase') === Case.CAMEL) {
    // ...
}

is(phrase: string, case: Case): boolean

Returns a boolean indicating whether the phrase is in the provided case or not.

import { is, Case } from '@calmdownval/casey';

if (is('some-string', Case.KEBAB)) {
    // ...
}

convert(phrase: string, options: object | Case): string

Converts a phrase between cases. The options argument can be an object with the following options:

  • caseTo: Case - Required. The case to convert the phrase into.
  • caseFrom?: Case - If provided, phrase will be treated as a string in the specified case. If omitted the function will attempt to auto-detect the input case. This will throw when auto-detection fails.
  • acronyms?: string[] - Allows to preserve acronyms across cases (more info below).

You can also pass just a member of the Case enum instead of the options object. In such case the argument is treated as the caseTo option.

import { convert, Case } from '@calmdownval/casey';

// returns: 'some-phrase'
convert('SomePhrase', Case.KEBAB);

split(phrase: string, caseFrom?: Case): string[]

Splits a phrase into an array of words. This array is always lowercased. If the second argument is omitted the function will attempt to auto-detect the input case. This throw throw when auto-detection fails.

join(words: string[], caseTo: Case): string

Joins an array of words into a single phrase in the specified case.

Acronym Preservation

When converting between pascal- or camel-case and one of the dash or underscore delimited cases acronyms become a problem since usually acronyms are written in all-caps when using pascal- or camel-case but are written together when using the delimited cases.

import { convert, Case } from '@calmdownval/casey';

// 1) returns 'FftHelper'
convert('fft-helper', Case.PASCAL);

// 2) returns 'f-f-t-helper'
convert('FFTHelper', Case.KEBAB);

// 3) returns 'FFTHelper'
convert('fft-helper', {
    caseTo: Case.PASCAL,
    acronyms: [ 'fft' ]
});

// 4) returns 'fft-helper'
convert('FFTHelper', {
    caseTo: Case.KEBAB,
    acronyms: [ 'fft' ]
});

The problem is perhaps not very apparent in the first example, but notice we do lose information about 'FFT' being an acronym during the conversion. The second example better shows an undesirable output caused by an acronym. Examples 3) and 4) showcase the usage of the options object and its acronyms option to overcome this issue. Please note that all acronyms in this array MUST be lowercase for this to function properly.

Supported Cases

| Case | Example | |-------------------|--------------| | Case.CAMEL | camelCase | | Case.PASCAL | PascalCase | | Case.SNAKE | snake_case | | Case.SNAKE_CAPS | SNAKE_CAPS | | Case.KEBAB | kebab-case |