Socket
Book a DemoInstallSign in
Socket

browser-date-formatter

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-date-formatter

Format dates real fancy-like in the browser. Good for search engines and humans.

latest
Source
npmnpm
Version
3.0.3
Version published
Maintainers
1
Created
Source

browser-date-formatter

Format dates real fancy-like in the browser. Good for search engines and humans.

This was originally implemented on the npmjs.com website, then proved useful enough to extract into a standalone module.

Weighs in at 4K, minified and gzipped.

Installation

npm install browser-date-formatter --save

Usage

Specify date and format data attributes on all HTML elements you want formatted:

<span data-date="Thu Apr 07 2016 17:00:00 GMT-0700 (PDT)" data-format="%Y-%m-%d">
  (any textContent you put here will be replaced with "2016-04-07")
</span>

The date data attribute should be a stringified representation of a JavaScript Date object, e.g. String(new Date())

The format data attribute is optional. If omitted, a human-friendly relative date string like "5 minutes ago" is displayed. If specified, the format is expected to be a strftime pattern, such as %Y-%m-%d.

Require and invoke the function in your javascript code:

require('browser-date-formatter')()

When the DOM is ready, this module finds all elements with a data-date attribute and converts their text content to the given data-format. The formatter function is executed every 5 seconds to keep relative dates fresh.

Usage without browserify

If you're not using browserify in your project, you can use the unpkg.com hosted version instead:

<script src="https://unpkg.com/browser-date-formatter/dist.js"></script>
<script>
  browserDateFormatter()
</script>

Tests

npm install
npm test

Dependencies

  • domready: modern domready
  • strftime: Format dates nicely
  • relative-date: Javascript module for outputting relative dates.

License

MIT

Generated by package-json-to-readme

Keywords

browser

FAQs

Package last updated on 17 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts