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

Use default argument value syntax #2595

Closed
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
10 changes: 5 additions & 5 deletions src/formatDuration/index.js
Expand Up @@ -73,17 +73,17 @@ 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) => {
Expand Down
7 changes: 4 additions & 3 deletions src/getWeekYear/index.ts
Expand Up @@ -53,21 +53,22 @@ 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 =
options?.locale?.options?.firstWeekContainsDate
locale && locale.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
2 changes: 1 addition & 1 deletion src/getWeeksInMonth/index.ts
Expand Up @@ -37,7 +37,7 @@ import { LocaleOptions, WeekStartOptions } from '../types'
*/
export default function getWeeksInMonth(
date: Date | number,
options?: LocaleOptions & WeekStartOptions
options: LocaleOptions & WeekStartOptions = {}
): number {
requiredArgs(1, arguments)

Expand Down