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

lahze

v0.3.7

Published

Lightweight package for formatting dates between jalali and gregorian. Supports both node and browser environments.

Downloads

94

Readme

Lahze

npm npm bundle size install size

Lightweight package for formatting dates between jalali and gregorian. Supports both node and browser environments.

Usage

Basic usage

lahze can be initialized using 3 arguments: date, format of the date and locale.

After that lahze can manipulate and display date between locales easily.

import lahze from 'lahze';

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').format('YYYY/MM/DD', 'en'); // 2019/12/31
  • Date can be on of the following items:

    1. Instance of Date object
    2. String with a specific format
    3. Timestamp

    If date is not specified or null, it will be equal to today.

  • Format accepted types are as followed:

    • YYYY: full year (4 digits).
    • YY: short year (last 2 digits).
    • MM: full month (2 digits).
    • M: short month (1-2 digit).
    • DD: full day (2 digits).
    • D: short day (1-2 digits).
    • HH: full hours (2 digits).
    • H: short hours (1-2 digits).
    • mm: full minutes (2 digits).
    • m: short minutes (1-2 digits).
    • ss: full seconds (2 digits).
    • s: short seconds (1-2 digits).
    • Supported delimiters are \, /, -, :.

    If format is not specified or null, it will be equal to whatever Date object accepts.

  • Locale can be either fa or en (defaults en).

After initializing lahze with the desired arguments, you can easily manupulate date and display it with a specific format at the end.

Manipulating

Setters

setFullYear

This method accepts 4-digits year as the first argument and locale as it's second argument which specifies the locale of the first argument (defaults to initial locale which was specified by creating lahze instance).

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').setFullYear(1399, 'fa'); // 1399/10/10
setMonth

This method accepts month (value between 1 and 12) as the first argument and locale as it's second argument which specifies the locale of the first argument (defaults to initial locale which was specified by creating lahze instance).

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').setMonth(12, 'fa'); // 1398/12/10
setDay

This method accepts day of the month (value between 1 and 31) as the first argument and locale as it's second argument which specifies the locale of the first argument (defaults to initial locale which was specified by creating lahze instance).

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').setDay(5, 'fa'); // 1398/10/5
setHours

This method accepts hours (value between 0 and 23) as the first argument.

lahze('1398/10/10 12:00:00', 'YYYY/MM/DD HH:mm:ss', 'fa').setHours(5); // 1398/10/10 5:00:00
setMinutes

This method accepts minutes (value between 0 and 59) as the first argument.

lahze('1398/10/10 12:00:00', 'YYYY/MM/DD HH:mm:ss', 'fa').setHours(50); // 1398/10/10 12:50:00
setSeconds

This method accepts minutes (value between 0 and 59) as the first argument.

lahze('1398/10/10 12:00:00', 'YYYY/MM/DD HH:mm:ss', 'fa').setHours(10); // 1398/10/10 12:00:10

Getters

getFullYear

This method returns full year (4-digits) of the lahze instance.

This method accepts locale as the first argument which specifies the locale of the returning value (defaults to initial locale which was specified by creating lahze instance).

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').getFullYear('en'); // 2019

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').getFullYear('fa'); // 1398
getMonth

This method returns month number (1-12) of the lahze instance.

This method accepts locale as the first argument which specifies the locale of the returning value (defaults to initial locale which was specified by creating lahze instance).

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').getMonth('fa'); // 10

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').getMonth('en'); // 12
getDay

This method returns day of the month of the lahze instance.

This method accepts locale as the first argument which specifies the locale of the returning value (defaults to initial locale which was specified by creating lahze instance).

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').getDay('fa'); // 10

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').getDay('en'); // 31
getHours

This method returns hours of the month of the lahze instance.

lahze('1398/10/10 12:00:00', 'YYYY/MM/DD HH:mm:ss', 'fa').getHours(); // 12
getMinutes

This method returns hours of the month of the lahze instance.

lahze('1398/10/10 12:20:00', 'YYYY/MM/DD HH:mm:ss', 'fa').getMinutes(); // 20
getSeconds

This method returns hours of the month of the lahze instance.

lahze('1398/10/10 12:00:50', 'YYYY/MM/DD HH:mm:ss', 'fa').getSeconds(); // 50

Advanced manipulation

You can set the year, month or day in a locale and get it in the opposite locale:

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').setMonth(11, 'en').getMonth('fa'); // 8

Display

lahze can return date in the given format with the desired locale:

lahze('1398/10/10', 'YYYY/MM/DD', 'fa').format('YYYY/MM/DD', 'en'); // 2019/12/31

Supported formats are listed above.

License

MIT