og-players 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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -0
  3. package/package.json +24 -0
  4. package/src/index.js +80 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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
@@ -0,0 +1,144 @@
1
+ # og-players
2
+
3
+ > Mapea y construye la información en crudo de un jugador.
4
+
5
+ ## Instalación
6
+
7
+ ```bash
8
+ npm install og-players
9
+ ```
10
+
11
+ ## mapPlayers
12
+ > Mapea players e incomers de una plantilla de equipo,
13
+
14
+ ```js
15
+ const { mapPlayers } = require('og-players');
16
+
17
+ mapPlayers(players);
18
+
19
+ ```
20
+
21
+ ```json
22
+ {
23
+ "squad": [
24
+ {
25
+ "id": 940871,
26
+ "name": "Nico Schlotterbeck",
27
+ "country": "Germany",
28
+ "position": "D",
29
+ "age": 26,
30
+ "height": 191,
31
+ "shirt": 4,
32
+ "market": {
33
+ "label": "57 M",
34
+ "digit": 57
35
+ },
36
+ "contract": {
37
+ "date": "30/06/2027",
38
+ "remain": {
39
+ "years": 1,
40
+ "months": 4,
41
+ "days": 10
42
+ }
43
+ },
44
+ "national": true,
45
+ "injured": {
46
+ "reason": "Muscle Injury",
47
+ "status": "out",
48
+ "started": {
49
+ "daytime": "LUN | 16/02/2026",
50
+ "date": "16/02/2026",
51
+ "remain": false,
52
+ "weekend": false,
53
+ "since": {
54
+ "years": 0,
55
+ "months": 0,
56
+ "days": 4
57
+ },
58
+ "detailed": {
59
+ "name": "lunes",
60
+ "day": 16,
61
+ "month": "febrero",
62
+ "year": 2026
63
+ }
64
+ },
65
+ "ended": {
66
+ "daytime": "DOM | 22/02/2026",
67
+ "date": "22/02/2026",
68
+ "remain": {
69
+ "years": 0,
70
+ "months": 0,
71
+ "days": 2
72
+ },
73
+ "weekend": true,
74
+ "since": {
75
+ "years": 0,
76
+ "months": 0,
77
+ "days": 0
78
+ },
79
+ "detailed": {
80
+ "name": "domingo",
81
+ "day": 22,
82
+ "month": "febrero",
83
+ "year": 2026
84
+ }
85
+ }
86
+ }
87
+ }
88
+ ],
89
+ "incomers": [
90
+ {
91
+ "id": 954076,
92
+ "age": 23,
93
+ "name": "Fábio Silva",
94
+ "country": "Portugal",
95
+ "position": "F",
96
+ "last": {
97
+ "name": "Wolverhampton",
98
+ "country": "England"
99
+ },
100
+ "date": {
101
+ "daytime": "VIE | 29/08/2025",
102
+ "date": "29/08/2025",
103
+ "remain": false,
104
+ "weekend": false,
105
+ "since": {
106
+ "years": 0,
107
+ "months": 5,
108
+ "days": 22
109
+ },
110
+ "detailed": {
111
+ "name": "viernes",
112
+ "day": 29,
113
+ "month": "agosto",
114
+ "year": 2025
115
+ }
116
+ },
117
+ "contract": {
118
+ "date": "30/06/2030",
119
+ "remain": {
120
+ "years": 4,
121
+ "months": 4,
122
+ "days": 10
123
+ }
124
+ },
125
+ "market": {
126
+ "label": "27 M",
127
+ "digit": 27
128
+ }
129
+ }
130
+ ]
131
+ }
132
+ ```
133
+
134
+
135
+ ## API
136
+
137
+
138
+ ### `hello(name)`
139
+
140
+ Descripción de la función.
141
+
142
+ ## License
143
+
144
+ MIT
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "og-players",
3
+ "version": "0.0.2",
4
+ "description": "",
5
+ "main": "./src/index.js",
6
+ "scripts": {
7
+ "test": "node test/index.test.js",
8
+ "prepublishOnly": "npm test"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "MIT",
13
+ "files": [
14
+ "src/"
15
+ ],
16
+ "engines": {
17
+ "node": ">=18.0.0"
18
+ },
19
+ "dependencies": {
20
+ "og-currency": "^0.0.3",
21
+ "og-dates": "^0.0.15",
22
+ "og-tools": "^0.0.1"
23
+ }
24
+ }
package/src/index.js ADDED
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ const { ogDates } = require("og-dates");
4
+ const { ogCurrency } = require("og-currency");
5
+ const { comillas } = require("og-tools");
6
+
7
+ function _construct_incomers(data = {}) {
8
+ const { player: p, previousTeam: previous, transferDate: transfer } = data;
9
+
10
+ const transdate = ogDates(transfer);
11
+ const plates = ogDates(p?.dateOfBirthTimestamp);
12
+ const plurrency = ogCurrency(p?.proposedMarketValue ?? 0);
13
+ const plontrato = ogDates(p?.contractUntilTimestamp);
14
+
15
+ return {
16
+ id: p.id,
17
+ age: plates?.since?.years ?? "?",
18
+ name: comillas(p?.name),
19
+ country: comillas(p?.country?.name),
20
+ position: p?.position,
21
+ last: {
22
+ name: comillas(previous?.name),
23
+ country: comillas(previous?.country?.name),
24
+ },
25
+ date: transdate,
26
+ contract: p?.contractUntilTimestamp
27
+ ? { date: plontrato.date, remain: plontrato.remain }
28
+ : null,
29
+ market: plurrency,
30
+ };
31
+ }
32
+
33
+ function _construct_players(p, nationals = []) {
34
+ const plates = ogDates(p?.dateOfBirthTimestamp);
35
+ const plurrency = ogCurrency(p?.proposedMarketValue ?? 0);
36
+ const plontrato = ogDates(p?.contractUntilTimestamp);
37
+
38
+ const isNational = nationals.filter(s => s.id === p.id);
39
+
40
+ const injury_start = ogDates(p?.injury?.startDateTimestamp);
41
+ const injury_end = ogDates(p?.injury?.endDateTimestamp);
42
+
43
+ return {
44
+ id: p.id,
45
+ name: comillas(p?.name),
46
+ country: comillas(p?.country?.name),
47
+ position: p?.position,
48
+ age: plates?.since?.years ?? "?",
49
+ height: p?.height,
50
+ shirt: p?.shirtNumber,
51
+ market: plurrency,
52
+ contract: p?.contractUntilTimestamp
53
+ ? { date: plontrato.date, remain: plontrato.remain }
54
+ : null,
55
+ national: isNational ? true : false,
56
+ injured: p?.injury
57
+ ? {
58
+ reason: p.injury.reason,
59
+ status: p.injury.status,
60
+ started: injury_start,
61
+ ended: injury_end,
62
+ }
63
+ : null,
64
+ };
65
+ }
66
+
67
+ function mapPlayers(data = {}) {
68
+ const {
69
+ players = [],
70
+ playerPreviousTeam: previous = [],
71
+ nationalPlayers: national = [],
72
+ } = data;
73
+
74
+ return {
75
+ squad: players.map(o => _construct_players(o.player, national)),
76
+ incomers: previous.map(o => _construct_incomers(o)),
77
+ };
78
+ }
79
+
80
+ module.exports = { mapPlayers };