Giter Club home page Giter Club logo

opened-closed's Introduction

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!

opened-closed's People

Contributors

khalyomede avatar

Watchers

 avatar  avatar  avatar  avatar

opened-closed's Issues

Unecessary files in NPM tarball package

Current NPM package tarball is containing files that, IMO, have nothing to do in the tarball because they will never be used (such as the source files as they are not listed in the main property of the package.json file).

Here is what is currently in the tarball.

$ npm pack --dry-run
npm notice package: [email protected]
npm notice === Tarball Contents ===
npm notice 1.6kB   package.json
npm notice 3.3kB   api.md
npm notice 970B    gulpfile.js
npm notice 1.1kB   LICENCE
npm notice 101B    npm
npm notice 5.6kB   README.md
npm notice 293B    stryker.conf.js
npm notice 213.8kB yarn.lock
npm notice 15.2kB  dist/opened-closed.js
npm notice 7.1kB   dist/opened-closed.min.js
npm notice 258B    example/example-1.js
npm notice 509B    example/example-2.js
npm notice 247B    example/example-3.js
npm notice 303B    example/example-4.js
npm notice 325B    example/example-5.js
npm notice 406B    example/example-6.js
npm notice 15.2kB  lib/main.js
npm notice 2.6kB   script/make-api.js
npm notice 14.0kB  src/main.ts
npm notice 14.0kB  src/opened-closed.ts
npm notice 24.6kB  test/opened-closed/private-functions.js
npm notice 13.0kB  test/opened-closed/public-functions.js
npm notice 13.1kB  test/opened-closed/usage.js
npm notice === Tarball Details ===
npm notice name:          opened-closed
npm notice version:       0.1.1
npm notice filename:      opened-closed-0.1.1.tgz
npm notice package size:  75.0 kB
npm notice unpacked size: 347.6 kB
npm notice shasum:        f2456a6ec35277adbaed2368f6e610c0070f0157
npm notice integrity:     sha512-FMIgwKwsuEd7f[...]N0oV6fTXWfB4g==
npm notice total files:   23

Now, if I'm not mistaken, we can make this package a little bit lighter by removing some files (such as the sources) that are not imported by the user-developper. Some files must remain, though everything is well documented in this page.

Documentation for the npm pack command.

New method openIn

Great project!
I would appreciate methods openIn() and openAt() which could be the counterparts to closeIn() and closeAt().
What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.