warframe-worldstate-data 3.1.23 → 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/cs/languages.json +31 -3
- package/dist/data/de/languages.json +31 -3
- package/dist/data/es/languages.json +31 -3
- package/dist/data/fr/languages.json +31 -3
- package/dist/data/it/languages.json +31 -3
- package/dist/data/ko/languages.json +31 -3
- package/dist/data/languages.json +49 -3
- package/dist/data/pl/languages.json +31 -3
- package/dist/data/pt/languages.json +31 -3
- package/dist/data/ru/languages.json +31 -3
- package/dist/data/sr/languages.json +31 -3
- package/dist/data/tr/languages.json +31 -3
- package/dist/data/uk/languages.json +31 -3
- package/dist/data/zh/languages.json +31 -3
- 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 -3
- package/dist/tools/utilities.mjs +2 -3
- package/dist/types.d.mts +93 -1
- package/package.json +3 -3
- package/dist/exports-BaguOygr.d.mts +0 -122
- package/dist/exports-M2P8p7tW.mjs +0 -78
- package/dist/safeImport-CE5wf6im.mjs +0 -19
- package/dist/timeDate-BI8dd5t-.d.mts +0 -77
- package/dist/timeDate-D3gcft_k.mjs +0 -113
- package/dist/translation-B1nyVzj0.mjs +0 -347
- package/dist/translation-DfnYeyoz.d.mts +0 -293
- package/dist/types-BambsMUW.d.mts +0 -94
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,94 @@
|
|
|
1
|
-
|
|
1
|
+
//#region types.d.ts
|
|
2
|
+
interface Arcane {
|
|
3
|
+
regex: string;
|
|
4
|
+
name: string;
|
|
5
|
+
effect: string;
|
|
6
|
+
rarity: string;
|
|
7
|
+
location: string;
|
|
8
|
+
thumbnail: string;
|
|
9
|
+
}
|
|
10
|
+
interface ArchonShard {
|
|
11
|
+
value: string;
|
|
12
|
+
upgradeTypes: Record<string, {
|
|
13
|
+
value: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
interface Conclave {
|
|
17
|
+
modes: Record<string, {
|
|
18
|
+
value: string;
|
|
19
|
+
}>;
|
|
20
|
+
categories: Record<string, {
|
|
21
|
+
value: string;
|
|
22
|
+
description: string;
|
|
23
|
+
}>;
|
|
24
|
+
challenges: Record<string, {
|
|
25
|
+
title: string;
|
|
26
|
+
description: string;
|
|
27
|
+
standing: number;
|
|
28
|
+
}>;
|
|
29
|
+
affectors: Record<string, {
|
|
30
|
+
title: string;
|
|
31
|
+
description: string;
|
|
32
|
+
standing: number;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
interface Events {
|
|
36
|
+
tags: Record<string, {
|
|
37
|
+
value: string;
|
|
38
|
+
}>;
|
|
39
|
+
scoreVariables: Record<string, {
|
|
40
|
+
value: {
|
|
41
|
+
value: string;
|
|
42
|
+
};
|
|
43
|
+
}>;
|
|
44
|
+
scoreMaxTags: Record<string, {
|
|
45
|
+
value: {
|
|
46
|
+
value: string;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
interface SteelPath {
|
|
51
|
+
rotation: SteelPathOffering[];
|
|
52
|
+
evergreen: SteelPathOffering[];
|
|
53
|
+
}
|
|
54
|
+
interface SteelPathOffering {
|
|
55
|
+
name: string;
|
|
56
|
+
cost: number;
|
|
57
|
+
}
|
|
58
|
+
interface SynthesisTarget {
|
|
59
|
+
name: string;
|
|
60
|
+
locations: SynthesisTargetLocation[];
|
|
61
|
+
}
|
|
62
|
+
interface SynthesisTargetLocation {
|
|
63
|
+
last_verified: string;
|
|
64
|
+
level: string;
|
|
65
|
+
spawn_rate: string;
|
|
66
|
+
mission: string;
|
|
67
|
+
planet: string;
|
|
68
|
+
type: string;
|
|
69
|
+
faction: string;
|
|
70
|
+
}
|
|
71
|
+
interface SolNode {
|
|
72
|
+
value: string;
|
|
73
|
+
enemy: string;
|
|
74
|
+
type: string;
|
|
75
|
+
}
|
|
76
|
+
interface SortieEndState {
|
|
77
|
+
bossName: string;
|
|
78
|
+
regions: {
|
|
79
|
+
name: string;
|
|
80
|
+
missions: string[];
|
|
81
|
+
}[];
|
|
82
|
+
}
|
|
83
|
+
interface SortieData {
|
|
84
|
+
modifierTypes: Record<string, string>;
|
|
85
|
+
modifierDescriptions: Record<string, string>;
|
|
86
|
+
bosses: Record<string, {
|
|
87
|
+
name: string;
|
|
88
|
+
faction: string;
|
|
89
|
+
}>;
|
|
90
|
+
endStates: SortieEndState[];
|
|
91
|
+
modifiers: string[];
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
2
94
|
export { Arcane, ArchonShard, Conclave, Events, SolNode, SortieData, SteelPath, SteelPathOffering, SynthesisTarget };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "warframe-worldstate-data",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Warframe data for use with warframe-worldstate-parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"warframe-worldstate",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@biomejs/biome": "2.3.
|
|
64
|
+
"@biomejs/biome": "2.3.14",
|
|
65
65
|
"@commitlint/cli": "^20.0.0",
|
|
66
66
|
"@commitlint/config-conventional": "^20.0.0",
|
|
67
67
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"nyc": "^17.1.0",
|
|
83
83
|
"sinon": "^21.0.0",
|
|
84
84
|
"sinon-chai": "^4.0.0",
|
|
85
|
-
"tsdown": "^0.
|
|
85
|
+
"tsdown": "^0.20.1",
|
|
86
86
|
"tsx": "^4.20.3",
|
|
87
87
|
"typescript": "^5.8.3",
|
|
88
88
|
"yargs": "^18.0.0"
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { a as SolNode, i as Events, l as SynthesisTarget, n as ArchonShard, o as SortieData, r as Conclave, s as SteelPath, t as Arcane } from "./types-BambsMUW.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
|
|
122
|
-
export { WorldstateLangBundle as n, _default as r, Locale as t };
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { t as safeImport } from "./safeImport-CE5wf6im.mjs";
|
|
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
|
|
78
|
-
export { exports_default as t };
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
export { safeImport as t };
|
|
@@ -1,77 +0,0 @@
|
|
|
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
|
|
77
|
-
export { fromNow as a, timeDeltaToString as c, dailyReset as i, toNow as l, LegacyTimestamp as n, parseDate as o, _default as r, pieceIsSmoller as s, ContentTimestamp as t, weeklyReset as u };
|
|
@@ -1,113 +0,0 @@
|
|
|
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
|
-
};
|
|
111
|
-
|
|
112
|
-
//#endregion
|
|
113
|
-
export { timeDate_default as a, weeklyReset as c, pieceIsSmoller as i, fromNow as n, timeDeltaToString as o, parseDate as r, toNow as s, dailyReset as t };
|