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

japanese-date

v2.0.0

Published

date parser of japanese

Downloads

36

Readme

japanese-date

japanese-date npm version

日本語からDateオブジェクトを取得するparser

Installation

$ npm install japanese-date

Usage

import { match, getDate } from 'japanese-date';

api

match

入力した日本語から日本語の日時表現にマッチした情報をarrayとして返します。

import { match } from 'japanese-date';
const matched = match('来年の昨日の10秒後');
[{
  index: 0, // matchした先頭のindex
  elem: '来年', // matchした文字列
  relative: 1, // typeに対する相対数値
  type: 'years' // matchした文字列の種類[ years, days, seconds ]
}, {
  index: 3, elem: '昨日', relative: -1, type: 'days'
}, {
  index: 6, elem: '10秒後', relative: 10, type: 'seconds'
}]

getDate

入力した日本語から日付のオブジェクトを配列で返します。
入力された文字の先頭から年/日付/時間を取得し、その最短の組み合わせを計算したものを返します。

// 実行日: 2016-11-24T15:22:02.451Z
import { getDate } from 'japanese-date';
const matched = getDate('来年の昨日の10秒後');
[ 2017-11-23T15:18:48.514Z ]

sample

$ npm run build
$ node sample.mjs
import * as jpdate from 'japanese-date';
const match = jpdate.match('来年の昨日');
// [ { index: 0, elem: '来年', relative: 1, type: 'years' },
//   { index: 3, elem: '昨日', relative: -1, type: 'days' } ]
const date = jpdate.getDate('来年の昨日');
console.log(date);
// [ 2017-11-23T15:18:48.514Z ]

入力パターン例

import * as jpdate from 'japanese-date';
const patterns = [
  '50分後',
  '10時半',
  'あさって',
  '2015年1月23日',
  '2015年の1月23日',
  '明日の一時間後',
  '来年のきょう',
  '来月の明日',
  '一年前の十日後',
  '2年後の21日前',
  '3年後',
  '10年後の昨日',
  '百年後の一昨日',
  '明日の10時',
  '来年の10時二十三分',
  '今週の土曜',
  '来週の水曜日',
  '先週の月曜日',
  '来月の11日',
  '来月の第三金曜日',
  '明日の正午',
  '来年の大晦日',
  '去年のクリスマスイブ',
  '一昨年の元日',
  '来年の成人の日',
  '2018年の建国記念の日',
];
for (const pattern of patterns) {
  console.log(jpdate.getDate(pattern));
}

License

MIT