@simcups/swiss-tools 1.0.15 → 1.0.16
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/__tests__/get-knockout-round-name.spec.d.ts +2 -0
- package/dist/__tests__/get-knockout-round-name.spec.d.ts.map +1 -0
- package/dist/__tests__/get-knockout-round-name.spec.js +31 -0
- package/dist/__tests__/get-knockout-round-name.spec.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/knockoutt-helpers.d.ts +3 -0
- package/dist/knockoutt-helpers.d.ts.map +1 -0
- package/dist/knockoutt-helpers.js +18 -0
- package/dist/knockoutt-helpers.js.map +1 -0
- package/package.json +4 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-knockout-round-name.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/get-knockout-round-name.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { getKnockoutRoundName, getKnockoutTotalRounds } from "../knockoutt-helpers.js";
|
|
3
|
+
describe(`Kncokout utils`, () => {
|
|
4
|
+
it(`getKnockoutTotalRounds`, () => {
|
|
5
|
+
// 8-team knockout
|
|
6
|
+
expect(getKnockoutTotalRounds(7)).equals(3);
|
|
7
|
+
expect(getKnockoutTotalRounds(8)).equals(3);
|
|
8
|
+
// 16-team knockout
|
|
9
|
+
expect(getKnockoutTotalRounds(11)).equals(4);
|
|
10
|
+
expect(getKnockoutTotalRounds(16)).equals(4);
|
|
11
|
+
// 32-team knockout
|
|
12
|
+
expect(getKnockoutTotalRounds(17)).equals(5);
|
|
13
|
+
expect(getKnockoutTotalRounds(24)).equals(5);
|
|
14
|
+
expect(getKnockoutTotalRounds(27)).equals(5);
|
|
15
|
+
expect(getKnockoutTotalRounds(32)).equals(5);
|
|
16
|
+
// 64-team knockout
|
|
17
|
+
expect(getKnockoutTotalRounds(47)).equals(6);
|
|
18
|
+
expect(getKnockoutTotalRounds(48)).equals(6);
|
|
19
|
+
expect(getKnockoutTotalRounds(49)).equals(6);
|
|
20
|
+
});
|
|
21
|
+
it(`getKnockoutRoundName`, () => {
|
|
22
|
+
expect(getKnockoutRoundName(0, 8)).toBe("Quarter");
|
|
23
|
+
expect(getKnockoutRoundName(1, 8)).toBe("Semi");
|
|
24
|
+
expect(getKnockoutRoundName(2, 8)).toBe("Final");
|
|
25
|
+
expect(getKnockoutRoundName(0, 16)).toBe("RD16");
|
|
26
|
+
expect(getKnockoutRoundName(1, 16)).toBe("Quarter");
|
|
27
|
+
expect(getKnockoutRoundName(2, 16)).toBe("Semi");
|
|
28
|
+
expect(getKnockoutRoundName(3, 16)).toBe("Final");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=get-knockout-round-name.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-knockout-round-name.spec.js","sourceRoot":"","sources":["../../src/__tests__/get-knockout-round-name.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAC,oBAAoB,EAAE,sBAAsB,EAAC,MAAM,yBAAyB,CAAC;AACrF,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;QAC9B,kBAAkB;QAClB,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5C,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5C,mBAAmB;QACnB,MAAM,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAA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AAoB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpD,MAAM,CAAC,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjD,MAAM,CAAC,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export * from './chunk-pots.js';
|
|
|
3
3
|
export * from './delay.js';
|
|
4
4
|
export * from './errors.js';
|
|
5
5
|
export * from './format-signed-number.js';
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./knockoutt-helpers.js";
|
|
7
7
|
export * from './get-ordinal.js';
|
|
8
8
|
export * from './get-percentage.js';
|
|
9
9
|
export * from './string-utils.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export * from './chunk-pots.js';
|
|
|
3
3
|
export * from './delay.js';
|
|
4
4
|
export * from './errors.js';
|
|
5
5
|
export * from './format-signed-number.js';
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./knockoutt-helpers.js";
|
|
7
7
|
export * from './get-ordinal.js';
|
|
8
8
|
export * from './get-percentage.js';
|
|
9
9
|
export * from './string-utils.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knockoutt-helpers.d.ts","sourceRoot":"","sources":["../src/knockoutt-helpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,oBAAoB,CAChC,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,GAClB,MAAM,CAYR;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,UAEvD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { nextPowerOf2 } from "./power-of-2.js";
|
|
2
|
+
export function getKnockoutRoundName(thisRoundIndex, teamCount) {
|
|
3
|
+
const totalRounds = Math.ceil(Math.log(teamCount) / Math.log(2));
|
|
4
|
+
const isLastRound = thisRoundIndex === totalRounds - 1;
|
|
5
|
+
if (isLastRound) {
|
|
6
|
+
return "Final";
|
|
7
|
+
}
|
|
8
|
+
const teamTotal = nextPowerOf2(teamCount) / Math.pow(2, thisRoundIndex);
|
|
9
|
+
return teamTotal >= 16
|
|
10
|
+
? `RD${teamTotal}`
|
|
11
|
+
: teamTotal === 8
|
|
12
|
+
? "Quarter"
|
|
13
|
+
: "Semi";
|
|
14
|
+
}
|
|
15
|
+
export function getKnockoutTotalRounds(teamCount) {
|
|
16
|
+
return Math.ceil(Math.log(teamCount) / Math.log(2));
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=knockoutt-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knockoutt-helpers.js","sourceRoot":"","sources":["../src/knockoutt-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C,MAAM,UAAU,oBAAoB,CAChC,cAAsB,EACtB,SAAiB;IAEjB,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,MAAM,WAAW,GAAG,cAAc,KAAK,WAAW,GAAG,CAAC,CAAC;IACvD,IAAI,WAAW,EAAE,CAAC;QACd,OAAO,OAAO,CAAC;IACnB,CAAC;IACD,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;IACxE,OAAO,SAAS,IAAI,EAAE;QAClB,CAAC,CAAC,KAAK,SAAS,EAAE;QAClB,CAAC,CAAC,SAAS,KAAK,CAAC;YACb,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,MAAM,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,SAAiB;IACpD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simcups/swiss-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "Slim utility.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -27,5 +27,8 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"typescript": "^6.0.2"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"vitest": "^4.1.2"
|
|
30
33
|
}
|
|
31
34
|
}
|