@nukleus-sports/core 0.6.0 → 0.7.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/index.cjs CHANGED
@@ -74,6 +74,7 @@ __export(src_exports, {
74
74
  getTeamRankingConfigIds: () => getTeamRankingConfigIds,
75
75
  getTeamStatColumns: () => getTeamStatColumns,
76
76
  getTeamVenueConfig: () => getTeamVenueConfig,
77
+ getTeamWebsiteHref: () => getTeamWebsiteHref,
77
78
  getVisibleTeamStatTypes: () => getVisibleTeamStatTypes,
78
79
  hasTeamFacts: () => hasTeamFacts,
79
80
  isGameBeforeDay: () => isGameBeforeDay,
@@ -88,6 +89,7 @@ __export(src_exports, {
88
89
  resolveRecentGameOpponent: () => resolveRecentGameOpponent,
89
90
  selectRecentGames: () => selectRecentGames,
90
91
  showsTeamStatCategoryPicker: () => showsTeamStatCategoryPicker,
92
+ sortTeamPlayers: () => sortTeamPlayers,
91
93
  sortTeamStaff: () => sortTeamStaff,
92
94
  startOfLocalDay: () => startOfLocalDay,
93
95
  teamFactsDisplayFields: () => teamFactsDisplayFields,
@@ -236,55 +238,9 @@ function computeSeasonSummary(games, espnId, leagueId) {
236
238
  return { record, gamesPlayed: completedGames, totalGames };
237
239
  }
238
240
 
239
- // src/teamRosterColumns.ts
240
- var NFL_NBA_WNBA_LEAGUE_IDS = [1, 4, 5];
241
- var MLB_NHL_LEAGUE_IDS = [7, 14];
242
- var NCAAF_LEAGUE_IDS = [2, 13];
243
- var NCAAM_LEAGUE_ID = 6;
241
+ // src/teamRosterFormat.ts
244
242
  var MLS_LEAGUE_ID = 10;
245
243
  var MLB_LEAGUE_ID = 7;
246
- var BASE_COLUMNS = [
247
- { key: "first_name", label: "Name" },
248
- { key: "number", label: "No." },
249
- { key: "position", label: "Position" },
250
- { key: "height", label: "Height" },
251
- { key: "weight", label: "Weight" },
252
- { key: "age", label: "Age" }
253
- ];
254
- function getRosterColumns(leagueId) {
255
- if (NFL_NBA_WNBA_LEAGUE_IDS.includes(leagueId)) {
256
- return [
257
- ...BASE_COLUMNS,
258
- { key: "experience", label: "Exp." },
259
- { key: "college", label: "College" }
260
- ];
261
- }
262
- if (MLB_NHL_LEAGUE_IDS.includes(leagueId)) {
263
- return [
264
- ...BASE_COLUMNS,
265
- { key: "experience", label: "Exp" },
266
- { key: "birthplace", label: "Birthplace" }
267
- ];
268
- }
269
- if (NCAAF_LEAGUE_IDS.includes(leagueId)) {
270
- return [
271
- ...BASE_COLUMNS,
272
- { key: "experience", label: "Class" },
273
- { key: "hometown", label: "Hometown" }
274
- ];
275
- }
276
- if (leagueId === NCAAM_LEAGUE_ID) {
277
- return [
278
- ...BASE_COLUMNS,
279
- { key: "experience", label: "Class" },
280
- { key: "birthplace", label: "Birthplace" }
281
- ];
282
- }
283
- if (leagueId === MLS_LEAGUE_ID) {
284
- return [...BASE_COLUMNS, { key: "birthplace", label: "Birthplace" }];
285
- }
286
- return [];
287
- }
288
244
  function calculateAge(birthDateString) {
289
245
  const birthDate = new Date(birthDateString);
290
246
  const today = /* @__PURE__ */ new Date();
@@ -335,6 +291,54 @@ function formatHometown(specificData) {
335
291
  if (state) return state;
336
292
  return "--";
337
293
  }
294
+
295
+ // src/teamRosterColumns.ts
296
+ var NFL_NBA_WNBA_LEAGUE_IDS = [1, 4, 5];
297
+ var MLB_NHL_LEAGUE_IDS = [7, 14];
298
+ var NCAAF_LEAGUE_IDS = [2, 13];
299
+ var NCAAM_LEAGUE_ID = 6;
300
+ var BASE_COLUMNS = [
301
+ { key: "first_name", label: "Name" },
302
+ { key: "number", label: "No." },
303
+ { key: "position", label: "Position" },
304
+ { key: "height", label: "Height" },
305
+ { key: "weight", label: "Weight" },
306
+ { key: "age", label: "Age" }
307
+ ];
308
+ function getRosterColumns(leagueId) {
309
+ if (NFL_NBA_WNBA_LEAGUE_IDS.includes(leagueId)) {
310
+ return [
311
+ ...BASE_COLUMNS,
312
+ { key: "experience", label: "Exp." },
313
+ { key: "college", label: "College" }
314
+ ];
315
+ }
316
+ if (MLB_NHL_LEAGUE_IDS.includes(leagueId)) {
317
+ return [
318
+ ...BASE_COLUMNS,
319
+ { key: "experience", label: "Exp" },
320
+ { key: "birthplace", label: "Birthplace" }
321
+ ];
322
+ }
323
+ if (NCAAF_LEAGUE_IDS.includes(leagueId)) {
324
+ return [
325
+ ...BASE_COLUMNS,
326
+ { key: "experience", label: "Class" },
327
+ { key: "hometown", label: "Hometown" }
328
+ ];
329
+ }
330
+ if (leagueId === NCAAM_LEAGUE_ID) {
331
+ return [
332
+ ...BASE_COLUMNS,
333
+ { key: "experience", label: "Class" },
334
+ { key: "birthplace", label: "Birthplace" }
335
+ ];
336
+ }
337
+ if (leagueId === MLS_LEAGUE_ID) {
338
+ return [...BASE_COLUMNS, { key: "birthplace", label: "Birthplace" }];
339
+ }
340
+ return [];
341
+ }
338
342
  function getRosterCellValue(player, columnKey, leagueId) {
339
343
  switch (columnKey) {
340
344
  case "first_name":
@@ -418,10 +422,13 @@ function getTeamPlaceSummaries(specificData, leagueAbbreviation) {
418
422
  function formatTeamName(team, nickname) {
419
423
  return [team, nickname].map((part) => part?.trim()).filter(Boolean).join(" ");
420
424
  }
425
+ function getTeamWebsiteHref(officialWebsite) {
426
+ return /^https?:\/\//i.test(officialWebsite) ? officialWebsite : `http://${officialWebsite}`;
427
+ }
421
428
 
422
- // src/teamStaffSort.ts
423
- var EMPTY_VALUES = /* @__PURE__ */ new Set(["", "-"]);
424
- function compareValues(left, right, desc) {
429
+ // src/compareSortValues.ts
430
+ var EMPTY_VALUES = /* @__PURE__ */ new Set(["", "-", "--"]);
431
+ function compareSortValues(left, right, desc) {
425
432
  const leftMissing = typeof left === "string" && EMPTY_VALUES.has(left);
426
433
  const rightMissing = typeof right === "string" && EMPTY_VALUES.has(right);
427
434
  if (leftMissing && rightMissing) return 0;
@@ -433,6 +440,8 @@ function compareValues(left, right, desc) {
433
440
  }
434
441
  return String(left).localeCompare(String(right), void 0, { numeric: true, sensitivity: "base" }) * direction;
435
442
  }
443
+
444
+ // src/teamStaffSort.ts
436
445
  function sortTeamStaff(staff, sorting) {
437
446
  const activeSort = sorting[0];
438
447
  if (!activeSort) return staff;
@@ -447,10 +456,53 @@ function sortTeamStaff(staff, sorting) {
447
456
  return member.display_order;
448
457
  }
449
458
  };
450
- return compareValues(value(left), value(right), activeSort.desc);
459
+ return compareSortValues(value(left), value(right), activeSort.desc);
451
460
  });
452
461
  }
453
462
 
463
+ // src/teamRosterSort.ts
464
+ function sortValue(player, columnId, leagueId) {
465
+ const data = player.specific_data;
466
+ switch (columnId) {
467
+ case "first_name":
468
+ return [player.first_name, player.last_name].filter(Boolean).join(" ");
469
+ case "number": {
470
+ if (player.number === null || player.number === void 0 || player.number === "") return "-";
471
+ return Number.parseInt(String(player.number), 10) || String(player.number);
472
+ }
473
+ case "position":
474
+ return player.position ?? "-";
475
+ case "height":
476
+ return String(data?.height ?? "-");
477
+ case "weight":
478
+ return Number(data?.weight) || "-";
479
+ case "age":
480
+ return data?.birth_date ? calculateAge(data.birth_date) : "-";
481
+ case "experience":
482
+ if (player.experience === "0") return 0;
483
+ return Number(player.experience) || player.experience || "-";
484
+ case "college":
485
+ return String(data?.college_name ?? "-");
486
+ case "birthplace":
487
+ return formatBirthplace(data ?? null, leagueId ?? 0);
488
+ case "hometown":
489
+ return formatHometown(data ?? null);
490
+ default:
491
+ return "-";
492
+ }
493
+ }
494
+ function sortTeamPlayers(players, sorting, leagueId) {
495
+ const activeSort = sorting[0];
496
+ if (!activeSort) return players;
497
+ return [...players].sort(
498
+ (left, right) => compareSortValues(
499
+ sortValue(left, activeSort.id, leagueId),
500
+ sortValue(right, activeSort.id, leagueId),
501
+ activeSort.desc
502
+ )
503
+ );
504
+ }
505
+
454
506
  // src/teamSeasonStats.ts
455
507
  var FOOTBALL_TEAM_STAT_IDS = {
456
508
  PASSING_YARDS: 255,
@@ -1526,6 +1578,7 @@ function getTeamConferenceInfo(conference, division) {
1526
1578
  getTeamRankingConfigIds,
1527
1579
  getTeamStatColumns,
1528
1580
  getTeamVenueConfig,
1581
+ getTeamWebsiteHref,
1529
1582
  getVisibleTeamStatTypes,
1530
1583
  hasTeamFacts,
1531
1584
  isGameBeforeDay,
@@ -1540,6 +1593,7 @@ function getTeamConferenceInfo(conference, division) {
1540
1593
  resolveRecentGameOpponent,
1541
1594
  selectRecentGames,
1542
1595
  showsTeamStatCategoryPicker,
1596
+ sortTeamPlayers,
1543
1597
  sortTeamStaff,
1544
1598
  startOfLocalDay,
1545
1599
  teamFactsDisplayFields,