UNPKG

5.58 kBMarkdownView Raw
1stringcase
2==========
3
4<!-- Badge Start -->
5<a name="badges"></a>
6
7[![Build Status][bd_travis_shield_url]][bd_travis_url]
8[![Code Climate][bd_codeclimate_shield_url]][bd_codeclimate_url]
9[![Code Coverage][bd_codeclimate_coverage_shield_url]][bd_codeclimate_url]
10[![npm Version][bd_npm_shield_url]][bd_npm_url]
11
12[bd_repo_url]: https://github.com/okunishinishi/node-stringcase
13[bd_travis_url]: http://travis-ci.org/okunishinishi/node-stringcase
14[bd_travis_shield_url]: http://img.shields.io/travis/okunishinishi/node-stringcase.svg?style=flat
15[bd_license_url]: https://github.com/okunishinishi/node-stringcase/blob/master/LICENSE
16[bd_codeclimate_url]: http://codeclimate.com/github/okunishinishi/node-stringcase
17[bd_codeclimate_shield_url]: http://img.shields.io/codeclimate/github/okunishinishi/node-stringcase.svg?style=flat
18[bd_codeclimate_coverage_shield_url]: http://img.shields.io/codeclimate/coverage/github/okunishinishi/node-stringcase.svg?style=flat
19[bd_gemnasium_url]: https://gemnasium.com/okunishinishi/node-stringcase
20[bd_gemnasium_shield_url]: https://gemnasium.com/okunishinishi/node-stringcase.svg
21[bd_npm_url]: http://www.npmjs.org/package/stringcase
22[bd_npm_shield_url]: http://img.shields.io/npm/v/stringcase.svg?style=flat
23
24<!-- Badge End -->
25
26
27<!-- Description Start -->
28<a name="description"></a>
29
30Convert string cases between camel case, pascal case, snake case etc...
31
32<!-- Description End -->
33
34
35
36<!-- Sections Start -->
37<a name="sections"></a>
38
39Installation
40-----
41
42```bash
43npm install stringcase --save
44```
45
46Usage
47-------
48
49```Javascript
50var stringcase = require('stringcase');
51
52//------------------------
53// Convert to camelcase
54//------------------------
55stringcase.camelcase('foo_bar'); // => "fooBar"
56stringcase.camelcase('FOO_BAR'); // => "fooBar"
57stringcase.camelcase('fooBar'); // => "fooBar"
58stringcase.camelcase('FooBar'); // => "fooBar"
59
60
61//------------------------
62// Convert to capitalcase
63//------------------------
64stringcase.capitalcase('foo_bar'); // => "Foo_bar"
65stringcase.capitalcase('FOO_BAR'); // => "FOO_BAR"
66stringcase.capitalcase('fooBar'); // => "FooBar"
67stringcase.capitalcase('FooBar'); // => "FooBar"
68
69
70//------------------------
71// Convert to constcase
72//------------------------
73stringcase.constcase('foo_bar'); // => "FOO_BAR"
74stringcase.constcase('FOO_BAR'); // => "FOO_BAR"
75stringcase.constcase('fooBar'); // => "FOO_BAR"
76stringcase.constcase('FooBar'); // => "FOO_BAR"
77
78
79//------------------------
80// Convert to decapitalcase
81//------------------------
82stringcase.decapitalcase('foo_bar'); // => "foo_bar"
83stringcase.decapitalcase('FOO_BAR'); // => "fOO_BAR"
84stringcase.decapitalcase('fooBar'); // => "fooBar"
85stringcase.decapitalcase('FooBar'); // => "fooBar"
86
87
88//------------------------
89// Convert to lowercase
90//------------------------
91stringcase.lowercase('foo_bar'); // => "foo_bar"
92stringcase.lowercase('FOO_BAR'); // => "foo_bar"
93stringcase.lowercase('fooBar'); // => "foobar"
94stringcase.lowercase('FooBar'); // => "foobar"
95
96
97//------------------------
98// Convert to pascalcase
99//------------------------
100stringcase.pascalcase('foo_bar'); // => "FooBar"
101stringcase.pascalcase('FOO_BAR'); // => "FooBar"
102stringcase.pascalcase('fooBar'); // => "FooBar"
103stringcase.pascalcase('FooBar'); // => "FooBar"
104
105
106//------------------------
107// Convert to pathcase
108//------------------------
109stringcase.pathcase('foo_bar'); // => "foo/bar"
110stringcase.pathcase('FOO_BAR'); // => "foo/bar"
111stringcase.pathcase('fooBar'); // => "foo/bar"
112stringcase.pathcase('FooBar'); // => "foo/bar"
113
114
115//------------------------
116// Convert to sentencecase
117//------------------------
118stringcase.sentencecase('foo_bar'); // => "Foo bar"
119stringcase.sentencecase('FOO_BAR'); // => "Foo bar"
120stringcase.sentencecase('fooBar'); // => "Foo bar"
121stringcase.sentencecase('FooBar'); // => "Foo bar"
122
123
124//------------------------
125// Convert to snakecase
126//------------------------
127stringcase.snakecase('foo_bar'); // => "foo_bar"
128stringcase.snakecase('FOO_BAR'); // => "foo_bar"
129stringcase.snakecase('fooBar'); // => "foo_bar"
130stringcase.snakecase('FooBar'); // => "foo_bar"
131
132
133//------------------------
134// Convert to spinalcase
135//------------------------
136stringcase.spinalcase('foo_bar'); // => "foo-bar"
137stringcase.spinalcase('FOO_BAR'); // => "foo-bar"
138stringcase.spinalcase('fooBar'); // => "foo-bar"
139stringcase.spinalcase('FooBar'); // => "foo-bar"
140
141
142//------------------------
143// Convert to titlecase
144//------------------------
145stringcase.titlecase('foo_bar'); // => "Foo Bar"
146stringcase.titlecase('FOO_BAR'); // => "Foo Bar"
147stringcase.titlecase('fooBar'); // => "Foo Bar"
148stringcase.titlecase('FooBar'); // => "Foo Bar"
149
150
151//------------------------
152// Convert to trimcase
153//------------------------
154stringcase.trimcase('foo_bar'); // => "foo_bar"
155stringcase.trimcase('FOO_BAR'); // => "FOO_BAR"
156stringcase.trimcase('fooBar'); // => "fooBar"
157stringcase.trimcase('FooBar'); // => "FooBar"
158
159
160//------------------------
161// Convert to uppercase
162//------------------------
163stringcase.uppercase('foo_bar'); // => "FOO_BAR"
164stringcase.uppercase('FOO_BAR'); // => "FOO_BAR"
165stringcase.uppercase('fooBar'); // => "FOOBAR"
166stringcase.uppercase('FooBar'); // => "FOOBAR"
167
168
169
170```
171
172Fore more detail, see [API Guide of stringcase functions](http://okunishinishi.github.io/node-stringcase/apiguide/module-stringcase_lib.html).
173
174
175
176<!-- Sections Start -->
177
178
179<!-- LICENSE Start -->
180<a name="license"></a>
181
182License
183-------
184This software is released under the [MIT License](https://github.com/okunishinishi/node-stringcase/blob/master/LICENSE).
185
186<!-- LICENSE End -->
187
188