tolu / ISO8601-duration

Node/Js-module for parsing and making sense of ISO8601-durations
92 stars 10 forks source link

TypeError when passing invalid string to parse #15

Closed GodOfGrandeur closed 2 years ago

GodOfGrandeur commented 4 years ago

Steps To Reproduce

parse('abc');

The current behavior

Throws error

TypeError: Cannot read property 'slice' of null
at parse (node_modules/iso8601-duration/lib/index.js:35:10)

The expected behavior

Shouldn't throw a type error.

tolu commented 4 years ago

Could for instance add check that throws specific error when durationString doesn't match anything.

https://github.com/tolu/ISO8601-duration/blob/5cb2238944c95d6fb0ef9acc3dc15ff1edcd3029/src/index.js#L30

ssipos90 commented 3 years ago

@tolu I was just encountering this. Maybe nullcheck and throw something specific or return a 0 duration.