$ cnpm install varname
Convert strings between different variable naming formats.
You can use Varname on the server side with Node.js and npm:
npm install varname
On the client side, you can include the built version of Varname in your page (found in build/varname.js):
<script src="varname.js"></script>
In Node.js you can include Varname in your script by using require:
var varname = require('varname');
If you're just including with a <script>, varname is available as a global variable.
Convert a variable name to camelBack format (capitalize the first letter of all but the first word).
name: (string) The variable name to convert.
return: (string) Returns the converted variable name.
varname.camelback('foo_bar_baz'); // 'fooBarBaz'
Convert a variable name to CamelCase format (capitalize the first letter of each word).
name: (string) The variable name to convert.
return: (string) Returns the converted variable name.
varname.camelcase('foo_bar_baz'); // 'FooBarBaz'
Convert a variable name to dash format.
name: (string) The variable name to convert.
return: (string) Returns the converted variable name.
varname.dash('FooBarBaz'); // 'foo-bar-baz'
Convert a variable name to underscore format.
name: (string) The variable name to convert.
return: (string) Returns the converted variable name.
varname.underscore('FooBarBaz'); // 'foo_bar_baz'
Split a string into separate variable parts. This allows you to write your own format converters easily.
name: (string) The variable name to split.
return: (array) Returns an array of parts.
varname.split('fooBarBaz');
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']
Varname is officially supported in the following browsers:
To contribute to Varname, clone this repo locally and commit your code on a separate branch.
If you're making core library changes please write unit tests for your code, and check that everything works by running the following before opening a pull-request:
make ci
Varname is licensed under the MIT license.
Copyright © 2015, Rowan Manning
Copyright 2013 - present © cnpmjs.org | Home |