Skip to content

Commit

Permalink
remove zero-fill dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantiago committed Aug 28, 2020
1 parent cc98a87 commit 1dd727b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 26 deletions.
2 changes: 2 additions & 0 deletions lib/padLeft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const padLeft = (value, length = 2) =>
value.toString().padStart(length, 0)
14 changes: 5 additions & 9 deletions lib/toSrtTime.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* Module dependencies.
*/

import zeroFill from 'zero-fill'
import { padLeft } from './padLeft'

/**
* Return the given milliseconds as SRT timestamp.
Expand All @@ -17,10 +13,10 @@ export default function toSrtTime (timestamp) {

const date = new Date(0, 0, 0, 0, 0, 0, timestamp)

const hours = zeroFill(2, date.getHours())
const minutes = zeroFill(2, date.getMinutes())
const seconds = zeroFill(2, date.getSeconds())
const hours = padLeft(date.getHours())
const minutes = padLeft(date.getMinutes())
const seconds = padLeft(date.getSeconds())
const ms = timestamp - ((hours * 3600000) + (minutes * 60000) + (seconds * 1000))

return `${hours}:${minutes}:${seconds},${zeroFill(3, ms)}`
return `${hours}:${minutes}:${seconds},${padLeft(ms, 3)}`
}
14 changes: 5 additions & 9 deletions lib/toVttTime.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* Module dependencies.
*/

import zeroFill from 'zero-fill'
import { padLeft } from './padLeft'

/**
* Return the given milliseconds as WebVTT timestamp.
Expand All @@ -17,10 +13,10 @@ export default function toVttTime (timestamp) {

const date = new Date(0, 0, 0, 0, 0, 0, timestamp)

const hours = zeroFill(2, date.getHours())
const minutes = zeroFill(2, date.getMinutes())
const seconds = zeroFill(2, date.getSeconds())
const hours = padLeft(date.getHours())
const minutes = padLeft(date.getMinutes())
const seconds = padLeft(date.getSeconds())
const ms = timestamp - ((hours * 3600000) + (minutes * 60000) + (seconds * 1000))

return `${hours}:${minutes}:${seconds}.${zeroFill(3, ms)}`
return `${hours}:${minutes}:${seconds}.${padLeft(ms, 3)}`
}
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,5 @@
"standard": "^8.0.0",
"webpack": "^3.11.0"
},
"dependencies": {
"zero-fill": "^2.2.3"
}
"dependencies": {}
}

0 comments on commit 1dd727b

Please sign in to comment.