mirror of
https://github.com/spacebarchat/server.git
synced 2026-04-26 10:57:31 +00:00
rid of Math.clamp
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
import { route } from "@spacebar/api";
|
||||
import { Config, Message, User } from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { DmMessagesResponseSchema } from "@spacebar/schemas"
|
||||
import { DmMessagesResponseSchema } from "@spacebar/schemas";
|
||||
const router = Router({ mergeParams: true });
|
||||
|
||||
router.get(
|
||||
@@ -42,7 +42,7 @@ router.get(
|
||||
await Message.find({
|
||||
where: { channel_id: channel?.id },
|
||||
order: { timestamp: "DESC" },
|
||||
take: Math.clamp(req.query.limit ? Number(req.query.limit) : 50, 1, Config.get().limits.message.maxPreloadCount),
|
||||
take: Math.min(Math.max(req.query.limit ? Number(req.query.limit) : 50, 1), Config.get().limits.message.maxPreloadCount),
|
||||
})
|
||||
).filter((x) => x !== null) as Message[];
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import moduleAlias from "module-alias";
|
||||
moduleAlias();
|
||||
import './Math';
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
describe("Math extensions", () => {
|
||||
|
||||
it("clamp", async () => {
|
||||
assert.strictEqual(Math.clamp(5, 1, 10), 5);
|
||||
assert.strictEqual(Math.clamp(0, 1, 10), 1);
|
||||
assert.strictEqual(Math.clamp(15, 1, 10), 10);
|
||||
assert.strictEqual(Math.clamp(-5, -10, -1), -5);
|
||||
assert.strictEqual(Math.clamp(-15, -10, -1), -10);
|
||||
assert.strictEqual(Math.clamp(-0.5, -1, 0), -0.5);
|
||||
assert.strictEqual(Math.clamp(1.5, 1, 2), 1.5);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
|
||||
Copyright (C) 2025 Spacebar and Spacebar Contributors
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare global {
|
||||
interface Math {
|
||||
clamp(value: number, min: number, max: number): number;
|
||||
}
|
||||
}
|
||||
|
||||
export function mathClamp(value: number, min: number, max: number): number {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
// register extensions
|
||||
if (!Math.clamp)
|
||||
Math.clamp = mathClamp;
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from "./Array";
|
||||
export * from "./Math";
|
||||
export * from "./Url";
|
||||
export * from "./String";
|
||||
|
||||
Reference in New Issue
Block a user