From d54d763383deaafd90be4b835a42544a12d29329 Mon Sep 17 00:00:00 2001 From: Adam Fanello Date: Mon, 17 Aug 2020 17:46:12 -0700 Subject: [PATCH] Issue #3 Add CommonJS and Typescript compatibility Based on guide @ https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1 --- esm/esm.js | 36 ++++++++++++++++++++++++++++++++++++ index.d.ts | 36 ++++++++++++++++++++++++++++++++++++ index.js | 10 +++++----- package.json | 8 +++++++- 4 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 esm/esm.js create mode 100644 index.d.ts diff --git a/esm/esm.js b/esm/esm.js new file mode 100644 index 0000000..74b1dc0 --- /dev/null +++ b/esm/esm.js @@ -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; diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..17c683b --- /dev/null +++ b/index.d.ts @@ -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[]; diff --git a/index.js b/index.js index bafca40..952c2e1 100644 --- a/index.js +++ b/index.js @@ -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, @@ -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' }, @@ -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' }, diff --git a/package.json b/package.json index dc249f0..1627359 100644 --- a/package.json +++ b/package.json @@ -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"