daily-box 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-present Homer Chen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
File without changes
package/lib/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ !function(e){var t={};function o(a){if(t[a])return t[a].exports;var n=t[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,o),n.l=!0,n.exports}o.m=e,o.c=t,o.d=function(e,t,a){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(o.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)o.d(a,n,function(t){return e[t]}.bind(null,n));return a},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=35)}([function(e,t){e.exports=require("chalk")},function(e,t){e.exports=require("@babel/runtime/helpers/asyncToGenerator")},function(e,t){e.exports=require("wide-align")},function(e,t){e.exports=require("node-emoji")},function(e,t){e.exports=require("blessed")},function(e,t){e.exports=require("path")},function(e,t){e.exports=require("@babel/runtime/helpers/objectSpread")},function(e,t){e.exports=require("@babel/runtime/helpers/slicedToArray")},function(e,t){e.exports=require("ramda")},function(e,t){e.exports=require("inquirer")},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("commander")},function(e,t){e.exports=require("date-fns/format")},function(e,t){e.exports=require("ora")},function(e,t){e.exports=require("cli-table3")},function(e,t){e.exports=require("axios")},function(e,t){e.exports=require("date-fns/parse")},function(e,t){e.exports=require("nba-color")},function(e,t){e.exports=require("stringz")},function(e,t){e.exports=require("iconv-lite")},function(e){e.exports={name:"daily-box",description:"A CLI tool for daily information: NBA games, stock prices, novels and more.",license:"MIT",author:"linwei",homepage:"https://github.com/linwei/daily-cli#readme",repository:{type:"git",url:"git+https://github.com/linwei/daily-cli.git"},bugs:{url:"https://github.com/linwei/daily-cli/issues"},version:"0.4.0",main:"lib/cli.js",bin:{"daily-box":"lib/cli.js",daily:"lib/cli.js"},files:["lib"],scripts:{build:"NODE_OPTIONS=--openssl-legacy-provider npm run clean && NODE_OPTIONS=--openssl-legacy-provider webpack --config webpack.config.js -p",clean:"rimraf lib packed",dev:"NODE_OPTIONS=--openssl-legacy-provider webpack --config webpack.config.js -d -w",lint:"eslint src","lint:fix":"npm run lint -- --fix",pack:"pkg . --out-path packed",prepublishOnly:"npm run build && echo '#!/usr/bin/env node' | cat - lib/cli.js > temp && mv temp lib/cli.js",test:"npm run lint:fix && npm run testonly:cov",testonly:"NODE_ENV=test jest","testonly:cov":"jest --coverage --runInBand --forceExit --no-cache","testonly:watch":"jest --watch"},dependencies:{"@babel/register":"^7.0.0","async-to-gen":"^1.4.0",axios:"^1.14.0",blessed:"^0.1.81",cfonts:"^2.4.0",chalk:"^2.4.2","cli-table3":"^0.5.1",commander:"^2.19.0","date-fns":"^1.30.1",delay:"^4.1.0",didyoumean:"^1.2.1","iconv-lite":"^0.6.3",inquirer:"^6.2.1","is-async-supported":"^1.2.0","log-update":"^2.2.0",luxon:"^1.10.0",nba:"^4.5.0","nba-color":"^1.3.9","nba-stats-client":"^1.0.0","node-emoji":"^1.8.1",ora:"^3.0.0","p-map":"^2.0.0",ramda:"^0.26.1",stringz:"^1.0.0","update-notifier":"^2.5.0","wide-align":"^1.1.3","yahoo-finance2":"^3.14.0"},devDependencies:{"@babel/cli":"^7.2.3","@babel/core":"^7.2.2","@babel/plugin-proposal-class-properties":"^7.2.3","@babel/plugin-proposal-object-rest-spread":"^7.2.0","@babel/plugin-transform-runtime":"^7.2.0","@babel/preset-env":"^7.2.3","@babel/runtime":"^7.2.0","babel-core":"^7.0.0-bridge.0","babel-eslint":"^10.0.1","babel-jest":"^23.6.0","babel-loader":"^8.0.5","copy-webpack-plugin":"^4.6.0",eslint:"^5.12.0","eslint-config-airbnb":"^17.1.0","eslint-config-prettier":"^3.4.0","eslint-plugin-babel":"^5.3.0","eslint-plugin-import":"^2.14.0","eslint-plugin-jsx-a11y":"^6.1.2","eslint-plugin-prettier":"^3.0.1","eslint-plugin-react":"^7.12.3",husky:"^1.3.1",jest:"^23.6.0","lint-staged":"^8.1.0","moment-timezone":"^0.5.23",pkg:"^4.3.7",prettier:"^1.15.3","prettier-package-json":"^2.0.1",rimraf:"^2.6.3","terser-webpack-plugin":"^1.2.1",webpack:"^4.28.4","webpack-cli":"^3.2.1","webpack-node-externals":"^1.7.2"},keywords:["NBA","cli"],engines:{node:">=6.0.0"},husky:{hooks:{"pre-commit":"lint-staged"}},jest:{collectCoverageFrom:["src/**/*.js"],coveragePathIgnorePatterns:["/node_modules/","/__tests__/"],testPathIgnorePatterns:["node_modules/"]},"lint-staged":{"package.json":["prettier-package-json --write","git add"],"*.js":["eslint --fix","git add"]},pkg:{scripts:["lib/**/*.js","node_modules/blessed/lib/**/*.js"],assets:"lib/data/fonts/*",targets:["node8-macos","node8-linux","node8-win"]}}},function(e,t){e.exports=require("didyoumean")},function(e,t){e.exports=require("is-async-supported")},function(e,t){e.exports=require("update-notifier")},function(e,t){e.exports=require("date-fns/add_days")},function(e,t){e.exports=require("date-fns/sub_days")},function(e,t){e.exports=require("date-fns/is_valid")},function(e,t){e.exports=require("p-map")},function(e,t){e.exports=require("date-fns/get_month")},function(e,t){e.exports=require("date-fns/get_year")},function(e,t){e.exports=require("date-fns/start_of_day")},function(e,t){e.exports=require("luxon")},function(e,t){e.exports=require("cfonts")},function(e,t){e.exports=require("os")},function(e,t){e.exports=require("async-to-gen/register")},function(e,t,o){"use strict";o.r(t);var a=o(1),n=o.n(a),s=o(11),r=o.n(s),i=o(21),l=o.n(i),c=o(22),d=o.n(c),p=o(0),u=o.n(p),m=o(23),g=o.n(m),h=o(7),f=o.n(h),y=o(6),b=o.n(y),v=o(8),$=o.n(v),x=o(16),_=o.n(x),w=o(24),S=o.n(w),k=o(25),A=o.n(k),T=o(12),P=o.n(T),j=o(26),F=o.n(j),I=o(3),N=o.n(I),C=o(13),L=o.n(C),O=o(9),D=o.n(O),M=o(18),G=o(2),E=o(27),B=o.n(E);var q=e=>{const t=t=>$.a.find($.a.propEq("home_visitor",t))(e);let o=t("home"),a=t("visitor"),n=t("natl");return n=n?n.display_name:"N/A",{homeTeam:o=o?o.display_name:n,visitorTeam:a=a?a.display_name:n}},R=o(17);const V=e=>{console.log(u.a`{red.bold ${e}}`)},Y=e=>u.a`{white.bold ${e}}`,W=e=>u.a`{bold.hex('#f00b47') ${e}}`,H=e=>u.a`{hex('#66ff66') ${e}}`,Q=(e,t)=>u.a`{bold.white.bgHex('${e}') ${t}}`;class U{constructor({teamId:e,teamCity:t,teamName:o,teamAbbreviation:a,id:n,city:s,nickname:r,name:i,abbreviation:l,score:c,w:d,l:p,divRank:u,linescores:m,isHomeTeam:g,records:h}){this.id=e||n,this.city=t||s,this.name=o||r||i,this.abbreviation=a||l,this.score=""===c?"0":c||"0";const y=h&&h.find(e=>"overall"===e.name&&"total"===e.type);if(y&&y.summary){const e=y.summary.split("-"),t=f()(e,2),o=t[0],a=t[1];this.wins=o,this.loses=a}else this.wins=d,this.loses=p;this.divRank=u,this.gameStats={},this.players=[],this.gameLeaders={},this.color=Object(R.getMainColor)(this.abbreviation),this.isHomeTeam=g,m?Array.isArray(m)&&m.length>0?this.linescores=m.map((e,t)=>({period_value:e.period||t+1,score:e.displayValue||e.value||"0"})):m.period?this.linescores=Array.isArray(m.period)?m.period:[m.period]:this.linescores=[]:this.linescores=[]}getID(){return this.id}getCity(){return this.city}getAbbreviation({color:e}){return!1===e?this.abbreviation:Q(this.getColor(),this.abbreviation)}getName({color:e}){return!1===e?this.name:Q(this.getColor(),this.name)}getScore(){return this.score}getWins(){return this.wins}getLoses(){return this.loses}getFullName({color:e}){return!1===e?`${this.city} ${this.name}`:Q(this.getColor(),`${this.city} ${this.name}`)}getColor(){return this.color?this.color.hex:void 0}getWinnerName(e){return"left"===e?`${N.a.get("crown")} ${Q(this.getColor(),this.name)}`:`${Q(this.getColor(),this.name)} ${N.a.get("crown")}`}getQuarterScore(e){const t=this.linescores.find(t=>t&&t.period_value===e);return t?t.score:"-"}getGameStats(){return this.gameStats}getPlayers(){return this.players}getGameLeaders(e){return this.gameLeaders[e]||{StatValue:"-",leader:[{FirstName:"",LastName:""}]}}getIsHomeTeam(){return this.isHomeTeam}setScore(e){this.score=e}setGameStats(e){this.gameStats=e}setPlayers(e){this.players=e}setGameLeaders(e){this.gameLeaders=e}setLinescores(e){e&&e.length>0&&(this.linescores=e.map((e,t)=>({period_value:e.period_value||t+1,score:e.score||e.displayValue||"0"})))}setQuarterScore(e,t){this.linescores.find(t=>t.period_value===e).score=t}}const K=e=>Y(Object(G.right)(e,20)),z=e=>Y(Object(G.left)(e,20)),J=e=>Object(G.center)(e,18),X=e=>Y(Object(G.right)(e,35)),Z=e=>Y(Object(G.left)(e,35)),ee=(e,t,o,a)=>{let n="";const s=o.period_status,r=o.game_clock;n=+e.getScore()>+t.getScore()?"home":+e.getScore()==+t.getScore()?null:"visitor";const i=K("home"===n?e.getWinnerName("left"):e.getName({color:!0})),l=z("visitor"===n?t.getWinnerName("right"):t.getName({color:!0})),c=`${i}${Object(G.center)(N.a.get("basketball"),8)}${l}`,d=`${"home"===n?Object(G.right)(Y(H(e.getScore())),4):Object(G.right)(Y(e.getScore()),4)} : ${"visitor"===n?Object(G.left)(Y(H(t.getScore())),4):Object(G.left)(Y(t.getScore()),4)}`;if(a){const e=q(a.tv.broadcaster),t=`${X(e.homeTeam)} ${N.a.get("tv")} ${Z(e.visitorTeam)}|`;return`│⌘${c}│${d}│${J(`${Y(s)} ${r}`)}│${t}`}return`│⌘${c}│${d}│${J(`${Y(s)} ${r}`)}│`},te=function(){var e=n()(function*(e){return new U({teamId:e.id,teamCity:e.city||e.location,teamName:e.name||e.nickname,teamAbbreviation:e.abbreviation,score:e.score,w:e.w||"0",l:e.l||"0",divRank:e.divRank||"0",linescores:e.linescores,isHomeTeam:!0,records:e.records,id:e.id,city:e.city||e.location,nickname:e.nickname||e.name,abbreviation:e.abbreviation})});return function(t){return e.apply(this,arguments)}}();var oe=function(){var e=n()(function*(e,t){const o=L()(`Loading Game Schedule...(0/${e.length})`).start();let a="";t.networks&&(a=`${X("Home")} ${N.a.get("tv")} ${Z("Away")}|`);const s=`│ ${K("Home")}${Object(G.center)(N.a.get("basketball"),8)}${z("Away")}│${Object(G.center)("Score",11)}│${J("Status")}│${a}`,r=t.networks?156:81,i=[{name:"game",message:"Which game do you want to watch?",type:"list",pageSize:30,choices:[new D.a.Separator(`${Object(M.limit)("",r,"─")}`),new D.a.Separator(s),new D.a.Separator(`${Object(M.limit)("",r,"─")}`)]}];e.length;return yield B()(e,function(){var a=n()(function*(a,n){const s=a.home,l=a.visitor,c=a.period_time,d=a.broadcasters,p=yield te(s,process.env.season),u=yield te(l,process.env.season);o.text=`Loading Game Schedule...(${n+1}/${e.length})`,i[0].choices.push({name:ee(p,u,c,t.networks?d:null),value:{gameData:a,homeTeam:p,visitorTeam:u}}),i[0].choices.push(new D.a.Separator(`${Object(M.limit)("",r,"─")}`))});return function(e,t){return a.apply(this,arguments)}}(),{concurrency:1}),o.stop(),yield D.a.prompt(i)});return function(t,o){return e.apply(this,arguments)}}(),ae=o(14),ne=o.n(ae);const se=()=>new ne.a({head:[],chars:{top:"═","top-mid":"╤","top-left":"╔","top-right":"╗",bottom:"═","bottom-mid":"╧","bottom-left":"╚","bottom-right":"╝",left:"║","left-mid":"╟",mid:"─","mid-mid":"┼",right:"║","right-mid":"╢",middle:"│"}}),re=e=>e.map(e=>"string"==typeof e?{content:e,vAlign:"center",hAlign:"center"}:b()({},e,{vAlign:"center",hAlign:"center"})),ie=(e,{gp:t="0",w:o="0",l:a="0",pts:n="0",fgPct:s=0,fg3Pct:r=0,ftPct:i=0,oreb:l="0",dreb:c="0",reb:d="0",ast:p="0",blk:u="0",stl:m="0",tov:g="0",pf:h="0",plusMinus:f="0"}={})=>[e,`${o} - ${a}`,(o/t).toFixed(3),`${n}`,`${(100*s).toFixed(1)}`,`${(100*r).toFixed(1)}`,`${(100*i).toFixed(1)}`,`${l}`,`${c}`,`${d}`,`${p}`,`${u}`,`${m}`,`${g}`,`${h}`,`${f}`];var le=(e,t,{date:o,time:a,arena:n,city:s,state:r,display_year:i,display_season:l,broadcasters:c,homeTeamDashboardData:d,visitorTeamDashboardData:p})=>{const u=se(),m=Math.max(e.getFullName({color:!1}).length,t.getFullName({color:!1}).length),g=q(c.tv.broadcaster);u.push(re([{colSpan:16,content:Y(`${i} ${l}`)}]),re([{colSpan:16,content:Y(`${N.a.get("calendar")} ${P()(o,"YYYY/MM/DD")} ${a.slice(0,2)}:${a.slice(2,4)}`)}]),re([{colSpan:16,content:Y(`${N.a.get("house")} ${n} | ${s}, ${r}`)}]),re([{colSpan:16,content:Y(`${g.homeTeam} ${N.a.get("tv")} ${g.visitorTeam}`)}]),re(ie(Object(G.center)(e.getFullName({color:!0}),m),d)),re(["",Y("RECORD"),Y("WIN%"),Y("PTS"),Y("FG%"),Y("3P%"),Y("FT%"),Y("OREB"),Y("DREB"),Y("REB"),Y("AST"),Y("BLK"),Y("STL"),Y("TOV"),Y("PF"),Y("+/-")]),re(ie(Object(G.center)(t.getFullName({color:!0}),m),p))),console.log(u.toString())};const ce=e=>e.map(e=>"string"==typeof e?{content:e,vAlign:"center",hAlign:"center"}:b()({},e,{vAlign:"center"})),de=e=>{return(e.getPlayers()||[]).filter(e=>e&&(""!==e.starting_position||"1"===e.on_court)).map(e=>({name:`${e.first_name} ${e.last_name}`,position:e.starting_position||e.position_short||"G"}))},pe=(e,t)=>{const o=e.find(e=>e.position===t);return o?o.name:"-"},ue=(e,t)=>{const o=e.filter(e=>e.position&&e.position.indexOf("G")>-1);return o[t]?o[t].name:"-"},me=(e,t)=>{const o=e.filter(e=>e.position&&e.position.indexOf("F")>-1);return o[t]?o[t].name:"-"},ge=(e,t,o)=>{const a=e.getGameLeaders(o),n=t.getGameLeaders(o),s=a&&a.leader&&a.leader[0]&&a.leader[0].FirstName||"-",r=a&&a.leader&&a.leader[0]&&a.leader[0].LastName||"",i=n&&n.leader&&n.leader[0]&&n.leader[0].FirstName||"-",l=n&&n.leader&&n.leader[0]&&n.leader[0].LastName||"",c=a&&a.StatValue||"-",d=n&&n.StatValue||"-";return ce([{colSpan:3,content:Y(`${s} ${r}`),hAlign:"right"},W(c),{colSpan:2,content:o,hAlign:"center"},W(d),{colSpan:3,content:Y(`${i} ${l}`),hAlign:"left"}])};var he=(e,t,{date:o,time:a,arena:n,city:s,state:r,display_year:i,display_season:l,broadcasters:c})=>{const d=se(),p=a?`${a.slice(0,2)}:${a.slice(2,4)}`:"",u=de(e),m=de(t),g=q(c.tv.broadcaster);d.push(ce([{colSpan:10,content:Y(`${i} ${l}`),hAlign:"center"}]),ce([{colSpan:2,content:Y(e.getName({color:!0})),hAlign:"center"},{colSpan:6,content:Y("Final"),hAlign:"center"},{colSpan:2,content:Y(t.getName({color:!0})),hAlign:"center"}]),ce(["PG",{content:Y(ue(u,1)),hAlign:"left"},Y("Team"),Y("Q1"),Y("Q2"),Y("Q3"),Y("Q4"),Y(Object(G.center)("Total",9)),"PG",{content:Y(ue(m,1)),hAlign:"left"}]),ce(["SG",{content:Y(ue(u,0)),hAlign:"left"},`${e.getAbbreviation({color:!0})} (${e.getWins()}-${e.getLoses()})`,Y(e.getQuarterScore("1")),Y(e.getQuarterScore("2")),Y(e.getQuarterScore("3")),Y(e.getQuarterScore("4")),Y(H(e.getScore())),"SG",{content:Y(ue(m,0)),hAlign:"left"}]),ce(["SF",{content:Y(me(u,1)),hAlign:"left"},`${t.getAbbreviation({color:!0})} (${t.getWins()}-${t.getLoses()})`,Y(t.getQuarterScore("1")),Y(t.getQuarterScore("2")),Y(t.getQuarterScore("3")),Y(t.getQuarterScore("4")),Y(H(t.getScore())),"SF",{content:Y(me(m,1)),hAlign:"left"}]),ce(["PF",{content:Y(me(u,0)),hAlign:"left"},{colSpan:6,content:Y(o?`${N.a.get("calendar")} ${P()(o,"YYYY/MM/DD")} ${p}`:"N/A"),hAlign:"center"},"PF",{content:Y(me(m,0)),hAlign:"left"}]),ce(["C",{content:Y(pe(u,"C")),hAlign:"left"},{colSpan:6,content:Y(`${N.a.get("house")} ${n||"N/A"} │ ${s||""}, ${r||""}`),hAlign:"center"},"C",{content:Y(pe(m,"C")),hAlign:"left"}]),ce([{colSpan:10,content:Y(`${g.homeTeam} ${N.a.get("tv")} ${g.visitorTeam}`),hAlign:"center"}]),ce([{colSpan:10,content:Y("Game Record Leaders"),hAlign:"center"}]),ge(e,t,"Points"),ge(e,t,"Assists"),ge(e,t,"Rebounds")),console.log(d.toString())};const fe=e=>e.map(e=>({content:e,hAlign:"left",vAlign:"center"})),ye=(e,t,o,a)=>{const n=e.map(e=>Number.parseInt(e[t],10));return o>=Math.max(...n)?H(o):((e,t)=>+e>=t?W(e):e)(o,a)},be=e=>{const t=e.getPlayers(),o=e.getGameStats(),a=se();a.push([{colSpan:16,content:e.getFullName({color:!0}),hAlign:"left",vAlign:"center"}],fe([Y("PLAYER"),Y("POS"),Y("MIN"),Y("FG"),Y("3FG"),Y("FT"),Y("+/-"),Y("OREB"),Y("DREB"),Y("REB"),Y("AST"),Y("STL"),Y("BLK"),Y("TO"),Y("PF"),Y("PTS")])),t.forEach(e=>{const o=e.first_name,n=e.last_name,s=e.position_short,r=e.minutes,i=e.field_goals_made,l=e.field_goals_attempted,c=e.three_pointers_made,d=e.three_pointers_attempted,p=e.free_throws_made,u=e.free_throws_attempted,m=e.plus_minus,g=e.rebounds_offensive,h=e.rebounds_defensive,f=e.assists,y=e.steals,b=e.blocks,v=e.turnovers,$=e.fouls,x=e.points,_=+g+ +h;a.push(fe([Y(`${o} ${n}`),Y(s),ye(t,"minutes",r,35),`${i}-${l}`,`${c}-${d}`,`${p}-${u}`,ye(t,"plus_minus",m,15),ye(t,"rebounds_offensive",g,10),ye(t,"rebounds_defensive",h,10),ye(t,"totalRebounds",_,10),ye(t,"assists",f,10),ye(t,"steals",y,5),ye(t,"blocks",b,5),ye(t,"turnovers",v,5),ye(t,"fouls",$,6),ye(t,"points",x,20)]))});const n=o.points,s=o.field_goals_made,r=o.field_goals_attempted,i=o.free_throws_made,l=o.free_throws_attempted,c=o.three_pointers_made,d=o.three_pointers_attempted,p=o.rebounds_offensive,u=o.rebounds_defensive,m=o.assists,g=o.fouls,h=o.steals,f=o.turnovers,y=o.blocks;a.push(fe(["Totals","","",Y(`${s}-${r}`),Y(`${c}-${d}`),Y(`${i}-${l}`),"",Y(p),Y(u),Y(parseInt(p,10)+parseInt(u,10)),Y(m),Y(h),Y(y),Y(f),Y(g),Y(H(n))])),console.log(a.toString())};var ve=(e,t)=>{be(e),console.log(""),be(t)};const $e=(e,t)=>+e>=t?W(e):e,xe=(e,t,o)=>{if(!(o=Array.isArray(o)?o:[o])||0===o.length)return;const a=o.filter(e=>e&&e.period_value).find(e=>e.period_value===t);a&&a.score&&t&&(e.getIsHomeTeam(),e.setQuarterScore(t,a.score))},_e=e=>parseInt(e,10)-4,we=e=>{const t=["","Q1","Q2","Q3","Q4"],o=_e(e);for(let e=0;e<o;e+=1)t.push(`OT${o}`);return t.push("Total"),t},Se=(e,t)=>{const o=[`${e.getAbbreviation({color:!0})}`];for(let a=1;a<=t;a+=1)o.push(Y(e.getQuarterScore(`${a}`)));for(let e=0;e<4-t;e+=1)o.push(" ");return o.push(H(e.getScore())),o},ke=(e,t)=>{const o=[];return o.push([e.getAbbreviation({color:!0}),Y("PTS"),Y("AST"),Y("REB")]),t.sort((e,t)=>+t.minutes-+e.minutes).slice(0,5).forEach(e=>{o.push([Y(Object(G.left)(e.last_name,14)),Object(G.left)($e(e.points,20),3),Object(G.left)($e(e.assists,10),3),Object(G.left)(`${$e(+e.rebounds_offensive+ +e.rebounds_defensive,10)}`,3)])}),o};var Ae=(e,t,o,a,n)=>{const s=o.play,r=o.isFinal,i=s.slice(-1).pop(),l=i.period,c=i.clock,d=n.screen,p=n.scoreboardTable,u=n.timeText,m=n.homeTeamScoreText,g=n.visitorTeamScoreText,h=n.playByPlayBox,f=n.boxscoreTable,y=a.home.linescores.period,b=a.visitor.linescores.period;if(xe(e,l,y),xe(t,l,b),p.setRows([we(l),Se(e,l),Se(t,l)]),f.setRows([...ke(e,a.home.players.player),...ke(t,a.visitor.players.player)]),h.setContent((e=>{e.reverse();const t=[];for(let o=0;o<e.length;o+=1){const a=e[o],n=a.clock,s=a.period,r=a.description,i=a.home_score,l=a.visitor_score,c=a.team_abr,d=_e(s),p=`${+d>1?`OT${d}`:`Q${s}`} ${n&&""!==n?n:"--:--"}`,u=`${Object(G.right)(i>$.a.prop("home_score",e[o+1])?Y(H(i)):Y(i),3)} - ${Object(G.left)(l>$.a.prop("visitor_score",e[o+1])?Y(H(l)):Y(l),3)}`,m=c&&Object(R.getMainColor)(c)?Object(R.getMainColor)(c).hex:"#000",g=c&&""!==c.trim()?c:"",h=`${Object(G.left)(Q(m,g),3)} ${r?r.replace(/\[.*\]/i,""):""}\n`;t.push([p,u,h].join(" │ "))}return t.join("\n")})(s)),h.focus(),r)u.setContent(Y("Final"));else{const e=_e(l);u.setContent(Y(`${N.a.get("stopwatch")} ${+e>1?"OT":"Q"}${+e>1?e:l} ${c}`))}m.setContent(e.getScore()),g.setContent(t.getScore()),d.render()},Te=o(28),Pe=o.n(Te),je=o(29),Fe=o.n(je);var Ie=e=>{const t=$.a.compose(Fe.a,_.a)(e),o=$.a.compose(Pe.a,_.a)(e);return(t<2012||2012===t&&o<5)&&(V(`Sorry, https://stats.nba.com/ doesn't provide season data before 2012-13 ${N.a.get("confused")}`),process.exit(1)),process.env.season=o>9?`${t}-${(t+1).toString().slice(-2)}`:`${t-1}-${t.toString().slice(-2)}`,e},Ne=o(30),Ce=o.n(Ne),Le=o(31),Oe=o(15),De=o.n(Oe);const Me=De.a.create({baseURL:"https://site.api.espn.com/apis/site/v2/sports/basketball/nba",headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}}),Ge=e=>{const t=e.competitions[0],o=t.competitors.find(e=>"home"===e.homeAway),a=t.competitors.find(e=>"away"===e.homeAway),n=(t.broadcasts||[]).map(e=>{return{name:e.names?e.names.join(", "):e.media&&e.media.shortName||"",market:e.market}}),s=(t.status&&t.status.type||{}).shortDetail||"Scheduled",r=(e=>e&&e.type?e.type.completed?"3":"STATUS_IN_PROGRESS"===e.type.name?"2":"STATUS_HALFTIME"===e.type.name?"Halftime":"1":"1")(t.status),i={period_status:s,game_clock:t.status&&t.status.displayClock||"",game_status:r,time_remaining:t.status&&t.status.clock&&t.status.clock.displayValue||"",period:t.status&&t.status.period||0},l=e=>e&&Array.isArray(e)?e.map((e,t)=>({period_value:void 0!==e.period?e.period.toString():(t+1).toString(),score:void 0!==e.displayValue?e.displayValue:(e.value||"0").toString()})):[],c=e=>{if(e.records){const t=e.records.find(e=>"overall"===e.name);return t?t.summary:"0-0"}return"0-0"},d=c(o),p=c(a);return{id:e.id,home:{id:o.team.id,city:o.team.location,nickname:o.team.name,abbreviation:o.team.abbreviation,score:o.score||"0",linescores:l(o.linescores),records:o.records,w:d.split("-")[0],l:d.split("-")[1]},visitor:{id:a.team.id,city:a.team.location,nickname:a.team.name,abbreviation:a.team.abbreviation,score:a.score||"0",linescores:l(a.linescores),records:a.records,w:p.split("-")[0],l:p.split("-")[1]},period_time:i,broadcasters:{tv:{broadcaster:n}},venue:t.venue,date:e.date}},Ee=(e,t)=>{if(!e||!Array.isArray(e))return[];const o=[],a=e.find(e=>e.team&&e.team.id===t);if(!a)return[];if(!a.statistics||!a.statistics[0]||!a.statistics[0].athletes)return[];const n=a.statistics[0],s=n.keys||[],r=(n.names,{minutes:"minutes",points:"points","fieldGoalsMade-fieldGoalsAttempted":"field_goals","threePointFieldGoalsMade-threePointFieldGoalsAttempted":"three_pointers","freeThrowsMade-freeThrowsAttempted":"free_throws",rebounds:"rebounds",assists:"assists",turnovers:"turnovers",steals:"steals",blocks:"blocks",offensiveRebounds:"rebounds_offensive",defensiveRebounds:"rebounds_defensive",fouls:"fouls",plusMinus:"plus_minus"});return n.athletes.forEach(e=>{if(e.didNotPlay)return;const t=(e.athlete&&e.athlete.displayName||"").split(" "),a=t[0]||"",n=t.slice(1).join(" ")||"",i=e.athlete&&e.athlete.position&&e.athlete.position.abbreviation||"G",l={first_name:a,last_name:n,starting_position:e.starter||e.started?i:"",on_court:e.active?"1":"0",position_short:i};e.stats&&Array.isArray(e.stats)&&e.stats.forEach((t,o)=>{const a=s[o],n=r[a];if(n)if(a.includes("Made-fieldGoalsAttempted")||a.includes("Made-threePointFieldGoalsAttempted")||a.includes("Made-freeThrowsAttempted")){const e=t.split("-"),o=f()(e,2),n=o[0],s=o[1],r=a.includes("fieldGoals")?"field_goals":a.includes("threePoint")?"three_pointers":"free_throws";l[r+"_made"]=n||"0",l[r+"_attempted"]=s||"0"}else if("fieldGoalsMade-fieldGoalsAttempted"===a){const e=t.split("-"),o=f()(e,2),a=o[0],n=o[1];l.field_goals_made=a||"0",l.field_goals_attempted=n||"0"}else if("threePointFieldGoalsMade-threePointFieldGoalsAttempted"===a){const e=t.split("-"),o=f()(e,2),a=o[0],n=o[1];l.three_pointers_made=a||"0",l.three_pointers_attempted=n||"0"}else if("freeThrowsMade-freeThrowsAttempted"===a){const e=t.split("-"),o=f()(e,2),a=o[0],n=o[1];l.free_throws_made=a||"0",l.free_throws_attempted=n||"0"}else if("rebounds"===a){l.rebounds=t;const o=e.stats[s.indexOf("offensiveRebounds")]||"0",a=e.stats[s.indexOf("defensiveRebounds")]||"0";l.rebounds_offensive=o,l.rebounds_defensive=a}else l[n]=t}),o.push(l)}),o};var Be={getGames:e=>n()(function*(){let t;const o=(e=>{const t=new Date(e);return`${t.getFullYear()}${String(t.getMonth()+1).padStart(2,"0")}${String(t.getDate()).padStart(2,"0")}`})(t=e&&e.year&&e.month&&e.day?new Date(e.year,e.month-1,e.day):e instanceof Date?e:new Date);return{sports_content:{games:{game:((yield Me.get(`/scoreboard?dates=${o}`)).data.events||[]).map(Ge)}}}})(),getBoxScore:({gameId:e})=>n()(function*(){const t=(yield Me.get(`/summary?event=${e}`)).data,o=t.header&&t.header.competitions&&t.header.competitions[0],a=o&&o.competitors&&o.competitors.find(e=>"home"===e.homeAway),n=o&&o.competitors&&o.competitors.find(e=>"away"===e.homeAway),s=a&&a.team&&a.team.id,r=n&&n.team&&n.team.id,i=a&&a.linescores||[],l=n&&n.linescores||[],c=e=>e&&Array.isArray(e)?e.map((e,t)=>({period_value:(t+1).toString(),score:e.displayValue||"0"})):[],d=c(i),p=c(l),u=(e=>{if(!e||!Array.isArray(e))return{};const t={},o={points:"Points",rebounds:"Rebounds",assists:"Assists"};return e.forEach(e=>{const a=e.team&&e.team.id;if(!a)return;const n={};e.leaders&&Array.isArray(e.leaders)&&e.leaders.forEach(e=>{if(!e.leaders||0===e.leaders.length)return;const t=e.leaders[0],a=t.athlete;if(!a)return;const s=(a.displayName||a.fullName||"").split(" "),r=o[e.name]||e.name;n[r]={StatValue:t.displayValue||t.value||"0",leader:[{FirstName:s[0]||"",LastName:s.slice(1).join(" ")||""}]}}),t[a]=n}),t})(t.leaders),m=t.boxscore&&t.boxscore.teams&&t.boxscore.teams.find(e=>e.team&&e.team.id===s),g=t.boxscore&&t.boxscore.teams&&t.boxscore.teams.find(e=>e.team&&e.team.id===r),h=a&&a.score,f=n&&n.score,y=(e,t)=>{if(!e||!Array.isArray(e))return{};const o={};return e.forEach(e=>{if("fieldGoalsMade-fieldGoalsAttempted"===e.name){const t=e.displayValue.split("-");o.field_goals_made=t[0]||"0",o.field_goals_attempted=t[1]||"0"}else if("threePointFieldGoalsMade-threePointFieldGoalsAttempted"===e.name){const t=e.displayValue.split("-");o.three_pointers_made=t[0]||"0",o.three_pointers_attempted=t[1]||"0"}else if("freeThrowsMade-freeThrowsAttempted"===e.name){const t=e.displayValue.split("-");o.free_throws_made=t[0]||"0",o.free_throws_attempted=t[1]||"0"}else"offensiveRebounds"===e.name?o.rebounds_offensive=e.displayValue||"0":"defensiveRebounds"===e.name?o.rebounds_defensive=e.displayValue||"0":"rebounds"===e.name?o.rebounds=e.displayValue||"0":"points"===e.name?o.points=e.displayValue||"0":"assists"===e.name?o.assists=e.displayValue||"0":"steals"===e.name?o.steals=e.displayValue||"0":"blocks"===e.name?o.blocks=e.displayValue||"0":"turnovers"===e.name?o.turnovers=e.displayValue||"0":"fouls"===e.name&&(o.fouls=e.displayValue||"0")}),void 0!==t&&(o.points=t.toString()),o};return{sports_content:{game:{home:{stats:y(m&&m.statistics,h),linescores:d,players:{player:Ee(t.boxscore&&t.boxscore.players,s)},Leaders:u[s]||{}},visitor:{stats:y(g&&g.statistics,f),linescores:p,players:{player:Ee(t.boxscore&&t.boxscore.players,r)},Leaders:u[r]||{}},arena:t.gameInfo&&t.gameInfo.venue&&t.gameInfo.venue.fullName||"",city:t.gameInfo&&t.gameInfo.venue&&t.gameInfo.venue.address&&t.gameInfo.venue.address.city||"",state:t.gameInfo&&t.gameInfo.venue&&t.gameInfo.venue.address&&t.gameInfo.venue.address.state||"",date:o&&o.date||"",time:"",broadcasters:{tv:{broadcaster:t.broadcasts||[]}}},sports_meta:{season_meta:{display_year:t.header&&t.header.season&&t.header.season.year,display_season:t.header&&t.header.season&&2===t.header.season.type?"Regular Season":"Playoffs"}}}}})(),getPlayByPlay:({gameId:e})=>n()(function*(){return{sports_content:{game:{play:((yield Me.get(`/summary?event=${e}`)).data.plays||[]).map((e,t)=>({period:e.period&&e.period.number&&e.period.number.toString()||"",description:e.text||"",home_score:e.homeScore&&e.homeScore.toString()||"0",visitor_score:e.awayScore&&e.awayScore.toString()||"0",clock:e.clock&&e.clock.displayValue?e.clock.displayValue:"",id:e.id||t.toString()}))}}}})(),updatePlayers:()=>n()(function*(){return[]})(),searchPlayers:()=>n()(function*(){return[]})(),playerInfo:()=>n()(function*(){return{}})(),playerProfile:()=>n()(function*(){return{}})(),teamSplits:({TeamID:e})=>n()(function*(){return{overallTeamDashboard:[{teamId:e,gp:"0",w:"0",l:"0",pts:"0",fgPct:0,fg3Pct:0,ftPct:0,oreb:"0",dreb:"0",reb:"0",ast:"0",blk:"0",stl:"0",tov:"0",pf:"0",plusMinus:"0"}]}})(),teamInfoCommon:({TeamID:e})=>n()(function*(){return{teamInfoCommon:[{teamId:e,teamCity:"",teamName:"",teamAbbreviation:"",w:"0",l:"0",divRank:"0"}]}})()},qe=o(32),Re=o.n(qe);const Ve=e=>{Re.a.say(P()(e,"YYYY/MM/DD"),{font:"block",align:"left",colors:["blue","red"],background:"black",letterSpacing:1,lineHeight:1,space:!0,maxLength:"10"})};var Ye=o(5),We=o.n(Ye),He=o(4),Qe=o.n(He);var Ue=(e,t)=>{const o=Qe.a.screen({smartCSR:!0,fullUnicode:!0,title:"NBA-GO"}),a=Qe.a.box({top:0,left:0,width:"100%",height:"100%",padding:0,style:{fg:"black",bg:"black",border:{fg:"#f0f0f0",bg:"black"}}}),n=Qe.a.table({top:5,left:"center",width:"33%",height:8,tags:!0,border:{type:"line"},style:{header:{fg:"white"},cell:{fg:"white"}}}),s=Qe.a.text({parent:o,top:7,left:`33%-${e.getFullName({color:!1}).length+24}`,width:25,align:"left",content:`${e.getFullName({color:!0})}`,style:{fg:"white"}}),r=Qe.a.text({top:8,left:"33%-39",width:15,align:"right",content:Object(G.right)(`HOME (${e.getWins()} - ${e.getLoses()})`,15),style:{fg:"#fbfbfb"}}),i=Qe.a.bigtext({font:We.a.join(__dirname,"./fonts/ter-u12n.json"),fontBold:We.a.join(__dirname,"./fonts/ter-u12b.json"),top:2,left:"33%-20",width:15,align:"right",vlign:"center",style:{fg:"white"}}),l=Qe.a.text({top:7,left:"66%+28",width:25,align:"left",content:`${t.getFullName({color:!0})}`,tags:!0,style:{fg:"white"}}),c=Qe.a.text({top:8,left:"66%+28",width:15,align:"left",content:`(${t.getWins()} - ${t.getLoses()}) AWAY`,style:{fg:"#fbfbfb"}}),d=Qe.a.bigtext({font:We.a.join(__dirname,"./fonts/ter-u12n.json"),fontBold:We.a.join(__dirname,"./fonts/ter-u12b.json"),top:2,left:"66%+6",width:15,align:"left",style:{fg:"white"}}),p=Qe.a.text({top:0,left:"center",align:"center",style:{fg:"white"}}),u=Qe.a.text({top:13,left:"center",align:"center",style:{fg:"white"}}),m=Qe.a.text({top:2,left:"center",align:"center",style:{fg:"white"}}),g=Qe.a.text({top:3,left:"center",align:"center",style:{fg:"white"}}),h=Qe.a.text({top:4,left:"center",align:"center",style:{fg:"white"}}),f=Qe.a.box({parent:o,top:15,left:3,width:"70%-3",height:"100%-15",padding:{top:0,right:0,left:2,bottom:0},align:"left",keys:!0,mouse:!1,scrollable:!0,focused:!0,label:" Play By Play ",border:{type:"line"},scrollbar:{ch:" ",track:{bg:"#0253a4"},style:{inverse:!0}}}),y=Qe.a.table({parent:o,top:15,left:"70%",width:"30%-3",height:"100%-15",tags:!0,pad:0,label:" Box Score ",border:{type:"line"}});return o.append(a),o.append(p),o.append(u),o.append(m),o.append(g),o.append(h),o.append(s),o.append(r),o.append(i),o.append(l),o.append(c),o.append(d),o.append(n),o.append(f),o.append(y),o.key(["escape","q","C-c"],()=>process.exit(1)),{screen:o,scoreboardTable:n,seasonText:p,timeText:u,dateText:m,arenaText:g,networkText:h,homeTeamScoreText:i,visitorTeamScoreText:d,playByPlayBox:f,boxscoreTable:y}};var Ke=(e,t,o=!0)=>{console.log(""),console.log(""),V(e),console.log(""),V(`Oops, ${t} goes wrong.`),V("Please run nba-go again.\nIf it still does not work, feel free to open an issue on https://github.com/xxhomey19/nba-go/issues"),o&&process.exit(1)};const ze=e=>new Promise(t=>setTimeout(t,e));class Je{constructor(e={}){this.minInterval=e.minInterval||2e3,this.maxInterval=e.maxInterval||1e4,this.currentInterval=this.minInterval,this.lastPlayCount=0,this.lastPlayHash="",this.consecutiveNoChange=0,this.isLastTwoMinutes=!1,this.gameStatus="2"}updateGameState(e,t){const o=+(e.period||0),a=e.clock||"",n=(e.description||"").toLowerCase();let s=99;if(a){const e=a.split(":");e.length>=2&&(s=parseInt(e[0],10)||0)}this.isLastTwoMinutes=(4===o||o>4)&&s<=2;const r=n.includes("timeout")||n.includes("break")||n.includes("end period")||n.includes("start period"),i=`${e.period}-${e.clock}-${e.home_score}-${e.visitor_score}`,l=t>this.lastPlayCount||i!==this.lastPlayHash;return l?this.consecutiveNoChange=0:this.consecutiveNoChange++,this.lastPlayCount=t,this.lastPlayHash=i,{hasNewData:l,isTimeout:r}}calculateInterval(e,t){return"Halftime"===this.gameStatus?1e4:this.isLastTwoMinutes?e?1500:2e3:t?8e3:(this.currentInterval=e?Math.max(this.minInterval,this.currentInterval-500):Math.min(this.maxInterval,this.currentInterval+1e3),this.currentInterval)}}const Xe=function(){var e=n()(function*(e,t){if(t.filter&&"team"===t.filter.split("=")[0]){const o=t.filter.split("=")[1].toLowerCase(),a=e.filter(e=>-1!==`${e.home.city.toLowerCase()} ${e.home.nickname.toLowerCase()}`.indexOf(o)||-1!==`${e.visitor.city.toLowerCase()} ${e.visitor.nickname.toLowerCase()}`.indexOf(o));if(a.length){if(1===a.length){const e=yield te(a[0].home),t=yield te(a[0].visitor);return{game:{gameData:a[0],homeTeam:e,visitorTeam:t}}}return oe(a)}V(`Can't find any teams that match ${o}`)}return oe(e,t)});return function(t,o){return e.apply(this,arguments)}}();var Ze=function(){var e=n()(function*(e){let t,o,a,n;e.date?$.a.compose(F.a,_.a)(e.date)?t=P()(e.date,"YYYY-MM-DD"):(V("Date is invalid"),process.exit(1)):e.today?t=Date.now():e.tomorrow?t=S()(Date.now(),1):e.yesterday?t=A()(Date.now(),1):(V(`Can't find any option ${N.a.get("confused")}`),process.exit(1)),$.a.compose(Ve,Ie)(t);const s=function(e){const t=Le.DateTime.fromJSDate(Ce()(e),{zone:"America/New_York"}).startOf("day");return{year:t.year,month:t.month,day:t.day}}(t);try{o=(yield Be.getGames(s)).sports_content.games.game}catch(e){Ke(e,"NBA.getGames()")}const r=(yield Xe(o,e)).game,i=r.homeTeam,l=r.visitorTeam,c=r.gameData;try{const e=(yield Be.getBoxScore(b()({},s,{gameId:c.id}))).sports_content,t=e.game,o=e.sports_meta.season_meta;a=t,n=o}catch(e){Ke(e,"NBA.getBoxScore()")}const d=a,p=d.home,u=d.visitor;i.setGameStats(p.stats),i.setPlayers(p.players.player),i.setGameLeaders(p.Leaders),i.setLinescores(p.linescores),l.setGameStats(u.stats),l.setPlayers(u.players.player),l.setGameLeaders(u.Leaders),l.setLinescores(u.linescores);const m=Ue(i,l),g=m.screen,h=m.scoreboardTable,y=m.seasonText,v=m.timeText,x=m.dateText,w=m.arenaText,k=m.networkText,T=m.homeTeamScoreText,j=m.visitorTeamScoreText,I=m.playByPlayBox,C=m.boxscoreTable;switch(c.period_time.game_status){case"1":{g.destroy(),console.log("");const e=L()("Loading Game Preview").start();let t,o;try{const e=yield Be.teamSplits({Season:process.env.season,TeamID:i.getID()}),a=f()(e.overallTeamDashboard,1)[0],n=yield Be.teamSplits({Season:process.env.season,TeamID:l.getID()}),s=f()(n.overallTeamDashboard,1)[0];t=a,o=s}catch(e){Ke(e,"NBA.teamSplits()",!1),t={},o={}}e.stop(),le(i,l,b()({},n,a,{homeTeamDashboardData:t,visitorTeamDashboardData:o}));break}case"Halftime":case"2":{let e,t;const o=new Je({minInterval:1500,maxInterval:8e3});o.gameStatus=c.period_time.game_status,y.setContent(Y(`${n.display_year} ${n.display_season}`));const r=a,d=r.arena,p=r.city,u=r.state,m=r.date,f=r.time,$=r.broadcasters,_=q($.tv.broadcaster);for(x.setContent(`${N.a.get("calendar")} ${P()(m,"YYYY/MM/DD")} ${f.slice(0,2)}:${f.slice(2,4)}`),w.setContent(`${N.a.get("house")} ${d} | ${p}, ${u}`),k.setContent(`${_.homeTeam} ${N.a.get("tv")} ${_.visitorTeam}`);;){let r={};try{e=(yield Be.getPlayByPlay(b()({},s,{gameId:c.id}))).sports_content.game}catch(e){Ke(e,"NBA.getPlayByPlay()")}try{t=(yield Be.getBoxScore(b()({},s,{gameId:c.id}))).sports_content.game}catch(e){Ke(e,"NBA.getBoxScore()")}a=t;const d=(r=e).play||[],p=d.slice(-1).pop(),u=o.updateGameState(p,d.length),m=u.hasNewData,f=u.isTimeout;i.setScore(p.home_score),l.setScore(p.visitor_score);const y=("4"===p.period||+p.period>4)&&"End Period"===p.description&&p.home_score!==p.visitor_score;if(Ae(i,l,b()({},r,n,{isFinal:y,hasNewData:m,isLastTwoMinutes:o.isLastTwoMinutes}),a,{screen:g,scoreboardTable:h,timeText:v,homeTeamScoreText:T,visitorTeamScoreText:j,playByPlayBox:I,boxscoreTable:C}),y)break;const $=o.calculateInterval(m,f);yield ze($)}break}case"3":default:g.destroy(),console.log(""),he(i,l,b()({},a,n)),console.log(""),ve(i,l)}});return function(t){return e.apply(this,arguments)}}(),et=o(10),tt=o.n(et),ot=o(33),at=o.n(ot);const nt=function(){var e=n()(function*(e,t){return(yield De.a.get("https://api.twelvedata.com/quote",{params:{symbol:e.toUpperCase(),apikey:t}})).data});return function(t,o){return e.apply(this,arguments)}}(),st=function(){var e=n()(function*(e,t){return(yield De.a.get("https://api.twelvedata.com/statistics",{params:{symbol:e.toUpperCase(),apikey:t}})).data});return function(t,o){return e.apply(this,arguments)}}(),rt=function(){var e=n()(function*(e,t,o=30){return(yield De.a.get("https://api.twelvedata.com/time_series",{params:{symbol:e.toUpperCase(),apikey:t,interval:"1day",outputsize:o,format:"JSON"}})).data});return function(t,o){return e.apply(this,arguments)}}();var it=function(){var e=n()(function*(e){e||(V("Please provide a stock symbol"),console.log(` Example: ${H("nba-go stock AAPL")}`),process.exit(1));const t=(()=>{if(process.env.TWELVEDATA_API_KEY)return process.env.TWELVEDATA_API_KEY;const e=process.argv.find(e=>e.startsWith("--api-key="));if(e)return e.split("=")[1];const t=We.a.join(process.cwd(),".nba-go-config.json");if(tt.a.existsSync(t))try{const e=JSON.parse(tt.a.readFileSync(t,"utf8"));if(e.twelvedataApiKey)return e.twelvedataApiKey}catch(e){}const o=We.a.join(at.a.homedir(),".nba-go-config.json");if(tt.a.existsSync(o))try{const e=JSON.parse(tt.a.readFileSync(o,"utf8"));if(e.twelvedataApiKey)return e.twelvedataApiKey}catch(e){}})();t||(V("TwelveData API key not found."),console.log(""),["Please set your API key in one of these ways:"," 1. Config file: ~/.nba-go-config.json",' Content: { "twelvedataApiKey": "your-key" }'," 2. Environment variable: TWELVEDATA_API_KEY=your-key nba-go stock AAPL"," 3. Command line: nba-go stock AAPL --api-key=your-key"].forEach(e=>console.log(e)),process.exit(1));const o=L()(`Loading stock data for ${e.toUpperCase()}...`).start();try{const a=yield Promise.all([nt(e,t),st(e,t)]),n=f()(a,2),s=n[0],r=n[1];o.stop();const i=yield rt(e,t,30);let l=[];"error"!==i.status&&i.values&&(l=i.values.reverse());const c=Array.isArray(s)?s[0]:s;"error"!==c.status&&(c.price||c.close)||(V(`Could not find stock: ${e}`),console.log(`Error: ${c.message||"Unknown error"}`),process.exit(1));const d=((e,t)=>{const o=parseFloat(e.price||e.close||0),a=parseFloat(e.previous_close||e.previousClose||o),n=parseFloat(e.change||o-a),s=parseFloat(e.percent_change||e.percentChange||n/a*100),r=n>=0?u.a.green:u.a.red,i=n>=0?"+":"";return{symbol:e.symbol,name:e.name||e.symbol,exchange:e.exchange||"N/A",price:o,change:n,changePercent:s,changeColor:r,changeSign:i,open:parseFloat(e.open||0),high:parseFloat(e.high||0),low:parseFloat(e.low||0),volume:parseInt(e.volume||0,10),week52High:t.fifty_two_week&&t.fifty_two_week.high?parseFloat(t.fifty_two_week.high):null,week52Low:t.fifty_two_week&&t.fifty_two_week.low?parseFloat(t.fifty_two_week.low):null,marketCap:t.valuations&&t.valuations.market_cap?parseFloat(t.valuations.market_cap):null,currency:e.currency||"USD"}})(c,r),p=(e=>{const t=new ne.a({head:[Y("Metric"),Y("Value")],colWidths:[20,40]});return t.push(["Symbol",u.a.bold(e.symbol)],["Name",e.name],["Exchange",e.exchange],["Price",`$${e.price.toFixed(2)}`],["Change",e.changeColor(`${e.changeSign}${e.change.toFixed(2)} (${e.changeSign}${e.changePercent.toFixed(2)}%)`)],["Open",`$${e.open.toFixed(2)}`],["High",`$${e.high.toFixed(2)}`],["Low",`$${e.low.toFixed(2)}`],["Volume",e.volume.toLocaleString()],["52W High",e.week52High?`$${e.week52High.toFixed(2)}`:"N/A"],["52W Low",e.week52Low?`$${e.week52Low.toFixed(2)}`:"N/A"],["Market Cap",e.marketCap?`$${(e.marketCap/1e9).toFixed(2)}B`:"N/A"]),t})(d);console.log(""),console.log(p.toString()),l.length>0&&(console.log(""),console.log(((e,t=70,o=14)=>{if(!e||0===e.length)return"";const a=e.map(e=>parseFloat(e.close)),n=e.map(e=>e.datetime),s=Math.max(...a),r=Math.min(...a),i=s-r||1,l=a[0],c=a[a.length-1],d=c-l,p=d/l*100,m=d>=0?u.a.green:u.a.red,g=d>=0?"▲":"▼",h=Array(o).fill(null).map(()=>Array(t).fill(" ")),f=a.map((e,n)=>({x:Math.round(n/(a.length-1)*(t-1)),y:o-1-Math.round((e-r)/i*(o-1)),price:e,isUp:n>0&&e>=a[n-1]}));for(let e=0;e<f.length-1;e++){const a=f[e],n=f[e+1],s=n.price>=a.price,r=s?u.a.green("│"):u.a.red("│"),i=s?u.a.green("╱"):u.a.red("╱"),l=s?u.a.green("╲"):u.a.red("╲"),c=s?u.a.green("─"):u.a.red("─"),d=n.x-a.x,p=n.y-a.y,m=Math.max(Math.abs(d),Math.abs(p));for(let e=0;e<=m;e++){const n=0===m?0:e/m,s=Math.round(a.x+d*n),u=Math.round(a.y+p*n);u>=0&&u<o&&s>=0&&s<t&&(h[u][s]=0===d?r:0===p?c:p<0?i:l)}}f.forEach((e,a)=>{if(e.y>=0&&e.y<o&&e.x>=0&&e.x<t)if(0===a)h[e.y][e.x]=u.a.cyan("◆");else if(a===f.length-1)h[e.y][e.x]=m(g);else{const t=e.isUp?u.a.green("●"):u.a.red("●");h[e.y][e.x]=t}});const y=[],b=`${m(g)} ${u.a.bold("30-Day Trend")} | Start: $${l.toFixed(2)} → End: $${c.toFixed(2)} | Change: ${d>=0?"+":""}${d.toFixed(2)} (${p>=0?"+":""}${p.toFixed(2)}%)`;y.push(b),y.push("");const v=s.toFixed(2).padStart(10);y.push(`${u.a.gray(v)} ┌${"─".repeat(t)}┐`);for(let e=0;e<o;e++){const t=s-e/(o-1)*i;let a;a=0===e?" ".repeat(10):e===o-1?" ".repeat(10):e===Math.floor(o/2)?u.a.gray(t.toFixed(2).padStart(10)):" ".repeat(10);const n=h[e].map((t,o)=>" "===t&&e%2==0&&o%4==0?u.a.gray("·"):t);y.push(`${a} │${n.join("")}${u.a.gray("│")}`)}const $=r.toFixed(2).padStart(10);y.push(`${u.a.gray($)} └${"─".repeat(t)}┘`);const x=n[0],_=n[n.length-1],w=`${x.slice(5,7)}/${x.slice(8,10)}`,S=`${_.slice(5,7)}/${_.slice(8,10)}`,k=" ".repeat(11)+u.a.gray(w.padEnd(t/2-2))+u.a.gray(S.padStart(t/2-2));y.push(k);const A=Math.max(...a),T=Math.min(...a),P=a.reduce((e,t)=>e+t,0)/a.length;return y.push(""),y.push(u.a.gray(` High: $${A.toFixed(2)} | Low: $${T.toFixed(2)} | Avg: $${P.toFixed(2)} | Days: ${a.length}`)),y.join("\n")})(l))),console.log(""),console.log(`Data provided by TwelveData | Currency: ${d.currency}`),console.log("")}catch(e){o.stop(),V(`Failed to fetch stock data: ${e.message}`),e.response&&(console.log(`Status: ${e.response.status}`),console.log(`Message: ${e.response.data&&e.response.data.message?e.response.data.message:"Unknown error"}`)),process.exit(1)}});return function(t){return e.apply(this,arguments)}}(),lt=o(19),ct=o.n(lt);const dt=We.a.join(process.cwd(),"novels"),pt=()=>{tt.a.existsSync(dt)||tt.a.mkdirSync(dt,{recursive:!0});const e=tt.a.readdirSync(dt),t=[];return e.forEach(e=>{if(".txt"===We.a.extname(e).toLowerCase()){const o=tt.a.statSync(We.a.join(dt,e));t.push({id:e,title:We.a.basename(e,".txt"),author:"未知作者",description:"本地TXT小说",filePath:We.a.join(dt,e),size:o.size,modified:o.mtime})}}),t},ut=e=>{const t=pt();if(!e||""===e.trim())return t;const o=e.toLowerCase();return t.filter(e=>e.title.toLowerCase().includes(o)||e.author.toLowerCase().includes(o))},mt=e=>{const t=pt().find(t=>t.id===e);if(!t)return null;try{const e=gt(t.filePath),o=ht(e);return b()({},t,{chapters:o,content:e})}catch(e){return console.error("读取小说失败:",e.message),null}},gt=e=>{const t=tt.a.readFileSync(e);try{const e=t.toString("utf-8");if(!e.includes("�"))return e}catch(e){}try{return ct.a.decode(t,"gbk")}catch(e){}try{return ct.a.decode(t,"gb2312")}catch(e){}return t.toString("utf-8")},ht=e=>{const t=[],o=[/^第[一二三四五六七八九十百千万零\d]+章\s*.+$/gm,/^第[一二三四五六七八九十百千万零\d]+卷\s*.+$/gm,/^第[一二三四五六七八九十百千万零\d]+节\s*.+$/gm,/^Chapter\s*\d+.*$/gim,/^\d+[.、]\s*.+$/gm,/^正文\s*\d+.*$/gm],a=e.split("\n");let n={id:"ch0",title:"序章",content:""},s=0;return a.forEach(e=>{const a=e.trim();let r=!1,i="";for(var l=0;l<o.length;l++){const e=o[l],t=a.match(e);if(t&&t[0]===a){r=!0,i=a;break}}r?(n.content&&t.push({id:n.id,title:n.title,content:n.content.trim()}),n={id:`ch${++s}`,title:i,content:""}):n.content+=e+"\n"}),n.content&&t.push({id:n.id,title:n.title,content:n.content.trim()}),0===t.length&&t.push({id:"ch1",title:"全文",content:e.trim()}),t},ft=()=>`\n请将TXT格式的小说文件放入以下目录:\n ${dt}\n\n支持的编码格式:UTF-8、GBK、GB2312\n\n使用示例:\n nba-go novel\n`,yt=function(){var e=n()(function*(){return(yield D.a.prompt([{type:"input",name:"keyword",message:"请输入书名或作者名(留空显示所有):"}])).keyword.trim()});return function(){return e.apply(this,arguments)}}(),bt=function(){var e=n()(function*(e){if(0===e.length)return null;const t=e.map(e=>({name:`${e.title} | ${(e.size/1024).toFixed(1)} KB`,value:e,short:e.title}));return t.push({name:"返回搜索",value:null,short:"搜索"}),(yield D.a.prompt([{type:"list",name:"selected",message:"请选择小说:",choices:t,pageSize:10}])).selected});return function(t){return e.apply(this,arguments)}}(),vt=function(){var e=n()(function*(e){const t=e.chapters.map(e=>({name:e.title,value:e,short:e.title}));return t.push({name:"返回小说详情",value:null,short:"返回"}),(yield D.a.prompt([{type:"list",name:"selected",message:`《${e.title}》- 选择章节:`,choices:t,pageSize:15}])).selected});return function(t){return e.apply(this,arguments)}}(),$t=(e,t,o)=>{console.clear(),console.log(""),console.log(u.a.bold.cyan("━".repeat(70)));const a=`《${e.title}》 - ${t.title}`,n=Math.max(0,Math.floor((70-a.length)/2));if(console.log(" ".repeat(n)+u.a.bold(a)),console.log(u.a.bold.cyan("━".repeat(70))),console.log(""),o&&"暂无内容"!==o){const e=o.split("\n").filter(e=>e.trim()),t=60;e.forEach(e=>{const o=e.trim();if(!o)return;let a="";var n=!0,s=!1,r=void 0;try{for(var i,l=o[Symbol.iterator]();!(n=(i=l.next()).done);n=!0){const e=i.value;a.length>=t&&(console.log(" "+a),a=""),a+=e}}catch(e){s=!0,r=e}finally{try{n||null==l.return||l.return()}finally{if(s)throw r}}a&&console.log(" "+a),console.log("")})}else console.log(u.a.gray(" 暂无章节内容"));console.log(u.a.gray(" ─".repeat(35))),console.log("")},xt=function(){var e=n()(function*(e=!0,t=!0){const o=[];return e&&o.push({name:"下一章",value:"next",short:"下一章"}),t&&o.push({name:"上一章",value:"prev",short:"上一章"}),o.push({name:"返回章节列表",value:"list",short:"章节列表"},{name:"返回搜索",value:"search",short:"搜索"},{name:"退出",value:"exit",short:"退出"}),(yield D.a.prompt([{type:"list",name:"action",message:"选择操作:",choices:o}])).action});return function(){return e.apply(this,arguments)}}(),_t=(e,t)=>{const o=e.chapters.findIndex(e=>e.id===t);return-1===o||o>=e.chapters.length-1?null:e.chapters[o+1]},wt=(e,t)=>{const o=e.chapters.findIndex(e=>e.id===t);return o<=0?null:e.chapters[o-1]},St=function(){var e=n()(function*(){console.log(""),console.log(H("📚 欢迎使用小说阅读功能")),console.log("");let e=yield yt();for(;;){const t=L()("扫描本地小说...").start();try{const o=ut(e);if(t.stop(),0===o.length){if(console.log(""),console.log(ft()),console.log(""),e&&V(`未找到包含 "${e}" 的小说`),(yield bt([])).retry){e=yield yt();continue}return}console.log(`\n找到 ${o.length} 本小说:\n`);const a=yield bt(o);if(!a){e=yield yt();continue}(yield kt(a))&&(e=yield yt())}catch(e){return t.stop(),void V(`操作失败: ${e.message}`)}}});return function(){return e.apply(this,arguments)}}(),kt=function(){var e=n()(function*(e){const t=L()("加载小说详情...").start();try{const o=mt(e.id);if(t.stop(),!o)return V("加载小说详情失败"),!0;console.log(""),console.log((e=>{const t=new ne.a({head:[Y("属性"),Y("内容")],colWidths:[15,55]});return t.push(["书名",u.a.cyan.bold(e.title)],["文件大小",`${(e.size/1024).toFixed(1)} KB`],["章节数",e.chapters.length.toString()]),t})(o).toString()),console.log("");let a=yield vt(o);for(;;){if(!a)return!0;$t(o,a,a.content);const e=null!==_t(o,a.id),t=null!==wt(o,a.id);switch(yield xt(e,t)){case"next":{const e=_t(o,a.id);e?a=e:V("已经是最后一章了");break}case"prev":{const e=wt(o,a.id);e?a=e:V("已经是第一章了");break}case"list":a=yield vt(o);break;case"search":return!0;case"exit":console.log(""),console.log(H("感谢使用,再见!")),process.exit(0)}}}catch(e){return t.stop(),V(`加载失败: ${e.message}`),!0}});return function(t){return e.apply(this,arguments)}}();var At=St,Tt=o(20);d()()||o(34),n()(function*(){yield g()({pkg:Tt}).notify({defer:!1})})(),r.a.version(`DAILY CLI version: ${Tt.version}`,"-v, --version"),r.a.command("game").alias("g").option("-d, --date <date>","Watch games at specific date").option("-y, --yesterday","Watch yesterday's games").option("-t, --today","Watch today's games").option("-T, --tomorrow","Watch tomorrow's games").option("-f, --filter <filter>","Filter game choices to watch").option("-n, --networks","See the networks game is/was televised on.").on("--help",()=>{console.log(""),console.log(" Watch NBA live play-by-play, game preview and box score."),console.log(" You have to enter what day's schedule at first."),console.log(` Notice that if you don't provide any option, default date will be ${H("today")}.`),console.log(""),console.log(" Example:"),console.log(` ${H("daily game -d 2017/11/11")} => Show game schedule on 2017/11/11.`),console.log(` ${H("daily game -t")} => Show today's game schedule.`),console.log(""),console.log(` For more detailed information, please check the GitHub page: ${H("https://github.com/linwei/daily-cli#game")} `)}).action(e=>{e.date||e.yesterday||e.today||e.tomorrow||(e.today=!0),Ze(e)}),r.a.command("stock <symbol>").alias("s").description("Get stock price information").on("--help",()=>{console.log(""),console.log(" Get current stock price and market data."),console.log(""),console.log(" Example:"),console.log(` ${H("daily stock AAPL")} => Show Apple stock price.`),console.log(` ${H("daily stock TSLA")} => Show Tesla stock price.`),console.log("")}).action(e=>{it(e)}),r.a.command("novel").alias("n").description("Search and read novels").on("--help",()=>{console.log(""),console.log(" Search for novels by title or author name."),console.log(" Then select a novel and choose chapters to read."),console.log(""),console.log(" Example:"),console.log(` ${H("daily novel")} => Start novel search.`),console.log("")}).action(()=>{At()}),r.a.on("--help",()=>{console.log(""),console.log(""),console.log(" Welcome to DAILY CLI!"),console.log(""),console.log(` Wanna watch NBA game please enter: ${H("daily game")}`),console.log(""),console.log(` For more detailed information please check the GitHub page: ${H("https://github.com/linwei/daily-cli")}`),console.log(` Or enter ${H("daily game -h")} to get more helpful information.`),console.log("")}),r.a.command("*").action(e=>{V(`Unknown command: ${Y(e)}`);const t=r.a.commands.map(e=>e._name).filter(e=>"*"!==e),o=l()(e,t);o&&V(`Did you mean ${Y(o)} ?`),process.exit(1)}),2===process.argv.length&&r.a.help(),r.a.parse(process.argv)}]);