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 🙏

© 2024 – Pkg Stats / Ryan Hefner

date-japanese

v1.0.1

Published

Convert Japanese calendar to Western calendar, Western calendar to Japanese calendar.

Downloads

301

Readme

date-japanese

Convert Japanese calendar to Western calendar, Western calendar to Japanese calendar.

Installation

npm install --save date-japanese

Quick Start

  • Node.js

    const {jp2west, west2jp} = require('date-japanese');
    
    jp2west('令和4年2月21日', 'YYYY-MM-DD');// -> 2022-02-21
    west2jp('2022-02-21');// -> 令和4年2月21日

    Or in ES6 syntax:

    import {jp2west, west2jp} from 'date-japanese';
    
    jp2west('令和4年2月21日', 'YYYY-MM-DD');// -> 2022-02-21
    west2jp('2022-02-21');// -> 令和4年2月21日
  • Browser

    <script src="node_modules/date-japanese/dist/build.js"></script>
    <script>
      dateJapanese.jp2west('令和4年2月21日', 'YYYY-MM-DD');// -> 2022-02-21
      dateJapanese.west2jp('2022-02-21');// -> 令和4年2月21日
    </script>

API

jp2west()

Convert Japanese calendar date to Western calendar date.
The eras that can be used are '明治' and '大正' and '昭和' and '平成' and '令和'.

import {jp2west} from 'date-japanese';

jp2west('令和元年5月1日', 'YYYY-MM-DD');// -> 2019-05-01
jp2west('令和4年2月21日', 'YYYY-MM-DD');// -> 2022-02-21
jp2west('平成元年1月', 'YYYY-MM');// -> 1989-01
jp2west('平成31年4月', 'YYYY-MM');// -> 2019-04
jp2west('昭和元年', 'YYYY');// -> 1926
jp2west('昭和64年', 'YYYY');// -> 1989

Parameters

  • {string} input Japanese calendar date. e.g. '令和4年2月20日', '令和4年2月' , '令和4年'
  • {string} format Output date format. The following tokens are available. The default is 'YYYY-MM-DD'.
    • YYYY - 4 digit of year (2022)
    • YY - 2 digit of year (22)
    • M - month number (1 2 ... 11 12)
    • MM - month number with 0 padding (01 02 ... 11 12)
    • MMM - short month name (Jan Feb ... Nov Dec)
    • MMMM - full month name (January February ... November December)
    • D - Day of Month (1 2 ... 30 31)
    • DD - Day of Month with zero padding (01 02 ... 30 31)
  • {boolean} throwException If set to true, an exception will be thrown if the input date is invalid as the Japanese calendar.

Return value

{string} Returns a Japanese calendar date as a date in the specified format.

west2jp()

Convert a Western calendar date to a Japanese calendar date.

import {west2jp} from 'date-japanese';

west2jp('2019-05-01');// -> 令和元年5月1日
west2jp('2022-02-21');// -> 令和4年2月21日
west2jp('1989-02');// -> 平成元年2月
west2jp('2019-04');// -> 平成31年4月
west2jp('1989');// -> 昭和64年

Parameters

  • {string} input Western calendar date.

Return value

{string} Converts the Western calendar date to the Japanese calendar date and returns it.

isJapaneseCalendar()

Check if it is a Japanese calendar.

import {isJapaneseCalendar} from 'date-japanese';

isJapaneseCalendar('令和元年5月1日');// -> true
isJapaneseCalendar('令和4年2月21日');// -> true
isJapaneseCalendar('令和元年5月');// -> true
isJapaneseCalendar('令和4年2月');// -> true
isJapaneseCalendar('令和元年');// -> true
isJapaneseCalendar('令和4年');// -> true
isJapaneseCalendar('2022-02-21');// -> false
isJapaneseCalendar('2022-02');// -> false
isJapaneseCalendar('2022');// -> false

Parameters

  • {string} value Value to be validated.

Return value

{boolean} Pass is true, fail is false.

Testing

With npm do:

npm test

Author

Takuya Motoshima

License

MIT