npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

datefr

v1.3.3

Published

Simple date parser for French formats

Downloads

5

Readme

DateFR

Utility

This package can be used to :

  • Format a date from a set of formats to the main French format
  • Extract all dates from a given string, formatting them to the main French format
  • Convert a date string that the default Date constructor couldn't parse to a JS Date object
  • Calculate the time between two dates
  • Compare dates
  • GEt max and min dates in arrays

Installation

npm i datefr

Usage

Importation

You can just require the package and you'll be able to use the functions.

require("datefr")

Input formats

Below is the list of the formats that can be parsed by the package.

  • ddmmyy[yy]
  • d[d]*m[m]*yy[yy]
  • yyyy*m[m]*d[d]
  • d[d]*mmmm*yy[yy]
  • mmmm*yy[yy]

[x] means that x is optional

* can be one either a backslash, a slash, a space, a dot, a semi-colon or a hyphen

String.prototype.toDateString()

require("datefr")

const string = "30 janvier 2022"
console.log(string.toDateString()) // Expected output: '30/01/2022'

String.prototype.extractDates()

require("datefr")

const string = "Today is 251221. Can't wait to be in january 2022!"
console.log(string.extractDates()) // Expected output: ['25/12/2021', '01/2022']

String.prototype.toDateObject()

require("datefr")

const string = "5 jan 2010"
console.log(string.toDateObject()) // Expected output: 2010-01-05T00:00:00.000Z

Note that the date object thus created will always have the time set as 00:00:00.000Z

String.prototype.diffDate(date, ?includeEndDate, ?unit)

require("datefr")

const string = "1 may 2003"
console.log(string.diffDate("01/05/2022")) // Expected output : 6940
console.log(string.diffDate("01/05/2022", true)) // Expected output : 6941
console.log(string.diffDate("01/05/2022", false, "s")) // Expected output : 599616000

Note that the difference will always be positive

includeEndDate

  • true : includes the end date
  • false : doesn't include the end date (default)

unit

  • ms : processes the difference in milliseconds
  • s : processes the difference in seconds
  • m : processes the difference in minutes
  • h : processes the difference in hours
  • d : processes the difference in days (default)

String.prototype.getMaxDate(date)

require("datefr")

const string = "1 may 2003"
console.log(string.getMaxDate("01/05/2022")) // Expected output : '01/05/2022'

String.prototype.getMinDate(date)

require("datefr")

const string = "1 may 2003"
console.log(string.getMinDate("01/05/2022")) // Expected output : '01/05/2003'

Array.prototype.getMaxDate(?key)

require("datefr")

const array = ["1 may 2003", "010522", "2001-05-22"]
const arrayObj = [
	{ name: "Cindy", birthday: "1 may 2003" },
	{ name: "Ryan", birthday: "010522" },
	{ name: "John", birthday: "2001-05-22" },
]
console.log(array.getMaxDate()) // Expected output : '01/05/2022'
console.log(arrayObj.getMaxDate("birthday")) // Expected output : '01/05/2022'

Array.prototype.getMinDate(?key)

require("datefr")

const array = ["1 may 2003", "010522", "2001-05-22"]
const arrayObj = [
	{ name: "Cindy", birthday: "1 may 2003" },
	{ name: "Ryan", birthday: "010522" },
	{ name: "John", birthday: "2001-05-22" },
]
console.log(array.getMinDate()) // Expected output : '22/05/2001'
console.log(arrayObj.getMinDate("birthday")) // Expected output : '01/05/2022'