Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .release-it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ export default {
publish: false,
},
hooks: {
"before:init": ["bun run test:run", "bun run typecheck", "bun run check", "bun run prepack", "bun run publint"],
"after:bump": ["bun run git-cliff --output CHANGELOG.md --tag ${version}", "bun run check:fix"],
"before:init": [
"bun run test:run",
"bun run typecheck",
"bun run check",
"bun run prepack",
"bun run publint",
],
"after:bump": [
"bun run git-cliff --output CHANGELOG.md --tag ${version}",
"bun run check:fix",
],
},
plugins: {
"@release-it/bumper": {
Expand Down
24 changes: 17 additions & 7 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"$schema": "https://biomejs.dev/schemas/2.3.13/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": true,
"ignore": []
"includes": ["**"]
},
"formatter": {
"enabled": true,
"useEditorconfig": true,
"lineEnding": "lf",
"indentStyle": "space",
"indentWidth": 4,
"ignore": ["**/dist", "**/coverage", "**/node_modules"]
},
"organizeImports": {
"enabled": true
"includes": ["**", "!**/dist", "!**/coverage", "!**/node_modules"]
},
"assist": { "actions": { "source": { "organizeImports": "on" } } },
"linter": {
"enabled": true,
"rules": {
Expand All @@ -30,5 +28,17 @@
"formatter": {
"quoteStyle": "double"
}
}
},
"overrides": [
{
"includes": [".release-it.ts"],
"linter": {
"rules": {
"suspicious": {
"noTemplateCurlyInString": "off"
}
}
}
}
]
}
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"description": "NMS Calc Library",
"type": "commonjs",
"version": "0.0.0",
"keywords": ["nomanssky", "No Man's Sky", "calculator"],
"keywords": [
"nomanssky",
"No Man's Sky",
"calculator"
],
"engines": {
"node": "^24.0.0"
},
Expand All @@ -26,7 +30,9 @@
"default": "./dist/index.mjs"
}
},
"files": ["dist"],
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
Expand Down
4 changes: 2 additions & 2 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>gander-settings/renovate:automerge-delayed"]
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>gander-settings/renovate:automerge-delayed"]
}
13 changes: 10 additions & 3 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ export type SumStatsArgument = number | string | undefined | null;

export function sumStats(stats: SumStatsArgument[] = []): number {
return stats
.map((v: SumStatsArgument) => Number.parseInt(String(v)))
.map((v: SumStatsArgument) => Number.parseInt(String(v), 10))
.filter((v) => Number.isInteger(v))
.reduce((s, v) => s + v, 0);
}

export function calcBaseStats(mainStats: number, bonusStats: number, rank_ups: number): number {
export function calcBaseStats(
mainStats: number,
bonusStats: number,
rank_ups: number,
): number {
return mainStats - (Math.min(bonusStats, MAX_BONUS) + 6 * rank_ups);
}

export function calcRankUps(expeditions: number): number {
const correctExpeditions = Math.min(Math.max(0, expeditions), MAX_EXPEDITIONS);
const correctExpeditions = Math.min(
Math.max(0, expeditions),
MAX_EXPEDITIONS,
);
let closestRank = 0;
for (const [expCount, rankCount] of expeditionsRankUps) {
if (expCount <= correctExpeditions) {
Expand Down
29 changes: 23 additions & 6 deletions src/reactive.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import { type ComputedRef, type Ref, computed } from "@vue/reactivity";
import { type SumStatsArgument, calcBaseStats, calcRankUps, isGlitched, sumStats } from "./functions";
import { type ComputedRef, computed, type Ref } from "@vue/reactivity";
import {
calcBaseStats,
calcRankUps,
isGlitched,
type SumStatsArgument,
sumStats,
} from "./functions";

export function useCalcBaseStats(mainStats: Ref<number>, bonusStats: Ref<number>, rankUps: Ref<number>): ComputedRef<number> {
return computed(() => calcBaseStats(mainStats.value, bonusStats.value, rankUps.value));
export function useCalcBaseStats(
mainStats: Ref<number>,
bonusStats: Ref<number>,
rankUps: Ref<number>,
): ComputedRef<number> {
return computed(() =>
calcBaseStats(mainStats.value, bonusStats.value, rankUps.value),
);
}

export function useCalcRankUps(expeditions: Ref<number>): ComputedRef<number> {
return computed(() => calcRankUps(expeditions.value));
}

export function useIsGlitched(baseStats: Ref<number>, expeditions: Ref<number>): ComputedRef<boolean> {
export function useIsGlitched(
baseStats: Ref<number>,
expeditions: Ref<number>,
): ComputedRef<boolean> {
return computed(() => isGlitched(baseStats.value, expeditions.value));
}

export function useSumStats(stats: Ref<SumStatsArgument[]>): ComputedRef<number> {
export function useSumStats(
stats: Ref<SumStatsArgument[]>,
): ComputedRef<number> {
return computed(() => sumStats(stats.value));
}
5 changes: 4 additions & 1 deletion test/calcRankUps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ describe("calcRankUps", () => {
{ expeditions: 58, total: 10 },
{ expeditions: 59, total: 10 },
{ expeditions: 60, total: 10 },
])("calc rankUps for $expeditions expeditions", ({ expeditions, total }) => {
])("calc rankUps for $expeditions expeditions", ({
expeditions,
total,
}) => {
expect(calcRankUps(expeditions)).toBe(total);
});
});
5 changes: 4 additions & 1 deletion test/isGlitched.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ describe("isGlitched", () => {
{ expeditions: 58, rankUp: false },
{ expeditions: 59, rankUp: false },
{ expeditions: 60, rankUp: false },
])("is glitched when $expeditions match rankUp", ({ expeditions, rankUp }) => {
])("is glitched when $expeditions match rankUp", ({
expeditions,
rankUp,
}) => {
expect(isGlitched(0, expeditions)).toBe(rankUp);
});
});
24 changes: 22 additions & 2 deletions test/sumStats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,33 @@ describe("sumStats", () => {
});

it("should sum integer values", () => {
const result = sumStats([1, 3.9, "4.9", undefined, null, "nope", "0", "0.9", "2"]);
const result = sumStats([
1,
3.9,
"4.9",
undefined,
null,
"nope",
"0",
"0.9",
"2",
]);

expect(result).toBe(10);
});

it("should sum positive and negative values", () => {
const result = sumStats([1, 3.9, "-4.9", undefined, null, "nope", "0", "0.9", "-2"]);
const result = sumStats([
1,
3.9,
"-4.9",
undefined,
null,
"nope",
"0",
"0.9",
"-2",
]);

expect(result).toBe(-2);
});
Expand Down
5 changes: 4 additions & 1 deletion test/useCalcRankUps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ describe("useCalcRankUps", () => {
{ expeditions: 58, total: 10 },
{ expeditions: 59, total: 10 },
{ expeditions: 60, total: 10 },
])("calc rankUps for $expeditions expeditions", ({ expeditions, total }) => {
])("calc rankUps for $expeditions expeditions", ({
expeditions,
total,
}) => {
const expCount = ref(expeditions);
const rankUps = useCalcRankUps(expCount);

Expand Down
5 changes: 4 additions & 1 deletion test/useIsGlitched.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ describe("useIsGlitched", () => {
{ expeditions: 58, rankUp: false },
{ expeditions: 59, rankUp: false },
{ expeditions: 60, rankUp: false },
])("is glitched when $expeditions match rankUp", ({ expeditions, rankUp }) => {
])("is glitched when $expeditions match rankUp", ({
expeditions,
rankUp,
}) => {
const exp = ref(expeditions);
const stats = ref(0);

Expand Down
8 changes: 6 additions & 2 deletions test/useSumStats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ describe("useSumStats", () => {
});

it("should sum integer values", () => {
const result = useSumStats(ref([1, 3.9, "4.9", undefined, null, "nope", "0", "0.9", "2"]));
const result = useSumStats(
ref([1, 3.9, "4.9", undefined, null, "nope", "0", "0.9", "2"]),
);

expect(isRef(result)).toBe(true);
expect(result.value).toBe(10);
});

it("should sum positive and negative values", () => {
const result = useSumStats(ref([1, 3.9, "-4.9", undefined, null, "nope", "0", "0.9", "-2"]));
const result = useSumStats(
ref([1, 3.9, "-4.9", undefined, null, "nope", "0", "0.9", "-2"]),
);

expect(isRef(result)).toBe(true);
expect(result.value).toBe(-2);
Expand Down