Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jalali-moment

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jalali-moment - npm Package Compare versions

Comparing version 1.2.5 to 2.0.0

4

jalali-moment.d.ts

@@ -667,3 +667,5 @@ declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, strict?: boolean): moment.Moment;

export function jIsLeapYear(): boolean;
export function loadPersian(convertNumbersToPersian?: boolean): void;
export function loadPersian(usePersianDigits?: boolean): void;
export function useJalaliSystemPrimarily(): void;
export function useJalaliSystemSecondary(): void;
export function unloadPersian(): void;

@@ -670,0 +672,0 @@ export var jConvert: any;

@@ -134,3 +134,25 @@

function replaceJalaliFormat(units) {
for (var i = 0; i < units.length; i++) {
if(!i || (units[i-1] !== "j" && units[i-1] !== units[i])) {
if (units[i] === "Y" || units[i] === "M" || units[i] === "D" || units[i] === "g") {
units = units.slice(0, i) + "j" + units.slice(i);
}
}
}
return units;
}
function toJalaliFormat(units) {
switch (units) {
case "year" : return "jYear";
case "month" : return "jMonth";
case "months" : return "jMonths";
case "monthName" : return "jMonthsShort";
case "monthsShort" : return "jMonthsShort";
}
}
function normalizeUnits(units) {
if(moment.justUseJalali){
units = toJalaliFormat(units);
}
if (units) {

@@ -521,2 +543,28 @@ var lowered = units.toLowerCase();

if(!format && moment.justUseJalali) {
if(/\d{4}\-\d{2}\-\d{2}/.test(input)) {
format = "jYYYY-jMM-jDD";
} else if (/\d{4}\-\d{2}\-\d{1}/.test(input)) {
format = "jYYYY-jMM-jD";
} else if (/\d{4}\-\d{1}\-\d{1}/.test(input)) {
format = "jYYYY-jM-jD";
} else if (/\d{4}\-\d{1}\-\d{2}/.test(input)) {
format = "jYYYY-jM-jDD";
} else if (/\d{4}\-W\d{2}\-\d{2}/.test(input)) {
format = "jYYYY-jW-jDD";
} else if (/\d{4}\-\d{3}/.test(input)) {
format = "jYYYY-jDDD";
} else if (/\d{8}/.test(input)) {
format = "jYYYYjMMjDD";
} else if (/\d{4}W\d{2}\d{1}/.test(input)) {
format = "jYYYYjWWjD";
} else if (/\d{4}W\d{2}/.test(input)) {
format = "jYYYYjWW";
} else if (/\d{4}\d{3}/.test(input)) {
format = "jYYYYjDDD";
}
}
if (format && moment.justUseJalali){
format = replaceJalaliFormat(format);
}
if (format && typeof format === "string"){

@@ -602,2 +650,5 @@ format = fixFormat(format, moment);

if (format) {
if(moment.justUseJalali) {
format = replaceJalaliFormat(format);
}
format = fixFormat(format, this);

@@ -611,3 +662,3 @@

var formatted = moment.fn.format.call(this, format);
if (moment.isPersian) {
if (moment.usePersianDigits) {
formatted = formatted.replace(/\d/g, convertToPerianNumber);

@@ -618,2 +669,7 @@ }

jMoment.fn.year = function (input) {
if (input && moment.justUseJalali) return jMoment.fn.jYear.call(this,input);
else return moment.fn.year.call(this, input);
};
function convertToPerianNumber(s) {

@@ -639,2 +695,7 @@ return persianMap[parseInt(s)];

jMoment.fn.month = function (input) {
if (input && moment.justUseJalali) return jMoment.fn.jMonth.call(this,input);
else return moment.fn.month.call(this, input);
};
jMoment.fn.jMonth = function (input) {

@@ -668,2 +729,7 @@ var lastDay

jMoment.fn.date = function (input) {
if (input && moment.justUseJalali) return jMoment.fn.jDate.call(this,input);
else return moment.fn.date.call(this, input);
};
jMoment.fn.jDate = function (input) {

@@ -683,2 +749,7 @@ var j

jMoment.fn.dayOfYear = function (input) {
if (input && moment.justUseJalali) return jMoment.fn.jDayOfYear.call(this,input);
else return moment.fn.dayOfYear.call(this, input);
};
jMoment.fn.jDayOfYear = function (input) {

@@ -689,2 +760,7 @@ var dayOfYear = Math.round((jMoment(this).startOf("day") - jMoment(this).startOf("jYear")) / 864e5) + 1;

jMoment.fn.week = function (input) {
if (input && moment.justUseJalali) return jMoment.fn.jWeek.call(this,input);
else return moment.fn.week.call(this, input);
};
jMoment.fn.jWeek = function (input) {

@@ -695,2 +771,7 @@ var week = jWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).week;

jMoment.fn.weekYear = function (input) {
if (input && moment.justUseJalali) return jMoment.fn.jWeekYear.call(this,input);
else return moment.fn.weekYear.call(this, input);
};
jMoment.fn.jWeekYear = function (input) {

@@ -774,2 +855,9 @@ var year = jWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year;

jMoment.useJalaliSystemPrimarily = function (calendarSystem) {
moment.justUseJalali = true;
};
jMoment.useJalaliSystemSecondary = function (usePersianDigits) {
moment.justUseJalali = false;
};
jMoment.fn.jYears = jMoment.fn.jYear;

@@ -805,11 +893,11 @@ jMoment.fn.jMonths = jMoment.fn.jMonth;

jMoment.unloadPersian = function () {
moment.isPersian = false;
moment.usePersianDigits = false;
moment.locale(moment.prevLocale);
};
jMoment.loadPersian = function (makeNumberPersian) {
jMoment.loadPersian = function (usePersianDigits) {
if (moment.locale()!=="fa") {
moment.prevLocale = moment.locale();
}
moment.isPersian = makeNumberPersian;
moment.usePersianDigits = usePersianDigits;
moment.locale("fa", {

@@ -816,0 +904,0 @@ months: ("ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر").split("_")

{
"name": "jalali-moment",
"version": "1.2.5",
"version": "2.0.0",
"description": "Jalali (Persian, Khorshidi, Shamsi) calendar system to use in javascript or typescript.",

@@ -5,0 +5,0 @@ "author": {

@@ -136,3 +136,3 @@ # jalali-moment

moment().format('jYYYY/jMMMM/jD'); // 1367/بهمن/4
moment.loadPersian(true);
moment.loadPersian(true); //use persian digits
moment().format('jYYYY/jMMMM/jD'); // ۱۳۶۷/بهمن/۴

@@ -143,2 +143,19 @@ moment.unloadPersian();

## Just use jalali calendar system
We could use both calendar system concurrently but
sometimes we just need jalali system or we wouldn't like to change all moment.js methods and formats to work in jalali system.
for example when you want to edit a datepicker (which is written by using moment.js) to work in jalali calendar system.
```js
moment().format('YYYY/MMMM/D'); // 1989/January/24
moment.useJalaliSystemPrimarily();
moment().format('YYYY/MMMM/D'); // 1367/Bahman/4
moment().subtract(1,'year').format('YYYY/MMMM/D'); // 1366/bahman/4
moment().subtract(1,'month').format('YYYY/MMMM/D'); // 1367/dey/4
moment.useJalaliSystemSecondary();
moment().format('YYYY/MMMM/D'); // 1989/January/24
```
## Related Projects

@@ -145,0 +162,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc