Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default argument value usage #2423

Merged
merged 1 commit into from Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/formatDuration/index.js
Expand Up @@ -7,7 +7,7 @@ const defaultFormat = [
'days',
'hours',
'minutes',
'seconds'
'seconds',
]

/**
Expand Down Expand Up @@ -73,21 +73,21 @@ const defaultFormat = [
* formatDuration({ years: 2, months: 9, weeks: 3 }, { delimiter: ', ' })
* //=> '2 years, 9 months, 3 weeks'
*/
export default function formatDuration(duration, options = {}) {
export default function formatDuration(duration, options) {
if (arguments.length < 1) {
throw new TypeError(
`1 argument required, but only ${arguments.length} present`
)
}

const format = options.format || defaultFormat
const locale = options.locale || defaultLocale
const zero = options.zero || false
const delimiter = options.delimiter || ' '
const format = options?.format || defaultFormat
const locale = options?.locale || defaultLocale
const zero = options?.zero || false
const delimiter = options?.delimiter || ' '

const result = format
.reduce((acc, unit) => {
const token = `x${unit.replace(/(^.)/, m => m.toUpperCase())}`
const token = `x${unit.replace(/(^.)/, (m) => m.toUpperCase())}`
const addChunk =
typeof duration[unit] === 'number' && (zero || duration[unit])
return addChunk
Expand Down
7 changes: 3 additions & 4 deletions src/getWeekYear/index.ts
Expand Up @@ -53,22 +53,21 @@ import {
*/
export default function getWeekYear(
dirtyDate: Date | number,
options: LocaleOptions & WeekStartOptions & FirstWeekContainsDateOptions = {}
options?: LocaleOptions & WeekStartOptions & FirstWeekContainsDateOptions
): number {
requiredArgs(1, arguments)

const date = toDate(dirtyDate)
const year = date.getFullYear()

const locale = options.locale
const localeFirstWeekContainsDate =
locale && locale.options && locale.options.firstWeekContainsDate
options?.locale?.options?.firstWeekContainsDate
const defaultFirstWeekContainsDate =
localeFirstWeekContainsDate == null
? 1
: toInteger(localeFirstWeekContainsDate)
const firstWeekContainsDate =
options.firstWeekContainsDate == null
options?.firstWeekContainsDate == null
? defaultFirstWeekContainsDate
: toInteger(options.firstWeekContainsDate)

Expand Down
5 changes: 4 additions & 1 deletion src/getWeeksInMonth/index.ts
Expand Up @@ -35,7 +35,10 @@ import { LocaleOptions, WeekStartOptions } from '../types'
* const result = getWeeksInMonth(new Date(2017, 6, 5), { weekStartsOn: 1 })
* //=> 6
*/
export default function getWeeksInMonth(date: Date | number, options: LocaleOptions & WeekStartOptions = {}): number {
export default function getWeeksInMonth(
date: Date | number,
options?: LocaleOptions & WeekStartOptions
): number {
requiredArgs(1, arguments)

return (
Expand Down