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

better-date-functions

v1.1.3

Published

A JavaScript library with more functions for the normal Date class.

Downloads

18

Readme

Installation

BDF requires Node.js v10+ to run.

Documentation

Getting the BDF dependency

// import the the BDF dependency
import BDF from 'better-date-functions';

const { 
    getMonthLength,
    getMonthName,
    getWeekDayName,
    getWeekDayNameWithADate,
    setLanguage,
    getCurrentLanguage,
    getMonthInfo,
    getYearLength,
    setThrowingErrors,
    getCurrentThrowingErrorsState,
} = BDF; // Destructuring (optional)
// Using the functions

// Days must be a number between 1~31
// Months must be a number between 1~12
// Year Must be a number

//Example:

const day = 24
const month = 1
const year = 2022

const weekDayName = getWeekDayNameWithADate(day, month, year);

console.log(weekDayName) // returns "Monday"

All examples

//Example 1:

const weekDay = 1
const weekDayName = getWeekDayName(weekDay)
console.log(weekDayName) // returns "Sunday"
//Example 2:

const month = 3
const monthName = getMonthName(month)
console.log(monthName) // returns "March"
//Example 3:

const month = 3
const monthName = getMonthName(month)
console.log(monthName) // returns "March"
//Example 4:

const month = 2
const year = 2024
const monthLength = getMonthLength(month, year) // Year is optional, but for precise Length in February you need the year
console.log(monthLength) // returns 29
//Example 5:

const month = 1
const year = 2022
const monthInfo = getMonthInfo(month, year) // Year is optional, but for precise Length in February you need the year
console.log(monthInfo) // returns  { length: 31, name: "January", year: 2022 }
//Example 6:

const year1 = 2022
const year2 = 2024
const year1Length = getYearLength(year1)
const year2Length = getYearLength(year2)
console.log([year1Length, year2Length]) // returns [365, 366]

Examples with date

import { withDate } from 'better-date-functions'    // import the withDate functions
                                                    // you can destructurate too
                                                    // const { withDate } = BDF;
//Examples:

const date = new Date() // currently on 26th January, 2022

const weekDayName = withDate.getWeekDayName(date)
console.log(weekDayName) // returns "Wednesday"

const monthLength = withDate.getMonthLength(date)
console.log(monthLength) // returns 31

const monthName = withDate.getMonthName(date)
console.log(monthName) // returns "January"

const monthInfo = withDate.getMonthInfo(date)
console.log(monthInfo) // returns { name: "January", length: 31, year: 2022 }

const yearLength = withDate.getYearLength(date)
console.log(yearLength) // returns 365

const formatedDate = withDate.getformatedDate(date)
console.log(formatedDate) // returns 01/26/2022

const separator = "-"
const formatedDateWithCustomSeparator = withDate.getformatedDate(date, separator)
console.log(formatedDateWithCustomSeparator) // returns 01-26-2022

Configurations

//Changing the language of the returns

const weekDay = 1
const date = new Date() // currently on 26th January, 2022

let weekDayName = getWeekDayName(weekDay)
console.log(weekDayName) // returns "Sunday"

let formatedDate = withDate.getformatedDate(date)
console.log(formatedDate) // returns 01/26/2022

setLanguage('ptBR') // Currently supports "enUs" and "ptBr"

weekDayName = getWeekDayName(weekDay)
console.log(weekDayName) // returns "Domingo"

formatedDate = withDate.getformatedDate(date)
console.log(formatedDate) // returns 26/01/2022

const currentLanguage = getCurrentLanguage() // to get the current language configurated

console.log(currentLanguage) // returns "ptBr"
//Change the throwing errors configuration

let isThrowingErrors = getCurrentThrowingErrorsState() // by default the value of the state is true

console.log(isThrowingErrors) // returns true

setThrowingErrors(false) // you can change the state using this function

isThrowingErrors = getCurrentThrowingErrorsState()

console.log(isThrowingErrors) // returns false