postgres-range

Range data type parser and serializer for PostgreSQL

MIT 9 个版本
安装
npm install postgres-range
yarn add postgres-range
pnpm add postgres-range
bun add postgres-range
README

postgres-range tests

Parse postgres range columns

Install

npm install --save postgres-range

Usage

const range = require('postgres-range')

const rng = range.parse('[0,5)', (value) => parseInt(value, 10))
rng.isBounded()
// => true
rng.isLowerBoundClosed()
// => true
rng.isUpperBoundClosed()
// => false
rng.hasLowerBound()
// => true
rng.hasUpperBound()
// => true

rng.containsPoint(4)
// => true
rng.containsRange(range.parse('[1,2]', x => parseInt(x)))
// => true

range.parse('empty').isEmpty()
// => true

range.serialize(new range.Range(0, 5))
// => '(0,5)'
range.serialize(new range.Range(0, 5, range.RANGE_LB_INC | RANGE_UB_INC))
// => '[0,5]'

API

parse(input, [transform]) -> Range

input

Required
Type: string

A Postgres range string.

transform

Type: function
Default: identity

A function that transforms non-null bounds of the range.

serialize(range, [format]) -> string

range

Required
Type: Range

A Range object.

format

Type: function
Default: identity

A function that formats non-null bounds of the range.

License

MIT © Abbas Mashayekh

版本列表
1.1.4 2024-01-29
1.1.3 2022-08-29
1.1.2 2022-06-14
1.1.1 2022-01-01
1.1.0 2021-12-31
1.0.3 2021-06-08
1.0.2 2021-03-24
1.0.1 2021-03-18
1.0.0 2021-03-11