From 711aa60ddbbf23e76c1e1ec7231bc42cda253fd5 Mon Sep 17 00:00:00 2001 From: 6tail <6tail@6tail.cn> Date: Thu, 30 Apr 2020 00:19:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81Node.js=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=EF=BC=8C=E5=8F=91=E5=B8=83=E5=88=B0NPM=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 29 +++++++++++++++++++++++++++++ README_EN.md | 29 +++++++++++++++++++++++++++++ index.js | 13 +++++++++++++ lunar.js | 37 +++++++++++++++++++++++++------------ package.json | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+), 12 deletions(-) create mode 100644 index.js create mode 100644 package.json diff --git a/README.md b/README.md index cbc5491..e3b4531 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历) ## 示例 +### 普通页面 + ```html @@ -23,6 +25,33 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历) ``` +### npm + + npm init + npm install lunar-javascript + + //test.js + const {Solar} = require('lunar-javascript') + //const {Solar, Lunar, HolidayUtil} = require('lunar-javascript') + + let solar = Solar.fromYmd(1986,5,29); + console.log(solar.toFullString()); + console.log(solar.getLunar().toFullString()); + + node test.js + +### Node.js + + //test.js + const {Solar} = require('./lunar.js') + //const {Solar, Lunar, HolidayUtil} = require('./lunar.js') + + let solar = Solar.fromYmd(1986,5,29); + console.log(solar.toFullString()); + console.log(solar.getLunar().toFullString()); + + node test.js + 输出结果: 1986-05-29 00:00:00 星期四 双子座 diff --git a/README_EN.md b/README_EN.md index 735a38c..bf5667d 100644 --- a/README_EN.md +++ b/README_EN.md @@ -6,6 +6,8 @@ lunar is a calendar library for Solar and Chinese Lunar. ## Example +### Normal Page + ```html @@ -23,6 +25,33 @@ lunar is a calendar library for Solar and Chinese Lunar. ``` +### npm + + npm init + npm install lunar-javascript + + //test.js + const {Solar} = require('lunar-javascript') + //const {Solar, Lunar, HolidayUtil} = require('lunar-javascript') + + let solar = Solar.fromYmd(1986,5,29); + console.log(solar.toFullString()); + console.log(solar.getLunar().toFullString()); + + node test.js + +### Node.js + + //test.js + const {Solar} = require('./lunar.js') + //const {Solar, Lunar, HolidayUtil} = require('./lunar.js') + + let solar = Solar.fromYmd(1986,5,29); + console.log(solar.toFullString()); + console.log(solar.getLunar().toFullString()); + + node test.js + Output: 1986-05-29 00:00:00 星期四 双子座 diff --git a/index.js b/index.js new file mode 100644 index 0000000..5d35340 --- /dev/null +++ b/index.js @@ -0,0 +1,13 @@ +const {Solar, Lunar, SolarWeek, SolarMonth, SolarSeason, SolarHalfYear, SolarUtil, LunarUtil, HolidayUtil} = require('./lunar.js') + +module.exports = { + Solar: Solar, + Lunar: Lunar, + SolarWeek: SolarWeek, + SolarMonth: SolarMonth, + SolarSeason: SolarSeason, + SolarHalfYear: SolarHalfYear, + SolarUtil: SolarUtil, + LunarUtil: LunarUtil, + HolidayUtil: HolidayUtil +} \ No newline at end of file diff --git a/lunar.js b/lunar.js index fbb46f4..1613d05 100644 --- a/lunar.js +++ b/lunar.js @@ -1,4 +1,15 @@ -(function(W){ +;(function(root,factory){ + if (typeof define==='function'&&define.amd){ + define(factory); + }else if(typeof module!='undefined'&&module.exports){ + module.exports = factory(); + }else{ + var o = factory(); + for(var i in o){ + root[i] = o[i]; + } + } +})(this,function(){ var Solar = (function(){ var _int2=function(v){ v = Math.floor(v); @@ -1639,14 +1650,16 @@ getHolidaysByTarget:function(){return _getHolidaysByTarget(arguments);} }; })(); - W.SolarUtil = SolarUtil; - W.LunarUtil = LunarUtil; - W.Solar = Solar; - W.Lunar = Lunar; - W.SolarWeek = SolarWeek; - W.SolarMonth = SolarMonth; - W.SolarSeason = SolarSeason; - W.SolarHalfYear = SolarHalfYear; - W.SolarYear = SolarYear; - W.HolidayUtil = HolidayUtil; -})(window); + return { + SolarUtil:SolarUtil, + LunarUtil:LunarUtil, + Solar:Solar, + Lunar:Lunar, + SolarWeek:SolarWeek, + SolarMonth:SolarMonth, + SolarSeason:SolarSeason, + SolarHalfYear:SolarHalfYear, + SolarYear:SolarYear, + HolidayUtil:HolidayUtil + }; +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..1869502 --- /dev/null +++ b/package.json @@ -0,0 +1,47 @@ +{ + "name": "lunar-javascript", + "version": "1.0.0", + "description": "lunar is a calendar library for Solar and Chinese Lunar.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/6tail/lunar-javascript.git" + }, + "keywords": [ + "calendar", + "lunar", + "solar", + "节假日", + "星座", + "儒略日", + "干支", + "生肖", + "节气", + "节日", + "彭祖百忌", + "喜神", + "福神", + "财神", + "阳贵神", + "阴贵神", + "胎神", + "冲煞", + "纳音", + "星宿", + "八字", + "五行", + "十神", + "建除十二值星", + "青龙名堂等十二神", + "黄道黑道日" + ], + "author": "6tail", + "license": "MIT", + "bugs": { + "url": "https://github.com/6tail/lunar-javascript/issues" + }, + "homepage": "https://github.com/6tail/lunar-javascript" +}