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\n * Original file: /npm/bat-publisher@2.0.24/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const querystring = require('querystring')\nconst url = require('url')\n\nconst Joi = require('joi')\nconst crypto = require('brave-crypto')\nconst datax = require('data-expression')\nconst npminfo = require('./package.json')\nconst tldjs = require('tldjs')\nconst trim = require('underscore.string/trim')\nconst underscore = require('underscore')\n\n/* foo.bar.example.com\n    QLD = 'bar'\n    RLD = 'foo.bar'\n    SLD = 'example.com'\n    TLD = 'com'\n\n   search.yahoo.co.jp\n    QLD = 'search'\n    RLD = 'search'\n    SLD = 'yahoo.co.jp'\n    TLD = 'co.jp'\n */\n\nconst schema = Joi.array().min(1).items(Joi.object().keys(\n  { condition: Joi.alternatives().try(Joi.string().description('a JavaScript boolean expression'),\n                                      Joi.boolean().allow(true).description('only \"true\" makes sense')).required(),\n    consequent: Joi.alternatives().try(Joi.string().description('a JavaScript string expression'),\n                                      Joi.any().allow(false, null).description('or null').required()),\n    dom: Joi.any().optional().description('DOM equivalent logic'),\n    description: Joi.string().optional().description('a brief annotation')\n  }\n))\n\nconst providerRE = /^([A-Za-z0-9][A-Za-z0-9-]{0,62})#([A-Za-z0-9][A-Za-z0-9-]{0,62}):(([A-Za-z0-9-._~]|%[0-9A-F]{2})+)$/\n\nlet jsdom\n\nconst getPublisher = (location, markup, ruleset) => {\n  const props = getPublisherProps(location)\n  let consequent, i, result, rule\n\n  if (!props) return\n\n  if ((!ruleset) && Array.isArray(markup)) {\n    ruleset = markup\n    markup = undefined\n  }\n\n  if (!jsdom) jsdom = require('jsdom').jsdom\n\n  if (!ruleset) ruleset = module.exports.ruleset\n  for (i = 0; i < ruleset.length; i++) {\n    rule = ruleset[i]\n\n    if (!datax.evaluate(rule.condition, props)) continue\n\n    if ((rule.dom) && (rule.dom.publisher)) {\n      if (!markup) throw new Error('markup parameter required')\n\n      if (typeof markup !== 'string') markup = markup.toString()\n\n      props.node = jsdom(markup).body.querySelector(rule.dom.publisher.nodeSelector)\n      consequent = rule.dom.publisher.consequent\n    } else {\n      delete props.node\n      consequent = rule.consequent\n    }\n\n    result = consequent ? datax.evaluate(consequent, props) : consequent\n    if (result === '') continue\n\n    if (typeof result === 'string') return trim(result, './')\n\n    // map null/false to undefined\n    return\n  }\n}\n\nconst publisherURLs = {\n  twitch: (props) => {\n    if (props.providerSuffix === 'channel') return ('https://www.twitch.tv/' + props.providerValue)\n  },\n\n  youtube: (props) => {\n    if (props.providerSuffix === 'channel') return ('https://www.youtube.com/channel/' + props.providerValue)\n  }\n}\n\nconst getPublisherProps = (publisher) => {\n  const provider = providerRE.exec(publisher)\n  let f, props, providerURL\n\n  if (provider) {\n    props = {\n      publisher: provider[0],\n      publisherType: 'provider',\n      providerName: provider[1],\n      providerSuffix: provider[2],\n      providerValue: querystring.unescape(provider[3])\n    }\n\n    f = publisherURLs[props.providerName.toLowerCase()]\n    providerURL = f && f(props)\n    if (providerURL) props.URL = providerURL\n\n    underscore.extend(props, {\n      TLD: props.publisher.split(':')[0],\n      SLD: props.publisher,\n      RLD: props.providerValue,\n      QLD: ''\n    })\n\n    return props\n  }\n\n  props = tldjs.parse(publisher)\n  if ((!props) || (!props.isValid) || (!props.publicSuffix)) return false\n\n  if (publisher.indexOf(':') === -1) publisher = 'https://' + publisher\n  props = url.parse(publisher, true)\n  if ((!props) || (props.hash) || (props.search)) return\n\n  props = underscore.mapObject(props, (value /* , key */) => { if (!underscore.isFunction(value)) return value })\n  props.URL = publisher\n  props.SLD = tldjs.getDomain(props.hostname)\n  props.RLD = tldjs.getSubdomain(props.hostname)\n  props.QLD = props.RLD ? underscore.last(props.RLD.split('.')) : ''\n\n  return props\n}\n\n//  cf., https://github.com/brave-intl/bat-publisher#syntax\n\nconst isPublisher = (publisher) => {\n  let props\n\n  if (providerRE.test(publisher)) return true\n\n  props = tldjs.parse(publisher)\n  if ((!props) || (!props.isValid) || (!props.publicSuffix)) return false\n\n  if (publisher.indexOf(':') === -1) publisher = 'https://' + publisher\n  props = url.parse(publisher)\n  return ((props) && (!props.hash) && (!props.search))\n}\n\nconst Synopsis = function (options) {\n  let p\n\n  this.publishers = {}\n  if ((typeof options === 'string') || (Buffer.isBuffer(options))) {\n    p = JSON.parse(options)\n  } else if ((typeof options === 'object') && options.options) {\n    p = options\n  }\n\n  if (p && p.options) options = p.options\n  if (p && p.publishers) this.publishers = p.publishers\n\n  this.options = options || {}\n  this.options.scorekeepers = underscore.keys(Synopsis.prototype.scorekeepers)\n  underscore.defaults(this.options, {\n    minPublisherDuration: 8 * 1000,\n    numFrames: 30,\n    frameSize: 24 * 60 * 60 * 1000,\n    _d: 1 / (30 * 1000),\n    minPublisherVisits: 0\n  })\n  if (!this.options.scorekeepers[this.options.scorekeeper]) {\n    this.options.scorekeeper = underscore.first(this.options.scorekeepers)\n  }\n  this.options.emptyScores = {}\n  this.options.scorekeepers.forEach(function (scorekeeper) {\n    this.options.emptyScores[scorekeeper] = 0\n  }, this)\n\n  underscore.defaults(this.options, { _a: (1 / (this.options._d * 2)) - this.options.minPublisherDuration })\n  this.options._a2 = this.options._a * 2\n  this.options._a4 = this.options._a2 * 2\n  underscore.defaults(this.options, { _b: this.options.minPublisherDuration - this.options._a })\n  this.options._b2 = this.options._b * this.options._b\n\n  underscore.keys(this.publishers).forEach(function (publisher) {\n    const entry = this.publishers[publisher]\n    let i\n\n// NB: legacy support\n    if (typeof entry.options === 'undefined') entry.options = {}\n    if (typeof entry.scores === 'undefined') {\n      entry.scores = underscore.clone(this.options.emptyScores)\n      if (entry.score) {\n        entry.scores.concave = entry.score\n        entry.scores.visits = entry.visits\n        delete entry.score\n      }\n    }\n\n    if (!entry.window) entry.window = []\n\n    for (i = 0; i < entry.window.length; i++) {\n      if (typeof entry.window[i].scores !== 'undefined') continue\n\n      entry.window[i].scores = underscore.clone(this.options.emptyScores)\n      if (entry.window[i].score) {\n        entry.window[i].scores.concave = entry.window[i].score\n        entry.window[i].scores.visits = entry.window[i].visits\n        delete entry.window[i].score\n      }\n    }\n  }, this)\n}\n\nSynopsis.prototype.addVisit = function (location, duration, markup) {\n  let publisher\n\n  if (duration < this.options.minPublisherDuration) return\n\n  try { publisher = getPublisher(location, markup) } catch (ex) { return }\n  if (!publisher) return\n\n  return this.addPublisher(publisher, { duration: duration, markup: markup, revisitP: false })\n}\n\nSynopsis.prototype.initPublisher = function (publisher, now, props) {\n  const entry = this.publishers[publisher]\n\n  if (!props) props = {}\n  if (entry) {\n    if (!entry.options) entry.options = {}\n    entry.options.stickyP = props.stickyP\n    entry.visits = entry.visits || 0\n    entry.duration = entry.duration || 0\n    entry.scores = entry.scores || underscore.clone(this.options.emptyScores)\n\n    if ((!entry.window) || (!entry.window.length)) {\n      entry.window = [ {\n        timestamp: now,\n        visits: entry.visits || 0,\n        duration: entry.duration || 0,\n        scores: entry.scores || underscore.clone(this.options.emptyScores)\n      } ]\n    }\n\n    return\n  }\n\n  this.publishers[publisher] = { visits: 0,\n    duration: 0,\n    options: { stickyP: props.stickyP },\n    scores: underscore.clone(this.options.emptyScores),\n    window: [ { timestamp: underscore.now(),\n      visits: 0,\n      duration: 0,\n      scores: underscore.clone(this.options.emptyScores) } ]\n  }\n}\n\nSynopsis.prototype.addPublisher = function (publisher, props) {\n  const now = underscore.now()\n  let entry, scores\n\n  if (!props) return\n\n  if (typeof props === 'number') props = { duration: props }\n  if (((!props.stickyP) && (!props.ignoreMinTime)) && (props.duration < this.options.minPublisherDuration)) return\n\n  scores = this.scores(props)\n  if (!scores) return\n\n  this.initPublisher(publisher, now, props)\n  entry = this.publishers[publisher]\n\n  if (entry.window[0].timestamp <= now - this.options.frameSize) {\n    entry.window = [ { timestamp: now,\n      visits: 0,\n      duration: 0,\n      scores: underscore.clone(this.options.emptyScores) }].concat(entry.window)\n  }\n\n  if (!props.revisitP) entry.window[0].visits++\n  entry.window[0].duration += props.duration\n  underscore.keys(scores).forEach(function (scorekeeper) {\n    if (!entry.window[0].scores) entry.window[0].scores = underscore.clone(this.options.emptyScores)\n    if (!entry.window[0].scores[scorekeeper]) entry.window[0].scores[scorekeeper] = 0\n    entry.window[0].scores[scorekeeper] += scores[scorekeeper]\n  }, this)\n\n  if (!props.revisitP) entry.visits++\n  entry.duration += props.duration\n  underscore.keys(scores).forEach(function (scorekeeper) {\n    if (!entry.scores) entry.scores = underscore.clone(this.options.emptyScores)\n    if (!entry.scores[scorekeeper]) entry.scores[scorekeeper] = 0\n    entry.scores[scorekeeper] += scores[scorekeeper]\n  }, this)\n\n  return publisher\n}\n\nSynopsis.prototype.topN = function (n) {\n  return this._topN(n, this.options.scorekeeper)\n}\n\nSynopsis.prototype.allN = function (n) {\n  const results = []\n  const weights = {}\n\n  underscore.keys(Synopsis.prototype.scorekeepers).forEach(function (scorekeeper) {\n    (this._topN(n, scorekeeper, true) || []).forEach(function (entry) {\n      if (!weights[entry.publisher]) weights[entry.publisher] = underscore.clone(this.options.emptyScores)\n      weights[entry.publisher][scorekeeper] = entry.weight\n    }, this)\n  }, this)\n\n  underscore.keys(weights).forEach(function (publisher) {\n    results.push(underscore.extend({ weights: weights[publisher] },\n                                   underscore.pick(this.publishers[publisher], [ 'scores', 'visits', 'duration', 'window' ])))\n  }, this)\n\n  return results\n}\n\nSynopsis.prototype._topN = function (n, scorekeeper, allP) {\n  let i, results, total\n\n  this.prune()\n\n  results = []\n  underscore.keys(this.publishers).forEach(function (publisher) {\n    if (\n      !this.publishers[publisher].scores ||\n      !this.publishers[publisher].scores[scorekeeper]) return\n\n    if (!this.publishers[publisher].options || !this.publishers[publisher].options.stickyP) {\n      if ((!allP) &&\n            ((this.options.minPublisherDuration > this.publishers[publisher].duration) ||\n             (this.options.minPublisherVisits > this.publishers[publisher].visits))) return\n    }\n\n    results.push(underscore.extend({ publisher: publisher }, underscore.omit(this.publishers[publisher], 'window')))\n  }, this)\n  results = underscore.sortBy(results, function (entry) { return -entry.scores[scorekeeper] })\n\n  if ((n > 0) && (results.length > n)) results = results.slice(0, n)\n  n = results.length\n\n  total = 0\n  for (i = 0; i < n; i++) { total += results[i].scores[scorekeeper] }\n  if (total === 0) return\n\n  for (i = 0; i < n; i++) {\n    results[i] = { publisher: results[i].publisher, weight: results[i].scores[scorekeeper] / total }\n  }\n\n  return results\n}\n\nSynopsis.prototype.winner = function () {\n  const result = this.winners()\n\n  return (result ? result[0] : result)\n}\n\nSynopsis.prototype.winners = function (n, weights) {\n  let results = underscore.shuffle(weights || this.topN())\n  const pinned = []\n  const winners = []\n  let count = 0\n  let allP = true\n\n  if (!results) return\n\n  results = results.filter((result) => {\n    if (result.pinPercentage == null) {\n      return result.weight > 0\n    }\n\n    return true\n  })\n\n  if (results.length === 0) return winners\n\n  if ((typeof n !== 'number') || (n < 1)) n = 1\n\n  results.forEach((result) => {\n    if ((typeof result.pinPercentage === 'number') && (result.pinPercentage > 0)) return\n\n    delete result.pinPercentage\n    allP = false\n  })\n\n  results.forEach((result) => {\n    let votes\n\n    if (!result.pinPercentage) return\n\n    votes = Math.round((result.pinPercentage * n) / 100)\n    pinned.push(underscore.extend({ votes: votes }, result))\n    count += votes\n  })\n\n  while (count > n) {\n    let mix = underscore.max(pinned, (result) => { return result.votes })\n\n    mix = underscore.min(pinned, (result) => { return ((result.votes === mix.votes) ? result.pinPercentage : 100) })\n    count--\n    if (--mix.votes <= 0) break\n  }\n  pinned.forEach((entry) => {\n    if (n === 0) return\n\n    if (entry.votes > n) entry.votes = n\n    underscore.times(entry.votes, () => { winners.push(entry.publisher) })\n    n -= entry.votes\n  })\n\n  // NB: if (!allP), then pinned publishers are no longer \"in the running\"\n  if (count === 0) allP = true\n  while (n > 0) {\n    const point = crypto.random.uniform_01()\n    let upper = 0\n    let i\n\n    for (i = 0; i < results.length; i++) {\n      upper += results[i].weight\n      if (upper < point) continue\n\n      if ((allP) || (!results[i].pinPercentage)) {\n        winners.push(results[i].publisher)\n        n--\n      }\n      break\n    }\n  }\n\n  return winners\n}\n\nSynopsis.prototype.toJSON = function () {\n  this.prune()\n\n  return { options: this.options, publishers: this.publishers }\n}\n\nSynopsis.prototype.scores = function (props) {\n  const result = {}\n  let emptyP = true\n\n  underscore.keys(Synopsis.prototype.scorekeepers).forEach(function (scorekeeper) {\n    let score = Synopsis.prototype.scorekeepers[scorekeeper].bind(this)(props)\n\n    result[scorekeeper] = score > 0 ? score : 0\n    if ((score === 0) && (props.stickyP)) score = 1\n    if (score > 0) emptyP = false\n  }, this)\n\n  if (!emptyP) return result\n}\n\nSynopsis.prototype.scorekeepers = {}\n\n// courtesy of @dimitry-xyz: https://github.com/brave/ledger/issues/2#issuecomment-221752002\nSynopsis.prototype.scorekeepers.concave = function (props) {\n  return (((-this.options._b) + Math.sqrt(this.options._b2 + (this.options._a4 * props.duration))) / this.options._a2)\n}\n\nSynopsis.prototype.scorekeepers.visits = function (/* props */) {\n  return 1\n}\n\nSynopsis.prototype.prune = function (then) {\n  const now = underscore.now()\n  const keys = Object.keys(this.publishers)\n  const oldSize = keys && keys.length\n\n  if (!then) then = now - (this.options.numFrames * this.options.frameSize)\n  keys.forEach(function (publisher) {\n    const entry = this.publishers[publisher]\n    const scores = {}\n    let i\n    let duration = 0\n    let visits = 0\n\n    // NB: in case of user editing...\n    if ((!entry.window) || (!entry.window.length)) {\n      entry.window = [ { timestamp: now, visits: entry.visits, duration: entry.duration, scores: entry.scores } ]\n      return\n    }\n\n    for (i = 0; i < entry.window.length; i++) {\n      if (entry.window[i].timestamp < then) {\n        if (entry.pinPercentage == null || entry.pinPercentage < 0) {\n          break\n        }\n\n        entry.window[i].timestamp = now\n      }\n\n      visits += entry.window[i].visits\n      duration += entry.window[i].duration\n      underscore.keys(entry.window[i].scores).forEach(function (scorekeeper) {\n        if (!scores[scorekeeper]) scores[scorekeeper] = 0\n        scores[scorekeeper] += entry.window[i].scores[scorekeeper]\n      }, this)\n    }\n\n    if (visits === 0) {\n      // do not delete the entry if it has options\n      if ((!entry.options) || (!entry.options.exclude)) {\n        delete this.publishers[publisher]\n        return\n      }\n\n      entry.visits = 0\n      entry.duration = 0\n      entry.scores = underscore.clone(this.options.emptyScores)\n      entry.window = [ { timestamp: now, visits: 0, duration: 0, scores: entry.scores } ]\n      return\n    }\n\n    if (i < entry.window.length) {\n      entry.visits = visits\n      entry.duration = duration\n      entry.scores = scores\n      entry.window = entry.window.slice(0, i)\n    }\n  }, this)\n\n  return oldSize !== Object.keys(this.publishers)\n}\n\nmodule.exports = {\n  getPublisher: getPublisher,\n  getPublisherProps: getPublisherProps,\n  getCategories: () => { return require('./categories') },\n  getRules: (done) => { return require('./categories').all(done) },\n  getMedia: () => { return require('./getMedia') },\n  isPublisher: isPublisher,\n  ruleset: () => { return require('./rules') },\n  schema: schema,\n  Synopsis: Synopsis,\n  version: npminfo.version\n}\n\nif (process.env.LEDGER_DEBUG) {\n  const ruleset = typeof module.exports.ruleset === 'function' ? module.exports.ruleset() : module.exports.ruleset\n  const validity = Joi.validate(ruleset, schema)\n\n  if (validity.error) throw new Error(validity.error)\n}\n"]}