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

@wojtekmaj/opening-hours-utils

v0.9.1

Published

A collection of opening hours-related utilities.

Downloads

829

Readme

npm downloads CI

Opening-Hours-Utils

A collection of opening hours-related utilities.

tl;dr

  • Install by executing npm install @wojtekmaj/opening-hours-utils or yarn add @wojtekmaj/opening-hours-utils.
  • Import by adding import * as openingHoursUtils from '@wojtekmaj/opening-hours-utils'.
  • Do stuff with it!
    const openingHours = getOpeningHours('Mo-Fr 08:00-18:00;Sa 08:00-12:00');

User guide

Table of contents

encodeOpeningHours()

Returns opening hours string given an array of objects with from, to, and hours properties.

Sample usage

import { encodeOpeningHours } from '@wojtekmaj/opening-hours-utils';

encodeOpeningHours([
  {
    from: 'Mo',
    to: 'Fr',
    hours: [{ from: '08:00', to: '17:30' }],
  },
]); // 'Mo-Fr 08:00-17:30'

getDailyOpeningHours()

Parses opening hours string and returns an array of objects with day and hours properties.

Sample usage

import { getDailyOpeningHours } from '@wojtekmaj/opening-hours-utils';

getDailyOpeningHours('Mo-Fr 08:00-17:30');
/**
 * [
 *   { day: 'Mo', hours: [{ from: '08:00', to: '17:30' }] },
 *   { day: 'Tu', hours: [{ from: '08:00', to: '17:30' }] },
 *   { day: 'We', hours: [{ from: '08:00', to: '17:30' }] },
 *   { day: 'Th', hours: [{ from: '08:00', to: '17:30' }] },
 *   { day: 'Fr', hours: [{ from: '08:00', to: '17:30' }] },
 * ]
 */

getIsOpenAt()

Checks if place is open at a given date.

Sample usage

import { getIsOpenAt } from '@wojtekmaj/opening-hours-utils';

getIsOpenAt('Mo-Fr 08:00-17:30', mondayNoon); // true

getIsOpenNow()

Checks if place is open.

Sample usage

import { getIsOpenNow } from '@wojtekmaj/opening-hours-utils';

getIsOpenNow('Mo-Fr 08:00-17:30'); // true

getNextClosedAt()

Gets the next closing time for a given date. Returns null if for a given date place is closed.

Sample usage

import { getNextClosedAt } from '@wojtekmaj/opening-hours-utils';

getNextClosedAt('Mo-Fr 08:00-17:30', mondayNoon); // 'Mo 17:30'

getNextClosedNow()

Gets the next closing time. Returns null if place is currently closed.

Sample usage

import { getNextClosedNow } from '@wojtekmaj/opening-hours-utils';

getNextClosedNow('Mo-Fr 08:00-17:30'); // 'Mo 17:30'

getNextOpenAt()

Gets the next opening time for a given date. Returns null if for a given date place is open.

Sample usage

import { getNextOpenAt } from '@wojtekmaj/opening-hours-utils';

getNextOpenAt('Mo-Fr 08:00-17:30', saturdayNoon); // 'Mo 08:00'

getNextOpenNow()

Gets the next opening time. Returns null if place is currently open.

Sample usage

import { getNextOpenNow } from '@wojtekmaj/opening-hours-utils';

getNextOpenNow('Mo-Fr 08:00-17:30'); // 'Mo 08:00'

getOpeningHours()

Parses opening hours string and returns an array of objects with from, to, and hours properties.

Sample usage

import { getOpeningHours } from '@wojtekmaj/opening-hours-utils';

getOpeningHours('Mo-Fr 08:00-17:30');
/**
 * [
 *   {
 *     from: 'Mo',
 *     to: 'Fr',
 *     hours: [{ from: '08:00', to: '17:30' }],
 *   },
 * ]
 */

License

The MIT License.

Author