@i-xi-dev/base64
Version:
A JavaScript Base64 encoder and decoder, implements Forgiving base64 defined in WHATWG Infra Standard.
38 lines (37 loc) • 1.17 kB
JavaScript
import * as _Utils from "./_utils.js";
import { BigIntRange } from "./bigint_range.js";
export const ZERO = 0n;
export const isBigInt = _Utils._isBigInt;
export function isPositiveBigInt(test) {
return isBigInt(test) && (test > ZERO);
}
export function isNonNegativeBigInt(test) {
return isBigInt(test) && (test >= ZERO);
}
export function isNonPositiveBigInt(test) {
return isBigInt(test) && (test <= ZERO);
}
export function isNegativeBigInt(test) {
return isBigInt(test) && (test < ZERO);
}
export function isOddBigInt(test) {
return isBigInt(test) ? ((test % 2n) !== ZERO) : false;
}
export function isEvenBigInt(test) {
return isBigInt(test) ? ((test % 2n) === ZERO) : false;
}
export function clampBigInt(source, range) {
if (isBigInt(source) !== true) {
throw new TypeError("source");
}
const [min, max] = BigIntRange.resolve(range);
const clamped = _Utils._max(min, _Utils._min(max, source));
return clamped;
}
export function inRange(test, range) {
if (isBigInt(test) !== true) {
return false;
}
const [min, max] = BigIntRange.resolve(range);
return (test >= min) && (test <= max);
}