Skip to content

Commit

Permalink
Issue filipdanic#3 Add CommonJS and Typescript compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Fanello committed Aug 18, 2020
1 parent a2742dc commit d54d763
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 6 deletions.
36 changes: 36 additions & 0 deletions esm/esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @fileoverview
*
* This package contains an array of timezones based on conventional options found online.
* It does not follow any complete data set, but all names are according to the tz format:
* https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.
*
* More specifically, the fields in the array are:
* – offset, a string from '-11:00' to '+14:00' representing the UTC offset
* - label, a readable label that contains the offset and a longer, descriptive name of the timezone
* - tzCode, the value from the tz standard
*
* Install:
* `npm install compact-timezone-list --save`
* # or
* `yarn add compact-timezone-list`
*
*
* Example:
* import timezones from 'compact-timezone-list';
* // or
* import { minimalTimezoneSet } from 'compact-timezone-list';
*
* Details:
* - The default export provides a long list of options, with multiple
* suggestions for each UTC offset.
* – The `minimalTimezoneSet` export provides one option per offset type, with
* a favourite chosen to represent each offset. This is mostly targeted to small,
* western-focused apps. But, every UTC offset is included.
*/

import cjsModule from '../index.js';

export default cjsModule.defaultTimezoneSet;
export var defaultTimezoneSet = cjsModule.defaultTimezoneSet;
export var minimalTimezoneSet = cjsModule.minimalTimezoneSet;
36 changes: 36 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @fileoverview
*
* This package contains an array of timezones based on conventional options found online.
* It does not follow any complete data set, but all names are according to the tz format:
* https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.
*
* Install:
* `npm install compact-timezone-list --save`
* # or
* `yarn add compact-timezone-list`
*
*
* Example:
* import { defaultTimezoneSet } from 'compact-timezone-list';
* // or
* import { minimalTimezoneSet } from 'compact-timezone-list';
*
* Details:
* - The 'defaultTimezoneSet' export provides a long list of options, with multiple
* suggestions for each UTC offset.
* – The `minimalTimezoneSet` export provides one option per offset type, with
* a favourite chosen to represent each offset. This is mostly targeted to small,
* western-focused apps. But, every UTC offset is included.
*/
export interface TimezoneEntry {
/** a string from '-11:00' to '+14:00' representing the UTC offset */
offset: string;
/** a readable label that contains the offset and a longer, descriptive name of the timezone */
label: string;
/** the value from the tz standard */
tzCode: string;
}

export declare var defaultTimezoneSet: TimezoneEntry[];
export declare var minimalTimezoneSet: TimezoneEntry[];
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*
*
* Example:
* import timezones from 'compact-timezone-list';
* const { defaultTimezoneSet } = require('compact-timezone-list');
* // or
* import { minimalTimezoneSet } from 'compact-timezone-list';
* const { minimalTimezoneSet } = require('compact-timezone-list');
*
* Details:
* - The default export provides a long list of options, with multiple
* - The 'defaultTimezoneSet' export provides a long list of options, with multiple
* suggestions for each UTC offset.
* – The `minimalTimezoneSet` export provides one option per offset type, with
* a favourite chosen to represent each offset. This is mostly targeted to small,
Expand All @@ -33,7 +33,7 @@
*
* @type {Array.<{ offset: string, label: string, tzCode: string }>}
*/
export default [
module.exports.defaultTimezoneSet = [
{ offset: '-11:00', label: '(GMT-11:00) Niue', tzCode: 'Pacific/Niue' },
{ offset: '-11:00', label: '(GMT-11:00) Pago Pago', tzCode: 'Pacific/Pago_Pago' },
{ offset: '-10:00', label: '(GMT-10:00) Hawaii Time', tzCode: 'Pacific/Honolulu' },
Expand Down Expand Up @@ -290,7 +290,7 @@ export default [
*
* @type {Array.<{ offset: string, label: string, tzCode: string }>}
*/
export var minimalTimezoneSet = [
module.exports.minimalTimezoneSet = [
{ offset: '-11:00', label: '(GMT-11:00) Pago Pago', tzCode: 'Pacific/Pago_Pago' },
{ offset: '-10:00', label: '(GMT-10:00) Hawaii Time', tzCode: 'Pacific/Honolulu' },
{ offset: '-10:00', label: '(GMT-10:00) Tahiti', tzCode: 'Pacific/Tahiti' },
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"name": "compact-timezone-list",
"version": "1.0.6",
"version": "2.0.0",
"description": "Array of timezones with their labels, tz code, and UTC/GMT offsets.",
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": {
"require": "./index.js",
"import": "./esm/esm.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/filipdanic/compact-timezone-list.git"
Expand Down

0 comments on commit d54d763

Please sign in to comment.