'use babel'

const extractionRegex = /at (.*?) \((.*?):(\d+):(\d+)\)/

export function capture() {
  const toReturn = []
  const stack = new Error().stack.split('\n')

  stack.shift()
  stack.forEach(function(entry) {
    const matches = extractionRegex.exec(entry)
    if (matches !== null) {
      toReturn.push({
        function: matches[1],
        file: matches[2],
        line: parseInt(matches[3]) || 1,
        col: parseInt(matches[4]) || 1
      })
    }
  })
  // Remove self from the stack
  toReturn.shift()

  return toReturn
}

'use babel'

const extractionRegex = /at (.*?) \((.*?):(\d+):(\d+)\)/

export function capture() {
  const traces = fromStack(new Error().stack)
  // Remove self from the stack
  traces.shift()
  return traces
}

export function fromStack(stack) {
  const stackChunks = stack.split('\n')
  const traces = []

  stackChunks.forEach(function(entry) {
    const matches = extractionRegex.exec(entry)
    if (matches !== null) {
      traces.push({
        function: matches[1],
        file: matches[2],
        line: parseInt(matches[3]) || 1,
        col: parseInt(matches[4]) || 1
      })
    }
  })

  return traces
}

Add fromStack method