@xcpcio/core 0.43.0 → 0.44.1

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
@@ -19,6 +19,7 @@ const Papa = require('papaparse');
19
19
  const ordinal = require('ordinal');
20
20
  const chroma = require('chroma-js');
21
21
  const colorDiff = require('color-diff');
22
+ const jsBase64 = require('js-base64');
22
23
 
23
24
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
24
25
 
@@ -1108,6 +1109,14 @@ class Giants {
1108
1109
  const m = Math.floor(penalty % 60);
1109
1110
  return [two(h), two(m)].join(":");
1110
1111
  }
1112
+ toJSON() {
1113
+ return {
1114
+ type: this.type,
1115
+ name: this.name,
1116
+ filterOrganizations: this.filterOrganizations,
1117
+ filterTeams: this.filterTeams
1118
+ };
1119
+ }
1111
1120
  }
1112
1121
  class BattleOfGiants {
1113
1122
  constructor() {
@@ -1118,6 +1127,30 @@ class BattleOfGiants {
1118
1127
  this.blueTeam = new Giants(0 /* BLUE */);
1119
1128
  this.redTeam = new Giants(1 /* RED */);
1120
1129
  }
1130
+ ToBase64() {
1131
+ return jsBase64.Base64.encode(JSON.stringify(this));
1132
+ }
1133
+ FromBase64(base64) {
1134
+ if (base64.length === 0) {
1135
+ return;
1136
+ }
1137
+ if (jsBase64.Base64.isValid(base64) === false) {
1138
+ return;
1139
+ }
1140
+ const j = JSON.parse(jsBase64.Base64.decode(base64));
1141
+ this.enable = j.enable;
1142
+ this.topX = j.topX;
1143
+ this.equalTeams = j.equalTeams;
1144
+ this.persist = j.persist;
1145
+ this.blueTeam = new Giants(0 /* BLUE */);
1146
+ this.blueTeam.name = j.blueTeam.name;
1147
+ this.blueTeam.setFilterOrganizations(j.blueTeam.filterOrganizations);
1148
+ this.blueTeam.setFilterTeams(j.blueTeam.filterTeams);
1149
+ this.redTeam = new Giants(1 /* RED */);
1150
+ this.redTeam.name = j.redTeam.name;
1151
+ this.redTeam.setFilterOrganizations(j.redTeam.filterOrganizations);
1152
+ this.redTeam.setFilterTeams(j.redTeam.filterTeams);
1153
+ }
1121
1154
  }
1122
1155
 
1123
1156
  class Group {
package/dist/index.d.ts CHANGED
@@ -264,6 +264,12 @@ declare class Giants {
264
264
  get totalSolvedProblemNum(): number;
265
265
  get totalPenalty(): number;
266
266
  get totalPenaltyToString(): string;
267
+ toJSON(): {
268
+ type: GiantsType;
269
+ name: string;
270
+ filterOrganizations: SelectOptionItem[];
271
+ filterTeams: SelectOptionItem[];
272
+ };
267
273
  }
268
274
  declare class BattleOfGiants {
269
275
  enable: boolean;
@@ -273,6 +279,8 @@ declare class BattleOfGiants {
273
279
  blueTeam: Giants;
274
280
  redTeam: Giants;
275
281
  constructor();
282
+ ToBase64(): string;
283
+ FromBase64(base64: string): void;
276
284
  }
277
285
 
278
286
  declare class RankOptions {
package/dist/index.mjs CHANGED
@@ -16,6 +16,7 @@ import Papa from 'papaparse';
16
16
  import ordinal from 'ordinal';
17
17
  import chroma from 'chroma-js';
18
18
  import { furthest } from 'color-diff';
19
+ import { Base64 } from 'js-base64';
19
20
 
20
21
  function stringToSubmissionStatus(status) {
21
22
  status = status.toUpperCase().replace(" ", "_");
@@ -1075,6 +1076,14 @@ class Giants {
1075
1076
  const m = Math.floor(penalty % 60);
1076
1077
  return [two(h), two(m)].join(":");
1077
1078
  }
1079
+ toJSON() {
1080
+ return {
1081
+ type: this.type,
1082
+ name: this.name,
1083
+ filterOrganizations: this.filterOrganizations,
1084
+ filterTeams: this.filterTeams
1085
+ };
1086
+ }
1078
1087
  }
1079
1088
  class BattleOfGiants {
1080
1089
  constructor() {
@@ -1085,6 +1094,30 @@ class BattleOfGiants {
1085
1094
  this.blueTeam = new Giants(0 /* BLUE */);
1086
1095
  this.redTeam = new Giants(1 /* RED */);
1087
1096
  }
1097
+ ToBase64() {
1098
+ return Base64.encode(JSON.stringify(this));
1099
+ }
1100
+ FromBase64(base64) {
1101
+ if (base64.length === 0) {
1102
+ return;
1103
+ }
1104
+ if (Base64.isValid(base64) === false) {
1105
+ return;
1106
+ }
1107
+ const j = JSON.parse(Base64.decode(base64));
1108
+ this.enable = j.enable;
1109
+ this.topX = j.topX;
1110
+ this.equalTeams = j.equalTeams;
1111
+ this.persist = j.persist;
1112
+ this.blueTeam = new Giants(0 /* BLUE */);
1113
+ this.blueTeam.name = j.blueTeam.name;
1114
+ this.blueTeam.setFilterOrganizations(j.blueTeam.filterOrganizations);
1115
+ this.blueTeam.setFilterTeams(j.blueTeam.filterTeams);
1116
+ this.redTeam = new Giants(1 /* RED */);
1117
+ this.redTeam.name = j.redTeam.name;
1118
+ this.redTeam.setFilterOrganizations(j.redTeam.filterOrganizations);
1119
+ this.redTeam.setFilterTeams(j.redTeam.filterTeams);
1120
+ }
1088
1121
  }
1089
1122
 
1090
1123
  class Group {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xcpcio/core",
3
- "version": "0.43.0",
3
+ "version": "0.44.1",
4
4
  "description": "XCPCIO Core",
5
5
  "author": "Dup4 <lyuzhi.pan@gmail.com>",
6
6
  "license": "MIT",
@@ -43,12 +43,13 @@
43
43
  "chroma-js": "^2.4.2",
44
44
  "color-diff": "^1.4.0",
45
45
  "dayjs": "^1.11.8",
46
+ "js-base64": "^3.7.5",
46
47
  "lodash": "^4.17.21",
47
48
  "ordinal": "^1.0.3",
48
49
  "papaparse": "^5.4.1",
49
50
  "string-width": "^6.1.0",
50
51
  "xlsx-js-style": "^1.2.0",
51
- "@xcpcio/types": "0.43.0"
52
+ "@xcpcio/types": "0.44.1"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@babel/types": "^7.22.4",
@@ -1,3 +1,4 @@
1
+ import { Base64 } from "js-base64";
1
2
  import { type SelectOptionItem } from "./basic-types";
2
3
  import type { Team } from "./team";
3
4
 
@@ -89,6 +90,15 @@ export class Giants {
89
90
 
90
91
  return [two(h), two(m)].join(":");
91
92
  }
93
+
94
+ toJSON() {
95
+ return {
96
+ type: this.type,
97
+ name: this.name,
98
+ filterOrganizations: this.filterOrganizations,
99
+ filterTeams: this.filterTeams,
100
+ };
101
+ }
92
102
  }
93
103
 
94
104
  export class BattleOfGiants {
@@ -109,4 +119,35 @@ export class BattleOfGiants {
109
119
  this.blueTeam = new Giants(GiantsType.BLUE);
110
120
  this.redTeam = new Giants(GiantsType.RED);
111
121
  }
122
+
123
+ ToBase64(): string {
124
+ return Base64.encode(JSON.stringify(this));
125
+ }
126
+
127
+ FromBase64(base64: string) {
128
+ if (base64.length === 0) {
129
+ return;
130
+ }
131
+
132
+ if (Base64.isValid(base64) === false) {
133
+ return;
134
+ }
135
+
136
+ const j = JSON.parse(Base64.decode(base64));
137
+
138
+ this.enable = j.enable;
139
+ this.topX = j.topX;
140
+ this.equalTeams = j.equalTeams;
141
+ this.persist = j.persist;
142
+
143
+ this.blueTeam = new Giants(GiantsType.BLUE);
144
+ this.blueTeam.name = j.blueTeam.name;
145
+ this.blueTeam.setFilterOrganizations(j.blueTeam.filterOrganizations);
146
+ this.blueTeam.setFilterTeams(j.blueTeam.filterTeams);
147
+
148
+ this.redTeam = new Giants(GiantsType.RED);
149
+ this.redTeam.name = j.redTeam.name;
150
+ this.redTeam.setFilterOrganizations(j.redTeam.filterOrganizations);
151
+ this.redTeam.setFilterTeams(j.redTeam.filterTeams);
152
+ }
112
153
  }