🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

mock-browser-timezone

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-browser-timezone

A Javascript library to mock the browser's timezone using ECMAScript Internationalization API.

1.0.2
latest
Source
npm
Version published
Weekly downloads
52
48.57%
Maintainers
1
Weekly downloads
 
Created
Source

mock-browser-timezone

A Javascript library to mock the browser's timezone using ECMAScript Internationalization API.

What's different?

Many modern browsers use the Intl API to get the desired IANA timezone string which depicts the current browser timezone.

This library is specifically designed to mock the browser timezone, assisting to test the relevant code which uses the Intl API.

Installation

Using npm:
npm install mock-browser-timezone --save-dev
Using yarn:
yarn add mock-browser-timezone -D

API

  • registerTimezone: For mocking the browser's timezone represented in IANA timezone string.
  • registerAbbreviatedTimezone: For mocking the abbreviated timezone string. Factually, there can be a lot of ambiguity in determining abbreviated timezone since it highly depends on the daylight time and a single abbreviated string can also represent many other timezone values.
    For a better read regarding the same: https://stackoverflow.com/tags/timezone/info.
  • reset: Used to bring back the mocked timezones to their original state.

Usage

For a better implementation of mock-browser-timezone, have a look at mock-browser-timezone.js file.

const {
  registerTimezone,
  registerAbbreviatedTimezone,
  reset,
} = require('mock-browser-timezone');

// Mocking the timezone using IANA timezone string.
registerTimezone('Europe/Paris');

reset(); // Default back to the orginal value.

new Intl.DateTimeFormat().resolvedOptions().timeZone; // Europe/Paris

registerAbbreviatedTimezone('CET');

new Intl.DateTimeFormat([], {
  timeZoneName: 'short',
})
  .formatToParts(date)
  .find((locale) => locale.type === 'timeZoneName').value; // CET

reset(); // Default back to the orginal abbreviated timezone value.

Supported Timezones

A list of supported IANA formatted timezones as well as abbreviated timezones can be found at timezones.json.

Keywords

mock

FAQs

Package last updated on 25 Apr 2021

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