Skip to content

Commit 13071a4

Browse files
committed
const/let
1 parent 3fcb43c commit 13071a4

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

index.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ function PostgresInterval (raw) {
88
}
99
Object.assign(this, parse(raw))
1010
}
11-
var properties = ['seconds', 'minutes', 'hours', 'days', 'months', 'years']
11+
const properties = ['seconds', 'minutes', 'hours', 'days', 'months', 'years']
1212
PostgresInterval.prototype.toPostgres = function () {
13-
var filtered = properties.filter(this.hasOwnProperty, this)
13+
const filtered = properties.filter(this.hasOwnProperty, this)
1414

1515
// In addition to `properties`, we need to account for fractions of seconds.
1616
if (this.milliseconds && filtered.indexOf('seconds') < 0) {
@@ -20,7 +20,7 @@ PostgresInterval.prototype.toPostgres = function () {
2020
if (filtered.length === 0) return '0'
2121
return filtered
2222
.map(function (property) {
23-
var value = this[property] || 0
23+
let value = this[property] || 0
2424

2525
// Account for fractional part of seconds,
2626
// remove trailing zeroes.
@@ -33,30 +33,30 @@ PostgresInterval.prototype.toPostgres = function () {
3333
.join(' ')
3434
}
3535

36-
var propertiesISOEquivalent = {
36+
const propertiesISOEquivalent = {
3737
years: 'Y',
3838
months: 'M',
3939
days: 'D',
4040
hours: 'H',
4141
minutes: 'M',
4242
seconds: 'S'
4343
}
44-
var dateProperties = ['years', 'months', 'days']
45-
var timeProperties = ['hours', 'minutes', 'seconds']
44+
const dateProperties = ['years', 'months', 'days']
45+
const timeProperties = ['hours', 'minutes', 'seconds']
4646
// according to ISO 8601
4747
PostgresInterval.prototype.toISOString = PostgresInterval.prototype.toISO = function () {
48-
var datePart = dateProperties
48+
const datePart = dateProperties
4949
.map(buildProperty, this)
5050
.join('')
5151

52-
var timePart = timeProperties
52+
const timePart = timeProperties
5353
.map(buildProperty, this)
5454
.join('')
5555

5656
return 'P' + datePart + 'T' + timePart
5757

5858
function buildProperty (property) {
59-
var value = this[property] || 0
59+
let value = this[property] || 0
6060

6161
// Account for fractional part of seconds,
6262
// remove trailing zeroes.
@@ -68,18 +68,18 @@ PostgresInterval.prototype.toISOString = PostgresInterval.prototype.toISO = func
6868
}
6969
}
7070

71-
var NUMBER = '([+-]?\\d+)'
72-
var YEAR = NUMBER + '\\s+years?'
73-
var MONTH = NUMBER + '\\s+mons?'
74-
var DAY = NUMBER + '\\s+days?'
75-
var TIME = '([+-])?([\\d]*):(\\d\\d):(\\d\\d)\\.?(\\d{1,6})?'
76-
var INTERVAL = new RegExp([YEAR, MONTH, DAY, TIME].map(function (regexString) {
71+
const NUMBER = '([+-]?\\d+)'
72+
const YEAR = NUMBER + '\\s+years?'
73+
const MONTH = NUMBER + '\\s+mons?'
74+
const DAY = NUMBER + '\\s+days?'
75+
const TIME = '([+-])?([\\d]*):(\\d\\d):(\\d\\d)\\.?(\\d{1,6})?'
76+
const INTERVAL = new RegExp([YEAR, MONTH, DAY, TIME].map(function (regexString) {
7777
return '(' + regexString + ')?'
7878
})
7979
.join('\\s*'))
8080

8181
// Positions of values in regex match
82-
var positions = {
82+
const positions = {
8383
years: 2,
8484
months: 4,
8585
days: 6,
@@ -89,22 +89,22 @@ var positions = {
8989
milliseconds: 12
9090
}
9191
// We can use negative time
92-
var negatives = ['hours', 'minutes', 'seconds', 'milliseconds']
92+
const negatives = ['hours', 'minutes', 'seconds', 'milliseconds']
9393

9494
function parseMilliseconds (fraction) {
9595
// add omitted zeroes
96-
var microseconds = fraction + '000000'.slice(fraction.length)
96+
const microseconds = fraction + '000000'.slice(fraction.length)
9797
return parseInt(microseconds, 10) / 1000
9898
}
9999

100100
function parse (interval) {
101101
if (!interval) return {}
102-
var matches = INTERVAL.exec(interval)
103-
var isNegative = matches[8] === '-'
102+
const matches = INTERVAL.exec(interval)
103+
const isNegative = matches[8] === '-'
104104
return Object.keys(positions)
105105
.reduce(function (parsed, property) {
106-
var position = positions[property]
107-
var value = matches[position]
106+
const position = positions[property]
107+
let value = matches[position]
108108
// no empty string
109109
if (!value) return parsed
110110
// milliseconds are actually microseconds (up to 6 digits)

test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
var test = require('tape')
4-
var interval = require('./')
3+
const test = require('tape')
4+
const interval = require('./')
55
const PostgresInterval = require('./')
66

77
test(function (t) {

0 commit comments

Comments
 (0)