🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

google-places-periods-parser

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-places-periods-parser

Transform Google Places Opening Hours Periods into the OpeningHoursSpecification format

latest
Source
npmnpm
Version
1.5.0
Version published
Weekly downloads
13
225%
Maintainers
1
Weekly downloads
 
Created
Source

google-places-periods-parser

Transforms opening hours data from Google Places into the schema.org/OpeningHoursSpecification format.

  • Zero dependencies
  • Typescript
  • Even has a few unit tests

Why would I want this?

When retrieving opening hours data from the Google Maps API you will notice the data looks like this:

[
  { "close": { "day": 0, "time": "1430" }, "open": { "day": 0, "time": "0830" } },
  { "close": { "day": 1, "time": "1430" }, "open": { "day": 1, "time": "0730" } },
  { "close": { "day": 2, "time": "1430" }, "open": { "day": 2, "time": "0730" } },
  { "close": { "day": 3, "time": "1430" }, "open": { "day": 3, "time": "0730" } },
  { "close": { "day": 4, "time": "1430" }, "open": { "day": 4, "time": "0730" } },
  { "close": { "day": 5, "time": "1430" }, "open": { "day": 5, "time": "0730" } },
  { "close": { "day": 6, "time": "1430" }, "open": { "day": 6, "time": "0830" } }
]

There are already plenty of libraries available for parsing opening hours, but I couldn't find any that worked with this format.

Instead of writing another parser, this library transform the data into another format -- the OpeningHoursSpecification.

import parseGooglePlacesPeriods from 'google-places-periods-parser'

const result = parseGooglePlacesPeriods(periods)

/*
result === [{
  dayOfWeek: [ 'sunday', 'saturday' ],
  opens: '08:30',
  closes: '14:30'
},
{
  dayOfWeek: [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday' ],
  opens: '07:30',
  closes: '14:30'
}]
*/

But are they open?

This library won't tell if you a store is open. I recommend you use openinghours.js to find this out.

import parseGooglePlacesPeriods from 'google-places-periods-parser'
import { getCurrentState } from 'openinghours.js'

const periods = [
  { open: { day: 0, time: '08:00' }, close: { day: 0, time: '14:00' } },
]

const state = getCurrentState(parseGooglePlacesPeriods(periods))

/*
state === {
  isOpen: true,
  closesAt: new Date("2019-12-05T14:00:00.000Z")
}
*/

FAQs

Package last updated on 26 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts