Gathering detailed insights and metrics for pg-numrange
Gathering detailed insights and metrics for pg-numrange
Gathering detailed insights and metrics for pg-numrange
Gathering detailed insights and metrics for pg-numrange
Built to help parse, work with, and create PostgreSQL compatible range strings.
npm install pg-numrange
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
14 Commits
1 Watchers
3 Branches
1 Contributors
Updated on Oct 29, 2023
Latest Version
1.0.2
Package Id
pg-numrange@1.0.2
Unpacked Size
14.38 kB
Size
3.95 kB
File Count
5
NPM Version
9.1.3
Node Version
18.12.1
Published on
Nov 29, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
The NumRange
class is a JavaScript implementation for working with numerical ranges, which allows you to define a range with lower and upper bounds and perform various operations on these ranges. This class is designed to be flexible and user-friendly for managing and manipulating numeric intervals.
Here are some examples of how to create and work with NumRanges
1const NumRange = require('pg_numrange') 2// Create a NumRange object with inclusive bounds. 3const range1 = new NumRange(1, 10, true, true) 4 5// Check if a number is within the range. 6const number = 5 7if (range1.contains(number)) { 8 console.log(`${number} is within the range.`) 9} else { 10 console.log(`${number} is outside the range.`) 11} 12 13// Calculate the union of two ranges. 14const range2 = NumRange.parse('[5,15]') 15const unionRange = range1.union(range2) 16console.log('Union Range:', unionRange.toString()) 17 18// Calculate the intersection of two ranges. 19const intersectionRange = range1.intersection(range2) 20if (intersectionRange) { 21 console.log('Intersection Range:', intersectionRange.toString()) 22} else { 23 console.log('The ranges do not intersect.') 24}
lower: The lower bound of the numerical range. This property represents the lower limit of the range.
upper: The upper bound of the numerical range. This property represents the upper limit of the range.
lowerInclusive: A boolean value indicating whether the lower bound is inclusive when working with ranges. When set to true
, the lower bound is inclusive, meaning values equal to the lower bound are considered within the range.
upperInclusive: A boolean value indicating whether the upper bound is inclusive when working with ranges. When set to true
, the upper bound is inclusive, meaning values equal to the upper bound are considered within the range.
constructor(lower, upper, lowerInclusive, upperInclusive): Create a NumRange
object with specified lower and upper bounds, and inclusive/exclusive flags. This method initializes a NumRange
instance with the provided boundaries and options.
parse(rangeString): Parse a range string and create a NumRange
object. This static method is used to create a NumRange
instance based on a range string in a specific format.
contains(number): Check if a number falls within the bounds of the range. This method returns true
if the specified number is within the range, taking into account the inclusive or exclusive bounds.
union(otherRange): Calculate the union of two NumRange
objects. This method returns a new NumRange
object that encompasses both input ranges, combining them into a single range.
intersection(otherRange): Calculate the intersection of two NumRange
objects. This method returns a new NumRange
object representing the common range between the two input ranges. If there is no intersection, it returns null
.
toString(): Convert the NumRange
object to a PostgreSQL-compatible string. This method returns a string representing the NumRange
object in a format suitable for PostgreSQL database operations.
No vulnerabilities found.
No security vulnerabilities found.