@std/math
概述 Jump to heading
数学函数,如取模和限制值。
import { clamp, modulo } from "@std/math";
import { assertEquals } from "@std/assert";
for (let n = -3; n <= 3; ++n) {
const val = n * 12 + 5;
// 无论加减多少个十二小时周期,五点总是五点
assertEquals(modulo(val, 12), 5);
assertEquals(clamp(val, 0, 11), n === 0 ? 5 : n > 0 ? 11 : 0);
}
添加到你的项目 Jump to heading
deno add jsr:@std/math