warframe-worldstate-data 3.1.24 → 3.2.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/dist/data/languages.json +18 -0
- package/dist/exports.d.mts +121 -1
- package/dist/exports.mjs +76 -1
- package/dist/safeImport.mjs +17 -1
- package/dist/tools/timeDate.d.mts +76 -1
- package/dist/tools/timeDate.mjs +111 -1
- package/dist/tools/translation.d.mts +291 -1
- package/dist/tools/translation.mjs +345 -2
- package/dist/tools/utilities.d.mts +2 -2
- package/dist/tools/utilities.mjs +2 -3
- package/dist/types.d.mts +93 -1
- package/package.json +2 -2
- package/dist/exports-Dnvn5acu.mjs +0 -78
- package/dist/exports-Ki41SFqn.d.mts +0 -122
- package/dist/safeImport-jQ3nFavf.mjs +0 -19
- package/dist/timeDate-CHdavm3I.d.mts +0 -77
- package/dist/timeDate-CoQsggGD.mjs +0 -113
- package/dist/translation-CUKRZoNL.d.mts +0 -292
- package/dist/translation-DQc7UbZg.mjs +0 -347
- package/dist/types-gmU0jfT4.d.mts +0 -94
package/dist/data/languages.json
CHANGED
|
@@ -242,12 +242,18 @@
|
|
|
242
242
|
"/Lotus/StoreItems/Types/Recipes/Components/WeaponUtilityUnlockerBlueprint": {
|
|
243
243
|
"value": "Exilus Weapon Adapter Blueprint"
|
|
244
244
|
},
|
|
245
|
+
"/Lotus/StoreItems/Types/Recipes/WarframeRecipes/DagathBlueprint": {
|
|
246
|
+
"value": "Dagath Blueprint"
|
|
247
|
+
},
|
|
245
248
|
"/Lotus/StoreItems/Types/Recipes/WarframeRecipes/DagathChassisComponent": {
|
|
246
249
|
"value": "Dagath Chassis"
|
|
247
250
|
},
|
|
248
251
|
"/Lotus/StoreItems/Types/Recipes/WarframeRecipes/DagathHelmetComponent": {
|
|
249
252
|
"value": "Dagath Neuroptics"
|
|
250
253
|
},
|
|
254
|
+
"/Lotus/StoreItems/Types/Recipes/WarframeRecipes/DagathSystemsComponent": {
|
|
255
|
+
"value": "Dagath Systems"
|
|
256
|
+
},
|
|
251
257
|
"/Lotus/StoreItems/Types/Restoratives/Consumable/AssassinBait": {
|
|
252
258
|
"value": "Stalker Beacon"
|
|
253
259
|
},
|
|
@@ -19347,6 +19353,10 @@
|
|
|
19347
19353
|
"value": "Secondary Wounds",
|
|
19348
19354
|
"desc": "Gain 1 Puncture Status Effect every time you take damage."
|
|
19349
19355
|
},
|
|
19356
|
+
"ContaminationZone": {
|
|
19357
|
+
"value": "Hold Your Breath",
|
|
19358
|
+
"desc": "The entire region deals Toxin damage over time, increasing the longer players remain."
|
|
19359
|
+
},
|
|
19350
19360
|
"DecayingFlesh": {
|
|
19351
19361
|
"value": "Permanent Injury",
|
|
19352
19362
|
"desc": "Max health reduced each time health damage is taken"
|
|
@@ -19484,6 +19494,10 @@
|
|
|
19484
19494
|
"value": "Miasmite Swarm",
|
|
19485
19495
|
"desc": "Techrot Miasmites swarm out of the shadows throught the mission."
|
|
19486
19496
|
},
|
|
19497
|
+
"MurmurIncursion": {
|
|
19498
|
+
"value": "Beyond The Wall",
|
|
19499
|
+
"desc": "Murmur enemies join Scaldra and Techrot forces."
|
|
19500
|
+
},
|
|
19487
19501
|
"MutatedEnemies": {
|
|
19488
19502
|
"value": "Parallel Evolution",
|
|
19489
19503
|
"desc": "As the Legacyte evolves other enemies present also gain new abilities."
|
|
@@ -19611,6 +19625,10 @@
|
|
|
19611
19625
|
"value": "Vampyric Liminus",
|
|
19612
19626
|
"desc": "Slow moving, immortal, Duviri Liminus drain health and energy from allies who get too close."
|
|
19613
19627
|
},
|
|
19628
|
+
"VoidEnergyOverload": {
|
|
19629
|
+
"value": "Ability Overload",
|
|
19630
|
+
"desc": "Using an Ability opens a Void Rift on top of you."
|
|
19631
|
+
},
|
|
19614
19632
|
"Voidburst": {
|
|
19615
19633
|
"value": "Postmortal Surges",
|
|
19616
19634
|
"desc": "Slain enemies burts with Void energy."
|
package/dist/exports.d.mts
CHANGED
|
@@ -1,2 +1,122 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Arcane, ArchonShard, Conclave, Events, SolNode, SortieData, SteelPath, SynthesisTarget } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region exports.d.ts
|
|
4
|
+
type Locale = 'de' | 'en' | 'es' | 'fr' | 'it' | 'ko' | 'pl' | 'pt' | 'ru' | 'zh' | 'cs' | 'sr' | 'uk';
|
|
5
|
+
/**
|
|
6
|
+
* Bundles all the data for a particular language
|
|
7
|
+
*/
|
|
8
|
+
interface WorldstateLangBundle {
|
|
9
|
+
/**
|
|
10
|
+
* Deprecated: Array of arcane data
|
|
11
|
+
*/
|
|
12
|
+
arcanes: Arcane[];
|
|
13
|
+
/**
|
|
14
|
+
* Data for Archon shard colors
|
|
15
|
+
*/
|
|
16
|
+
archonShards: Record<string, ArchonShard>;
|
|
17
|
+
/**
|
|
18
|
+
* Data for translating PvP categories and types
|
|
19
|
+
*/
|
|
20
|
+
conclave: Conclave;
|
|
21
|
+
/**
|
|
22
|
+
* Deprecated: Data for converting event tags to useable event data.
|
|
23
|
+
* Deprecated in favor of keeping values in languages.json
|
|
24
|
+
*/
|
|
25
|
+
events: Events;
|
|
26
|
+
/**
|
|
27
|
+
* Faction universal name to plain-usage name
|
|
28
|
+
*/
|
|
29
|
+
factions: Record<string, {
|
|
30
|
+
value: string;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Map of fissures to "Warframeified" tier names and numbers
|
|
34
|
+
*/
|
|
35
|
+
fissureModifiers: Record<string, {
|
|
36
|
+
value: string;
|
|
37
|
+
num: number;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Map of "internal" Warframe strings to useable language strings
|
|
41
|
+
*/
|
|
42
|
+
languages: Record<string, {
|
|
43
|
+
value: string;
|
|
44
|
+
desc: string;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Map of Mission Type identifiers to their corresponding values
|
|
48
|
+
*/
|
|
49
|
+
missionTypes: Record<string, {
|
|
50
|
+
value: string;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Global modifiers for applying operations to things like
|
|
54
|
+
* credits, affinity, etc.
|
|
55
|
+
*/
|
|
56
|
+
operationTypes: Record<string, {
|
|
57
|
+
value: string;
|
|
58
|
+
symbol: string;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Region mapping for indicies to planets
|
|
62
|
+
*/
|
|
63
|
+
persistentEnemy: {
|
|
64
|
+
regions: string[];
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Nodes in the Sol system, with enemy type and node information
|
|
68
|
+
*/
|
|
69
|
+
solNodes: Record<string, SolNode>;
|
|
70
|
+
/**
|
|
71
|
+
* Sortie-specific mapping for modifier type, description, and boss
|
|
72
|
+
*/
|
|
73
|
+
sortie: SortieData;
|
|
74
|
+
/**
|
|
75
|
+
* Steel Path mission type translations
|
|
76
|
+
*/
|
|
77
|
+
steelPath: SteelPath;
|
|
78
|
+
/**
|
|
79
|
+
* Syndicate data
|
|
80
|
+
*/
|
|
81
|
+
syndicates: Record<string, {
|
|
82
|
+
name: string;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Synthesis target data for optimal locations to find targets.
|
|
86
|
+
*/
|
|
87
|
+
synthTargets: SynthesisTarget[];
|
|
88
|
+
/**
|
|
89
|
+
* Official tutorials.
|
|
90
|
+
* Not many have been released in a long time.
|
|
91
|
+
*/
|
|
92
|
+
tutorials: {
|
|
93
|
+
regex: string;
|
|
94
|
+
name: string;
|
|
95
|
+
url: string;
|
|
96
|
+
}[];
|
|
97
|
+
/**
|
|
98
|
+
* Global upgrade types that are modified by #operationTypes
|
|
99
|
+
*/
|
|
100
|
+
upgradeTypes: Record<string, {
|
|
101
|
+
value: string;
|
|
102
|
+
}>;
|
|
103
|
+
}
|
|
104
|
+
declare const _default: WorldstateLangBundle & {
|
|
105
|
+
de?: WorldstateLangBundle | undefined;
|
|
106
|
+
en?: WorldstateLangBundle | undefined;
|
|
107
|
+
es?: WorldstateLangBundle | undefined;
|
|
108
|
+
fr?: WorldstateLangBundle | undefined;
|
|
109
|
+
it?: WorldstateLangBundle | undefined;
|
|
110
|
+
ko?: WorldstateLangBundle | undefined;
|
|
111
|
+
pl?: WorldstateLangBundle | undefined;
|
|
112
|
+
pt?: WorldstateLangBundle | undefined;
|
|
113
|
+
ru?: WorldstateLangBundle | undefined;
|
|
114
|
+
zh?: WorldstateLangBundle | undefined;
|
|
115
|
+
cs?: WorldstateLangBundle | undefined;
|
|
116
|
+
sr?: WorldstateLangBundle | undefined;
|
|
117
|
+
uk?: WorldstateLangBundle | undefined;
|
|
118
|
+
} & {
|
|
119
|
+
locales: Locale[];
|
|
120
|
+
};
|
|
121
|
+
//#endregion
|
|
2
122
|
export { Locale, WorldstateLangBundle, _default as default };
|
package/dist/exports.mjs
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { safeImport } from "./safeImport.mjs";
|
|
2
2
|
|
|
3
|
+
//#region exports.ts
|
|
4
|
+
const locales = [
|
|
5
|
+
"de",
|
|
6
|
+
"es",
|
|
7
|
+
"fr",
|
|
8
|
+
"it",
|
|
9
|
+
"ko",
|
|
10
|
+
"pl",
|
|
11
|
+
"pt",
|
|
12
|
+
"ru",
|
|
13
|
+
"zh",
|
|
14
|
+
"cs",
|
|
15
|
+
"sr",
|
|
16
|
+
"uk"
|
|
17
|
+
];
|
|
18
|
+
const makeBundle = async () => {
|
|
19
|
+
/**
|
|
20
|
+
* English United States translations bundle,
|
|
21
|
+
* default translations
|
|
22
|
+
* @type {WorldstateLangBundle}
|
|
23
|
+
*/
|
|
24
|
+
const enUS = {
|
|
25
|
+
arcanes: await safeImport("./data/arcanes.json"),
|
|
26
|
+
archonShards: await safeImport("./data/archonShards.json"),
|
|
27
|
+
conclave: await safeImport("./data/conclaveData.json"),
|
|
28
|
+
events: await safeImport("./data/eventsData.json"),
|
|
29
|
+
factions: await safeImport("./data/factionsData.json"),
|
|
30
|
+
fissureModifiers: await safeImport("./data/fissureModifiers.json"),
|
|
31
|
+
languages: await safeImport("./data/languages.json"),
|
|
32
|
+
missionTypes: await safeImport("./data/missionTypes.json"),
|
|
33
|
+
operationTypes: await safeImport("./data/operationTypes.json"),
|
|
34
|
+
persistentEnemy: await safeImport("./data/persistentEnemyData.json"),
|
|
35
|
+
solNodes: await safeImport("./data/solNodes.json"),
|
|
36
|
+
sortie: await safeImport("./data/sortieData.json"),
|
|
37
|
+
syndicates: await safeImport("./data/syndicatesData.json"),
|
|
38
|
+
tutorials: await safeImport("./data/tutorials.json"),
|
|
39
|
+
upgradeTypes: await safeImport("./data/upgradeTypes.json"),
|
|
40
|
+
synthTargets: await safeImport("./data/synthTargets.json"),
|
|
41
|
+
steelPath: await safeImport("./data/steelPath.json")
|
|
42
|
+
};
|
|
43
|
+
const bundle = {
|
|
44
|
+
en: enUS,
|
|
45
|
+
...enUS,
|
|
46
|
+
locales
|
|
47
|
+
};
|
|
48
|
+
for await (const locale of locales)
|
|
49
|
+
/**
|
|
50
|
+
* Translations bundle for $locale
|
|
51
|
+
* @type {WorldstateLangBundle}
|
|
52
|
+
*/
|
|
53
|
+
bundle[locale] = {
|
|
54
|
+
arcanes: await safeImport(`./data/${locale}/arcanes.json`, enUS.arcanes),
|
|
55
|
+
archonShards: await safeImport(`./data/${locale}/archonShards.json`, enUS.archonShards),
|
|
56
|
+
conclave: await safeImport(`./data/${locale}/conclaveData.json`, enUS.conclave),
|
|
57
|
+
events: await safeImport(`./data/${locale}/eventsData.json`, enUS.events),
|
|
58
|
+
factions: await safeImport(`./data/${locale}/factionsData.json`, enUS.factions),
|
|
59
|
+
fissureModifiers: await safeImport(`./data/${locale}/fissureModifiers.json`, enUS.fissureModifiers),
|
|
60
|
+
languages: await safeImport(`./data/${locale}/languages.json`, enUS.languages),
|
|
61
|
+
missionTypes: await safeImport(`./data/${locale}/missionTypes.json`, enUS.missionTypes),
|
|
62
|
+
operationTypes: await safeImport(`./data/${locale}/operationTypes.json`, enUS.operationTypes),
|
|
63
|
+
persistentEnemy: await safeImport(`./data/${locale}/persistentEnemyData.json`, enUS.persistentEnemy),
|
|
64
|
+
solNodes: await safeImport(`./data/${locale}/solNodes.json`, enUS.solNodes),
|
|
65
|
+
sortie: await safeImport(`./data/${locale}/sortieData.json`, enUS.sortie),
|
|
66
|
+
syndicates: await safeImport(`./data/${locale}/syndicatesData.json`, enUS.syndicates),
|
|
67
|
+
tutorials: await safeImport(`./data/${locale}/tutorials.json`, enUS.tutorials),
|
|
68
|
+
upgradeTypes: await safeImport(`./data/${locale}/upgradeTypes.json`, enUS.upgradeTypes),
|
|
69
|
+
synthTargets: await safeImport(`./data/${locale}/synthTargets.json`, enUS.synthTargets),
|
|
70
|
+
steelPath: await safeImport(`./data/${locale}/steelPath.json`, enUS.steelPath)
|
|
71
|
+
};
|
|
72
|
+
locales.push("en");
|
|
73
|
+
return bundle;
|
|
74
|
+
};
|
|
75
|
+
var exports_default = await makeBundle();
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
3
78
|
export { exports_default as default };
|
package/dist/safeImport.mjs
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
//#region safeImport.ts
|
|
2
|
+
/**
|
|
3
|
+
* Safely require path, fall back to fallback if module cannot load
|
|
4
|
+
* @param {string} path Path to attempt to load
|
|
5
|
+
* @param {Object} fallback fallback response if error or no module
|
|
6
|
+
* @returns {Promise<any>} module or the default object
|
|
7
|
+
*/
|
|
8
|
+
const safeImport = async (path, fallback = {}) => {
|
|
9
|
+
try {
|
|
10
|
+
const mod = path.includes(".json") ? await import(path, { with: { type: "json" } }) : await import(path);
|
|
11
|
+
return "default" in mod ? mod.default : mod;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
if ((process.env.LOG_LEVEL || "ERROR").toUpperCase() === "DEBUG") console.debug(`Failed to load module at ${path} ... returning fallback`);
|
|
14
|
+
return fallback;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
2
17
|
|
|
18
|
+
//#endregion
|
|
3
19
|
export { safeImport };
|
|
@@ -1,2 +1,77 @@
|
|
|
1
|
-
|
|
1
|
+
//#region tools/timeDate.d.ts
|
|
2
|
+
declare const pieceIsSmoller: (seconds: number, ceiling: number, label: string, timePieces: string[]) => {
|
|
3
|
+
seconds: number;
|
|
4
|
+
timePieces: string[];
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @param {number} millis The number of milliseconds in the time delta
|
|
8
|
+
* @returns {string} formatted time delta
|
|
9
|
+
*/
|
|
10
|
+
declare const timeDeltaToString: (millis: number) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the number of milliseconds between now and a given date
|
|
13
|
+
* @param {Date} d The date from which the current time will be subtracted
|
|
14
|
+
* @param {function} [now] A function that returns the current UNIX time in milliseconds
|
|
15
|
+
* @returns {number} The number of milliseconds after the given date to now
|
|
16
|
+
*/
|
|
17
|
+
declare const fromNow: (d: Date, now?: () => number) => number;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the number of milliseconds between a given date and now
|
|
20
|
+
* @param {Date} d The date that the current time will be subtracted from
|
|
21
|
+
* @param {function} [now] A function that returns the current UNIX time in milliseconds
|
|
22
|
+
* @returns {number} The number of milliseconds after now to the given date
|
|
23
|
+
*/
|
|
24
|
+
declare const toNow: (d: Date, now?: () => number) => number;
|
|
25
|
+
interface ContentTimestamp {
|
|
26
|
+
$date?: {
|
|
27
|
+
$numberLong: number | string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
interface LegacyTimestamp {
|
|
31
|
+
sec: number | string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns a new Date constructed from a worldState date object
|
|
35
|
+
* @param {Object} d The worldState date object
|
|
36
|
+
* @returns {Date} parsed date from DE date format
|
|
37
|
+
*/
|
|
38
|
+
declare const parseDate: (d?: ContentTimestamp | LegacyTimestamp | number) => Date;
|
|
39
|
+
/**
|
|
40
|
+
* Get a weekly reset timestamp
|
|
41
|
+
*/
|
|
42
|
+
declare const weeklyReset: (nowFunc?: () => Date) => {
|
|
43
|
+
activation: Date;
|
|
44
|
+
expiry: Date;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Get a daily reset timestamp
|
|
48
|
+
*/
|
|
49
|
+
declare const dailyReset: (nowFunc?: () => Date) => {
|
|
50
|
+
activation: Date;
|
|
51
|
+
expiry: Date;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* An object containing functions to format dates and times
|
|
55
|
+
* @typedef {Record<string, Function>} TimeDateFunctions
|
|
56
|
+
* @property {Function} timeDeltaToString - Converts a time difference to a string
|
|
57
|
+
* @property {Function} fromNow - Returns the number of milliseconds between now and
|
|
58
|
+
* a given date
|
|
59
|
+
* @property {Function} toNow - Returns the number of milliseconds between a given
|
|
60
|
+
* date and now
|
|
61
|
+
*/
|
|
62
|
+
declare const _default: {
|
|
63
|
+
timeDeltaToString: (millis: number) => string;
|
|
64
|
+
fromNow: (d: Date, now?: () => number) => number;
|
|
65
|
+
toNow: (d: Date, now?: () => number) => number;
|
|
66
|
+
parseDate: (d?: ContentTimestamp | LegacyTimestamp | number) => Date;
|
|
67
|
+
dailyReset: (nowFunc?: () => Date) => {
|
|
68
|
+
activation: Date;
|
|
69
|
+
expiry: Date;
|
|
70
|
+
};
|
|
71
|
+
weeklyReset: (nowFunc?: () => Date) => {
|
|
72
|
+
activation: Date;
|
|
73
|
+
expiry: Date;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
2
77
|
export { ContentTimestamp, LegacyTimestamp, dailyReset, _default as default, fromNow, parseDate, pieceIsSmoller, timeDeltaToString, toNow, weeklyReset };
|
package/dist/tools/timeDate.mjs
CHANGED
|
@@ -1,3 +1,113 @@
|
|
|
1
|
-
|
|
1
|
+
//#region tools/timeDate.ts
|
|
2
|
+
const epochZero = { $date: { $numberLong: 0 } };
|
|
3
|
+
const pieceIsSmoller = (seconds, ceiling, label, timePieces) => {
|
|
4
|
+
if (seconds >= ceiling) {
|
|
5
|
+
timePieces.push(`${Math.floor(seconds / ceiling)}${label}`);
|
|
6
|
+
seconds = Math.floor(seconds) % ceiling;
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
seconds,
|
|
10
|
+
timePieces
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @param {number} millis The number of milliseconds in the time delta
|
|
15
|
+
* @returns {string} formatted time delta
|
|
16
|
+
*/
|
|
17
|
+
const timeDeltaToString = (millis) => {
|
|
18
|
+
if (typeof millis !== "number") throw new TypeError("millis should be a number");
|
|
19
|
+
let timePieces = [];
|
|
20
|
+
const prefix = millis < 0 ? "-" : "";
|
|
21
|
+
let seconds = Math.abs(millis / 1e3);
|
|
22
|
+
({seconds, timePieces} = pieceIsSmoller(seconds, 86400, "d", timePieces));
|
|
23
|
+
({seconds, timePieces} = pieceIsSmoller(seconds, 3600, "h", timePieces));
|
|
24
|
+
({seconds, timePieces} = pieceIsSmoller(seconds, 60, "m", timePieces));
|
|
25
|
+
/* istanbul ignore else */
|
|
26
|
+
if (seconds >= 0) timePieces.push(`${Math.floor(seconds)}s`);
|
|
27
|
+
return `${prefix}${timePieces.join(" ")}`;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Returns the number of milliseconds between now and a given date
|
|
31
|
+
* @param {Date} d The date from which the current time will be subtracted
|
|
32
|
+
* @param {function} [now] A function that returns the current UNIX time in milliseconds
|
|
33
|
+
* @returns {number} The number of milliseconds after the given date to now
|
|
34
|
+
*/
|
|
35
|
+
const fromNow = (d, now = Date.now) => {
|
|
36
|
+
return d.getTime() - now();
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Returns the number of milliseconds between a given date and now
|
|
40
|
+
* @param {Date} d The date that the current time will be subtracted from
|
|
41
|
+
* @param {function} [now] A function that returns the current UNIX time in milliseconds
|
|
42
|
+
* @returns {number} The number of milliseconds after now to the given date
|
|
43
|
+
*/
|
|
44
|
+
const toNow = (d, now = Date.now) => {
|
|
45
|
+
return now() - d.getTime();
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Returns a new Date constructed from a worldState date object
|
|
49
|
+
* @param {Object} d The worldState date object
|
|
50
|
+
* @returns {Date} parsed date from DE date format
|
|
51
|
+
*/
|
|
52
|
+
const parseDate = (d) => {
|
|
53
|
+
const contentD = d || epochZero;
|
|
54
|
+
if (typeof contentD.$date?.$numberLong === "string") return new Date(Number.parseInt(contentD.$date.$numberLong, 10));
|
|
55
|
+
if (typeof contentD.$date?.$numberLong === "number") return new Date(contentD.$date.$numberLong);
|
|
56
|
+
const legacyD = d;
|
|
57
|
+
if (typeof legacyD.sec === "string") return /* @__PURE__ */ new Date(1e3 * Number.parseInt(legacyD.sec, 10));
|
|
58
|
+
if (typeof legacyD.sec !== "undefined") return /* @__PURE__ */ new Date(1e3 * legacyD.sec);
|
|
59
|
+
if (typeof d === "number") return new Date(d);
|
|
60
|
+
throw new Error(`Invalid date format ${d}`);
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Get a weekly reset timestamp
|
|
64
|
+
*/
|
|
65
|
+
const weeklyReset = (nowFunc = () => /* @__PURE__ */ new Date()) => {
|
|
66
|
+
const now = nowFunc();
|
|
67
|
+
const currentDay = now.getUTCDay();
|
|
68
|
+
const daysUntilNextMonday = currentDay === 0 ? 1 : 8 - currentDay;
|
|
69
|
+
const expiry = new Date(now.getTime());
|
|
70
|
+
expiry.setUTCDate(now.getUTCDate() + daysUntilNextMonday);
|
|
71
|
+
expiry.setUTCHours(0, 0, 0, 0);
|
|
72
|
+
const activation = new Date(expiry.getTime());
|
|
73
|
+
activation.setUTCDate(expiry.getUTCDate() - 7);
|
|
74
|
+
return {
|
|
75
|
+
activation,
|
|
76
|
+
expiry
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Get a daily reset timestamp
|
|
81
|
+
*/
|
|
82
|
+
const dailyReset = (nowFunc = () => /* @__PURE__ */ new Date()) => {
|
|
83
|
+
const now = nowFunc();
|
|
84
|
+
const activation = new Date(now.getTime());
|
|
85
|
+
activation.setUTCHours(0, 0, 0, 0);
|
|
86
|
+
const expiry = new Date(now.getTime());
|
|
87
|
+
expiry.setUTCDate(now.getUTCDate() + 1);
|
|
88
|
+
expiry.setUTCHours(0, 0, 0, 0);
|
|
89
|
+
return {
|
|
90
|
+
activation,
|
|
91
|
+
expiry
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* An object containing functions to format dates and times
|
|
96
|
+
* @typedef {Record<string, Function>} TimeDateFunctions
|
|
97
|
+
* @property {Function} timeDeltaToString - Converts a time difference to a string
|
|
98
|
+
* @property {Function} fromNow - Returns the number of milliseconds between now and
|
|
99
|
+
* a given date
|
|
100
|
+
* @property {Function} toNow - Returns the number of milliseconds between a given
|
|
101
|
+
* date and now
|
|
102
|
+
*/
|
|
103
|
+
var timeDate_default = {
|
|
104
|
+
timeDeltaToString,
|
|
105
|
+
fromNow,
|
|
106
|
+
toNow,
|
|
107
|
+
parseDate,
|
|
108
|
+
dailyReset,
|
|
109
|
+
weeklyReset
|
|
110
|
+
};
|
|
2
111
|
|
|
112
|
+
//#endregion
|
|
3
113
|
export { dailyReset, timeDate_default as default, fromNow, parseDate, pieceIsSmoller, timeDeltaToString, toNow, weeklyReset };
|