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

openstreetmap-date-format

v0.4.0

Published

Format openstreetmap dates (like start_date) in a localized string

Downloads

13

Readme

Format openstreetmap dates (like start_date) in a localized string.

Examples:

osmDateFormat.locale('en')
console.log(osmDateFormat('1940s'))
// 'the 1940s'

console.log(osmDateFormat('2018-10..2018-12-24'))
// 'between October 2018 and December 24, 2018'

osmDateFormat.locale('de')
console.log(osmDateFormat('2018-10..2018-12-24'))
// 'zwischen Oktober 2018 und 24. Dezember 2018'

Available locales:

  • English (en)
  • Deutsch / German (de)
  • Français / French (fr) (thanks to james2432)

If you want to contribute another language, please check the howto.

Installation

npm install --save openstreetmap-date-format

API

osmDateFormat(dateString, options)

Convert a date string (as found in a osm tage like 'start_date') to a localized string.

Available options:

  • format: choose an alternative format. Currently available: 'long' (default), 'short'

Example:

console.log(osmDateFormat('C19'))
// '19th century'
console.log(osmDateFormat('1980..~1990'))
// 'between 1980 and c. 1990'
console.log(osmDateFormat('1901-02-03'))
// 'February 3, 1901'
console.log(osmDateFormat('1901-02-03', { format: 'short' }))
// 'Feb 3, 1901'

osmDateFormat.locale([localeId])

Either return the currently set locale or set a different locale. When using browserify it will not be possible to change the current locale, see below how to embed locales.

osmDateFormat.locale('en')
console.log(osmDateFormat('1940s'))
// 'the 1940s'

osmDateFormat.locale('de')
console.log(osmDateFormat('1940s'))
// '1940er Jahre'

console.log(osmDateFormat.locale())
// 'de'

osmDateFormat.locales()

Return available locales as array.

Example:

console.log(osmDateFormat.locales())
// [ 'en', 'de', 'fr' ]

Localization

Using nodejs

const osmDateFormat = require('openstreetmap-date-format')

osmDateFormat.locale('en')

console.log(osmDateFormat('2010-10'))
// 'October 2010'

Using locales via browserify

It would be easy to bundle all locales using browserify, but this would also bloat code. I found the following solution by using a global variable with name locale:

Create files for each locale, example 'locale/de.js':

global.locale = {
  id: 'de',
  moment: require('moment'),
  osmDateFormatTemplates: require('openstreetmap-date-format/templates/de')
}
require('moment/locale/de') // don't do this for 'en'

Compile distribution files for each locale:

browserify locale/de.js -o dist/locale-de.js

Additionally include locale file in your app:

<html>
  <head>
    <script src='dist/app.js'></script>
    <script src='dist/locale-de.js'></script>
  </head>
  <body>
    ...
  </body>
</html>

Code:

const osmDateFormat = require('openstreetmap-date-format')

console.log(osmDateFormat('2010-10', { format: 'short' }))
// 'Oct 2010'

Command line usage

If installed globally (--global), a command line utility openstreetmap-date-format will be installed, which reads values from stdin and prints the formatted result to stdout.

For further options, use openstreetmap-date-format --help.

Example:

> echo C17 | openstreetmap-date-format
17th century
> echo C17 | openstreetmap-date-format --format short
17c.
> export LANG=de_DE.UTF-8
> echo C17 | openstreetmap-date-format
17. Jahrhundert

Further links

Code

  • Source code: https://github.com/plepe/openstreetmap-date-format

Documentation

  • https://wiki.openstreetmap.org/wiki/Key:start_date

Related modules