react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / lib / js-yaml / mark.js
80698 views'use strict';123var common = require('./common');456function Mark(name, buffer, position, line, column) {7this.name = name;8this.buffer = buffer;9this.position = position;10this.line = line;11this.column = column;12}131415Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {16var head, start, tail, end, snippet;1718if (!this.buffer) {19return null;20}2122indent = indent || 4;23maxLength = maxLength || 75;2425head = '';26start = this.position;2728while (start > 0 && -1 === '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1))) {29start -= 1;30if (this.position - start > (maxLength / 2 - 1)) {31head = ' ... ';32start += 5;33break;34}35}3637tail = '';38end = this.position;3940while (end < this.buffer.length && -1 === '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end))) {41end += 1;42if (end - this.position > (maxLength / 2 - 1)) {43tail = ' ... ';44end -= 5;45break;46}47}4849snippet = this.buffer.slice(start, end);5051return common.repeat(' ', indent) + head + snippet + tail + '\n' +52common.repeat(' ', indent + this.position - start + head.length) + '^';53};545556Mark.prototype.toString = function toString(compact) {57var snippet, where = '';5859if (this.name) {60where += 'in "' + this.name + '" ';61}6263where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);6465if (!compact) {66snippet = this.getSnippet();6768if (snippet) {69where += ':\n' + snippet;70}71}7273return where;74};757677module.exports = Mark;787980