Sha256: cda4ce2e90c57220c9af5aabab7e2b94571ca945748a4f9d90696e230f016f23

Contents?: true

Size: 1.86 KB

Versions: 24

Compression:

Stored size: 1.86 KB

Contents

'use strict'

var stringify = require('unist-util-stringify-position')

module.exports = VMessage

// Inherit from `Error#`.
function VMessagePrototype() {}
VMessagePrototype.prototype = Error.prototype
VMessage.prototype = new VMessagePrototype()

// Message properties.
var proto = VMessage.prototype

proto.file = ''
proto.name = ''
proto.reason = ''
proto.message = ''
proto.stack = ''
proto.fatal = null
proto.column = null
proto.line = null

// Construct a new VMessage.
//
// Note: We cannot invoke `Error` on the created context, as that adds readonly
// `line` and `column` attributes on Safari 9, thus throwing and failing the
// data.
function VMessage(reason, position, origin) {
  var parts
  var range
  var location

  if (typeof position === 'string') {
    origin = position
    position = null
  }

  parts = parseOrigin(origin)
  range = stringify(position) || '1:1'

  location = {
    start: {line: null, column: null},
    end: {line: null, column: null}
  }

  // Node.
  if (position && position.position) {
    position = position.position
  }

  if (position) {
    // Position.
    if (position.start) {
      location = position
      position = position.start
    } else {
      // Point.
      location.start = position
    }
  }

  if (reason.stack) {
    this.stack = reason.stack
    reason = reason.message
  }

  this.message = reason
  this.name = range
  this.reason = reason
  this.line = position ? position.line : null
  this.column = position ? position.column : null
  this.location = location
  this.source = parts[0]
  this.ruleId = parts[1]
}

function parseOrigin(origin) {
  var result = [null, null]
  var index

  if (typeof origin === 'string') {
    index = origin.indexOf(':')

    if (index === -1) {
      result[1] = origin
    } else {
      result[0] = origin.slice(0, index)
      result[1] = origin.slice(index + 1)
    }
  }

  return result
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
trusty-cms-6.3.1 node_modules/vfile-message/index.js
trusty-cms-5.0.7 node_modules/vfile-message/index.js
trusty-cms-5.0.6 node_modules/vfile-message/index.js
trusty-cms-5.0.5 node_modules/vfile-message/index.js
trusty-cms-5.0.4 node_modules/vfile-message/index.js
trusty-cms-5.0.3 node_modules/vfile-message/index.js
trusty-cms-5.0.2 node_modules/vfile-message/index.js
trusty-cms-5.0.1 node_modules/vfile-message/index.js
trusty-cms-4.3.5 node_modules/vfile-message/index.js
trusty-cms-5.0.0 node_modules/vfile-message/index.js
trusty-cms-4.3.4 node_modules/vfile-message/index.js
trusty-cms-4.3.3 node_modules/vfile-message/index.js
trusty-cms-4.3.2 node_modules/vfile-message/index.js
trusty-cms-4.3.1 node_modules/vfile-message/index.js
trusty-cms-4.3 node_modules/vfile-message/index.js
trusty-cms-4.2.3 node_modules/vfile-message/index.js
trusty-cms-4.2.2 node_modules/vfile-message/index.js
trusty-cms-4.2.1 node_modules/vfile-message/index.js
trusty-cms-4.2 node_modules/vfile-message/index.js
trusty-cms-4.1.9 node_modules/vfile-message/index.js