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

v0.1.3

Published

Builds a regexp from a date query, e.g. for usage with Overpass API.

Downloads

2

Readme

openstreetmap-date-query

Builds a regexp from a date query, e.g. for usage with Overpass API.

This can be used to search for date in the format of the start_date tag.

Examples

const osmDateQuery = require('openstreetmap-date-query')

osmDateQuery('2019')
// ^(((|early |mid |late )2019(-[0-9]{2}(-[0-9]{2})?)?|(|late )2010s|(|early )C21)|(((|early |mid |late )2019(-[0-9]{2}(-[0-9]{2})?)?|(|late )2010s|(|early )C21)(|\\.\\..*))|((|.*\\.\\.)((|early |mid |late )2019(-[0-9]{2}(-[0-9]{2})?)?|(|late )2010s|(|early )C21)))$

osmDateQuery('2019', { strict: true })
// '^(~?((|early |mid |late )2019(-[0-9]{2}(-[0-9]{2})?)?)|(~?((|early |mid |late )2019(-[0-9]{2}(-[0-9]{2})?)?)\\.\\.~?((|early |mid |late )2019(-[0-9]{2}(-[0-9]{2})?)?)))$'

osmDateQuery('2019', { op: '<', strict: true })
// ^(|.*\\.\\.)(.* BC|(|early |mid |late )C0?[0-9]|(|early |mid |late )C[1][0-9]|(|early |mid |late )0?[0-9][0-9](0s|[0-9](-[0-9]{2}(-[0-9]{2})?)?)|(|early |mid |late )[1][0-9][0-9](0s|[0-9](-[0-9]{2}(-[0-9]{2})?)?)|(|early |mid |late )C20|(|early |mid |late )20[0](0s|[0-9](-[0-9]{2}(-[0-9]{2})?)?)|(early |mid )2010s|(|early |mid |late )201[012345678](-[0-9]{2}(-[0-9]{2})?)?)$

// build a regexp object from a query
let regexp = new RegExp(osmDateQuery('2019', { op: '<', strict: true }))
// test query (use !! in front to ignore regexp details)
!!'2018-12-24'.match(regexp)
// true

!!'C21'.match(regexp)
// false - the 21st century is not before 2019

let regexp = new RegExp(osmDateQuery('2019', { op: '<', strict: false }))
!!'C21'.match(regexp)
// true - something which happend in the 21st century might have happened before 2019.

Support

The following parts of the start_date specification are supported:

  • year only (e.g. 2019)
  • year-month (e.g. 2019-09)
  • year-month-day (e.g. 2019-09-22)
  • decade (e.g. 2010s)
  • century (e.g. C21)
  • early, mid, late prefix (e.g. early C21, late 2019)
  • ranges (e.g. C17..1801-01-01)
  • BC or BCE suffix (e.g. 350 BC)
  • circa (e.g. ~2000) - will be handled like exact value

The following parts of the start_date specification are not supported (yet):

  • before, after
  • Julian calendar, Julian day system, other calendars
  • AD suffix

The following date formats are supported as input to osmDateQuery():

  • year only (e.g. 2019)
  • year-month (e.g. 2019-09)
  • year-month-day (e.g. 2019-09-22)
  • decade (e.g. 2010s)
  • century (e.g. C21)

The following date formats are not (yet?) supported as input to osmDateQuery():

  • early, mid, late prefix (e.g. early C21, late 2019)
  • ranges (e.g. C17..1801-01-01)
  • ~
  • Julian calendar, Julian day system, other calendars
  • ranges (e.g. C17..2019)
  • BC, BCE, AD suffixes (means: only dates AD can be used as input)

Strict mode

Strict mode will only match dates, which are definitely included in the query. Example: take a building which was built in "C17" (17th century). You query for buildings built in "1623". The building might have been built in that particular year, so it will be matched by when strict mode is false. When strict mode is true, only dates in the year of 1623 will match (e.g. 1623-02).

Examples:

| Date value | Query | Operator |Matches strict mode|Matches non-strict mode| |------------|-------|:--------:|:-----------------:|:---------------------:| | 1623 | C17 | = | true | true | | C17 | 1623 | = | false | true | | 1623 | C17 | <= | true | true | | C17 | 1623 | <= | false | true | | 1623 | C17 | < | false | false | | C17 | 1623 | < | false | true |

Installation

npm install --save openstreetmap-date-query

Development

Clone the repository and install development dependencies:

https://github.com/plepe/openstreetmap-date-query.git
cd openstreetmap-date-query
npm install
npm run test

node
> const osmDateQuery = require('./src/query')
> osmDateQuery('2019')
// regexp garbage

Related modules

API

osmDateQuery(dateString, options)

Convert a date string to a regular expression

Parameters:

dateString: a date string to query for

options: additional options

Option | Default | Description -------|---------|-------------- op | = | Operator. Possible values: =, <, <=, >, >= strict | false | If false, include matches which overlap the date specification.