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 🙏

© 2026 – Pkg Stats / Ryan Hefner

persian-date-parser

v2.1.0

Published

Parse date to various formats with Jalali support

Readme

Persian date parser

npm version GitHub forks GitHub stars GitHub issues Code coverage GitHub license

Library for parsing date and time to desired format (Jalali, Gregorian or mixed).

When possible consider using built-in Date.prototype.toLocaleDateString() method.

Usage

> npm i persian-date-parser
const parser = require('persian-date-parser')

From the above line parser accepts two optional arguments: cache capacity and cache type. Each cache entry has a string (format) as its key (i.e. 'gyyyy-gm-gd') and a function as its value. If in your use-case format strings are limited, parser can benefit from caching those functions. On subsequent parsings for the same format, tokenizing and arranging steps are the same and can be bypassed by using cache, which results in better performance.

| Cache Capacity | Description | |:--------------:|:-----------------------------------------------------------------------| | > 0 | Any positive number. Bigger numbers mean more memory usage. | | 0 | Unlimited caching a.k.a memory leak. Use with caution. | | < 0 | No caching. Default behavior. |

| Cache Type | Eviction Policy | |:----------:|:-------------------------------| | 'FIFO' | First in first out (default). | | 'LRU' | Least Recently Used. |

const parse = parser() // no caching by default

or

const parse = parser(1000) // or parser(1000, 'LRU')
const now = new Date()

Jalali example:

const format = 'pjyyyy/pjmm/pjdd - pjdddd - pjHH:pjMM pjTT'
const result = parse(format, now)
// result: ۱۳۹۹/۰۶/۰۹ - یکشنبه - ۲۱:۳۶ ب.ظ

Gregorian Example:

const format = 'gyyyy/gmm/gdd - gdddd - gHH:gMM gTT'
const result = parse(format, now)
// result: 2020/08/30 - Sunday - 21:36 PM

Masks

Masks are according to following table but there are three general prefixes used with them. Using g or j is mandatory.

  • g: Gregorian date.

  • j: Jalali date.

  • p: Represent results in Persian (numbers, month names, weekdays and their abbreviations).

| Mask | Description | |:-----|:-----------------------------------------------------------------------| | d | Day of the month as digits. No leading zero for single-digit days. | | dd | Day of the month as digits. Leading zero for single-digit days. | | ddd | Day of the week as a three-letter abbreviation. Persian -> one-letter. | | dddd | Day of the week as its full name. | | m | Month as digits. No leading zero for single-digit months. | | mm | Month as digits. Leading zero for single-digit months. | | mmm | Month as a three-letter abbreviation. | | mmmm | Month as its full name. | | yy | Year as last two digits. Leading zero for years less than 10. | | yyyy | Year represented by four digits. | | h | Hours. No leading zero for single-digit hours (12-hour clock). | | hh | Hours. Leading zero for single-digit hours (12-hour clock). | | H | Hours. No leading zero for single-digit hours (24-hour clock). | | HH | Hours. Leading zero for single-digit hours (24-hour clock). | | M | Minutes. No leading zero for single-digit minutes. | | MM | Minutes. Leading zero for single-digit minutes. | | s | Seconds. No leading zero for single-digit seconds. | | ss | Seconds. Leading zero for single-digit seconds. | | t | Lowercase, single-character time marker string: a or p. | | tt | Lowercase, two-character time marker string: am or pm. | | T | Uppercase, single-character time marker string: A or P. | | TT | Uppercase, two-character time marker string: AM or PM. |