warframe-worldstate-parser 2.31.1 → 3.0.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.
Files changed (98) hide show
  1. package/README.md +1 -0
  2. package/lib/WorldState.js +60 -94
  3. package/lib/models/Alert.js +18 -44
  4. package/lib/models/CambionCycle.js +8 -12
  5. package/lib/models/CetusCycle.js +34 -54
  6. package/lib/models/ChallengeInstance.js +11 -14
  7. package/lib/models/ConclaveChallenge.js +24 -44
  8. package/lib/models/ConstructionProgress.js +10 -22
  9. package/lib/models/DailyDeal.js +15 -34
  10. package/lib/models/DarkSector.js +14 -25
  11. package/lib/models/DarkSectorBattle.js +6 -8
  12. package/lib/models/DuviriCycle.js +9 -10
  13. package/lib/models/EarthCycle.js +36 -35
  14. package/lib/models/Fissure.js +36 -44
  15. package/lib/models/FlashSale.js +17 -37
  16. package/lib/models/GlobalUpgrade.js +23 -41
  17. package/lib/models/Invasion.js +37 -79
  18. package/lib/models/Kuva.js +20 -26
  19. package/lib/models/Mission.js +28 -38
  20. package/lib/models/News.js +34 -54
  21. package/lib/models/Nightwave.js +22 -48
  22. package/lib/models/NightwaveChallenge.js +19 -17
  23. package/lib/models/PersistentEnemy.js +21 -30
  24. package/lib/models/Reward.js +18 -20
  25. package/lib/models/SentientOutpost.js +11 -12
  26. package/lib/models/Simaris.js +9 -21
  27. package/lib/models/Sortie.js +36 -54
  28. package/lib/models/SortieVariant.js +23 -25
  29. package/lib/models/SteelPathOffering.js +26 -9
  30. package/lib/models/SyndicateJob.js +20 -30
  31. package/lib/models/SyndicateMission.js +22 -52
  32. package/lib/models/VallisCycle.js +37 -45
  33. package/lib/models/VoidTrader.js +35 -54
  34. package/lib/models/VoidTraderItem.js +5 -8
  35. package/lib/models/VoidTraderSchedule.js +7 -6
  36. package/lib/models/WeeklyChallenge.js +9 -17
  37. package/lib/models/WorldEvent.js +49 -74
  38. package/lib/models/WorldstateObject.js +23 -34
  39. package/lib/models/ZarimanCycle.js +34 -54
  40. package/lib/supporting/Dependency.js +2 -11
  41. package/lib/supporting/DuviriChoice.js +1 -5
  42. package/lib/supporting/ExternalMission.js +2 -6
  43. package/lib/supporting/MarkdownSettings.js +15 -19
  44. package/lib/supporting/RewardData.js +4 -6
  45. package/lib/supporting/RewardTypes.js +2 -4
  46. package/lib/utilities/integrity.js +11 -0
  47. package/lib/utilities/timeDate.js +16 -18
  48. package/lib/utilities/translation.js +188 -56
  49. package/main.js +2 -2
  50. package/package.json +3 -5
  51. package/types/lib/WorldState.d.ts +39 -28
  52. package/types/lib/models/Alert.d.ts +13 -24
  53. package/types/lib/models/CambionCycle.d.ts +5 -10
  54. package/types/lib/models/CetusCycle.d.ts +8 -26
  55. package/types/lib/models/ChallengeInstance.d.ts +7 -9
  56. package/types/lib/models/ConclaveChallenge.d.ts +11 -24
  57. package/types/lib/models/ConstructionProgress.d.ts +5 -16
  58. package/types/lib/models/DailyDeal.d.ts +7 -26
  59. package/types/lib/models/DarkSector.d.ts +11 -22
  60. package/types/lib/models/DarkSectorBattle.d.ts +3 -6
  61. package/types/lib/models/DuviriCycle.d.ts +5 -11
  62. package/types/lib/models/EarthCycle.d.ts +40 -17
  63. package/types/lib/models/Fissure.d.ts +10 -17
  64. package/types/lib/models/FlashSale.d.ts +8 -29
  65. package/types/lib/models/GlobalUpgrade.d.ts +8 -27
  66. package/types/lib/models/Invasion.d.ts +18 -53
  67. package/types/lib/models/Kuva.d.ts +10 -21
  68. package/types/lib/models/Mission.d.ts +11 -23
  69. package/types/lib/models/News.d.ts +18 -31
  70. package/types/lib/models/Nightwave.d.ts +12 -29
  71. package/types/lib/models/NightwaveChallenge.d.ts +14 -14
  72. package/types/lib/models/PersistentEnemy.d.ts +9 -20
  73. package/types/lib/models/Reward.d.ts +34 -18
  74. package/types/lib/models/SentientOutpost.d.ts +9 -13
  75. package/types/lib/models/Simaris.d.ts +6 -17
  76. package/types/lib/models/Sortie.d.ts +16 -25
  77. package/types/lib/models/SortieVariant.d.ts +13 -15
  78. package/types/lib/models/SteelPathOffering.d.ts +5 -8
  79. package/types/lib/models/SyndicateJob.d.ts +13 -14
  80. package/types/lib/models/SyndicateMission.d.ts +9 -22
  81. package/types/lib/models/VallisCycle.d.ts +28 -18
  82. package/types/lib/models/VoidTrader.d.ts +8 -21
  83. package/types/lib/models/VoidTraderItem.d.ts +4 -6
  84. package/types/lib/models/VoidTraderSchedule.d.ts +5 -8
  85. package/types/lib/models/WeeklyChallenge.d.ts +5 -14
  86. package/types/lib/models/WorldEvent.d.ts +38 -52
  87. package/types/lib/models/WorldstateObject.d.ts +50 -28
  88. package/types/lib/models/ZarimanCycle.d.ts +9 -27
  89. package/types/lib/supporting/Dependency.d.ts +2 -8
  90. package/types/lib/supporting/DuviriChoice.d.ts +1 -2
  91. package/types/lib/supporting/ExternalMission.d.ts +3 -7
  92. package/types/lib/supporting/MarkdownSettings.d.ts +29 -15
  93. package/types/lib/supporting/RewardData.d.ts +8 -2
  94. package/types/lib/supporting/RewardTypes.d.ts +2 -2
  95. package/types/lib/utilities/integrity.d.ts +1 -0
  96. package/types/lib/utilities/timeDate.d.ts +19 -12
  97. package/types/lib/utilities/translation.d.ts +188 -23
  98. package/types/main.d.ts +2 -4
@@ -1,7 +1,12 @@
1
- 'use strict';
1
+ import { steelPath } from '../utilities/translation.js';
2
+ import { timeDeltaToString } from '../utilities/timeDate.js';
2
3
 
3
4
  const monday = 1;
4
5
 
6
+ /**
7
+ * Gets the first day of the week
8
+ * @returns {Date} first day of the week
9
+ */
5
10
  function getFirstDayOfWeek() {
6
11
  const resultDate = new Date();
7
12
  /* istanbul ignore next */
@@ -14,6 +19,10 @@ function getFirstDayOfWeek() {
14
19
  return resultDate;
15
20
  }
16
21
 
22
+ /**
23
+ * Get the last day of the week
24
+ * @returns {Date} last day of the week
25
+ */
17
26
  function getLastDayOfWeek() {
18
27
  const last = new Date(getFirstDayOfWeek());
19
28
  last.setUTCDate(last.getUTCDate() + 6);
@@ -24,6 +33,10 @@ function getLastDayOfWeek() {
24
33
  return last;
25
34
  }
26
35
 
36
+ /**
37
+ * When was the start of the day
38
+ * @returns {Date} start of the day
39
+ */
27
40
  function getStartOfDay() {
28
41
  const today = new Date();
29
42
  today.setUTCHours(0);
@@ -33,6 +46,10 @@ function getStartOfDay() {
33
46
  return today;
34
47
  }
35
48
 
49
+ /**
50
+ * When was the end of the day
51
+ * @returns {Date} end of the day
52
+ */
36
53
  function getEndOfDay() {
37
54
  const last = new Date();
38
55
  last.setUTCHours(23);
@@ -48,28 +65,28 @@ function getEndOfDay() {
48
65
  */
49
66
  const start = new Date('2020-11-16T00:00:00.000Z');
50
67
 
51
- module.exports = class SteelPathOffering {
52
- constructor({ timeDate, translator, locale }) {
68
+ export default class SteelPathOffering {
69
+ constructor({ locale }) {
53
70
  const sSinceStart = (Date.now() - start.getTime()) / 1000;
54
71
  const eightWeeks = 4838400;
55
72
  const sevenDays = 604800;
56
73
 
57
74
  const ind = Math.floor((sSinceStart % eightWeeks) / sevenDays);
58
75
 
59
- this.currentReward = translator.steelPath(locale).rotation[ind];
76
+ this.currentReward = steelPath(locale).rotation[ind];
60
77
 
61
78
  this.activation = getFirstDayOfWeek();
62
79
 
63
80
  this.expiry = getLastDayOfWeek();
64
81
 
65
- this.remaining = timeDate.timeDeltaToString(this.expiry.getTime() - Date.now());
82
+ this.remaining = timeDeltaToString(this.expiry.getTime() - Date.now());
66
83
 
67
- this.rotation = translator.steelPath(locale).rotation;
68
- this.evergreens = translator.steelPath(locale).evergreen;
84
+ this.rotation = steelPath(locale).rotation;
85
+ this.evergreens = steelPath(locale).evergreen;
69
86
 
70
87
  /**
71
88
  * General data pertaining to incursions
72
- * @type {Object}
89
+ * @type {object}
73
90
  * @property {string} id Identifier for steel path incursion based on start of day.
74
91
  * @property {Date} activation when the current incursions became active
75
92
  * @property {Date} expiry when the current incursions become inactive
@@ -80,4 +97,4 @@ module.exports = class SteelPathOffering {
80
97
  expiry: getEndOfDay(),
81
98
  };
82
99
  }
83
- };
100
+ }
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import { languageString } from '../utilities/translation.js';
2
2
 
3
- const fetch = require('node-fetch');
4
-
5
- const WorldstateObject = require('./WorldstateObject');
3
+ import WorldstateObject from './WorldstateObject.js';
6
4
 
7
5
  const apiBase = process.env.API_BASE_URL || 'https://api.warframestat.us';
8
6
  const bountyRewardRegex = /(?:Tier([ABCDE])|Narmer)Table([ABC])Rewards/i;
@@ -10,7 +8,7 @@ const ghoulRewardRegex = /GhoulBountyTable([AB])Rewards/i;
10
8
 
11
9
  /**
12
10
  * Determine the level string for the bounty
13
- * @param {Object} job Original raw job data
11
+ * @param {object} job Original raw job data
14
12
  * @returns {string} level range string
15
13
  */
16
14
  const getLevelString = (job) => `${job.minEnemyLevel} - ${job.maxEnemyLevel}`;
@@ -82,32 +80,27 @@ const FIFTY_MINUTES = 3000000;
82
80
 
83
81
  /**
84
82
  * Represents a syndicate daily mission
85
- * @extends {WorldstateObject}
83
+ * @augments {WorldstateObject}
86
84
  */
87
- class SyndicateJob extends WorldstateObject {
85
+ export default class SyndicateJob extends WorldstateObject {
88
86
  /**
89
- * @param {Object} data The syndicate mission data
87
+ * @param {object} data The syndicate mission data
90
88
  * @param {Date} expiry The syndicate job expiration
91
- * @param {Object} deps The dependencies object
92
- * @param {Object} timeDate Time/Date functions
93
- * @param {Translator} translator The string translator
94
- * @param {string} locale Locale to use for translations
89
+ * @param {object} deps The dependencies object
90
+ * @param {string} deps.locale Locale to use for translations
95
91
  */
96
- constructor(data, expiry, { translator, timeDate, locale }) {
97
- super(
98
- {
99
- _id: {
100
- $oid: data.JobCurrentVersion
101
- ? data.JobCurrentVersion.$oid
102
- : `${(data.jobType || '').split('/').slice(-1)[0]}${expiry.getTime()}`,
103
- },
92
+ constructor(data, expiry, { locale = 'en' }) {
93
+ super({
94
+ _id: {
95
+ $oid: data.JobCurrentVersion
96
+ ? data.JobCurrentVersion.$oid
97
+ : `${(data.jobType || '').split('/').slice(-1)[0]}${expiry.getTime()}`,
104
98
  },
105
- { timeDate }
106
- );
99
+ });
107
100
 
108
101
  /**
109
102
  * Array of strings describing rewards
110
- * @type {Array.<String>}
103
+ * @type {Array.<string>}
111
104
  */
112
105
  this.rewardPool = [];
113
106
  getBountyRewards(data.rewards, data.isVault, data).then((rewards) => {
@@ -118,10 +111,9 @@ class SyndicateJob extends WorldstateObject {
118
111
 
119
112
  /**
120
113
  * The type of job this is
121
- * @type {String}
114
+ * @type {string}
122
115
  */
123
- this.type =
124
- translator.languageString(data.jobType, locale) || `${data.isVault ? 'Isolation Vault' : ''} ${chamber}`;
116
+ this.type = languageString(data.jobType, locale) || `${data.isVault ? 'Isolation Vault' : ''} ${chamber}`;
125
117
 
126
118
  /**
127
119
  * Array of enemy levels
@@ -137,14 +129,14 @@ class SyndicateJob extends WorldstateObject {
137
129
 
138
130
  /**
139
131
  * Minimum mastery required to participate
140
- * @type {Number}
132
+ * @type {number}
141
133
  */
142
134
  this.minMR = data.masteryReq || 0;
143
135
 
144
136
  /**
145
137
  * Whether or not this is a Vault job.
146
138
  * No indication for difference of normal vs arcana vaults.
147
- * @type {Boolean}
139
+ * @type {boolean}
148
140
  */
149
141
  this.isVault = data.isVault;
150
142
 
@@ -176,5 +168,3 @@ class SyndicateJob extends WorldstateObject {
176
168
  }
177
169
  }
178
170
  }
179
-
180
- module.exports = SyndicateJob;
@@ -1,84 +1,56 @@
1
- 'use strict';
1
+ import { node, syndicate } from '../utilities/translation.js';
2
+ import { fromNow, parseDate, timeDeltaToString } from '../utilities/timeDate.js';
3
+ import mdConfig from '../supporting/MarkdownSettings.js';
2
4
 
3
- const WorldstateObject = require('./WorldstateObject');
4
- const SyndicateJob = require('./SyndicateJob');
5
+ import SyndicateJob from './SyndicateJob.js';
6
+ import WorldstateObject from './WorldstateObject.js';
5
7
 
6
8
  /**
7
9
  * Represents a syndicate daily mission
8
- * @extends {WorldstateObject}
10
+ * @augments {WorldstateObject}
9
11
  */
10
- class SyndicateMission extends WorldstateObject {
12
+ export default class SyndicateMission extends WorldstateObject {
11
13
  /**
12
- * @param {Object} data The syndicate mission data
13
- * @param {Object} deps The dependencies object
14
- * @param {MarkdownSettings} deps.mdConfig The markdown settings
15
- * @param {Translator} deps.translator The string translator
16
- * @param {TimeDateFunctions} deps.timeDate The time and date functions
14
+ * @param {object} data The syndicate mission data
15
+ * @param {object} deps The dependencies object
17
16
  * @param {string} deps.locale Locale to use for translations
18
17
  */
19
- constructor(data, { mdConfig, translator, timeDate, locale }) {
20
- super(data, { timeDate });
18
+ constructor(data, { locale = 'en' } = { locale: 'en' }) {
19
+ super(data);
21
20
 
22
21
  const deps = {
23
- mdConfig,
24
- translator,
25
- timeDate,
26
22
  locale,
27
23
  };
28
24
 
29
- /**
30
- * The markdown settings
31
- * @type {MarkdownSettings}
32
- * @private
33
- */
34
- this.mdConfig = mdConfig;
35
- Object.defineProperty(this, 'mdConfig', { enumerable: false, configurable: false });
36
-
37
- /**
38
- * The time and date functions
39
- * @type {TimeDateFunctions}
40
- * @private
41
- */
42
- this.timeDate = timeDate;
43
- Object.defineProperty(this, 'timeDate', { enumerable: false, configurable: false });
44
-
45
- /**
46
- * The translation functions
47
- * @type {Translator}
48
- * @private
49
- */
50
- this.translator = translator;
51
- Object.defineProperty(this, 'translator', { enumerable: false, configurable: false });
52
-
53
25
  /**
54
26
  * The date and time at which the syndicate mission starts
55
27
  * @type {Date}
56
28
  */
57
- this.activation = timeDate.parseDate(data.Activation);
29
+ this.activation = parseDate(data.Activation);
58
30
 
59
31
  /**
60
32
  * The date and time at which the syndicate mission ends
61
33
  * @type {Date}
62
34
  */
63
- this.expiry = timeDate.parseDate(data.Expiry);
35
+ this.expiry = parseDate(data.Expiry);
64
36
 
65
37
  /**
66
38
  * The syndicate that is offering the mission
67
39
  * @type {string}
68
40
  */
69
- this.syndicate = translator.syndicate(data.Tag, locale);
41
+ this.syndicate = syndicate(data.Tag, locale);
70
42
 
71
43
  /**
72
44
  * The syndicate that is offering the mission
73
45
  * @type {string}
74
46
  */
75
- this.syndicateKey = translator.syndicate(data.Tag, 'en');
47
+ this.syndicateKey = syndicate(data.Tag, 'en');
76
48
 
77
49
  /**
78
50
  * The nodes on which the missions are taking place
79
51
  * @type {Array.<string>}
80
52
  */
81
- this.nodes = data.Nodes.map((n) => translator.node(n), locale);
53
+ this.nodes = data.Nodes.map((n) => node(n), locale);
82
54
 
83
55
  /**
84
56
  * The jobs for this syndicate. Will normally be []
@@ -94,31 +66,29 @@ class SyndicateMission extends WorldstateObject {
94
66
 
95
67
  /**
96
68
  * ETA string (at time of object creation)
97
- * @type {String}
69
+ * @type {string} time delta string from now to the expiry
98
70
  */
99
71
  this.eta = this.getETAString();
100
72
  }
101
73
 
102
74
  /**
103
75
  * Get a string indicating how much time is left before the syndicate mission expries
104
- * @returns {string}
76
+ * @returns {string} time delta string from now to the expiry
105
77
  */
106
78
  getETAString() {
107
- return this.timeDate.timeDeltaToString(this.timeDate.fromNow(this.expiry));
79
+ return timeDeltaToString(fromNow(this.expiry));
108
80
  }
109
81
 
110
82
  /**
111
83
  * Returns a string representation of the syndicate mission
112
- * @returns {string}
84
+ * @returns {string} the string representation
113
85
  */
114
86
  toString() {
115
87
  if (this.nodes.length > 0) {
116
- const missions = this.nodes.map((n) => ` \u2022${n.toString()}`).join(this.mdConfig.lineEnd);
117
- return `[${this.getETAString()}] ${this.syndicate} currently has missions on:${this.mdConfig.lineEnd}${missions}`;
88
+ const missions = this.nodes.map((n) => ` \u2022${n.toString()}`).join(mdConfig.lineEnd);
89
+ return `[${this.getETAString()}] ${this.syndicate} currently has missions on:${mdConfig.lineEnd}${missions}`;
118
90
  }
119
91
 
120
92
  return `No missions available for ${this.syndicate}`;
121
93
  }
122
94
  }
123
-
124
- module.exports = SyndicateMission;
@@ -1,12 +1,26 @@
1
- 'use strict';
1
+ import { fromNow, timeDeltaToString } from '../utilities/timeDate.js';
2
+ import mdConfig from '../supporting/MarkdownSettings.js';
2
3
 
3
- const WorldstateObject = require('./WorldstateObject');
4
+ import WorldstateObject from './WorldstateObject.js';
4
5
 
5
6
  const lStart = new Date('November 10, 2018 08:13:48 UTC');
6
7
  const loopTime = 1600000;
7
8
  const warmTime = 400000;
8
9
  const coldTime = loopTime - warmTime;
9
10
 
11
+ /**
12
+ * @typedef {object} CurrentCycle
13
+ * @property {string} state - Current cycle state. One of `warm`, `cold`
14
+ * @property {number} toNextMinor - Time remaining in the current cycle state
15
+ * @property {number} toNextFull - Time remaining until the next cycle
16
+ * @property {Date} timeAtPrevious - Date and time at which the event started
17
+ * @property {Date} timeAtNext - Date and time at which the event start
18
+ */
19
+
20
+ /**
21
+ * Get the current cycle state for Orb Vallis
22
+ * @returns {CurrentCycle} current cycle state
23
+ */
10
24
  function getCurrentCycle() {
11
25
  const sinceLast = (Date.now() - lStart) % loopTime;
12
26
  const toNextFull = loopTime - sinceLast;
@@ -36,88 +50,68 @@ function getCurrentCycle() {
36
50
 
37
51
  /**
38
52
  * Represents the current Earth Day/Night Cycle
39
- * @extends {WorldstateObject}
53
+ * @augments {WorldstateObject}
40
54
  */
41
- class VallisCycle extends WorldstateObject {
55
+ export default class VallisCycle extends WorldstateObject {
42
56
  /**
43
- * @param {Date} bountiesEndDate The end date for Ostron bounties
44
- * @param {Object} deps The dependencies object
45
- * @param {MarkdownSettings} deps.mdConfig The markdown settings
46
- * @param {TimeDateFunctions} deps.timeDate The time and date functions
57
+ * The current cetus cycle, for calculating the other fields
58
+ * @property {string} state - Current cycle state. One of `warm`, `cold`
59
+ * @property {number} toNextMinor - Time remaining in the current cycle state
60
+ * @property {number} toNextFull - Time remaining until the next cycle
61
+ * @property {Date} timeAtPrevious - Date and time at which the event started
62
+ * @private
47
63
  */
48
- constructor({ mdConfig, timeDate }) {
49
- super({ _id: { $oid: 'vallisCycle0' } }, { timeDate });
50
-
51
- /**
52
- * The markdown settings
53
- * @type {MarkdownSettings}
54
- * @private
55
- */
56
- this.mdConfig = mdConfig;
57
- Object.defineProperty(this, 'mdConfig', { enumerable: false, configurable: false });
64
+ #ec = getCurrentCycle();
58
65
 
59
- /**
60
- * The time and date functions
61
- * @type {TimeDateFunctions}
62
- * @private
63
- */
64
- this.timeDate = timeDate;
65
- Object.defineProperty(this, 'timeDate', { enumerable: false, configurable: false });
66
-
67
- /**
68
- * The current cetus cycle, for calculating the other fields
69
- * @type {Object}
70
- * @private
71
- */
72
- const ec = getCurrentCycle();
73
- Object.defineProperty(this, 'ec', { enumerable: false, configurable: false });
66
+ constructor() {
67
+ super({ _id: { $oid: 'vallisCycle0' } });
74
68
 
75
69
  /**
76
70
  * The date and time at which the event ends
77
71
  * @type {Date}
78
72
  */
79
- this.expiry = ec.timeAtNext;
73
+ this.expiry = this.#ec.timeAtNext;
80
74
 
81
75
  /**
82
76
  * Whether or not this it's daytime
83
77
  * @type {boolean}
84
78
  */
85
- this.isWarm = ec.state === 'warm';
79
+ this.isWarm = this.#ec.state === 'warm';
86
80
 
87
81
  /**
88
82
  * Current cycle state. One of `warm`, `cold`
89
83
  * @type {string}
90
84
  */
91
- this.state = ec.state;
85
+ this.state = this.#ec.state;
92
86
 
93
87
  /**
94
88
  * Date and time at which the event started
95
89
  * @type {Date}
96
90
  */
97
- this.activation = ec.timeAtPrevious;
91
+ this.activation = this.#ec.timeAtPrevious;
98
92
 
99
93
  /**
100
94
  * Time remaining string
101
95
  * @type {string}
102
96
  */
103
- this.timeLeft = timeDate.timeDeltaToString(ec.toNextMinor);
97
+ this.timeLeft = timeDeltaToString(this.#ec.toNextMinor);
104
98
 
105
- this.id = `vallisCycle${ec.timeAtPrevious.getTime()}`;
99
+ this.id = `vallisCycle${this.#ec.timeAtPrevious.getTime()}`;
106
100
 
107
101
  this.shortString = `${this.timeLeft.replace(/\s\d*s/gi, '')} to ${this.isWarm ? 'Cold' : 'Warm'}`;
108
102
  }
109
103
 
110
104
  /**
111
105
  * Get whether or not the event has expired
112
- * @returns {boolean}
106
+ * @returns {boolean} whether this event has expired
113
107
  */
114
108
  getExpired() {
115
- return this.timeDate.fromNow(this.expiry) < 0;
109
+ return fromNow(this.expiry) < 0;
116
110
  }
117
111
 
118
112
  /**
119
113
  * The event's string representation
120
- * @returns {string}
114
+ * @returns {string} the event's string representation
121
115
  */
122
116
  toString() {
123
117
  const lines = [
@@ -125,8 +119,6 @@ class VallisCycle extends WorldstateObject {
125
119
  `Time remaining until ${this.isWarm ? 'Cold' : 'Warm'}: ${this.timeLeft}`,
126
120
  ];
127
121
 
128
- return lines.join(this.mdConfig.lineEnd);
122
+ return lines.join(mdConfig.lineEnd);
129
123
  }
130
124
  }
131
-
132
- module.exports = VallisCycle;
@@ -1,52 +1,37 @@
1
- 'use strict';
1
+ import { fromNow, parseDate, timeDeltaToString } from '../utilities/timeDate.js';
2
+ import { node } from '../utilities/translation.js';
3
+ import { insist } from '../utilities/integrity.js';
4
+ import mdConfig from '../supporting/MarkdownSettings.js';
2
5
 
3
- const WorldstateObject = require('./WorldstateObject');
4
- const VoidTraderItem = require('./VoidTraderItem');
5
- const VoidTraderSchedule = require('./VoidTraderSchedule');
6
+ import WorldstateObject from './WorldstateObject.js';
7
+ import VoidTraderItem from './VoidTraderItem.js';
8
+ import VoidTraderSchedule from './VoidTraderSchedule.js';
6
9
 
7
10
  /**
8
11
  * Represents a void trader
9
- * @extends {WorldstateObject}
12
+ * @augments {WorldstateObject}
10
13
  */
11
- class VoidTrader extends WorldstateObject {
14
+ export default class VoidTrader extends WorldstateObject {
12
15
  /**
13
- * @param {Object} data The Void trader data
14
- * @param {Object} deps The dependencies object
15
- * @param {MarkdownSettings} deps.mdConfig The markdown settings
16
- * @param {Translator} deps.translator The string translator
17
- * @param {TimeDateFunctions} deps.timeDate The time and date functions
16
+ * @param {object} data The Void trader data
17
+ * @param {object} deps The dependencies object
18
18
  * @param {string} deps.locale Locale to use for translations
19
19
  */
20
- constructor(data, { mdConfig, translator, timeDate, locale }) {
21
- super(data, { timeDate });
22
-
23
- /**
24
- * The markdown settings
25
- * @type {MarkdownSettings}
26
- * @private
27
- */
28
- this.mdConfig = mdConfig;
29
- Object.defineProperty(this, 'mdConfig', { enumerable: false, configurable: false });
30
-
31
- /**
32
- * The time and date functions
33
- * @type {TimeDateFunctions}
34
- * @private
35
- */
36
- this.timeDate = timeDate;
37
- Object.defineProperty(this, 'timeDate', { enumerable: false, configurable: false });
20
+ constructor(data, { locale = 'en' } = { locale: 'en' }) {
21
+ super(data);
22
+ insist(data, 'Activation', 'Expiry');
38
23
 
39
24
  /**
40
25
  * The date and time at which the void trader arrives
41
26
  * @type {Date}
42
27
  */
43
- this.activation = this.timeDate.parseDate(data.Activation);
28
+ this.activation = parseDate(data.Activation);
44
29
 
45
30
  /**
46
31
  * The date and time at which the void trader leaves
47
32
  * @type {Date}
48
33
  */
49
- this.expiry = this.timeDate.parseDate(data.Expiry);
34
+ this.expiry = parseDate(data.Expiry);
50
35
 
51
36
  /**
52
37
  * The void trader's name
@@ -58,13 +43,13 @@ class VoidTrader extends WorldstateObject {
58
43
  * The node at which the Void Trader appears
59
44
  * @type {string}
60
45
  */
61
- this.location = translator.node(data.Node, locale);
46
+ this.location = node(data.Node, locale);
62
47
 
63
48
  /**
64
49
  * The trader's inventory
65
50
  * @type {VoidTraderItem[]}
66
51
  */
67
- this.inventory = data.Manifest ? data.Manifest.map((i) => new VoidTraderItem(i, { translator, locale })) : [];
52
+ this.inventory = data.Manifest ? data.Manifest.map((i) => new VoidTraderItem(i, { locale })) : [];
68
53
 
69
54
  /**
70
55
  * Pseudo Identifier for identifying changes in inventory
@@ -92,63 +77,59 @@ class VoidTrader extends WorldstateObject {
92
77
  */
93
78
  this.endString = this.getEndString();
94
79
 
95
- this.initialStart = timeDate.parseDate(data.InitialStartDate);
80
+ this.initialStart = parseDate(data.InitialStartDate);
96
81
  this.completed = data.Completed;
97
- this.schedule = data.ScheduleInfo
98
- ? data.ScheduleInfo.map((i) => new VoidTraderSchedule(i, { timeDate, translator, locale }))
99
- : [];
82
+ this.schedule = data.ScheduleInfo ? data.ScheduleInfo.map((i) => new VoidTraderSchedule(i, { locale })) : [];
100
83
  }
101
84
 
102
85
  /**
103
86
  * Get whether or not the trader is currently active
104
- * @returns {boolean}
87
+ * @returns {boolean} whether the trader is active
105
88
  */
106
89
  isActive() {
107
- return this.timeDate.fromNow(this.activation) < 0 && this.timeDate.fromNow(this.expiry) > 0;
90
+ return fromNow(this.activation) < 0 && fromNow(this.expiry) > 0;
108
91
  }
109
92
 
110
93
  /**
111
94
  * Get a string indicating how long it will take for the trader to arrive
112
- * @returns {string}
95
+ * @returns {string} time delta string from now to the start
113
96
  */
114
97
  getStartString() {
115
- return this.timeDate.timeDeltaToString(this.timeDate.fromNow(this.activation));
98
+ return timeDeltaToString(fromNow(this.activation));
116
99
  }
117
100
 
118
101
  /**
119
102
  * Get a string indicating how long it will take for the trader to leave
120
- * @returns {string}
103
+ * @returns {string} time delta string from now to the end
121
104
  */
122
105
  getEndString() {
123
- return this.timeDate.timeDeltaToString(this.timeDate.fromNow(this.expiry));
106
+ return timeDeltaToString(fromNow(this.expiry));
124
107
  }
125
108
 
126
109
  /**
127
110
  * Returns a string representation of the trader
128
- * @returns {string}
111
+ * @returns {string} string representation
129
112
  */
130
113
  toString() {
131
114
  if (!this.isActive()) {
132
- const timeDelta = this.timeDate.fromNow(this.activation);
133
- const nextArrivalTime = this.timeDate.timeDeltaToString(timeDelta);
115
+ const timeDelta = fromNow(this.activation);
116
+ const nextArrivalTime = timeDeltaToString(timeDelta);
134
117
  return (
135
- `${this.mdConfig.codeMulti}${this.character} is not here yet, he will arrive in ` +
136
- `${nextArrivalTime} at ${this.location}${this.mdConfig.blockEnd}`
118
+ `${mdConfig.codeBlock}${this.character} is not here yet, he will arrive in ` +
119
+ `${nextArrivalTime} at ${this.location}${mdConfig.blockEnd}`
137
120
  );
138
121
  }
139
122
 
140
123
  const inventoryString = this.inventory
141
124
  .map((i) => ` ${i.item} - ${i.ducats} ducats + ${i.credits}cr%s`)
142
- .join(this.mdConfig.lineEnd);
125
+ .join(mdConfig.lineEnd);
143
126
 
144
127
  const lines = [
145
- `${this.mdConfig.codeMulti}Void Trader at ${this.location}`,
128
+ `${mdConfig.codeBlock}Void Trader at ${this.location}`,
146
129
  inventoryString,
147
- `Trader departing in ${this.getEndString()}${this.mdConfig.blockEnd}`,
130
+ `Trader departing in ${this.getEndString()}${mdConfig.blockEnd}`,
148
131
  ];
149
132
 
150
- return lines.join(this.mdConfig.lineEnd);
133
+ return lines.join(mdConfig.lineEnd);
151
134
  }
152
135
  }
153
-
154
- module.exports = VoidTrader;
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ import { languageString } from '../utilities/translation.js';
2
2
 
3
3
  /**
4
4
  * A void trader inventory item
@@ -6,22 +6,19 @@
6
6
  * @property {number|string} ducats Ducat cost of the item
7
7
  * @property {number|string} credits Credit cost of the item
8
8
  */
9
- class VoidTraderItem {
9
+ export default class VoidTraderItem {
10
10
  /**
11
- * @param {Object} data The void trader item data
11
+ * @param {object} data The void trader item data
12
12
  * @param {string} data.ItemType Worldstate Item i18n path
13
13
  * @param {string} data.PrimePrice Ducat cost of the item
14
14
  * @param {string} data.RegularPrice Credit price of the item
15
15
  * @param {Dependency} deps The dependencies object
16
- * @param {Translator} deps.translator The string translator
17
16
  * @param {string} deps.locale Locale to use for translations
18
17
  */
19
- constructor({ ItemType, PrimePrice, RegularPrice }, { translator, locale }) {
18
+ constructor({ ItemType, PrimePrice, RegularPrice }, { locale = 'en' } = { locale: 'en' }) {
20
19
  this.uniqueName = ItemType;
21
- this.item = translator.languageString(ItemType, locale);
20
+ this.item = languageString(ItemType, locale);
22
21
  this.ducats = Number.parseInt(PrimePrice, 10);
23
22
  this.credits = Number.parseInt(RegularPrice, 10);
24
23
  }
25
24
  }
26
-
27
- module.exports = VoidTraderItem;