Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/date-fns/date-fns-upgrade-codemod
Code mods for upgrading date-fns versions
https://github.com/date-fns/date-fns-upgrade-codemod
Last synced: about 14 hours ago
JSON representation
Code mods for upgrading date-fns versions
- Host: GitHub
- URL: https://github.com/date-fns/date-fns-upgrade-codemod
- Owner: date-fns
- Created: 2019-08-06T07:40:51.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T06:24:52.000Z (almost 2 years ago)
- Last Synced: 2024-10-30T01:38:10.521Z (10 days ago)
- Language: JavaScript
- Homepage:
- Size: 1.32 MB
- Stars: 11
- Watchers: 7
- Forks: 4
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-codemods - date-fns-upgrade-codemod - Code mods for upgrading date-fns versions. (Misc / ant-design)
README
## date-fns-codemod
### Usage
`npx @date-fns/upgrade-codemod [...options]`
* `path` files or directory to transform
* `--dry` option for a dry-run
* `--print` option to print the output for comparison#### Example
```sh
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](https://github.com/date-fns/date-fns/blob/master/CHANGELOG.md#changed)\
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.```diff
+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
```diff
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!