jewish-date 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/index.js +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/interfaces.d.ts +52 -0
- package/lib/jewishDate.d.ts +8 -0
- package/lib/jewishDateHebrew.d.ts +5 -0
- package/lib/utils/dateUtils/dateConverterUtils.d.ts +5 -0
- package/lib/utils/dateUtils/index.d.ts +1 -0
- package/lib/utils/numberUtils/index.d.ts +1 -0
- package/lib/utils/numberUtils/numberUtils.d.ts +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Shmulik Kravitz.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Jewish Date · [](https://github.com/Shmulik-Kravitz/jewish-date/blob/master/LICENSE)   [](https://www.npmjs.com/package/jewish-date)
|
|
2
|
+
|
|
3
|
+
Jewish Date is a Hebrew date to Gregorian date and vice verser converter.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```console
|
|
8
|
+
yarn add jewish-date
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or with npm
|
|
12
|
+
|
|
13
|
+
```console
|
|
14
|
+
npm install jewish-date --save
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### TypeScript & ES6 example
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import {
|
|
23
|
+
toJewishDate, toGregorianDate, formatJewishDateInHebrew, toHebrewJewishDate, JewishMonth
|
|
24
|
+
} from "jewish-date";
|
|
25
|
+
|
|
26
|
+
const date = new Date("2020-01-01");
|
|
27
|
+
const jewishDate = toJewishDate(date);
|
|
28
|
+
console.log(jewishDate); // { year: 5780, monthName: "Tevet", day: 4 }
|
|
29
|
+
|
|
30
|
+
const jewishDateInHebrew = toHebrewJewishDate(jewishDate);
|
|
31
|
+
console.log(jewishDateInHebrew); // { day: "ד׳", monthName: "טבת", year: "התש״פ" }
|
|
32
|
+
|
|
33
|
+
const jewishDateInHebrewStr = formatJewishDateInHebrew(jewishDate);
|
|
34
|
+
console.log(jewishDateInHebrewStr); // ד׳ טבת התש
|
|
35
|
+
|
|
36
|
+
const date2 = toGregorianDate({ year: 5780, monthName: JewishMonth.Tevet, day: 4 });
|
|
37
|
+
console.log(date2); // Wed Jan 01 2020 00:00:00 GMT+0200 (Israel Standard Time)
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### For ES5
|
|
42
|
+
|
|
43
|
+
Replace
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import {
|
|
47
|
+
toJewishDate, toGregorianDate, formatJewishDateInHebrew, toHebrewJewishDate
|
|
48
|
+
} from "jewish-date";
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
With
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
const {
|
|
55
|
+
toJewishDate, toGregorianDate, formatJewishDateInHebrew, toHebrewJewishDate
|
|
56
|
+
} = require("jewish-date");
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
Jewish Date is [MIT licensed](https://github.com/Shmulik-Kravitz/jewish-date/blob/master/LICENSE).
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var q=Object.create;var b=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var P=(e,r)=>{for(var n in r)b(e,n,{get:r[n],enumerable:!0})},g=(e,r,n,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of L(r))!Y.call(e,o)&&o!==n&&b(e,o,{get:()=>r[o],enumerable:!(a=G(r,o))||a.enumerable});return e};var k=(e,r,n)=>(n=e!=null?q(R(e)):{},g(r||!e||!e.__esModule?b(n,"default",{value:e,enumerable:!0}):n,e)),F=e=>g(b({},"__esModule",{value:!0}),e);var ne={};P(ne,{JewishMonth:()=>t,convertNumberToHebrew:()=>J,formatJewishDate:()=>X,formatJewishDateInHebrew:()=>te,getIndexByJewishMonth:()=>B,getJewishMonthByIndex:()=>E,getJewishMonthInHebrew:()=>z,getJewishMonthsInOrder:()=>$,isLeapYear:()=>j,toGregorianDate:()=>ee,toHebrewJewishDate:()=>K,toJewishDate:()=>Z});module.exports=F(ne);var t={None:"None",Tishri:"Tishri",Cheshvan:"Cheshvan",Kislev:"Kislev",Tevet:"Tevet",Shevat:"Shevat",Adar:"Adar",Nisan:"Nisan",Iyyar:"Iyyar",Sivan:"Sivan",Tammuz:"Tammuz",Av:"Av",Elul:"Elul",AdarI:"AdarI",AdarII:"AdarII"};function u(e,r){return e-r*Math.floor(e/r)}function _(e){return e%4==0&&!(e%100==0&&e%400!=0)}var A=17214255e-1;function w(e,r,n){return A-1+365*(e-1)+Math.floor((e-1)/4)+-Math.floor((e-1)/100)+Math.floor((e-1)/400)+Math.floor((367*r-362)/12+(r<=2?0:_(e)?-1:-2)+n)}function T(e){var r,n,a,o,s,i,c,d,f,p,M;r=Math.floor(e-.5)+.5,n=r-A,a=Math.floor(n/146097),o=u(n,146097),s=Math.floor(o/36524),i=u(o,36524),c=Math.floor(i/1461),d=u(i,1461),f=Math.floor(d/365);let m=a*400+s*100+c*4+f;s==4||f==4||m++,p=r-w(m,1,1),M=r<w(m,3,1)?0:_(m)?1:2;let I=Math.floor(((p+M)*12+373)/367),O=r-w(m,I,1)+1;return[m,I,O]}var D=347995.5;function N(e){return u(e*7+1,19)<7}function W(e){return N(e)?13:12}function l(e){var r,n;r=Math.floor((235*e-234)/19),n=12084+13753*r;let a=r*29+Math.floor(n/25920);return u(3*(a+1),7)<3&&a++,a}function Q(e){var r,n,a;return r=l(e-1),n=l(e),a=l(e+1),a-n==356?2:n-r==382?1:0}function x(e){return h(e+1,7,1)-h(e,7,1)}function y(e,r){return r===2||r===4||r===6||r===10||r===13||r===12&&!N(e)||r===8&&u(x(e),10)!==5||r===9&&u(x(e),10)===3?29:30}function h(e,r,n){var a,o,s;if(s=W(e),a=D+l(e)+Q(e)+n+1,r<7){for(o=7;o<=s;o++)a+=y(e,o);for(o=1;o<r;o++)a+=y(e,o)}else for(o=7;o<r;o++)a+=y(e,o);return a}function H(e){var r,n,a,o,s,i;for(e=Math.floor(e)+.5,s=Math.floor((e-D)*98496/35975351),r=s-1,o=s;e>=h(o,7,1);o++)r++;for(i=e<h(r,1,1)?7:1,n=i,o=i;e>h(r,o,y(r,o));o++)n++;return a=e-h(r,n,1)+1,[r,n,a]}var v=(e,r)=>e.toString().padStart(r,"0");var U={[t.None]:0,[t.Tishri]:7,[t.Cheshvan]:8,[t.Kislev]:9,[t.Tevet]:10,[t.Shevat]:11,[t.Adar]:12,[t.AdarI]:13,[t.AdarII]:14,[t.Nisan]:1,[t.Iyyar]:2,[t.Sivan]:3,[t.Tammuz]:4,[t.Av]:5,[t.Elul]:6},B=e=>U[e]||0,V=[t.None,t.Nisan,t.Sivan,t.Tammuz,t.Iyyar,t.Av,t.Elul,t.Tishri,t.Cheshvan,t.Kislev,t.Tevet,t.Shevat,t.Adar,t.AdarI,t.AdarII],E=e=>V[e]||t.None,S=[t.None,t.Tishri,t.Cheshvan,t.Kislev,t.Tevet,t.Shevat,t.AdarI,t.AdarII,t.Nisan,t.Sivan,t.Tammuz,t.Iyyar,t.Av,t.Elul],j=e=>{let r=e%19;return r===0||r===3||r===6||r===8||r===11||r===14||r===17},$=e=>j(e)?S:S.filter(r=>r!=="AdarII").map(r=>r=="AdarI"?"Adar":r),X=e=>`${e.day} ${e.monthName} ${e.year}`,Z=e=>{let r=e.getFullYear(),n=e.getMonth()+1,a=e.getDate(),o=w(r,n,a),s=H(o),i=s[0],c=E(s[1]),d=$(i).findIndex(p=>p===c);return{year:i,monthName:c,month:d,day:s[2]}},ee=e=>{let r=h(e.year,B(e.monthName),e.day),n=T(r),a=`${v(n[0],4)}-${v(n[1],2)}-${v(n[2],2)}`,o=new Date(a);return o.getHours()>0&&o.setHours(0,0,0,0),o};var C=k(require("gematriya"));var re={[t.None]:"\u05DC\u05DC\u05D0",[t.Tishri]:"\u05EA\u05E9\u05E8\u05D9",[t.Cheshvan]:"\u05D7\u05E9\u05D5\u05DF",[t.Kislev]:"\u05DB\u05E1\u05DC\u05D5",[t.Tevet]:"\u05D8\u05D1\u05EA",[t.Shevat]:"\u05E9\u05D1\u05D8",[t.Adar]:"\u05D0\u05D3\u05E8",[t.AdarI]:"\u05D0\u05D3\u05E8 \u05D0",[t.AdarII]:"\u05D0\u05D3\u05E8 \u05D1",[t.Nisan]:"\u05E0\u05D9\u05E1\u05DF",[t.Iyyar]:"\u05D0\u05D9\u05D9\u05E8",[t.Sivan]:"\u05E1\u05D9\u05D5\u05DF",[t.Tammuz]:"\u05EA\u05DE\u05D5\u05D6",[t.Av]:"\u05D0\u05D1",[t.Elul]:"\u05D0\u05DC\u05D5\u05DC"},z=e=>re[e],J=(e,r=!0,n=!0)=>(0,C.default)(e,{geresh:r,punctuate:n}),K=e=>({day:J(e.day),monthName:z(e.monthName),year:J(e.year)}),te=e=>{let r=K(e);return`${r.day} ${r.monthName} ${r.year}`};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare const JewishMonth: {
|
|
2
|
+
readonly None: "None";
|
|
3
|
+
readonly Tishri: "Tishri";
|
|
4
|
+
readonly Cheshvan: "Cheshvan";
|
|
5
|
+
readonly Kislev: "Kislev";
|
|
6
|
+
readonly Tevet: "Tevet";
|
|
7
|
+
readonly Shevat: "Shevat";
|
|
8
|
+
readonly Adar: "Adar";
|
|
9
|
+
readonly Nisan: "Nisan";
|
|
10
|
+
readonly Iyyar: "Iyyar";
|
|
11
|
+
readonly Sivan: "Sivan";
|
|
12
|
+
readonly Tammuz: "Tammuz";
|
|
13
|
+
readonly Av: "Av";
|
|
14
|
+
readonly Elul: "Elul";
|
|
15
|
+
readonly AdarI: "AdarI";
|
|
16
|
+
readonly AdarII: "AdarII";
|
|
17
|
+
};
|
|
18
|
+
export declare type JewishMonthType = keyof typeof JewishMonth;
|
|
19
|
+
export interface BasicJewishDate {
|
|
20
|
+
/**
|
|
21
|
+
* day of month
|
|
22
|
+
*/
|
|
23
|
+
day: number;
|
|
24
|
+
/**
|
|
25
|
+
* monthName
|
|
26
|
+
*/
|
|
27
|
+
monthName: JewishMonthType;
|
|
28
|
+
/**
|
|
29
|
+
* month
|
|
30
|
+
*/
|
|
31
|
+
year: number;
|
|
32
|
+
}
|
|
33
|
+
export interface JewishDate extends BasicJewishDate {
|
|
34
|
+
/**
|
|
35
|
+
* month
|
|
36
|
+
*/
|
|
37
|
+
month: number;
|
|
38
|
+
}
|
|
39
|
+
export interface BasicJewishDateHebrew {
|
|
40
|
+
/**
|
|
41
|
+
* day of month
|
|
42
|
+
*/
|
|
43
|
+
day: string;
|
|
44
|
+
/**
|
|
45
|
+
* monthName
|
|
46
|
+
*/
|
|
47
|
+
monthName: string;
|
|
48
|
+
/**
|
|
49
|
+
* month
|
|
50
|
+
*/
|
|
51
|
+
year: string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BasicJewishDate, JewishDate, JewishMonthType } from "./interfaces";
|
|
2
|
+
export declare const getIndexByJewishMonth: (jewishMonth: JewishMonthType) => number;
|
|
3
|
+
export declare const getJewishMonthByIndex: (index: number) => JewishMonthType;
|
|
4
|
+
export declare const isLeapYear: (year: number) => boolean;
|
|
5
|
+
export declare const getJewishMonthsInOrder: (year: number) => string[];
|
|
6
|
+
export declare const formatJewishDate: (jewishDate: JewishDate) => string;
|
|
7
|
+
export declare const toJewishDate: (date: Date) => JewishDate;
|
|
8
|
+
export declare const toGregorianDate: (jewishDate: BasicJewishDate) => Date;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BasicJewishDate, BasicJewishDateHebrew, JewishMonthType } from "./interfaces";
|
|
2
|
+
export declare const getJewishMonthInHebrew: (jewishMonth: JewishMonthType) => string;
|
|
3
|
+
export declare const convertNumberToHebrew: (num: number, addGeresh?: boolean, addPunctuate?: boolean) => string;
|
|
4
|
+
export declare const toHebrewJewishDate: (jewishDate: BasicJewishDate) => BasicJewishDateHebrew;
|
|
5
|
+
export declare const formatJewishDateInHebrew: (jewishDate: BasicJewishDate) => string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function mod(a: number, b: number): number;
|
|
2
|
+
export declare function gregorian_to_jd(year: number, month: number, day: number): number;
|
|
3
|
+
export declare function jd_to_gregorian(jd: number): any[];
|
|
4
|
+
export declare function hebrew_to_jd(year: number, month: number, day: number): any;
|
|
5
|
+
export declare function jd_to_hebrew(jd: number): any[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dateConverterUtils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './numberUtils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const toLength: (num: number, len: number) => string;
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jewish-date",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/Shmulik-Kravitz/jewish-date"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "esr ./config/start.ts",
|
|
13
|
+
"build": "yarn clean && esr ./config/build.ts",
|
|
14
|
+
"clean": "rimraf dist",
|
|
15
|
+
"test": "vitest --config ./config/vitest.config.ts --coverage",
|
|
16
|
+
"p": "yarn pack --out %s-%v.tgz",
|
|
17
|
+
"inc-version": "yarn version patch",
|
|
18
|
+
"get-version": "node -p \"require('./package.json').version\""
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/gematriya": "^2.0.2",
|
|
22
|
+
"@types/node": "^16.11.7",
|
|
23
|
+
"@types/react": "^18.0.25",
|
|
24
|
+
"@types/react-dom": "^18.0.9",
|
|
25
|
+
"@vitest/coverage-c8": "^0.24.3",
|
|
26
|
+
"esbuild": "^0.15.11",
|
|
27
|
+
"esbuild-node-externals": "^1.5.0",
|
|
28
|
+
"esbuild-runner": "^2.2.2",
|
|
29
|
+
"prettier": "^2.7.1",
|
|
30
|
+
"react": "^18.2.0",
|
|
31
|
+
"react-dom": "^18.2.0",
|
|
32
|
+
"rimraf": "^3.0.2",
|
|
33
|
+
"tsc-prog": "^2.2.1",
|
|
34
|
+
"typescript": "^4.8.4",
|
|
35
|
+
"vite": "^3.1.8",
|
|
36
|
+
"vitest": "^0.24.3"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"gematriya": "^2.0.0"
|
|
40
|
+
},
|
|
41
|
+
"packageManager": "yarn@3.3.0",
|
|
42
|
+
"husky": {
|
|
43
|
+
"hooks": {
|
|
44
|
+
"pre-commit": "lint-staged"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"lint-staged": {
|
|
48
|
+
"**/*": "prettier --write --ignore-unknown"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"lib"
|
|
53
|
+
],
|
|
54
|
+
"keywords": [
|
|
55
|
+
"jewish",
|
|
56
|
+
"hebrew",
|
|
57
|
+
"date",
|
|
58
|
+
"luach",
|
|
59
|
+
"calendar",
|
|
60
|
+
"convert",
|
|
61
|
+
"hdate",
|
|
62
|
+
"hebcal",
|
|
63
|
+
"hcal"
|
|
64
|
+
]
|
|
65
|
+
}
|