Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@date-fns/upgrade

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@date-fns/upgrade

A tool for upgrading date-fns versions

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

date-fns upgrade

Support package with helper functions for date-fns upgrade from 1.x to 2.x

Codemod that will help you apply these helpers automatically located here - date-fns-upgrade-codemod.

Installation

npm install @date-fns/upgrade --save
# or with yarn
yarn add @date-fns/upgrade

Usage

convertTokens

convertTokens is a helper function used for 2nd argument of format function to convert date tokens like YYYY to new format. See this post for more details.

+import { convertTokens } from '@date-fns/upgrade/v2'

const formattedDate = format(
  new Date(),
- 'YYYY',
+ convertTokens('YYYY'),
)

legacyParse

date-fns@2.x functions don't accept string as arguments any more (see CHANGELOG), legacyParse is used to simplify that transition, it uses algorithm from 1.x to do that. See this post for details on "why" this was done.

+import { legacyParse } from '@date-fns/upgrade/v2'

const formattedDate = format(
- '2014',
+ legacyParse('2014'),
  'YYYY',
)

legacyParseMap

legacyParseMap is used same as legacyParse but for arguments that accept arrays.

+import { legacyParseMap } from '@date-fns/upgrade/v2'

var dateToCompare = new Date(2015, 8, 6)
var datesArray = [
  '2014-01-01',
  '2015-01-01'
]
-var result = closestIndexTo(dateToCompare, datesArray)
+var result = closestIndexTo(dateToCompare, legacyParseMap(datesArray))

License

MIT © Sasha Koss

FAQs

Package last updated on 04 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc