Skip to content
This is an experimental feature.

Range

Description

Import

import { Range } from "@tai-kun/surrealdb/decodeonly-datatypes";
import { Range } from "@tai-kun/surrealdb/encodable-datatypes";
import { Range } from "@tai-kun/surrealdb/standard-datatypes";

.constructor()

Creates a new Range object.

new Range(
source: [
begin: BoundIncluded | BoundExcluded | null,
end: BoundIncluded | BoundExcluded | null,
],
);

Arguments

source

A pair representing the minimum and maximum values of the range. null indicates an unbounded range.

Return Value

When called with new, Range returns its instance.

.begin instance property >=decode-only

The minimum value of the range. null if there is no lower bound.

.begin: BoundIncluded | BoundExcluded | null;

.end instance property >=decode-only

The maximum value of the range. null if there is no upper bound.

.end: BoundIncluded | BoundExcluded | null;

.toString() instance method >=encodable

Converts the Range object into a string usable in SurrealQL.

.toJSON() and .toSurql() return the same result as this method.

.toString(): string;

Arguments

None.

Return Value

Returns a string representation of the range.

Example

import {
Range,
BoundIncluded,
BoundExcluded,
} from "@tai-kun/surrealdb/encodable-datatypes";
const range = new Range([new BoundIncluded(1), new BoundIncluded(3)]);
console.log(range.toString());
// -> 1..=3
const range = new Range([new BoundExcluded(1), new BoundExcluded(3)]);
console.log(range.toString());
// -> 1>..3
const range = new Range([new BoundIncluded(1), new BoundExcluded(3)]);
console.log(range.toString());
// -> 1..3
const range = new Range([new BoundIncluded(1), null]);
console.log(range.toString());
// -> 1..
const range = new Range([null, new BoundExcluded(3)]);
console.log(range.toString());
// -> ..3
const range = new Range([new BoundExcluded(1), new BoundIncluded(3)]);
console.log(range.toString());
// -> 1>..=3
const range = new Range([new BoundExcluded(1), null]);
console.log(range.toString());
// -> 1>..
const range = new Range([null, new BoundIncluded(3)]);
console.log(range.toString());
// -> ..=3
const range = new Range([null, null]);
console.log(range.toString());
// -> ..

Advanced

Generic Range Object Check

To determine if a value is a Range object without relying on presets, it is recommended to use the isRange function. This function does not use instanceof, making it useful when the preset of the value being checked is unknown.

import { isRange } from "@tai-kun/surrealdb";