Socket
Book a DemoInstallSign in
Socket

@date-fns/upgrade-codemod

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-codemod

date-fns codemod 1.x -> 2.0

1.0.2
latest
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
3
Weekly downloads
 
Created
Source

date-fns-codemod

Usage

npx @date-fns/upgrade-codemod <path> [...options]

  • path files or directory to transform
  • --dry option for a dry-run
  • --print option to print the output for comparison

Example

npx @date-fns/upgrade-codemod src/

Codemods applied

N.B. At the moment this codemod applies fixes ONLY for first 3 points of 2.0 date-fns CHANGELOG
You'll have to take care of all the other breaking changes.

Codemod imports required tools from @date-fns/upgrade (you will have to add it as dependency in your project if required) and wraps date-fns function call arguments accordingly.

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

 const dateIs = '2019-07-01'

 const someToken = 'MM-DD';
-const format = importedFormat('2019-07-01', someToken)
-const closestIndex = closestToIndex(new Date(2015, 8, 6), [
-  new Date(2015, 0, 1),
-  new Date(2016, 0, 1),
-  new Date(2017, 0, 1)
-])
-const addSecondsPlease = addSeconds(dateIs, 999)
-const isoDay = getThatDay(new Date())
+const format = importedFormat(
+  legacyParse('2019-07-01'),
+  convertTokens(someToken)
+)
+const closestIndex = closestToIndex(
+  legacyParse(new Date(2015, 8, 6)),
+  legacyParseMap([
+    new Date(2015, 0, 1),
+    new Date(2016, 0, 1),
+    new Date(2017, 0, 1)
+  ])
+)
+const addSecondsPlease = addSeconds(legacyParse(dateIs), 999)
+const isoDay = getThatDay(legacyParse(new Date()))

Codemod also changes import locations

 import * as importedFormat from 'date-fns/format'
-import closestToIndex from 'date-fns/closest_to_index'
-import addSeconds from 'date-fns/add_seconds'
-import getThatDay from 'date-fns/get_iso_day'
+import closestToIndex from 'date-fns/closestToIndex'
+import addSeconds from 'date-fns/addSeconds'
+import getThatDay from 'date-fns/getISODay'

PRs welcome!

FAQs

Package last updated on 18 Oct 2019

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.