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

opened-closed

v0.1.2

Published

Provides availabiltiy and near-to-close information from periods.

Downloads

19

Readme

Opened Closed

Version License Gzip & minified size

Coverage Status Mutations Known Vulnerabilities Libraries.io dependency status for latest release

Provides availabiltiy and near-to-close information from periods.

const OpenedClosed = require("opened-closed");

const store = new OpenedClosed({
  timezone: "GMT+0100",
  openings: {
    monday: [
      { start: "10:00", end: "13:00" },
      { start: "15:00", end: "18:00" }
    ]
  }
});

console.log(store.opened());

Summary

Installation

Web

Include the following script in your project:

<script
  type="text/javascript"
  src="https://raw.githack.com/khalyomede/opened-closed/master/dist/opened-closed.min.js"
></script>

NPM

  1. Include Opened Closed in your dependencies:
npm install --save opened-closed@0.*
  1. Import it in your script:
const OpenedClosed = require('opened-closed');

Usage

All the examples can be found in the folder example of this repository.

Example 1: checking if a store is opened now

const OpenedClosed = require("opened-closed");

const store = new OpenedClosed({
  timezone: "GMT+0100",
  openings: {
    monday: [
      { start: "10:00", end: "13:00" },
      { start: "15:00", end: "18:00" }
    ]
  }
});

console.log(store.opened());

Example 2: adding exceptional closings dates

const OpenedClosed = require("opened-closed");

const store = new OpenedClosed({
  timezone: "GMT+0100",
  openings: {
    monday: [
      { start: "10:00", end: "13:00" },
      { start: "15:00", end: "18:00" }
    ],
    tuesday: [
      { start: "10:00", end: "13:00" },
      { start: "15:00", end: "18:00" }
    ]
  },
  closings: [
    {
      reason: "Christmas", // optional
      from: new Date("2018-12-25 00:00:00 GMT+0100"),
      to: new Date("2018-12-25 23:59:59 GMT+0100")
    }
  ]
});

Example 3: getting the opening state as a string

const OpenedClosed = require("opened-closed");

const store = new OpenedClosed({
  timezone: "GMT+0100",
  openings: {
    monday: [
      { start: "10:00", end: "13:00" },
      { start: "15:00", end: "18:00" }
    ]
  }
});

console.log(store.availability());

Example 4: changing the language

const OpenedClosed = require("opened-closed");

const store = new OpenedClosed({
  timezone: "GMT+0100",
  openings: {
    monday: [
      { start: "10:00", end: "13:00" },
      { start: "15:00", end: "18:00" }
    ]
  },
  language: {
    opened: "ouvert",
    closed: "fermé"
  }
});

console.log(store.availability());

Example 5: get the store closes in in seconds

const OpenedClosed = require("opened-closed");

const store = new OpenedClosed({
  timezone: "GMT+0100",
  openings: {
    monday: [
      { start: "10:00", end: "13:00" },
      { start: "15:00", end: "18:00" }
    ]
  }
});

if (store.opened()) {
  console.log("closes in", store.closeIn());
} else {
  console.log(store.availability());
}

Example 6: get the store closes in as a date

const OpenedClosed = require("opened-closed");

const store = new OpenedClosed({
  timezone: "GMT+0100",
  openings: {
    wednesday: [{ start: "10:00", end: "19:00" }]
  }
});

if (store.opened()) {
  const closeAt = store.closeAt().toLocaleString(); // Maybe GMT+01 is not yours, so LocalString take care of it.

  console.log("will close at", closeAt);
} else {
  console.log(store.availability()); // "closed"
}

Contributing

  • The code is located in src/main.ts. This is in TypeScript, but it also support plain JavaScript if you prefer.
  • I prefer no dependencies for the moment, because this is help making a working web solution (opened to suggestions to improve the workflow).
  • The web solution is simply removing the export statement, and using Gulp to transpile TypeScript in ES5 (opened to suggestions to improve the workflow).
  1. Create an issue
  2. Create a branche with the number of the issue in it: git checkout -b issue-36
  3. Create tests inside test/
  4. Light on dev: npm run dev
  5. Make your changes on src/main.ts
  6. Run test using npm run test
  7. Copy main.ts in opened-closed.ts, remove the export = OpenedClosed; line
  8. Run npm run prod
  9. Create a Pull Request from your branch to master

Thank you for your time!