Custom parse format doesn't support all constructor types
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.8k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
The dayjs constructor takes in an option type as such
`export type OptionType = { locale?: string, format?: string, utc?: boolean } | string | string[]`
but if you use object format { locale, format, etc} as an input using the `customParseFormat` it doesn't work as expected
https://github.com/iamkun/dayjs/blob/4aca4b1b584a15de1146d929f95c944594032f20/src/plugin/customParseFormat/index.js#L213
Only looks at that param as a string or array. So this just silently doesn't work properly. The typescript doesn't give any hints to this because the typing says sending in that format is ok
**Expected behavior**
Use a `{ locale, format, utc }` should work properly when sent into a customerParseFormat plugin or it should explicitly fail instead of silently failing.
**Information**
- Day.js Version [e.g. v1.0.0]
- OS: [e.g. iOS]
- Browser [e.g. chrome 62]
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]
Contributor guide
Research direction
The affected entry point is src/plugin/customParseFormat/index.js around line 213; start there and compare how the constructor's string and array inputs are handled with the object form described in the issue. Done means the { locale, format, utc } input behaves correctly with customParseFormat, or is rejected explicitly rather than silently ignored.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100