main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
504 bytes
|
Line | |
---|
1 | /*!
|
---|
2 | * toidentifier
|
---|
3 | * Copyright(c) 2016 Douglas Christopher Wilson
|
---|
4 | * MIT Licensed
|
---|
5 | */
|
---|
6 |
|
---|
7 | 'use strict'
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Module exports.
|
---|
11 | * @public
|
---|
12 | */
|
---|
13 |
|
---|
14 | module.exports = toIdentifier
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Trasform the given string into a JavaScript identifier
|
---|
18 | *
|
---|
19 | * @param {string} str
|
---|
20 | * @returns {string}
|
---|
21 | * @public
|
---|
22 | */
|
---|
23 |
|
---|
24 | function toIdentifier (str) {
|
---|
25 | return str
|
---|
26 | .split(' ')
|
---|
27 | .map(function (token) {
|
---|
28 | return token.slice(0, 1).toUpperCase() + token.slice(1)
|
---|
29 | })
|
---|
30 | .join('')
|
---|
31 | .replace(/[^ _0-9a-z]/gi, '')
|
---|
32 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.