JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5675
  • Score
    100M100P100Q137605F
  • License ISC

Adds a comprehensive Camel-Case (and Pascal-Case) converter to the String's prototype

Package Exports

  • @dfoverdx/tocamelcase

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@dfoverdx/tocamelcase) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

toCamelCase

A simple JavaScript script that adds a comprehensive toCamelCase function to String.prototype. toCamelCase() includes an optional boolean parameter to output PascalCase instead of CamelCase.

This "pollutes" the String prototype which may or may not be an issue for you. It will not, however, overwrite String.prototype.toCamelCase if it is already defined.

If performance is an issue and you're running this over millions of strings, there are probably faster modules out there. This one uses three Regex passes over the string. For the majority of cases, however, this is not an issue.

Installation

For NPM:

npm install @dfoverdx/tocamelcase

Without NPM:

  1. Download /dist/index.min.js from this repository and name it something like tocamelcase.min.js

  2. Place it somewhere your webpage can access (e.g. /scripts/)

  3. Add it to your HTML file

    <body>
        <!-- ... -->
        <script src="/scripts/tocamelcase.min.js" type="text/javascript"></script>
        <!-- scripts that use .toCamelCase() -->
    </body>

Usage

ES5

require('@dfoverdx/tocamelcase');

console.log('This is camel-case'.toCamelCase()); // outputs: 'thisIsCamelCase'
console.log('This is pascal-case'.toCamelCase(true)); // outputs 'ThisIsPascalCase'

ES6

import '@dfoverdx/tocamelcase';

console.log('This is camel-case'.toCamelCase()); // outputs: 'thisIsCamelCase'
console.log('This is pascal-case'.toCamelCase(true)); // outputs 'ThisIsPascalCase'