Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB][30GR][DRAFT] Replacing momentjs with datefns(BP040) #37

Open
3 tasks
titiBeOne opened this issue Apr 5, 2023 · 2 comments
Open
3 tasks

[WEB][30GR][DRAFT] Replacing momentjs with datefns(BP040) #37

titiBeOne opened this issue Apr 5, 2023 · 2 comments
Labels
ecoCode-standard Techno: javascript Refers to the JavaScript ecosystem

Comments

@titiBeOne
Copy link
Contributor

titiBeOne commented Apr 5, 2023

Replacing momentjs with datefns(BP040)

Platform

OS OS version Langage
- - JS

Main caracteristics

ID Title Category Sub-category
CRDOMxxx Replacing momentjs with datefns Best Practice -

Severity / Remediation Cost

  • Case 1: Optimized the size of static resources.
Severity Remediation Cost
Medium Medium

Rule short description

  • Case 1: Replace momentjs by another library

Rule complete description

Text

♻️ Momentjs is a library that is not maintained and is heavy to load.

Benefits

Optimized the size of static resources.

Links

JS

❌ Code to avoid

import moment from "moment";
const age = moment().diff(birthday, "years");

✔️ Recommended code

✔️ Code to use

import differenceInYears from "date-fns/differenceInYears";

const age = differenceInYears(new Date(), birthday);

Implementation principle

  • Check that the dependency is no longer in the package.json
  • Check that there is no more MomentJs import
  • Check that it is no longer in the generated bundle
@titiBeOne titiBeOne changed the title [WEB][30GR] Remplacement de momentjs par datefns(BP040) [WEB][30GR][DRAFT] Remplacement de momentjs par datefns(BP040) Apr 5, 2023
@titiBeOne titiBeOne changed the title [WEB][30GR][DRAFT] Remplacement de momentjs par datefns(BP040) [WEB][30GR][DRAFT] Replacing momentjs with datefns(BP040) Apr 5, 2023
@m-naim
Copy link

m-naim commented Apr 5, 2023

Name Tree-shaking Methods richness Pattern Locale Timezone Support Popularity (stars) Sizes
Moment.js No High OO 123 Good (moment-timezone) stars raw size
Luxon No High OO - Good (Intl) stars raw size
date-fns Yes High Functional 64 Good (date-fns-tz) stars raw size
dayjs No High OO 138 Good (Intl) stars raw size

@m-naim
Copy link

m-naim commented Apr 5, 2023

Large bundle size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ecoCode-standard Techno: javascript Refers to the JavaScript ecosystem
Projects
None yet
Development

No branches or pull requests

4 participants