index.js
function parse(meta) {
  if (typeof meta !== 'string') {
    throw new Error('`Parse`\'s first argument should be a string')
  }

  return meta.split(/[\r\n]/)
    .filter(function (line) { // remove blank line
      return /\S+/.test(line) &&
        line.indexOf('==UserScript==') === -1 &&
        line.indexOf('==/UserScript==') === -1
    })
    .reduce(function (obj, line) {
      var arr = line.trim().replace(/^\/\//, '').trim().split(/\s+/)
      var key = arr[0].slice(1)
      var value = arr.slice(1).join(' ')

      if (isUndefined(obj[key])) {
        obj[key] = value
      } else if (Array.isArray(obj[key])) {
        obj[key].push(value)
      } else {
        obj[key] = [obj[key], value]
      }

      return obj
    }, {})
}
function parse(meta) {
  if (typeof meta !== 'string') {
    throw new Error('`Parse`\'s first argument should be a string')
  }

  return meta.split(/[\r\n]/)
    .filter(function (line) { // remove blank line
      return /\S+/.test(line) &&
        line.indexOf('==UserScript==') === -1 &&
        line.indexOf('==/UserScript==') === -1
    })
    .reduce(function (obj, line) {
      var arr = line.trim().replace(/^\/\//, '').trim().split(/\s+/)
      var key = arr[0].slice(1)
      var value = arr.slice(1).join(' ')

      if (isUndefined(obj[key])) {
        obj[key] = value
      } else if (Array.isArray(obj[key])) {
        obj[key].push(value)
      } else {
        obj[key] = [obj[key], value]
      }

      return obj
    }, {})
}
function parse ( meta ) { if ( typeof meta !== 'string' ) { throw new Error ( '`Parse`\'s first argument should be a string' ) } return meta . split ( / [\r\n] / ) . filter ( function ( line ) { // remove blank line return / \S+ / . test ( line ) && line . indexOf ( '==UserScript==' ) === - 1 && line . indexOf ( '==/UserScript==' ) === - 1 } ) . reduce ( function ( obj , line ) { var arr = line . trim ( ) . replace ( / ^\/\/ / , '' ) . trim ( ) . split ( / \s+ / ) var key = arr [ 0 ] . slice ( 1 ) var value = arr . slice ( 1 ) . join ( ' ' ) if ( isUndefined ( obj [ key ] ) ) { obj [ key ] = value } else if ( Array . isArray ( obj [ key ] ) ) { obj [ key ] . push ( value ) } else { obj [ key ] = [ obj [ key ] , value ] } return obj } , { } ) }
Parse metadata to an object
Parse metadata to an object