JSPM

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

Convert strings between different variable naming formats

Package Exports

  • varname

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 (varname) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Varname

Convert strings between different variable naming formats.

Current Version: 1.0.2
Build Status: Build Status
Node Support: 0.6, 0.8, 0.10.0
Browser Support: Android Browser 2.2–4.2, Firefox 3.6, Firefox 4–17, Google Chrome 14–25, Internet Explorer 6–10, Mobile Safari iOS 3–6, Opera 12.10, Safari 5–6

Getting Started

You can use Varname on the server side with Node.js and npm:

$ npm install varname

On the client side, you can either install Varname through Component:

$ component install rowanmanning/varname

or by simply including varname.js in your page:

<script src="path/to/lib/varname.js"></script>

Usage

In Node.js or using Component, you can include Varname in your script by using require:

var varname = require('varname');

Varname also works with AMD-style module loaders, just specify it as a dependency.

If you're just including with a <script>, varname is available as a global variable.

varname.camelback( str )

Convert a variable name to camelBack format (capitalize the first letter of all but the first word).
str: (string) The string to convert.
return: (string) Returns the converted string.

varname.camelback('foo_bar_baz'); // 'fooBarBaz'

varname.camelcase( str )

Convert a variable name to CamelCase format (capitalize the first letter of each word).
str: (string) The string to convert.
return: (string) Returns the converted string.

varname.camelcase('foo_bar_baz'); // 'FooBarBaz'

varname.dash( str )

Convert a variable name to dash format.
str: (string) The string to convert.
return: (string) Returns the converted string.

varname.dash('FooBarBaz'); // 'foo-bar-baz'

varname.underscore( str )

Convert a variable name to underscore format.
str: (string) The string to convert.
return: (string) Returns the converted string.

varname.underscore('FooBarBaz'); // 'foo_bar_baz'

varname.split( str )

Split a string into separate variable parts. This allows you to write your own format converters easily. str: (string) The string to split.
return: (array) Returns an array of parts.

varname.split('fooBarBaz');
varname.split('FooBarBaz');
varname.split('foo-bar-baz');
varname.split('foo_bar_baz');
varname.split('♥~foo|bar|baz~♥');
// all return ['foo', 'bar', 'baz']

Development

To develop Varname, you'll need to clone the repo and install dependencies with make deps. If you're on Windows, you'll also need to install Make for Windows.

Once you're set up, you can run the following commands:

$ make deps         # Install dependencies
$ make lint         # Run JSHint with the correct config
$ make test         # Run unit tests in Node
$ make test-server  # Run a server for browser unit testing (visit localhost:3000)

When no build target is specified, make will run deps lint test. This means you can use the following command for brevity:

$ make

Code with lint errors or no/failing tests will not be accepted, please use the build tools outlined above.

License

Varname is licensed under the MIT license.