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

ranged-date

v2.1.0

Published

Converts a given string, number, or Date object to the number of milliseconds since the Unix epoch, provided that it can be recognized as millisecond, second, or microsecond time within a specified range from the current date.

Downloads

66

Readme

ranged-date

NPM

NPM NPM NPM NPM NPM NPM

MIGRATION NOTICE:

  • ranged-date 2.0.0: back and forward ranges are now mandatory (were 0.5 each by default in 1.x.x).
  • ranged-date 2.0.0: Date Objects with values outside of the specified range will return false (would return Date Object in 1.x.x).

Converts a given string, number, or Date object to the number of milliseconds since the Unix epoch, provided that it can be recognized as millisecond, second, or microsecond time within a specified range from the current date.

Milliseconds, seconds, or microseconds may be excluded as possibilities for range matching.

Useful for:

  • Parsing timestampted data from external APIs.
  • Integrating collections containing mixed timestamp formats.

Getting Started

Prerequisites

Node.JS version 6.0.0 or above.

Installing

npm i ranged-date

Testing

The following commands will test the package for errors.

cd /path/to/node_modules/ranged-date
npm test

API

Table of Contents

ranged-date

index.js:150-178

Converts a given string, number, or Date object to the number of milliseconds since the Unix epoch, provided that it can be recognized as millisecond, second, or microsecond time within a specified range from the current date.

Parameters

  • data (Date | number | string) Data to attempt to recognize as valid date.
  • yrBack number Years before current date as lower bound.
  • yrFwd number Years after current date as upper bound.
  • exclusions Object Specifies interpretation exclusions, if any.
    • exclusions.us boolean Exclude microseconds interpretation. (optional, default false)
    • exclusions.ms boolean Exclude milliseconds interpretation. (optional, default false)
    • exclusions.s boolean Exclude seconds interpretation. (optional, default false)

Examples

// All return current time in ms
rangedDate(new Date(), 1, 1)
rangedDate(Date.now(), 1, 1)
rangedDate(new Date().toString(), 1, 1)
rangedDate(String(Date.now()), 1, 1)

// All return false
rangedDate(Date.now() - 10000000, 0.0000001, 0.0000001)
rangedDate(Date.now(), 1, 1, {ms: true})

// All throw cert-is TypeAssertionErrors
rangedDate()
rangedDate(new Date())
rangedDate({})
rangedDate(328385)

// Throws cert-is RangeAssertionError
rangedDate(Date.now(), -1, -1)

Returns (number | boolean) Converted time in ms or false if outside range.

module:cert-is.TypeAssertionError

index.js:150-178

Thrown by cert-is in response to a type assertion error.

Type: Error

module:cert-is.RangeAssertionError

index.js:150-178

Thrown by cert-is in response to a range assertion error.

Type: Error

Versioning

Versioning using SemVer. For available versions, see the tags on this repository.

Author

  • Justin Collier - jpcx

License

This project is licensed under the ISC License - see the LICENSE.md file for details