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 2.0.1 to 2.0.2

102

jalali-moment.js

@@ -23,4 +23,4 @@

, unitAliases =
{ jm: "jmonth"
, unitAliases = {
jm: "jmonth"
, jmonths: "jmonth"

@@ -34,42 +34,42 @@ , jy: "jyear"

, ordinalizeTokens = "DDD w M D".split(" ")
, paddedTokens = "M D w".split(" ")
, paddedTokens = "M D w".split(" ");
, formatTokenFunctions =
{ jM: function () {
var formatTokenFunctions = {
jM: function () {
return this.jMonth() + 1;
}
, jMMM: function (format) {
},
jMMM: function (format) {
return this.localeData().jMonthsShort(this, format);
}
, jMMMM: function (format) {
},
jMMMM: function (format) {
return this.localeData().jMonths(this, format);
}
, jD: function () {
},
jD: function () {
return this.jDate();
}
, jDDD: function () {
},
jDDD: function () {
return this.jDayOfYear();
}
, jw: function () {
},
jw: function () {
return this.jWeek();
}
, jYY: function () {
},
jYY: function () {
return leftZeroFill(this.jYear() % 100, 2);
}
, jYYYY: function () {
},
jYYYY: function () {
return leftZeroFill(this.jYear(), 4);
}
, jYYYYY: function () {
},
jYYYYY: function () {
return leftZeroFill(this.jYear(), 5);
}
, jgg: function () {
},
jgg: function () {
return leftZeroFill(this.jWeekYear() % 100, 2);
}
, jgggg: function () {
},
jgggg: function () {
return this.jWeekYear();
}
, jggggg: function () {
},
jggggg: function () {
return leftZeroFill(this.jWeekYear(), 5);
}
};
};

@@ -113,2 +113,8 @@ function padToken(func, count) {

/**
* return a string which length is as much as you need
* @param {number} number input
* @param {number} targetLength expected length
* @example leftZeroFill(5,2) => 05
**/
function leftZeroFill(number, targetLength) {

@@ -122,2 +128,6 @@ var output = number + "";

/**
* determine object is array or not
* @param input
**/
function isArray(input) {

@@ -138,13 +148,24 @@ return Object.prototype.toString.call(input) === "[object Array]";

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);
/**
* Changes any moment Gregorian format to Jalali system format
* @param {string} format
* @example toJalaliFormat("YYYY/MMM/DD") => "jYYYY/jMMM/jDD"
**/
function toJalaliFormat(format) {
for (var i = 0; i < format.length; i++) {
if(!i || (format[i-1] !== "j" && format[i-1] !== format[i])) {
if (format[i] === "Y" || format[i] === "M" || format[i] === "D" || format[i] === "g") {
format = format.slice(0, i) + "j" + format.slice(i);
}
}
}
return units;
return format;
}
function toJalaliFormat(units) {
/**
* Changes any moment Gregorian units to Jalali system units
* @param {string} units
* @example toJalaliUnit("YYYY/MMM/DD") => "jYYYY/jMMM/jDD"
**/
function toJalaliUnit(units) {
switch (units) {

@@ -158,5 +179,10 @@ case "year" : return "jYear";

}
/**
* normalize units to be comparable
* @param {string} units
**/
function normalizeUnits(units) {
if(moment.justUseJalali){
units = toJalaliFormat(units);
units = toJalaliUnit(units);
}

@@ -572,3 +598,3 @@ if (units) {

if (format && moment.justUseJalali){
format = replaceJalaliFormat(format);
format = toJalaliFormat(format);
}

@@ -656,3 +682,3 @@ if (format && typeof format === "string"){

if(moment.justUseJalali) {
format = replaceJalaliFormat(format);
format = toJalaliFormat(format);
}

@@ -659,0 +685,0 @@ format = fixFormat(format, this);

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

@@ -49,6 +49,4 @@ "author": {

},
"dependencies": {
"moment": "^2.18.1"
},
"dependencies": {},
"typings": "./jalali-moment.d.ts"
}
# jalali-moment
A Jalali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js. [DEMO](https://fingerpich.github.io/jalali-moment)
It adds jalali (Persian, Khorshidi, Shamsi) calendar system to [moment.js](http://momentjs.com) library.
[DEMO](https://fingerpich.github.io/jalali-moment)

@@ -14,27 +15,25 @@ [![MIT License][license-image]][license-url]

Jalali calendar is a solar calendar. It gains approximately 1 day on the Julian calendar every 128 years. [Read more on Wikipedia](http://en.wikipedia.org/wiki/Jalali_calendar).
jalali calendar is a solar calendar. It gains approximately 1 day on the Julian calendar every 128 years. [Read more on Wikipedia](http://en.wikipedia.org/wiki/Jalali_calendar).
This plugin adds Jalali calendar support to [momentjs](http://momentjs.com) library.
Calendar conversion is based on the [algorithm provided by Kazimierz M. Borkowski](http://www.astro.uni.torun.pl/~kb/Papers/EMP/PersianC-EMP.htm) and has a very good performance.
## Where to use it
Like `momentjs`, `jalali-moment` works in browser and in Node.js.
### Install
Install via NPM
Install via **npm**
```shell
npm install jalali-moment -S
```
Install via bower
Install via **yarn**
```shell
yarn add jalali-moment
```
Install via **bower**
```shell
bower install jalali-moment --save
```
### Node.js
## Using in Node.js
install it via npm or yarn and following code will work
```js

@@ -45,7 +44,27 @@ var moment = require('jalali-moment');

### Angular
## Using in browser
#### ES5
```HTML
<!--<script src="bower_components/jalali-moment/dist/jalali-moment.browser.js"></script>-->
<!--<script src="node_modules/jalali-moment/dist/jalali-moment.browser.js"></script>-->
<script src="thisRepositoryPath/dist/jalali-moment.browser.js"></script>
<script>
moment().format('jYYYY/jM/jD');
</script>
```
#### Typescript
```ts
import * as moment from 'jalali-moment';
let todayJalali = moment().format('jYYYY/jM/jD');
```
#### Angular
```ts
import * as moment from 'jalali-moment';
```
add a jalali pipe

@@ -68,21 +87,7 @@ ```ts

### Typescript
```ts
import * as moment from 'jalali-moment';
let todayJalali = moment().format('jYYYY/jM/jD');
```
## Using in Plunker
### ES5
####ES5
```HTML
<!--<script src="bower_components/jalali-moment/dist/jalali-moment.browser.js"></script>-->
<!--<script src="node_modules/jalali-moment/dist/jalali-moment.browser.js"></script>-->
<script src="thisRepository/jalali-moment/dist/jalali-moment.browser.js"></script>
<script>
moment().format('jYYYY/jM/jD');
</script>
```
### Plunker
```HTML
<script src='https://unpkg.com/jalali-moment/dist/jalali-moment.browser.js'></script>

@@ -94,10 +99,15 @@ <script>

### Plunker and Typescript
####Typescript or es6
You could use systemjs to import this library into your project like [this](https://embed.plnkr.co/Gggh1u/)
## API
# API
This plugin tries to mimic [moment.js](https://momentjs.com/) api. Basically, when you want to format or parse a string, just add a `j` to the format token like 'jYYYY' or 'jM'. For example:
This plugin tries to mimic [moment.js](https://momentjs.com/) api.
Basically, when you want to format or parse a string,
just add a `j` to the format token like 'jYYYY' or 'jM'. For example:
```js
now = moment(); //get the current date and time,
m = moment('1367/11/4', 'jYYYY/jM/jD');

@@ -110,5 +120,4 @@ m.format('jYYYY/jM/jD [is] YYYY/M/D'); // 1367/11/4 is 1989/1/24

m.jYear(1368); // set jalali year
m.jMonth(); // 10
// jMonth Accepts numbers from 0 to 11. If the range is exceeded, it will bubble up to the year.
m.jMonth(3); // set a jalali month
// If the range is exceeded, it will bubble up to the year.
m.jMonth(3); // month will be 4 and m.format("M")=='4' , jMonth Accepts numbers from 0 to 11.
m.jDate(10); // set a date

@@ -132,3 +141,3 @@ m.format("jYYYY/jMM/jD"); // 1368/4/10

for more information about api you could read [moment.js](https://momentjs.com/docs/).
all features are documented in [here](https://momentjs.com/docs/).

@@ -148,6 +157,6 @@ #### Load Persian

## 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.
## Use jalali calendar system primarily
This plugin adds Jalali calendar system to moment.js which is using gregorian calendar system
so we could use both calendar system concurrently but
you could use Jalali calendar as default system like the following code:

@@ -166,8 +175,14 @@ ```js

For example:
to make a datepicker work with jalali calendar system you could use this feature.
## Related Projects
### jalali-angular-datepicker ( angular2 or more)
#### jalaali-moment
A Jalaali calendar system plugin for moment.js.
A highly configurable date picker built for Angular 2 applications using `jalali-moment` is [fingerpich/jalali-angular-datepicker](https://github.com/fingerpich/jalali-angular-datepicker) created by [@Fingerpich](https://github.com/fingerpich).
#### jalali-angular-datepicker ( angular2 or more)
A highly configurable date picker built for Angular 4 or Angular 2 applications using `jalali-moment` is [fingerpich/jalali-angular-datepicker](https://github.com/fingerpich/jalali-angular-datepicker) created by [@Fingerpich](https://github.com/fingerpich).
## License

@@ -193,3 +208,3 @@

[dev-dependencies-quality]: https://david-dm.org/fingerpich/jalali-moment/dev-status.svg
[dev-dependencies-quality-url]: https://david-dm.org/fingerpich/jalali-moment#info=devDependencies
[dev-dependencies-quality-url]: https://david-dm.org/fingerpich/jalali-moment?type=dev

@@ -196,0 +211,0 @@ [codacy-quality]:https://api.codacy.com/project/badge/Grade/1aa5b7aadfc24238bdf825d58cb2cba1

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