{"version":3,"sources":["../../src/use-date-format/index.ts"],"sourcesContent":["import { useCreation } from '../use-creation'\nimport { useLatest } from '../use-latest'\n\nimport { formatDate, normalizeDate } from './format-date'\nexport { formatDate, normalizeDate } from './format-date'\n\nimport type { DateLike, FormatDateOptions } from './format-date'\nexport type { DateLike, FormatDateOptions } from './format-date'\n\nexport interface UseDateFormatOptions extends FormatDateOptions {\n  /**\n   * fallback string when date is invalid\n   */\n  fallback?: string\n}\n\n/**\n * A dependency-free React Hook to format date using symbols, similar to the `format` function found in libraries.\n *\n * Such as [dayjs#format](https://day.js.org/docs/en/display/format), [momentjs#format](https://momentjs.com/docs/#/displaying/format/), or [date-fns#format](https://date-fns.org/docs/format).\n *\n * By default, the formatting behavior aligns with that of `dayjs`, `momentjs`, and `date-fns@^1`.\n *\n * You can set `unicodeSymbols` option to `true` to use [Unicode Standard Date Symbols](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table), which is similar to `date-fns@^2` and subsequent versions.\n */\nexport function useDateFormat(\n  /**\n   * a date object or a date string\n   */\n  date: DateLike | null | undefined,\n  /**\n   * format string\n   *\n   * @defaultValue 'YYYY-MM-DD HH:mm:ss'\n   */\n  formatStr = 'YYYY-MM-DD HH:mm:ss',\n  /**\n   * options for formatting\n   */\n  options: UseDateFormatOptions = {},\n): string {\n  const { fallback: fallbackStr = '', unicodeSymbols, locales } = options\n  const latest = useLatest({ options })\n\n  const result = useCreation(() => {\n    const nDate = normalizeDate(date)\n    const isInvalid = Number.isNaN(nDate.getTime())\n    return isInvalid ? fallbackStr : formatDate(nDate, formatStr, latest.current.options)\n  }, [date, formatStr, fallbackStr, unicodeSymbols, locales])\n\n  return result\n}\n"],"names":["formatDate","normalizeDate","useDateFormat","date","formatStr","options","fallbackStr","fallback","unicodeSymbols","locales","latest","useLatest","result","useCreation","nDate","isInvalid","Number","isNaN","getTime","current"],"mappings":";;;;;;;;;;;QAISA;eAAAA,sBAAU;;QAAEC;eAAAA,yBAAa;;QAqBlBC;eAAAA;;;2BAzBY;yBACF;0BAEgB;AAsBnC,SAASA,cACd;;GAEC,GACDC,IAAiC;QACjC;;;;GAIC,GACDC,YAAAA,iEAAY,uBACZ;;GAEC,GACDC,UAAAA,iEAAgC,CAAC;IAEjC,IAAkBC,MAA8CD,QAAxDE,UAAUD,cAAAA,iBAAc,KAAdA,KAAkBE,iBAA4BH,QAA5BG,gBAAgBC,UAAYJ,QAAZI;IACpD,IAAMC,SAASC,IAAAA,oBAAS,EAAC;QAAEN,SAAAA;IAAQ;IAEnC,IAAMO,SAASC,IAAAA,wBAAW,EAAC;QACzB,IAAMC,QAAQb,IAAAA,yBAAa,EAACE;QAC5B,IAAMY,YAAYC,OAAOC,KAAK,CAACH,MAAMI,OAAO;QAC5C,OAAOH,YAAYT,cAAcN,IAAAA,sBAAU,EAACc,OAAOV,WAAWM,OAAOS,OAAO,CAACd,OAAO;IACtF,GAAG;QAACF;QAAMC;QAAWE;QAAaE;QAAgBC;KAAQ;IAE1D,OAAOG;AACT"}