Sha256: 65882707f24b1f5694b2814c1c754f94806584ee7f960a16b4a51a1777e1b118

Contents?: true

Size: 1.53 KB

Versions: 117

Compression:

Stored size: 1.53 KB

Contents

'use strict';


var common = require('./common');


function Mark(name, buffer, position, line, column) {
  this.name     = name;
  this.buffer   = buffer;
  this.position = position;
  this.line     = line;
  this.column   = column;
}


Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
  var head, start, tail, end, snippet;

  if (!this.buffer) return null;

  indent = indent || 4;
  maxLength = maxLength || 75;

  head = '';
  start = this.position;

  while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
    start -= 1;
    if (this.position - start > (maxLength / 2 - 1)) {
      head = ' ... ';
      start += 5;
      break;
    }
  }

  tail = '';
  end = this.position;

  while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
    end += 1;
    if (end - this.position > (maxLength / 2 - 1)) {
      tail = ' ... ';
      end -= 5;
      break;
    }
  }

  snippet = this.buffer.slice(start, end);

  return common.repeat(' ', indent) + head + snippet + tail + '\n' +
         common.repeat(' ', indent + this.position - start + head.length) + '^';
};


Mark.prototype.toString = function toString(compact) {
  var snippet, where = '';

  if (this.name) {
    where += 'in "' + this.name + '" ';
  }

  where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);

  if (!compact) {
    snippet = this.getSnippet();

    if (snippet) {
      where += ':\n' + snippet;
    }
  }

  return where;
};


module.exports = Mark;

Version data entries

117 entries across 102 versions & 17 rubygems

Version Path
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/js-yaml/lib/js-yaml/mark.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/js-yaml/lib/js-yaml/mark.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/js-yaml/lib/js-yaml/mark.js
tang-0.2.0 spec/tang_app/node_modules/js-yaml/lib/js-yaml/mark.js
tang-0.1.0 spec/tang_app/node_modules/js-yaml/lib/js-yaml/mark.js
tang-0.0.9 spec/tang_app/node_modules/js-yaml/lib/js-yaml/mark.js
enju_library-0.3.8 spec/dummy/node_modules/js-yaml/lib/js-yaml/mark.js
ilog-0.4.1 node_modules/js-yaml/lib/js-yaml/mark.js
ilog-0.4.0 node_modules/js-yaml/lib/js-yaml/mark.js
ilog-0.3.3 node_modules/js-yaml/lib/js-yaml/mark.js
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/js-yaml/lib/js-yaml/mark.js
jester-data-8.0.0 node_modules/js-yaml/lib/js-yaml/mark.js
ezii-os-5.2.1 node_modules/js-yaml/lib/js-yaml/mark.js
ezii-os-2.0.1 node_modules/js-yaml/lib/js-yaml/mark.js
ezii-os-1.1.0 node_modules/js-yaml/lib/js-yaml/mark.js
ezii-os-1.0.0 node_modules/js-yaml/lib/js-yaml/mark.js
ezii-os-0.0.0.1.0 node_modules/js-yaml/lib/js-yaml/mark.js
ezii-os-0.0.0.0.1 node_modules/js-yaml/lib/js-yaml/mark.js
govuk_publishing_components-18.0.0 node_modules/js-yaml/lib/js-yaml/mark.js
govuk_publishing_components-17.21.0 node_modules/js-yaml/lib/js-yaml/mark.js