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