"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/camelcase/index.js" (11 Apr 2017, 1016 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict';
    2 
    3 function preserveCamelCase(str) {
    4     var isLastCharLower = false;
    5 
    6     for (var i = 0; i < str.length; i++) {
    7         var c = str.charAt(i);
    8 
    9         if (isLastCharLower && (/[a-zA-Z]/).test(c) && c.toUpperCase() === c) {
   10             str = str.substr(0, i) + '-' + str.substr(i);
   11             isLastCharLower = false;
   12             i++;
   13         } else {
   14             isLastCharLower = (c.toLowerCase() === c);
   15         }
   16     }
   17 
   18     return str;
   19 }
   20 
   21 module.exports = function () {
   22     var str = [].map.call(arguments, function (str) {
   23         return str.trim();
   24     }).filter(function (str) {
   25         return str.length;
   26     }).join('-');
   27 
   28     if (!str.length) {
   29         return '';
   30     }
   31 
   32     if (str.length === 1) {
   33         return str;
   34     }
   35 
   36     if (!(/[_.\- ]+/).test(str)) {
   37         if (str === str.toUpperCase()) {
   38             return str.toLowerCase();
   39         }
   40 
   41         if (str[0] !== str[0].toLowerCase()) {
   42             return str[0].toLowerCase() + str.slice(1);
   43         }
   44 
   45         return str;
   46     }
   47 
   48     str = preserveCamelCase(str);
   49 
   50     return str
   51     .replace(/^[_.\- ]+/, '')
   52     .toLowerCase()
   53     .replace(/[_.\- ]+(\w|$)/g, function (m, p1) {
   54         return p1.toUpperCase();
   55     });
   56 };