Socket
Socket
Sign inDemoInstall

postgres-interval

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postgres-interval - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

65

index.d.ts

@@ -11,6 +11,54 @@ declare namespace PostgresInterval {

/**
* Returns an interval string. This allows the interval object to be passed into prepared statements.
*
* ```js
* var parse = require('postgres-interval')
* var interval = parse('01:02:03')
* // => { hours: 1, minutes: 2, seconds: 3 }
* interval.toPostgres()
* // 1 hour 2 minutes 3 seconds
* ```
*/
toPostgres(): string;
/**
* Returns an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) compliant string, for example P0Y0M0DT0H9M0S.
*
* Also available as {@link toISOString toISOString}.
*
* ```js
* var parse = require('postgres-interval')
* var interval = parse('01:02:03')
* // => { hours: 1, minutes: 2, seconds: 3 }
* interval.toISO()
* // P0Y0M0DT1H2M3S
* ```
*/
toISO(): string;
/**
* Returns an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) compliant string, for example P0Y0M0DT0H9M0S.
*
* Also available as {@link toISO toISO} for backwards compatibility.
*
* ```js
* var parse = require('postgres-interval')
* var interval = parse('01:02:03')
* // => { hours: 1, minutes: 2, seconds: 3 }
* interval.toISOString()
* // P0Y0M0DT1H2M3S
* ```
*/
toISOString(): string;
/**
* Returns an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) compliant string shortened to minimum length, for example `PT9M`.
*
* ```js
* var parse = require('postgres-interval')
* var interval = parse('01:02:03')
* // => { hours: 1, minutes: 2, seconds: 3 }
* interval.toISOStringShort()
* // PT1H2M3S
* ```
*/
toISOStringShort(): string;

@@ -20,4 +68,21 @@ }

/**
* Parse Postgres interval columns.
*
* ```js
* var parse = require('postgres-interval')
* var interval = parse('01:02:03')
* // => { hours: 1, minutes: 2, seconds: 3 }
* interval.toPostgres()
* // 1 hour 2 minutes 3 seconds
* interval.toISOString()
* // P0Y0M0DT1H2M3S
* interval.toISOStringShort()
* // PT1H2M3S
* ```
*
* @param raw A Postgres interval string.
*/
declare function PostgresInterval(raw: string): PostgresInterval.IPostgresInterval;
export = PostgresInterval;

9

index.js

@@ -12,3 +12,3 @@ 'use strict'

}
const properties = ['seconds', 'minutes', 'hours', 'days', 'months', 'years']
const properties = ['years', 'months', 'days', 'hours', 'minutes', 'seconds']
PostgresInterval.prototype.toPostgres = function () {

@@ -18,3 +18,3 @@ const filtered = properties.filter(key => Object.prototype.hasOwnProperty.call(this, key) && this[key] !== 0)

// In addition to `properties`, we need to account for fractions of seconds.
if (this.milliseconds && filtered.indexOf('seconds') < 0) {
if (this.milliseconds && !filtered.includes('seconds')) {
filtered.push('seconds')

@@ -34,3 +34,6 @@ }

return value + ' ' + property
// fractional seconds will be a String, all others are Number
const isSingular = String(value) === '1'
// Remove plural 's' when the value is singular
return value + ' ' + (isSingular ? property.replace(/s$/, '') : property)
}, this)

@@ -37,0 +40,0 @@ .join(' ')

{
"name": "postgres-interval",
"main": "index.js",
"version": "3.0.0",
"version": "4.0.0",
"description": "Parse Postgres interval columns",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -18,7 +18,9 @@ # postgres-interval [![tests](https://github.com/bendrucker/postgres-interval/workflows/tests/badge.svg)](https://github.com/bendrucker/postgres-interval/actions?query=workflow%3Atests)

var interval = parse('01:02:03')
//=> {hours: 1, minutes: 2, seconds: 3}
// => { hours: 1, minutes: 2, seconds: 3 }
interval.toPostgres()
// 3 seconds 2 minutes 1 hours
// 1 hour 2 minutes 3 seconds
interval.toISOString()
// P0Y0M0DT1H2M3S
interval.toISOStringShort()
// PT1H2M3S
```

@@ -25,0 +27,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc