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

shopping-hours

v0.0.4

Published

A flexible shopping-hours calendar & calculator

Downloads

5

Readme

shopping-hours

A flexible shopping-hours calendar & calculator.

| dist/* | lang | type | minified | |-------------------------| ----- | ---- | -------- | | shopping_hours.min.js | es5 | UMD | x | | shopping_hours.js | es6 | UMD | |

  • ~8KB minified.
  • Uses a standard JS Date object.
  • Moveable feasts (Easter & Pentecost).
  • User-provided plugins for moveble dates.
  • Elastic dates as fri.4/11 (the 4th Friday of November), wed.last/-, sat/-.
  • Returns the current status (open/closed) for any date.
  • Automatically calculates the next opening/closing datetime.

Calendar itself is .txt file that uses a simple line-oriented DSL, e.g.:

-/-                 9:00-13:00,14:00-18:00
1/1                 0:0-0:0                   o   new year
easter_orthodox     0:0-0:0                   o
fri.4/11            6:30-23:00                -   black friday
sun/-               0:0-0:0

Why?

TODO (explain how UA online stores work)

Quick Start

$ npm i shopping-hours

Create a simple calendar:

$ node
> sh = require('shopping-hours')
[Function: shopping_hours]
> cal = `-/- 9:00-13:00,14:00-18:00
... sat/- 11:00-16:00
... sun/- :-:`
'-/- 9:00-13:00,14:00-18:00\nsat/- 11:00-16:00\nsun/- :-:'

Next, parse the cal:

> my_shop = sh(cal)
{ parsed_input: { vars: {}, events: [ [Object], [Object], [Object] ] },
  parse: [Function: parse],
  resolve: [Function: resolve],
  business: [Function: business] }

The fn of interest here is #business(). To get the status of our little online store, pass an optional date to it:

> my_shop.business('2018-02-08 01:00')
{ status: 'closed', next: 2018-02-08T07:00:00.000Z }

Because it resolves the cal for 1am, it says that the shop is 'closed', & 'next' key indicates (printed in UTC here; the diff for Europe/Kiev timezone is +2h) when the shop 'opens'.

If we update the time to 9am:

> my_shop.business('2018-02-08 09:00')
{ status: 'open', next: 2018-02-08T11:00:00.000Z }

it says, the shop is 'open' & it closes at 1pm for a lunch break.

2018-02-08 is Thursday, if we specify the next day as

> my_shop.business('2018-02-09 18:01')
{ status: 'closed', next: 2018-02-10T09:00:00.000Z }

it says the shop is 'closed' & it opens at 11am next day (Saturday).

For Saturday it returns:

> my_shop.business('2018-02-10 18:01')
{ status: 'closed', next: 2018-02-12T07:00:00.000Z }

Because we set no working hours for Sundays, it jumps to the next available date, which in this case is Monday.

DSL

TODO

API

TODO

License

MIT.