ronantakizawa/codereview-bench huggingface dataset:
Repository: iamkun/dayjs
File: src/plugin/isToday/index.js (JavaScript)

Code before:
export default (o, c, d) => {
  const proto = c.prototype
  proto.isToday = function () {
    const comparisonKey = ['$y', '$D', '$m']
    const now = d()

    return comparisonKey.filter(function (key) {
      return now[key] !== this[key]
    }, this).length === 0
  }
}


Review comment (suggestion):
Please avoid using private variables start from `$`

try `format('YYYY-MM-DD')` instead

Code after:
export default (o, c, d) => {
  const proto = c.prototype
  proto.isToday = function () {
    const comparisonTemplate = 'YYYY-MM-DD'
    const now = d()

    return this.format(comparisonTemplate) === now.format(comparisonTemplate)
  }
}
Repository: iamkun/dayjs
File: src/plugin/objectSupport/index.js (JavaScript)

Code before:
   */
  const parseObjectArgument = (d, utc) => parseArrayArgument([
    0,
    d.y || d.year || d.years || 1970,
    d.M || d.month || d.months || 1,
    d.d || d.day || d.days || d.date || 1,
    d.h || d.hour || d.hours || 0,
    d.m || d.minute || d.minutes || 0,
    d.s || d.second || d.seconds || 0,
    d.ms || d.millisecond || d.milliseconds || 0
  ], utc)

  const isObject = obj => !(obj instanceof Date) && !(obj instanceof Array) && obj instanceof Object
  const parseDate = (cfg) => {
    const { date, utc } = cfg
    if (isObject(date)) return parseObjectArgument(date, utc)
    return date
  }

  const oldParse = proto.parse
  proto.parse = function (cfg) {
    cfg.date = parseDate(cfg)
    oldParse.bind(this)(cfg)
  }

  proto.setObject = function (argument) {
    const keys = Object.keys(argument)
    let chain = this.clone()
    keys.forEach((key) => {
      chain = chain.$set(key, argument[key])
    })
    return chain
  }
  const oldSet = proto.set
  proto.set = function (string, int) {
    if (string instanceof Object) {
      return this.setObject(string)
    }
    return oldSet.bind(this)(string, int)
  }

  proto.addObject = function (argument) {
    const keys = Object.keys(argument)
    let chain = this
    keys.forEach((key) => {
      chain = chain.add(argument[key], key)
    })
    return chain
  }
  const oldAdd = proto.add
  proto.add = function (number, string) {

Review comment (suggestion):
seems no need to put it on the `proto`, just a simple function will be better.

Code after:
      if (utc) {
        return new Date(Date.UTC(y, M, d, h, m, s, ms))
      }
      return new Date(y, M, d, h, m, s, ms)
    }
    return date
  }

  const oldParse = proto.parse
  proto.parse = function (cfg) {
    cfg.date = parseDate.bind(this)(cfg)
    oldParse.bind(this)(cfg)
  }

  const oldSet = proto.set
  const oldAdd = proto.add

  const callObject = function (call, argument, string, offset = 1) {
    if (argument instanceof Object) {
      const keys = Object.keys(argument)
      let chain = this
      keys.forEach((key) => {
        chain = call.bind(chain)(argument[key] * offset, key)
      })
      return chain
    }
    return call.bind(this)(argument * offset, string)
  }

  proto.set = function (string, int) {
    int = int === undefined ? string : int
    return callObject.bind(this)(function (i, s) {
      return oldSet.bind(this)(s, i)
    }, int, string)
  }
  proto.add = function (number, string) {
    return callObject.bind(this)(oldAdd, number, string)
  }
  proto.subtract = function (number, string) {
    return callObject.bind(this)(oldAdd, number, string, -1)
  }
}
Repository: iamkun/dayjs
File: src/plugin/objectSupport/index.js (JavaScript)

Code before:
  }

  const setObject = function (argument) {
    const keys = Object.keys(argument)
    let chain = this.clone()
    keys.forEach((key) => {
      chain = chain.$set(key, argument[key])
    })
    return chain
  }
  const addObject = function (argument) {
    const keys = Object.keys(argument)
    let chain = this
    keys.forEach((key) => {
      chain = chain.add(argument[key], key)
    })
    return chain
  }

  const subtractObject = function (argument) {
    const keys = Object.keys(argument)
    let chain = this
    keys.forEach((key) => {
      chain = chain.subtract(argument[key], key)
    })
    return chain
  }

  const oldSet = proto.set
  proto.set = function (string, int) {
    if (string instanceof Object) {
      return setObject.bind(this)(string)
    }
    return oldSet.bind(this)(string, int)
  }
  const oldAdd = proto.add
  proto.add = function (number, string) {
    if (number instanceof Object) {
      return addObject.bind(this)(number)
    }
    return oldAdd.bind(this)(number, string)
  }
  const oldSubtract = proto.subtract
  proto.subtract = function (number, string) {
    if (number instanceof Object) {
      return subtractObject.bind(this)(number)
    }
    return oldSubtract.bind(this)(number, string)
  }
}


Review comment (suggestion):
`substract` could be implemented as negative `add`, subtract { day: 1 } => add { day: 1 * -1 }, so that we could only care `add` and `set` logic

Code after:

  const oldSet = proto.set
  const oldAdd = proto.add

  const callObject = function (call, argument, string, offset = 1) {
    if (argument instanceof Object) {
      const keys = Object.keys(argument)
      let chain = this
      keys.forEach((key) => {
        chain = call.bind(chain)(argument[key] * offset, key)
      })
      return chain
    }
    return call.bind(this)(argument * offset, string)
  }

  proto.set = function (string, int) {
    int = int === undefined ? string : int
    return callObject.bind(this)(function (i, s) {
      return oldSet.bind(this)(s, i)
    }, int, string)
  }
  proto.add = function (number, string) {
    return callObject.bind(this)(oldAdd, number, string)
  }
  proto.subtract = function (number, string) {
    return callObject.bind(this)(oldAdd, number, string, -1)
  }
}
Repository: iamkun/dayjs
File: src/plugin/timezone/index.js (JavaScript)

Code before:
const typeToPos = {
  year: 0,
  month: 1,
  day: 2,
  hour: 3,
  minute: 4,
  second: 5
}

const ms = 'ms'

// Cache time-zone lookups from Intl.DateTimeFormat,
// as it is a *very* slow method.
const dtfCache = {}
const getDateTimeFormat = (timezone, options = {}) => {
  const key = `${timezone}|${(options.timeZoneName || 'short')}`
  let dtf = dtfCache[key]
  if (!dtf) {
    dtf = new Intl.DateTimeFormat('en-US', {
      hour12: false,
      timeZone: timezone,
      year: 'numeric',
      month: '2-digit',
      day: '2-digit',
      hour: '2-digit',
      minute: '2-digit',
      second: '2-digit',
      timeZoneName: options.timeZoneName || 'short'
    })
    dtfCache[key] = dtf
  }
  return dtf
}

export default (o, c, d) => {
  let defaultTimezone

  const localUtcOffset = d().utcOffset()

  const makeFormatParts = (timestamp, timezone, options = {}) => {
    const date = new Date(timestamp)

Review comment (suggestion):
```
const = timeZoneName  = options.timeZoneName || 'short'
```
and replace the one below

Code after:
const typeToPos = {
  year: 0,
  month: 1,
  day: 2,
  hour: 3,
  minute: 4,
  second: 5
}

const ms = 'ms'

// Cache time-zone lookups from Intl.DateTimeFormat,
// as it is a *very* slow method.
const dtfCache = {}
const getDateTimeFormat = (timezone, options = {}) => {
  const timeZoneName = options.timeZoneName || 'short'
  const key = `${timezone}|${timeZoneName}`
  let dtf = dtfCache[key]
  if (!dtf) {
    dtf = new Intl.DateTimeFormat('en-US', {
      hour12: false,
      timeZone: timezone,
      year: 'numeric',
      month: '2-digit',
      day: '2-digit',
      hour: '2-digit',
      minute: '2-digit',
      second: '2-digit',
      timeZoneName
    })
    dtfCache[key] = dtf
  }
  return dtf
}

export default (o, c, d) => {
  let defaultTimezone

  const localUtcOffset = d().utcOffset()

  const makeFormatParts = (timestamp, timezone, options = {}) => {
Repository: iamkun/dayjs
File: src/plugin/duration/index.js (JavaScript)

Code before:
  minutes() { return this.get('minutes') }
  asMinutes() { return this.as('minutes') }
  hours() { return this.get('hours') }
  asHours() { return this.as('hours') }
  days() { return this.get('days') }
  asDays() { return this.as('days') }
  weeks() { return this.get('weeks') }
  asWeeks() { return this.as('weeks') }
  months() { return this.get('months') }
  asMonths() { return this.as('months') }
  years() { return this.get('years') }
  asYears() { return this.as('years') }
}
export default (option, Dayjs, dayjs) => {
  $d = dayjs
  $u = dayjs().$utils()
  dayjs.duration = function (input, unit) {
    const $l = dayjs.locale()
    return wrapper(input, { $l }, unit)
  }
  dayjs.isDuration = isDuration

  const oldAdd = Dayjs.prototype.add
  Dayjs.prototype.add = function (addition, units) {
    if (isDuration(addition)) {
      return oldAdd.bind(this)(addition.asMilliseconds(), 'ms')
    }
    return oldAdd.bind(this)(addition, units)
  }
}


Review comment (refactor):
better DRY here
```
let a 
return oldAdd.bind(this)(a, 'ms')
```

Code after:
  minutes() { return this.get('minutes') }
  asMinutes() { return this.as('minutes') }
  hours() { return this.get('hours') }
  asHours() { return this.as('hours') }
  days() { return this.get('days') }
  asDays() { return this.as('days') }
  weeks() { return this.get('weeks') }
  asWeeks() { return this.as('weeks') }
  months() { return this.get('months') }
  asMonths() { return this.as('months') }
  years() { return this.get('years') }
  asYears() { return this.as('years') }
}
export default (option, Dayjs, dayjs) => {
  $d = dayjs
  $u = dayjs().$utils()
  dayjs.duration = function (input, unit) {
    const $l = dayjs.locale()
    return wrapper(input, { $l }, unit)
  }
  dayjs.isDuration = isDuration

  const oldAdd = Dayjs.prototype.add
  Dayjs.prototype.add = function (addition, units) {
    if (isDuration(addition)) {
      addition = addition.asMilliseconds()
      units = 'ms'
    }
    return oldAdd.bind(this)(addition, units)
  }
}
Repository: iamkun/dayjs
File: src/locale/hu.js (JavaScript)

Code before:
// Hungarian [hu]
import dayjs from 'dayjs'

const locale = {
  name: 'hu',
  weekdays: 'vasárnap_hétfő_kedd_szerda_csütörtök_péntek_szombat'.split('_'),
  weekdaysShort: 'vas_hét_kedd_sze_csüt_pén_szo'.split('_'),
  weekdaysMin: 'v_h_k_sze_cs_p_szo'.split('_'),
  months: 'január_február_március_április_május_június_július_augusztus_szeptember_október_november_december'.split('_'),
  monthsShort: 'jan_feb_márc_ápr_máj_jún_júl_aug_szept_okt_nov_dec'.split('_'),
  ordinal: n => `${n}.`,
  weekStart: 1,
  relativeTime: {
    future: '%s múlva',
    past: '%s',
    s: 'néhány másodperc',
    m: 'egy perc',
    mm: '%d perc',
    h: 'egy óra',
    hh: '%d óra',
    d: 'egy nap',
    dd: '%d nap',
    M: 'egy hónap',
    MM: '%d hónap',
    y: 'egy éve',
    yy: '%d év'
  },
  formats: {
    LT: 'H:mm',
    LTS: 'H:mm:ss',
    L: 'YYYY.MM.DD.',
    LL: 'YYYY. MMMM D.',
    LLL: 'YYYY. MMMM D. H:mm',
    LLLL: 'YYYY. MMMM D., dddd H:mm'
  }
}

dayjs.locale(locale, null, true)

export default locale



Review comment (suggestion):
@vassbence, I think that here you could move `év` right after `egy ` (just like you did with `egy perc(e)`). That would save you another two chars. :wink:

Code after:
// Hungarian [hu]
import dayjs from 'dayjs'

const locale = {
  name: 'hu',
  weekdays: 'vasárnap_hétfő_kedd_szerda_csütörtök_péntek_szombat'.split('_'),
  weekdaysShort: 'vas_hét_kedd_sze_csüt_pén_szo'.split('_'),
  weekdaysMin: 'v_h_k_sze_cs_p_szo'.split('_'),
  months: 'január_február_március_április_május_június_július_augusztus_szeptember_október_november_december'.split('_'),
  monthsShort: 'jan_feb_márc_ápr_máj_jún_júl_aug_szept_okt_nov_dec'.split('_'),
  ordinal: n => `${n}.`,
  weekStart: 1,
  relativeTime: {
    future: '%s múlva',
    past: '%s',
    s: (_, s, ___, isFuture) => `néhány másodperc${isFuture || s ? '' : 'e'}`,
    m: (_, s, ___, isFuture) => `egy perc${isFuture || s ? '' : 'e'}`,
    mm: (n, s, ___, isFuture) => `${n} perc${isFuture || s ? '' : 'e'}`,
    h: (_, s, ___, isFuture) => `egy ${isFuture || s ? 'óra' : 'órája'}`,
    hh: (n, s, ___, isFuture) => `${n} ${isFuture || s ? 'óra' : 'órája'}`,
    d: (_, s, ___, isFuture) => `egy ${isFuture || s ? 'nap' : 'napja'}`,
    dd: (n, s, ___, isFuture) => `${n} ${isFuture || s ? 'nap' : 'napja'}`,
    M: (_, s, ___, isFuture) => `egy ${isFuture || s ? 'hónap' : 'hónapja'}`,
    MM: (n, s, ___, isFuture) => `${n} ${isFuture || s ? 'hónap' : 'hónapja'}`,
    y: (_, s, ___, isFuture) => `egy ${isFuture || s ? 'év' : 'éve'}`,
    yy: (n, s, ___, isFuture) => `${n} ${isFuture || s ? 'év' : 'éve'}`
  },
  formats: {
    LT: 'H:mm',
    LTS: 'H:mm:ss',
    L: 'YYYY.MM.DD.',
    LL: 'YYYY. MMMM D.',
    LLL: 'YYYY. MMMM D. H:mm',
    LLLL: 'YYYY. MMMM D., dddd H:mm'
  }
}

dayjs.locale(locale, null, true)

export default locale
Repository: iamkun/dayjs
File: src/plugin/duration/index.js (JavaScript)

Code before:
const MILLISECONDS_A_YEAR = MILLISECONDS_A_DAY * 365
const MILLISECONDS_A_MONTH = MILLISECONDS_A_DAY * 30

const durationRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/

const unitToMS = {
  years: MILLISECONDS_A_YEAR,
  months: MILLISECONDS_A_MONTH,
  days: MILLISECONDS_A_DAY,
  hours: MILLISECONDS_A_HOUR,
  minutes: MILLISECONDS_A_MINUTE,
  seconds: MILLISECONDS_A_SECOND,
  milliseconds: 1,
  weeks: MILLISECONDS_A_WEEK
}

const isDuration = d => (d instanceof Duration) // eslint-disable-line no-use-before-define

let $d
let $u

const wrapper = (input, instance, unit) =>
  new Duration(input, unit, instance.$l) // eslint-disable-line no-use-before-define

const prettyUnit = unit => `${$u.p(unit)}s`
const roundNumber = number => number < 0 ? Math.ceil(number) : Math.floor(number)

class Duration {
  constructor(input, unit, locale) {
    this.$d = {}
    this.$l = locale
    if (unit) {
      return wrapper(input * unitToMS[prettyUnit(unit)], this)
    }
    if (typeof input === 'number') {
      this.$ms = input
      this.parseFromMilliseconds()
      return this
    }
    if (typeof input === 'object') {
      Object.keys(input).forEach((k) => {
        this.$d[prettyUnit(k)] = input[k]
      })
      this.calMilliseconds()
      return this
    }
    if (typeof input === 'string') {
      const d = input.match(durationRegex)
      if (d) {
        [,,
          this.$d.years, this.$d.months, this.$d.weeks,

Review comment (suggestion):
This could be replaced with `Math.trunc(number)`, which is shorter.

Code after:
  MILLISECONDS_A_HOUR,
  MILLISECONDS_A_MINUTE,
  MILLISECONDS_A_SECOND,
  MILLISECONDS_A_WEEK,
  REGEX_FORMAT
} from '../../constant'

const MILLISECONDS_A_YEAR = MILLISECONDS_A_DAY * 365
const MILLISECONDS_A_MONTH = MILLISECONDS_A_DAY * 30

const durationRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/

const unitToMS = {
  years: MILLISECONDS_A_YEAR,
  months: MILLISECONDS_A_MONTH,
  days: MILLISECONDS_A_DAY,
  hours: MILLISECONDS_A_HOUR,
  minutes: MILLISECONDS_A_MINUTE,
  seconds: MILLISECONDS_A_SECOND,
  milliseconds: 1,
  weeks: MILLISECONDS_A_WEEK
}

const isDuration = d => d instanceof Duration // eslint-disable-line no-use-before-define

let $d
let $u

const wrapper = (input, instance, unit) =>
  new Duration(input, unit, instance.$l) // eslint-disable-line no-use-before-define

const prettyUnit = unit => `${$u.p(unit)}s`
const isNegative = number => number < 0
const roundNumber = number =>
  (isNegative(number) ? Math.ceil(number) : Math.floor(number))
const absolute = number => Math.abs(number)
const getNumberUnitFormat = (number, unit) => {
  if (!number) {
    return {
      negative: false,
      format: ''
    }
  }

  if (isNegative(number)) {
    return {
      negative: true,
      format: `${absolute(number)}${unit}`
    }
  }
Repository: iamkun/dayjs
File: src/index.js (JavaScript)

Code before:
import * as C from './constant'
import en from './locale/en'
import U from './utils'

let L = 'en' // global locale
const Ls = {} // global loaded locale
Ls[L] = en

const isDayjs = d => d instanceof Dayjs // eslint-disable-line no-use-before-define

const parseLocale = (preset, object, isLocal) => {
  let l
  if (!preset) return L
  if (typeof preset === 'string') {
    const presetLower = preset.toLowerCase()
    if (Ls[presetLower]) {
      l = presetLower
    }
    if (object) {
      Ls[presetLower] = object
      l = presetLower
    }
    if (!l && preset.split('-').length > 1) {
      return parseLocale(preset.split('-')[0])
    }
  } else {
    const { name } = preset
    Ls[name] = preset
    l = name
  }
  if (!isLocal && l) L = l
  return l || (!isLocal && L)
}

const dayjs = function (date, c) {
  if (isDayjs(date)) {
    return date.clone()
  }
  // eslint-disable-next-line no-nested-ternary
  const cfg = typeof c === 'object' ? c : {}
  cfg.date = date
  cfg.args = arguments// eslint-disable-line prefer-rest-params
  return new Dayjs(cfg) // eslint-disable-line no-use-before-define
}

const wrapper = (date, instance) =>
  dayjs(date, {
    locale: instance.$L,

Review comment (refactor):
maybe we can simplify the logic to 
const presetSplit = preset.split('-')
if (!l && presetSplit.length) {
  return parseLocale(presetSplit[0])
}

Code after:
import * as C from './constant'
import en from './locale/en'
import U from './utils'

let L = 'en' // global locale
const Ls = {} // global loaded locale
Ls[L] = en

const isDayjs = d => d instanceof Dayjs // eslint-disable-line no-use-before-define

const parseLocale = (preset, object, isLocal) => {
  let l
  if (!preset) return L
  if (typeof preset === 'string') {
    const presetLower = preset.toLowerCase()
    if (Ls[presetLower]) {
      l = presetLower
    }
    if (object) {
      Ls[presetLower] = object
      l = presetLower
    }
    const presetSplit = preset.split('-')
    if (!l && presetSplit.length > 1) {
      return parseLocale(presetSplit[0])
    }
  } else {
    const { name } = preset
    Ls[name] = preset
    l = name
  }
  if (!isLocal && l) L = l
  return l || (!isLocal && L)
}

const dayjs = function (date, c) {
  if (isDayjs(date)) {
    return date.clone()
  }
  // eslint-disable-next-line no-nested-ternary
  const cfg = typeof c === 'object' ? c : {}
  cfg.date = date
  cfg.args = arguments// eslint-disable-line prefer-rest-params
  return new Dayjs(cfg) // eslint-disable-line no-use-before-define
}

const wrapper = (date, instance) =>
  dayjs(date, {
Repository: iamkun/dayjs
File: src/locale/ku.js (JavaScript)

Code before:
// Kurdish [ku]
import dayjs from 'dayjs'

const locale = {
  name: 'ku',
  weekdays: 'یه‌كشه‌ممه‌_دووشه‌ممه‌_سێشه‌ممه‌_چوارشه‌ممه‌_پێنجشه‌ممه‌_هه‌ینی_شه‌ممه‌'.split('_'),
  months: 'کانونی دووەم_شوبات_ئازار_نیسان_ئایار_حوزەیران_تەمموز_ئاب_ئەیلوول_تشرینی یەكەم_تشرینی دووەم_كانونی یەکەم'.split('_'),
  weekStart: 6,
  weekdaysShort: 'یه‌كشه‌م_دووشه‌م_سێشه‌م_چوارشه‌م_پێنجشه‌م_هه‌ینی_شه‌ممه‌'.split('_'),
  monthsShort: 'کانونی دووەم_شوبات_ئازار_نیسان_ئایار_حوزەیران_تەمموز_ئاب_ئەیلوول_تشرینی یەكەم_تشرینی دووەم_كانونی یەکەم'.split('_'),
  weekdaysMin: 'ی_د_س_چ_پ_ه_ش'.split('_'),
  ordinal: n => n,
  formats: {
    LT: 'HH:mm',
    LTS: 'HH:mm:ss',
    L: 'DD/MM/YYYY',
    LL: 'D MMMM YYYY',
    LLL: 'D MMMM YYYY HH:mm',
    LLLL: 'dddd, D MMMM YYYY HH:mm'
  },
  relativeTime: {
    future: 'له‌ %s',
    past: '%s',
    s: 'چه‌ند چركه‌یه‌ك',
    m: 'یه‌ك خوله‌ك',
    mm: '%d خوله‌ك',
    h: 'یه‌ك كاتژمێر',
    hh: '%d كاتژمێر',
    d: 'یه‌ك ڕۆژ',
    dd: '%d ڕۆژ',
    M: 'یه‌ك مانگ',
    MM: '%d مانگ',
    y: 'یه‌ك ساڵ',
    yy: '%d ساڵ'
  }
}

dayjs.locale(locale, null, true)

export default locale



Review comment (performance):
Hi, should we keep the same with momentjs as https://github.com/moment/moment/blob/e96809208c9d1b1bbe22d605e76985770024de42/locale/ku.js#L76
```
meridiem: function (hour, minute, isLower) {
            if (hour < 12) {
                return 'به‌یانی';
            } else {
                return 'ئێواره‌';
            }
        },
```

Code after:
// Kurdish [ku]
import dayjs from 'dayjs'

const locale = {
  name: 'ku',
  weekdays: 'یه‌كشه‌ممه‌_دووشه‌ممه‌_سێشه‌ممه‌_چوارشه‌ممه‌_پێنجشه‌ممه‌_هه‌ینی_شه‌ممه‌'.split('_'),
  months: 'کانونی دووەم_شوبات_ئازار_نیسان_ئایار_حوزەیران_تەمموز_ئاب_ئەیلوول_تشرینی یەكەم_تشرینی دووەم_كانونی یەکەم'.split('_'),
  weekStart: 6,
  weekdaysShort: 'یه‌كشه‌م_دووشه‌م_سێشه‌م_چوارشه‌م_پێنجشه‌م_هه‌ینی_شه‌ممه‌'.split('_'),
  monthsShort: 'کانونی دووەم_شوبات_ئازار_نیسان_ئایار_حوزەیران_تەمموز_ئاب_ئەیلوول_تشرینی یەكەم_تشرینی دووەم_كانونی یەکەم'.split('_'),
  weekdaysMin: 'ی_د_س_چ_پ_ه_ش'.split('_'),
  ordinal: n => n,
  formats: {
    LT: 'HH:mm',
    LTS: 'HH:mm:ss',
    L: 'DD/MM/YYYY',
    LL: 'D MMMM YYYY',
    LLL: 'D MMMM YYYY HH:mm',
    LLLL: 'dddd, D MMMM YYYY HH:mm'
  },
  meridiem: hour => (hour < 12 ? 'پ.ن' : 'د.ن'),
  relativeTime: {
    future: 'له‌ %s',
    past: '%s',
    s: 'چه‌ند چركه‌یه‌ك',
    m: 'یه‌ك خوله‌ك',
    mm: '%d خوله‌ك',
    h: 'یه‌ك كاتژمێر',
    hh: '%d كاتژمێر',
    d: 'یه‌ك ڕۆژ',
    dd: '%d ڕۆژ',
    M: 'یه‌ك مانگ',
    MM: '%d مانگ',
    y: 'یه‌ك ساڵ',
    yy: '%d ساڵ'
  }
}

dayjs.locale(locale, null, true)

export default locale
Repository: iamkun/dayjs
File: src/plugin/isYesterday.ts (TypeScript)

Code before:
import type { Dayjs, Plugin } from '..'

export type isYesterdayType = () => boolean

declare module '../types' {
  export interface Extend {
    isYesterday: isYesterdayType
  }
}

const plugin: Plugin = (cls, fn) => {
  const isYesterday: isYesterdayType = function (this: Dayjs): boolean {
    const comparisonTemplate = 'YYYY-MM-DD'
    const now = fn()
    return this.format(comparisonTemplate) === now.format(comparisonTemplate)
  }

  cls.prototype.isYesterday = isYesterday
}
export default plugin


Review comment (suggestion):
```suggestion
export type IsYesterday = () => boolean
```

Code after:
import type { Dayjs, Plugin } from '..'

export type IsYesterday = () => boolean

declare module '../types' {
  export interface Extend {
    isYesterday: IsYesterday
  }
}

const plugin: Plugin = (cls, fn) => {
  const isYesterday: IsYesterday = function (this: Dayjs): boolean {
    const comparisonTemplate = 'YYYY-MM-DD'
    const now = fn()
    return this.format(comparisonTemplate) === now.format(comparisonTemplate)
  }

  cls.prototype.isYesterday = isYesterday
}
export default plugin
Repository: iamkun/dayjs
File: src/plugin/toArray.ts (TypeScript)

Code before:
  number,
  number,
  number,
  number
]

declare module '../types' {
  export interface Extend {
    toArray: toArrayType
  }
}

const plugin: Plugin = (cls) => {
  const toArray: toArrayType = function (
    this: Dayjs
  ): [number, number, number, number, number, number, number] {
    return [
      this.year(),
      this.month(),
      this.date(),
      this.hour(),
      this.minute(),
      this.second(),
      this.millisecond(),
    ]
  }

  cls.prototype.toArray = toArray
}
export default plugin


Review comment (refactor):
The `toArray` function can be extracted to the top level.

Code after:
import type { Dayjs, Plugin } from '..'

declare module '../types' {
  export interface Extend {
    toArray: typeof toArray
  }
}

function toArray(
  this: Dayjs
): [number, number, number, number, number, number, number] {
  return [
    this.year(),
    this.month(),
    this.date(),
    this.hour(),
    this.minute(),
    this.second(),
    this.millisecond(),
  ]
}

const plugin: Plugin = (cls) => {
  cls.prototype.toArray = toArray
}
export default plugin