"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/coffee-script/lib/coffee-script/helpers.js" (8 Mar 2017, 6951 Bytes) of archive /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 // Generated by CoffeeScript 1.9.0
    2 (function() {
    3   var buildLocationData, extend, flatten, last, repeat, syntaxErrorToString, _ref;
    4 
    5   exports.starts = function(string, literal, start) {
    6     return literal === string.substr(start, literal.length);
    7   };
    8 
    9   exports.ends = function(string, literal, back) {
   10     var len;
   11     len = literal.length;
   12     return literal === string.substr(string.length - len - (back || 0), len);
   13   };
   14 
   15   exports.repeat = repeat = function(str, n) {
   16     var res;
   17     res = '';
   18     while (n > 0) {
   19       if (n & 1) {
   20         res += str;
   21       }
   22       n >>>= 1;
   23       str += str;
   24     }
   25     return res;
   26   };
   27 
   28   exports.compact = function(array) {
   29     var item, _i, _len, _results;
   30     _results = [];
   31     for (_i = 0, _len = array.length; _i < _len; _i++) {
   32       item = array[_i];
   33       if (item) {
   34         _results.push(item);
   35       }
   36     }
   37     return _results;
   38   };
   39 
   40   exports.count = function(string, substr) {
   41     var num, pos;
   42     num = pos = 0;
   43     if (!substr.length) {
   44       return 1 / 0;
   45     }
   46     while (pos = 1 + string.indexOf(substr, pos)) {
   47       num++;
   48     }
   49     return num;
   50   };
   51 
   52   exports.merge = function(options, overrides) {
   53     return extend(extend({}, options), overrides);
   54   };
   55 
   56   extend = exports.extend = function(object, properties) {
   57     var key, val;
   58     for (key in properties) {
   59       val = properties[key];
   60       object[key] = val;
   61     }
   62     return object;
   63   };
   64 
   65   exports.flatten = flatten = function(array) {
   66     var element, flattened, _i, _len;
   67     flattened = [];
   68     for (_i = 0, _len = array.length; _i < _len; _i++) {
   69       element = array[_i];
   70       if (element instanceof Array) {
   71         flattened = flattened.concat(flatten(element));
   72       } else {
   73         flattened.push(element);
   74       }
   75     }
   76     return flattened;
   77   };
   78 
   79   exports.del = function(obj, key) {
   80     var val;
   81     val = obj[key];
   82     delete obj[key];
   83     return val;
   84   };
   85 
   86   exports.last = last = function(array, back) {
   87     return array[array.length - (back || 0) - 1];
   88   };
   89 
   90   exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
   91     var e, _i, _len;
   92     for (_i = 0, _len = this.length; _i < _len; _i++) {
   93       e = this[_i];
   94       if (fn(e)) {
   95         return true;
   96       }
   97     }
   98     return false;
   99   };
  100 
  101   exports.invertLiterate = function(code) {
  102     var line, lines, maybe_code;
  103     maybe_code = true;
  104     lines = (function() {
  105       var _i, _len, _ref1, _results;
  106       _ref1 = code.split('\n');
  107       _results = [];
  108       for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  109         line = _ref1[_i];
  110         if (maybe_code && /^([ ]{4}|[ ]{0,3}\t)/.test(line)) {
  111           _results.push(line);
  112         } else if (maybe_code = /^\s*$/.test(line)) {
  113           _results.push(line);
  114         } else {
  115           _results.push('# ' + line);
  116         }
  117       }
  118       return _results;
  119     })();
  120     return lines.join('\n');
  121   };
  122 
  123   buildLocationData = function(first, last) {
  124     if (!last) {
  125       return first;
  126     } else {
  127       return {
  128         first_line: first.first_line,
  129         first_column: first.first_column,
  130         last_line: last.last_line,
  131         last_column: last.last_column
  132       };
  133     }
  134   };
  135 
  136   exports.addLocationDataFn = function(first, last) {
  137     return function(obj) {
  138       if (((typeof obj) === 'object') && (!!obj['updateLocationDataIfMissing'])) {
  139         obj.updateLocationDataIfMissing(buildLocationData(first, last));
  140       }
  141       return obj;
  142     };
  143   };
  144 
  145   exports.locationDataToString = function(obj) {
  146     var locationData;
  147     if (("2" in obj) && ("first_line" in obj[2])) {
  148       locationData = obj[2];
  149     } else if ("first_line" in obj) {
  150       locationData = obj;
  151     }
  152     if (locationData) {
  153       return ((locationData.first_line + 1) + ":" + (locationData.first_column + 1) + "-") + ((locationData.last_line + 1) + ":" + (locationData.last_column + 1));
  154     } else {
  155       return "No location data";
  156     }
  157   };
  158 
  159   exports.baseFileName = function(file, stripExt, useWinPathSep) {
  160     var parts, pathSep;
  161     if (stripExt == null) {
  162       stripExt = false;
  163     }
  164     if (useWinPathSep == null) {
  165       useWinPathSep = false;
  166     }
  167     pathSep = useWinPathSep ? /\\|\// : /\//;
  168     parts = file.split(pathSep);
  169     file = parts[parts.length - 1];
  170     if (!(stripExt && file.indexOf('.') >= 0)) {
  171       return file;
  172     }
  173     parts = file.split('.');
  174     parts.pop();
  175     if (parts[parts.length - 1] === 'coffee' && parts.length > 1) {
  176       parts.pop();
  177     }
  178     return parts.join('.');
  179   };
  180 
  181   exports.isCoffee = function(file) {
  182     return /\.((lit)?coffee|coffee\.md)$/.test(file);
  183   };
  184 
  185   exports.isLiterate = function(file) {
  186     return /\.(litcoffee|coffee\.md)$/.test(file);
  187   };
  188 
  189   exports.throwSyntaxError = function(message, location) {
  190     var error;
  191     error = new SyntaxError(message);
  192     error.location = location;
  193     error.toString = syntaxErrorToString;
  194     error.stack = error.toString();
  195     throw error;
  196   };
  197 
  198   exports.updateSyntaxError = function(error, code, filename) {
  199     if (error.toString === syntaxErrorToString) {
  200       error.code || (error.code = code);
  201       error.filename || (error.filename = filename);
  202       error.stack = error.toString();
  203     }
  204     return error;
  205   };
  206 
  207   syntaxErrorToString = function() {
  208     var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, start, _ref1, _ref2;
  209     if (!(this.code && this.location)) {
  210       return Error.prototype.toString.call(this);
  211     }
  212     _ref1 = this.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;
  213     if (last_line == null) {
  214       last_line = first_line;
  215     }
  216     if (last_column == null) {
  217       last_column = first_column;
  218     }
  219     filename = this.filename || '[stdin]';
  220     codeLine = this.code.split('\n')[first_line];
  221     start = first_column;
  222     end = first_line === last_line ? last_column + 1 : codeLine.length;
  223     marker = codeLine.slice(0, start).replace(/[^\s]/g, ' ') + repeat('^', end - start);
  224     if (typeof process !== "undefined" && process !== null) {
  225       colorsEnabled = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS;
  226     }
  227     if ((_ref2 = this.colorful) != null ? _ref2 : colorsEnabled) {
  228       colorize = function(str) {
  229         return "\x1B[1;31m" + str + "\x1B[0m";
  230       };
  231       codeLine = codeLine.slice(0, start) + colorize(codeLine.slice(start, end)) + codeLine.slice(end);
  232       marker = colorize(marker);
  233     }
  234     return filename + ":" + (first_line + 1) + ":" + (first_column + 1) + ": error: " + this.message + "\n" + codeLine + "\n" + marker;
  235   };
  236 
  237   exports.nameWhitespaceCharacter = function(string) {
  238     switch (string) {
  239       case ' ':
  240         return 'space';
  241       case '\n':
  242         return 'newline';
  243       case '\r':
  244         return 'carriage return';
  245       case '\t':
  246         return 'tab';
  247       default:
  248         return string;
  249     }
  250   };
  251 
  252 }).call(this);