index.js
 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  }