convert japanese Wareki(和暦) to Era(西暦) of date for javascript
Switch branches/tags
Nothing to show
Clone or download
kei kei
kei and kei bump 0.3.3
Latest commit d2bef53 Dec 5, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
src
.babelrc
.gitignore
.jshintignore
.jshintrc
.npmignore
LICENSE
README.md
index.html
index.js
package-lock.json
package.json
rollup.config.js
test.js

README.md

wareki2era.js

convert Japanese Wareki(日本の元号 | 和暦) to the Era(西暦) for javascript

wareki2era.js is tiny javascript library. which is able to convert Japanese Wareki(和暦|元号) to Era (西暦).

Installation

# npm
npm i wareki2era
# yarn
yarn add wareki2era

Or you can import directly via CDN.

<script src="https://unpkg.com/wareki2era/dist/wareki2era.browser.js"></script>

Basic Usage

wareki2era( JapaneseEraDate ) : String

japaneseEraDate shoud be (明治|大正|昭和|平成)YYYY年MM月DD日

CommonJS (node.js) || ES6 or later (babel)

const wareki2era = require("wareki2era");
// import wareki2era from "wareki2era";

let jpnEra = "明治四五年一二月十日";

wareki2era(jpnEra); // 1912-12-10

Web browser

<script>
var jpnEra = '昭和八年九月九日';

console.log(wareki2era(jpnEra)); // 1933-09-09

</script>

With options

With second argument, you can assgin splited character whatever you want.

var jpnEra = "明治四五年一二月十日";

// default
wareki2era(jpnEra); // 1912-12-10

// with option
wareki2era(jpnEra, "/"); // 1912/12/10
wareki2era(jpnEra, "#"); // 1912#12#10

In addition j option is return japanese date of string.

// with 'j' option
wareki2era(jpnEra, "j"); // 1912年12月10日

Credit

Special thanks to http://sm.2-d.jp's liblary. wareki2era.js is using it while converting kan-suji(漢数字) to Arabic number.

Licence

MIT