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

@aegenet/belt-light-date

v1.5.0

Published

(Very) light `Date` tools

Downloads

16

Readme

npm version

@aegenet/belt-light-date

(Very) light Date tools

💾 Installation

yarn add @aegenet/belt-light-date@^1.4.0
# or
npm i @aegenet/belt-light-date@^1.4.0

📝 Usage

LightDate

import { lightDate } from '@aegenet/belt-light-date';

// today
lightDate.today(); // Like new Date()
lightDate.today('2022-04-20T12:14:00.072Z'); // new Date('2022-04-20T12:14:00.072Z')

/**
 * Today at 00:00:00 (current language)
 * @remark It's not a UTC midight
 */
lightDate.todayStart('2022-04-20T12:14:00.072Z').toLocaleString('fr'); // '20/04/2022, 00:00:00'

// todayEnd
lightDate.todayEnd('2022-04-20T12:14:00.072Z').toLocaleString('fr'); // '20/04/2022, 23:59:59'

// tomorrow
lightDate.tomorrow('2022-04-20T12:14:00.072Z').toISOString(); // '2022-04-21T12:14:00.072Z'

// yesterday
lightDate.yesterday('2022-04-20T12:14:00.072Z').toISOString(); // '2022-04-19T12:14:00.072Z'

// tomorrowStart
lightDate.tomorrowStart('2022-04-20T12:14:00.072Z').toLocaleString('fr'); // '21/04/2022, 00:00:00'

// tomorrowEnd
lightDate.tomorrowEnd('2022-04-20T12:14:00.072Z').toLocaleString('fr'); // '21/04/2022, 23:59:59'

// monthStart
lightDate.monthStart('2022-04-20T12:14:00.072Z').toLocaleString('fr'); // '01/04/2022, 00:00:00'

// monthEnd
lightDate.monthEnd('2022-04-20T12:14:00.072Z').toLocaleString('fr'); // '30/04/2022, 23:59:59'

// weekStart
lightDate.weekStart('2022-04-20T12:14:00.072Z', 'fr-FR').toLocaleString('fr'); // '18/04/2022, 00:00:00'
lightDate.weekStart('2022-04-20T12:14:00.072Z', 'en-US').toLocaleString('fr'); // '17/04/2022, 00:00:00'

// weekEnd
lightDate.weekEnd('2022-04-20T12:14:00.072Z', 'fr-FR').toLocaleString('fr'); // '24/04/2022, 23:59:59'
lightDate.weekEnd('2022-04-20T12:14:00.072Z', 'en-US').toLocaleString('fr'); // '23/04/2022, 23:59:59'

// nextMonthStart
lightDate.nextMonthStart('2022-04-20T12:14:00.072Z').toLocaleString('fr'); // '01/05/2022, 00:00:00'

// nextMonthEnd
lightDate.nextMonthEnd('2022-04-20T12:14:00.072Z').toLocaleString('fr'); // '31/05/2022, 23:59:59'

// prevMonthStart
lightDate.prevMonthStart('2022-04-20T12:14:00.072Z').toLocaleString('fr'); // '01/03/2022, 00:00:00'

// prevMonthEnd
lightDate.prevMonthEnd('2022-04-20T12:14:00.072Z').toLocaleString('fr'); // '31/03/2022, 23:59:59'

// Get current locale
getIntlLocale(); // Object

isLeapYear

import { isLeapYear } from '@aegenet/belt-light-date';
isLeapYear(2000); // true
isLeapYear(2001); // false
isLeapYear(2019); // false
isLeapYear(2020); // true
isLeapYear(2021); // false
isLeapYear(2024); // true
isLeapYear(2027); // false

getDaysArrayInMonth

import { getDaysArrayInMonth } from '@aegenet/belt-light-date';
getDaysArrayInMonth(2021); // [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
getDaysArrayInMonth(2020); // [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

getDaysInMonth

import { getDaysInMonth } from '@aegenet/belt-light-date';

getDaysInMonth(new Date(2019, 0)); // 31
getDaysInMonth(new Date(2021, 1)); // 28
getDaysInMonth(new Date(2020, 0)); // 31
getDaysInMonth(new Date(2020, 1)); // 29

getDayNames

import { getDayNames } from '@aegenet/belt-light-date';

getDayNames();
// Long & Default locale
// ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

getDayNames('short');
// Default locale
// ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']

getDayNames('short', 'en');
// ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  
getDayNames('long', 'en');
// ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
  
getDayNames('long', 'fr');
// ['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche']);

getMonthNames

import { getMonthNames } from '@aegenet/belt-light-date';

getMonthNames();
// long & default locale
// ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

getMonthNames('short');
// default locale
// ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

getMonthNames('short', 'en');
// ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

getMonthNames('long', 'en');
// ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

getMonthNames('long', 'fr');
// ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre']

splitDate

import { splitDate } from '@aegenet/belt-light-date';

// Split date
const splited = splitDate({
  days: 365,
  dateFrom: '2022-04-20T12:14:00.072Z',
  startEndOf: 'week',
});

splited.start.toLocaleString('fr'); // '18/10/2021, 00:00:00'
splited.end.toLocaleString('fr'); // '23/10/2022, 23:59:59'

Input date utils

import { dateToInputDate, inputDateToDate } from '@aegenet/belt-light-date';

// Convert a Date to an compatible input date string
dateToInputDate(new Date()); // YYYY-MM-dd

// Convert back a input date string to a Date object
inputDateToDate('YYYY-MM-dd'); // Date object

Input date time utils

import { dateToInputDateTime, inputDateTimeToDate } from '@aegenet/belt-light-date';

// Convert a Date to an compatible input date time string
dateToInputDateTime(new Date()); // YYYY-MM-ddTHH:mm

// Convert back a input date time string to a Date object
inputDateToDate('YYYY-MM-ddTHH:mm'); // Date object

getCurrentTimezone

import { getCurrentTimezone } from '@aegenet/belt-light-date';

// Get current timezone
getCurrentTimezone(); // +0200