@algoux/standard-ranklist-utils 0.2.1 → 0.2.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.
package/dist/index.cjs CHANGED
@@ -269,6 +269,21 @@ function sortRows(rows) {
269
269
  });
270
270
  return rows;
271
271
  }
272
+ function cloneDeep(obj) {
273
+ if (obj === null || typeof obj !== "object") {
274
+ return obj;
275
+ }
276
+ if (Array.isArray(obj)) {
277
+ return obj.map((item) => cloneDeep(item));
278
+ }
279
+ const clonedObj = {};
280
+ for (const key in obj) {
281
+ if (obj.hasOwnProperty(key)) {
282
+ clonedObj[key] = cloneDeep(obj[key]);
283
+ }
284
+ }
285
+ return clonedObj;
286
+ }
272
287
  function regenerateRanklistBySolutions(originalRanklist, solutions) {
273
288
  var _a;
274
289
  if (!canRegenerateRanklist(originalRanklist)) {
@@ -278,15 +293,18 @@ function regenerateRanklistBySolutions(originalRanklist, solutions) {
278
293
  penalty: [20, "min"],
279
294
  noPenaltyResults: ["FB", "AC", "?", "CE", "UKE", null],
280
295
  timeRounding: "floor",
281
- ...JSON.parse(JSON.stringify(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {}))
282
- };
283
- const ranklist = {
284
- ...originalRanklist,
285
- rows: []
296
+ ...cloneDeep(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {})
286
297
  };
298
+ const ranklist = {};
299
+ for (const key in originalRanklist) {
300
+ if (key !== "rows" && originalRanklist.hasOwnProperty(key)) {
301
+ ranklist[key] = cloneDeep(originalRanklist[key]);
302
+ }
303
+ }
304
+ ranklist.rows = [];
287
305
  const rows = [];
288
306
  const userRowMap = /* @__PURE__ */ new Map();
289
- const problemCount = originalRanklist.problems.length;
307
+ const problemCount = ranklist.problems.length;
290
308
  originalRanklist.rows.forEach((row) => {
291
309
  const userId = row.user.id && `${row.user.id}` || `${typeof row.user.name === "string" ? row.user.name : JSON.stringify(row.user.name)}`;
292
310
  userRowMap.set(userId, {
@@ -382,7 +400,7 @@ function regenerateRowsByIncrementalSolutions(originalRanklist, solutions) {
382
400
  penalty: [20, "min"],
383
401
  noPenaltyResults: ["FB", "AC", "?", "CE", "UKE", null],
384
402
  timeRounding: "floor",
385
- ...JSON.parse(JSON.stringify(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {}))
403
+ ...cloneDeep(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {})
386
404
  };
387
405
  const userRowIndexMap = /* @__PURE__ */ new Map();
388
406
  const rows = [...originalRanklist.rows];
package/dist/index.mjs CHANGED
@@ -267,6 +267,21 @@ function sortRows(rows) {
267
267
  });
268
268
  return rows;
269
269
  }
270
+ function cloneDeep(obj) {
271
+ if (obj === null || typeof obj !== "object") {
272
+ return obj;
273
+ }
274
+ if (Array.isArray(obj)) {
275
+ return obj.map((item) => cloneDeep(item));
276
+ }
277
+ const clonedObj = {};
278
+ for (const key in obj) {
279
+ if (obj.hasOwnProperty(key)) {
280
+ clonedObj[key] = cloneDeep(obj[key]);
281
+ }
282
+ }
283
+ return clonedObj;
284
+ }
270
285
  function regenerateRanklistBySolutions(originalRanklist, solutions) {
271
286
  var _a;
272
287
  if (!canRegenerateRanklist(originalRanklist)) {
@@ -276,15 +291,18 @@ function regenerateRanklistBySolutions(originalRanklist, solutions) {
276
291
  penalty: [20, "min"],
277
292
  noPenaltyResults: ["FB", "AC", "?", "CE", "UKE", null],
278
293
  timeRounding: "floor",
279
- ...JSON.parse(JSON.stringify(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {}))
280
- };
281
- const ranklist = {
282
- ...originalRanklist,
283
- rows: []
294
+ ...cloneDeep(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {})
284
295
  };
296
+ const ranklist = {};
297
+ for (const key in originalRanklist) {
298
+ if (key !== "rows" && originalRanklist.hasOwnProperty(key)) {
299
+ ranklist[key] = cloneDeep(originalRanklist[key]);
300
+ }
301
+ }
302
+ ranklist.rows = [];
285
303
  const rows = [];
286
304
  const userRowMap = /* @__PURE__ */ new Map();
287
- const problemCount = originalRanklist.problems.length;
305
+ const problemCount = ranklist.problems.length;
288
306
  originalRanklist.rows.forEach((row) => {
289
307
  const userId = row.user.id && `${row.user.id}` || `${typeof row.user.name === "string" ? row.user.name : JSON.stringify(row.user.name)}`;
290
308
  userRowMap.set(userId, {
@@ -380,7 +398,7 @@ function regenerateRowsByIncrementalSolutions(originalRanklist, solutions) {
380
398
  penalty: [20, "min"],
381
399
  noPenaltyResults: ["FB", "AC", "?", "CE", "UKE", null],
382
400
  timeRounding: "floor",
383
- ...JSON.parse(JSON.stringify(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {}))
401
+ ...cloneDeep(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {})
384
402
  };
385
403
  const userRowIndexMap = /* @__PURE__ */ new Map();
386
404
  const rows = [...originalRanklist.rows];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algoux/standard-ranklist-utils",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "author": "bLue",
5
5
  "keywords": [
6
6
  "standard ranklist",