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-shortcode

v1.0.0

Published

A small and simple date shortcode library.

Downloads

250

Readme

date-shortcode

npm package version Travis build status npm package downloads code style license

A small and simple date shortcode library.

Installation

npm install --save date-shortcode

Usage

const dateShortcode = require('date-shortcode')

var str = 'It is {h:mm A} on the {Do} day of {MMMM YYYY}.'
dateShortcode.parse(str)
//=> 'It is 3:26 PM on the 1st day of March 2018.'

API

config(conf)

Change date-shortcode configuration parameters.

Parameters
conf (Object)

An object containing the configuration parameters to change.

Example
var dateShortcodeConfig = {
  openTag: '\\[',
  closeTag: '\\]'
}

const dateShortcode = require('date-shortcode').config(dateShortcodeConfig)

parse(str, [ date ])

Parse a string with date shortcodes in it.

Parameters
str (String)

The string to do the parsing on.

date (String/Date)

Optional

A date object or a string to pass to a date object. Defaults to now.

Example
var str = 'Current date: {MMMM Do, YYYY}'
dateShortcode.parse(str, '2006-10-09')
//=> 'Current date: October 9th, 2006'

strip(str)

Strip date shortcodes from a string.

Parameters
str (String)

The string to strip date shortcodes from.

Example
var str = 'It is {h:mm A} on the {Do} day of {MMMM YYYY}.'
dateShortcode.strip(str)
//=> 'It is  on the  day of .'

test(str1, str2)

Test if two strings would be the same without date shortcodes.

Parameters
str1 (String)

First string to test

str2 (String)

Second string to test

Example
var str1 = 'It is {h:mm A} on the {Do} day of {MMMM YYYY}.'
var str2 = 'It is 3:26 PM on the 1st day of March 2018.'
dateShortcode.test(str1, str2)
//=> true

var str3 = 'This string is nothing like the rest.'
dateShortcode.test(str1, str3)
//=> false

Shortcodes

| Description | Token | Output | |--------------------------------|-------|------------------------------------------| | Month | MMMM | January February ... November December | | Month (3 characters) | MMM | Jan Feb ... Nov Dec | | Month Number (Padded) | MM | 01 02 ... 11 12 | | Month Number (Suffixed) | Mo | 1st 2nd ... 11th 12th | | Month Number | M | 1 2 ... 11 12 | | Quarter (Suffixed) | Qo | 1st 2nd 3rd 4th | | Quarter | Q | 1 2 3 4 | | Day of Year (Padded) | DDDD | 001 002 ... 364 365 | | Day of Year (Suffixed) | DDDo | 1st 2nd ... 364th 365th | | Day of Year | DDD | 1 2 ... 364 365 | | Day of Month (Padded) | DD | 01 02 ... 30 31 | | Day of Month (Suffixed) | Do | 1st 2nd ... 30th 31st | | Day of Month | D | 1 2 ... 30 31 | | Day of Week | dddd | Sunday Monday ... Friday Saturday | | Day of Week (3 characters) | ddd | Sun Mon ... Fri Sat | | Day of Week (2 characters) | dd | Su Mo ... Fr Sa | | Day of Week Number (Suffixed) | do | 0th 1st ... 5th 6th | | Day of Week Number | d | 0 1 ... 5 6 | | Week of Year (Padded) | ww | 01 02 ... 52 53 | | Week of Year (Suffixed) | wo | 1st 2nd ... 52nd 53rd | | Week of Year | w | 1 2 ... 52 53 | | Year | YYYY | 1970 1971 ... 2029 2030 | | Year (2 characters) | YY | 70 71 ... 29 30 | | AM/PM | A | AM PM | | am/pm | a | am pm | | Hour (24 hours/Padded) | kk | 01 02 ... 23 24 | | Hour (24 hours) | k | 1 2 ... 23 24 | | Hour (12 hours/Padded) | hh | 01 02 ... 11 12 | | Hour (12 hours) | h | 1 2 ... 11 12 | | Hour (24 hours/0-Index/Padded) | HH | 00 01 ... 22 23 | | Hour (24 hours/0-Index) | H | 0 1 ... 22 23 | | Minute (Padded) | mm | 00 01 ... 58 59 | | Minute | m | 0 1 ... 58 59 | | Second (Padded) | ss | 00 01 ... 58 59 | | Second | s | 0 1 ... 58 59 |

License

MIT. See the license.md file for more info.