Merge pull request #43 from prolink007/master
Added error checking for when an invalid string is input.
This commit is contained in:
commit
a3ed595a17
2
index.js
2
index.js
@ -61,6 +61,8 @@ function parseTimestring (string, returnUnit, opts) {
|
||||
|
||||
totalSeconds += getSeconds(value, unit, unitValues)
|
||||
})
|
||||
} else {
|
||||
throw new Error(`The string [${string}] is invalid for timestring`)
|
||||
}
|
||||
|
||||
if (returnUnit) {
|
||||
|
8
test.js
8
test.js
@ -87,6 +87,14 @@ describe('timestring', () => {
|
||||
expect(() => timestring('1g')).to.throw(Error)
|
||||
})
|
||||
|
||||
it('throws an error when no numbers are in the timestring', () => {
|
||||
expect(() => timestring('asdf')).to.throw(Error)
|
||||
})
|
||||
|
||||
it('throws an error when numbers tail the timestring', () => {
|
||||
expect(() => timestring('asdf123')).to.throw(Error)
|
||||
})
|
||||
|
||||
it('can parse a messy time string', () => {
|
||||
expect(timestring('5 D a YS 4 h 2 0 mI nS')).to.equal(447600)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user