UNPKG

@dsottimano/trendspy-js

Version:

ALPHA VERSION: JavaScript port of trendspy - A library for analyzing Google Trends data

52 lines (51 loc) 2.72 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var _require = require('luxon'), DateTime = _require.DateTime; var NewsArticle = /*#__PURE__*/function () { function NewsArticle(title, snippet, source, url, time) { _classCallCheck(this, NewsArticle); this.title = title; this.snippet = snippet; this.source = source; this.url = url; this.time = time; } return _createClass(NewsArticle, [{ key: "toString", value: function toString() { var s = "Title : ".concat(this.title); if (this.source) s += "\nSource : ".concat(this.source); if (this.time) { s += "\nTime : ".concat(DateTime.fromSeconds(this.time).toFormat('yyyy-MM-dd HH:mm:ss')); } if (this.snippet) s += "\nSnippet : ".concat(this.snippet); return s; } }], [{ key: "fromApi", value: function fromApi(data) { var title = data.title || data.snippet; var snippet = data.snippet || data.title; var source = data.source; var url = data.url || data.link; var time = null; if (data.time) { time = typeof data.time === 'number' ? data.time : DateTime.fromISO(data.time).toSeconds(); } else if (data.pubDate) { time = DateTime.fromFormat(data.pubDate, 'EEE, dd MMM yyyy HH:mm:ss ZZZ', { zone: 'utc' }).toSeconds(); } return new NewsArticle(title, snippet, source, url, time); } }]); }(); module.exports = { NewsArticle: NewsArticle };