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

v1.0.1

Published

Easily persist or get stored dates/times. Useful for conditionally making updates in an application based on the amount of time that has passed.

Downloads

242

Readme

date-store NPM version NPM monthly downloads NPM total downloads Linux Build Status

Easily persist or get stored dates/times. Useful for conditionally making updates in an application based on the amount of time that has passed.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.

Install

Install with npm:

$ npm install --save date-store

Usage

const DateStore = require('date-store');

API

Params

  • name {String}: If options.path is supplied, name will be ignored. Otherwise name is used as the filename for the JSON store: ~/.date-store/{name}.json
  • options {Object}: Optionally pass a dir and/or path to use for the JSON store. Default is ~/.date-store.json

Example

const store = new DateStore();

Params

  • key {string}
  • returns {object}: Returns the instance for chaining.

Example

store.set(key);

Params

  • key {String}: The name of the stored date to get.
  • returns {Date}: Returns the date object for key

Example

store.set('foo');
console.log(store.get('foo'));
//=> Mon Apr 11 2016 06:18:31 GMT-0400 (EDT)

console.log(store.get('foo') instanceof Date);
//=> true

Params

  • key {String}: The name of the stored date to get.
  • returns {String}: Returns the stringified date for key

Example

store.set('foo');
console.log(store.getRaw('foo'));
//=> Mon Apr 11 2016 08:39:10 GMT-0400 (EDT)

console.log(store.getRaw('foo') instanceof Date);
//=> false

console.log(store.get('foo') instanceof Date);
//=> true

Params

  • key {String}: The name of the stored date to get.
  • returns {Number}

Example

store.set('foo');
console.log(store.getTime('foo'));
//=> 1460378350000

Params

  • key {String}
  • returns {Boolean}

Example

store.set('foo');
console.log(store.has('foo'));
//=> true

Params

  • key {String|Array}: Property name or array of property names.
  • returns {Object}: Returns the instance for chaining.

Example

store.del('foo');

Params

  • str {String}: A human-readable string to pass to date.js
  • returns {Date}: JavaScript Date object

Example

console.log(store.date('1 day from now'));
//=> Tue Apr 12 2016 10:05:12 GMT-0400 (EDT)

Params

  • timespan {String}: A human-readable string to pass to date.js
  • returns {Date}: JavaScript Date object

Example

console.log(store.date('1 day from now'));
//=> Tue Apr 12 2016 10:05:12 GMT-0400 (EDT)

Params

  • key {String}: The stored date to compare
  • timespan {String}: A human-readable string to pass to date.js
  • returns {Number}: The difference in seconds between the two dates, or NaN if invalid.

Example

console.log(store.diff('foo', '10 minutes ago'));
//=> 338563

Params

  • key {String}: The name of the stored date to set on .current
  • returns {Object}: Returns the instance for chaining.

Example

store.set('bar');
store.lastSaved('bar');
console.log(store.current);
//=> 1460378350000
console.log(store.lastSaved('bar').moreThan('31 minutes ago'));
//= false
console.log(store.lastSaved('bar').lessThan('31 minutes ago'));
//=> true

Params

  • key {String}: The name of the stored date to set on .current
  • returns {Object}: Returns the instance for chaining.

Example

store.set('bar');

console.log(store.lastSaved('bar').moreThan('31 minutes ago'));
//= false
console.log(store.lastSaved('bar').lessThan('1 minutes ago'));
//=> true

Params

  • key {String}: The name of the stored date to set on .current
  • returns {Object}: Returns the instance for chaining.

Example

store.set('bar');

console.log(store.lastSaved('bar').moreThan('31 minutes ago'));
//= false
console.log(store.lastSaved('bar').lessThan('1 minutes ago'));
//=> true

Params

  • timespan {String}: A human-readable string to pass to date.js
  • returns {Array}: Returns an array of keys

Example

var keys = store.filterSince('1 week ago');

.clear

Reset store.dates to an empty object.

  • returns {undefined}

Example

store.clear();

.json

Stringify the store. Takes the same arguments as JSON.stringify.

  • returns {string}

Example

console.log(store.json(null, 2));

.save

Calls .writeFile() to persist the store to the file system, after an optional debounce period. This method should probably not be called directly as it's used internally by other methods.

  • returns {undefined}

Example

store.save();

.dates

Getter/setter for the store.dates object, which holds the values that are persisted to the file system.

  • returns {object}

Example

console.log(store.dates); //=> {}

store.set('foo');
store.set('bar');

console.log(store.dates);
// { foo: 'Mon Apr 11 2016 08:39:10 GMT-0400 (EDT)',
//   bar: 'Mon Apr 11 2016 08:39:10 GMT-0400 (EDT)' }

About

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on May 29, 2018.