og-tools 0.0.1 → 0.0.2

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +63 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "og-tools",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -16,4 +16,4 @@
16
16
  "engines": {
17
17
  "node": ">=18.0.0"
18
18
  }
19
- }
19
+ }
package/src/index.js CHANGED
@@ -1,11 +1,67 @@
1
1
  'use strict';
2
2
 
3
- function comillas(d){
4
- try {
5
- return d.replace(/'/g, " ").replace(/\s+/g, " ").trim();
6
- } catch (error) {
7
- return null;
8
- }
3
+ function comillas(d) {
4
+ try {
5
+ return d.replace(/'/g, " ").replace(/\s+/g, " ").trim();
6
+ } catch (error) {
7
+ return null;
8
+ }
9
9
  }
10
10
 
11
- module.exports = { comillas };
11
+ function correlateTournaments(teamA, teamB) {
12
+ try {
13
+ const mapB = new Map();
14
+
15
+ // indexar torneos del equipo B
16
+ for (const t of teamB) {
17
+ mapB.set(t.uniqueTournament.id, t);
18
+ }
19
+
20
+ const result = [];
21
+
22
+ for (const tournamentA of teamA) {
23
+ const id = tournamentA.uniqueTournament.id;
24
+
25
+ if (!mapB.has(id)) continue;
26
+
27
+ const tournamentB = mapB.get(id);
28
+
29
+ // crear mapa de seasons del B por year
30
+ const seasonsB = new Map(
31
+ tournamentB.seasons.map(s => [s.year, s])
32
+ );
33
+
34
+ const sharedSeasons = [];
35
+
36
+ for (const seasonA of tournamentA.seasons) {
37
+ if (seasonsB.has(seasonA.year)) {
38
+ sharedSeasons.push({
39
+ year: seasonA.year,
40
+ seasonAId: seasonA.id,
41
+ seasonBId: seasonsB.get(seasonA.year).id
42
+ });
43
+ }
44
+ }
45
+
46
+ if (sharedSeasons.length > 0) {
47
+ result.push({
48
+ tournamentId: id,
49
+ tournamentName: tournamentA.uniqueTournament.name,
50
+ slug: tournamentA.uniqueTournament.slug,
51
+ seasons: sharedSeasons
52
+ });
53
+ }
54
+ }
55
+
56
+ return result;
57
+ } catch (error) {
58
+ return { ok: false, error: { code: error.message, message: error.stack } };
59
+ }
60
+ }
61
+
62
+
63
+
64
+ module.exports = {
65
+ comillas,
66
+ correlateTournaments
67
+ };