react-timezone-select 1.2.3-experimental.2 → 1.2.3-experimental.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-timezone-select",
3
- "version": "1.2.3-experimental.2",
3
+ "version": "1.2.3-experimental.3",
4
4
  "description": "Usable, dynamic React Timezone Select",
5
5
  "scripts": {
6
6
  "start": "concurrently npm:start:example npm:build",
@@ -34,7 +34,7 @@
34
34
  "types": "./dist/index.d.ts",
35
35
  "exports": {
36
36
  ".": {
37
- "import": "./dist/index.js",
37
+ "import": "./dist/index.mjs",
38
38
  "require": "./dist/index.cjs"
39
39
  }
40
40
  },
package/dist/index.js DELETED
@@ -1,109 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import * as React from 'react';
3
- import Select from 'react-select';
4
- import spacetime from 'spacetime';
5
- import soft from 'timezone-soft';
6
- import allTimezones from './timezone-list.js';
7
- export { allTimezones };
8
- const TimezoneSelect = ({ value, onBlur, onChange, labelStyle = 'original', timezones, ...props }) => {
9
- if (!timezones)
10
- timezones = allTimezones;
11
- const getOptions = React.useMemo(() => {
12
- return Object.entries(timezones)
13
- .reduce((selectOptions, zone) => {
14
- const now = spacetime.now(zone[0]);
15
- const tz = now.timezone();
16
- const tzStrings = soft(zone[0]);
17
- let label = '';
18
- let abbr = now.isDST()
19
- ? // @ts-expect-error
20
- tzStrings[0].daylight?.abbr
21
- : // @ts-expect-error
22
- tzStrings[0].standard?.abbr;
23
- let altName = now.isDST()
24
- ? tzStrings[0].daylight?.name
25
- : tzStrings[0].standard?.name;
26
- const min = tz.current.offset * 60;
27
- const hr = `${(min / 60) ^ 0}:` + (min % 60 === 0 ? '00' : Math.abs(min % 60));
28
- const prefix = `(GMT${hr.includes('-') ? hr : `+${hr}`}) ${zone[1]}`;
29
- switch (labelStyle) {
30
- case 'original':
31
- label = prefix;
32
- break;
33
- case 'altName':
34
- label = `${prefix} ${altName?.length ? `(${altName})` : ''}`;
35
- break;
36
- case 'abbrev':
37
- label = `${prefix} ${abbr?.length < 5 ? `(${abbr})` : ''}`;
38
- break;
39
- default:
40
- label = `${prefix}`;
41
- }
42
- selectOptions.push({
43
- value: tz.name,
44
- label: label,
45
- offset: tz.current.offset,
46
- abbrev: abbr,
47
- altName: altName,
48
- });
49
- return selectOptions;
50
- }, [])
51
- .sort((a, b) => a.offset - b.offset);
52
- }, [labelStyle, timezones]);
53
- const handleChange = (tz) => {
54
- onChange && onChange(tz);
55
- };
56
- const findFuzzyTz = (zone) => {
57
- let currentTime = spacetime.now('GMT');
58
- try {
59
- currentTime = spacetime.now(zone);
60
- }
61
- catch (err) {
62
- return;
63
- }
64
- return getOptions
65
- .filter((tz) => tz.offset === currentTime.timezone().current.offset)
66
- .map((tz) => {
67
- let score = 0;
68
- if (currentTime.timezones[tz.value.toLowerCase()] &&
69
- !!currentTime.timezones[tz.value.toLowerCase()].dst ===
70
- currentTime.timezone().hasDst) {
71
- if (tz.value
72
- .toLowerCase()
73
- .indexOf(currentTime.tz.substring(currentTime.tz.indexOf('/') + 1)) !== -1) {
74
- score += 8;
75
- }
76
- if (tz.label
77
- .toLowerCase()
78
- .indexOf(currentTime.tz.substring(currentTime.tz.indexOf('/') + 1)) !== -1) {
79
- score += 4;
80
- }
81
- if (tz.value
82
- .toLowerCase()
83
- .indexOf(currentTime.tz.substring(0, currentTime.tz.indexOf('/')))) {
84
- score += 2;
85
- }
86
- score += 1;
87
- }
88
- else if (tz.value === 'GMT') {
89
- score += 1;
90
- }
91
- return { tz, score };
92
- })
93
- .sort((a, b) => b.score - a.score)
94
- .map(({ tz }) => tz)[0];
95
- };
96
- const parseTimezone = (zone) => {
97
- if (typeof zone === 'object' && zone.value && zone.label)
98
- return zone;
99
- if (typeof zone === 'string') {
100
- return (getOptions.find(tz => tz.value === zone) ||
101
- (zone.indexOf('/') !== -1 && findFuzzyTz(zone)));
102
- }
103
- else if (zone.value && !zone.label) {
104
- return getOptions.find(tz => tz.value === zone.value);
105
- }
106
- };
107
- return (_jsx(Select, { value: parseTimezone(value), onChange: handleChange, options: getOptions, onBlur: onBlur, ...props }, void 0));
108
- };
109
- export default TimezoneSelect;
@@ -1,82 +0,0 @@
1
- const allTimezones = {
2
- "Pacific/Midway": "Midway Island, Samoa",
3
- "Pacific/Honolulu": "Hawaii",
4
- "America/Juneau": "Alaska",
5
- "America/Boise": "Mountain Time",
6
- "America/Dawson": "Dawson, Yukon",
7
- "America/Chihuahua": "Chihuahua, La Paz, Mazatlan",
8
- "America/Phoenix": "Arizona",
9
- "America/Chicago": "Central Time",
10
- "America/Regina": "Saskatchewan",
11
- "America/Mexico_City": "Guadalajara, Mexico City, Monterrey",
12
- "America/Belize": "Central America",
13
- "America/Detroit": "Eastern Time",
14
- "America/Bogota": "Bogota, Lima, Quito",
15
- "America/Caracas": "Caracas, La Paz",
16
- "America/Santiago": "Santiago",
17
- "America/St_Johns": "Newfoundland and Labrador",
18
- "America/Sao_Paulo": "Brasilia",
19
- "America/Tijuana": "Tijuana",
20
- "America/Montevideo": "Montevideo",
21
- "America/Argentina/Buenos_Aires": "Buenos Aires, Georgetown",
22
- "America/Godthab": "Greenland",
23
- "America/Los_Angeles": "Pacific Time",
24
- "Atlantic/Azores": "Azores",
25
- "Atlantic/Cape_Verde": "Cape Verde Islands",
26
- GMT: "UTC",
27
- "Europe/London": "Edinburgh, London",
28
- "Europe/Dublin": "Dublin",
29
- "Europe/Lisbon": "Lisbon",
30
- "Africa/Casablanca": "Casablanca, Monrovia",
31
- "Atlantic/Canary": "Canary Islands",
32
- "Europe/Belgrade": "Belgrade, Bratislava, Budapest, Ljubljana, Prague",
33
- "Europe/Sarajevo": "Sarajevo, Skopje, Warsaw, Zagreb",
34
- "Europe/Brussels": "Brussels, Copenhagen, Madrid, Paris",
35
- "Europe/Amsterdam": "Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna",
36
- "Africa/Algiers": "West Central Africa",
37
- "Europe/Bucharest": "Bucharest",
38
- "Africa/Cairo": "Cairo",
39
- "Europe/Helsinki": "Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius",
40
- "Europe/Athens": "Athens, Minsk",
41
- "Asia/Jerusalem": "Jerusalem",
42
- "Africa/Harare": "Harare, Pretoria",
43
- "Europe/Moscow": "Istanbul, Moscow, St. Petersburg, Volgograd",
44
- "Asia/Kuwait": "Kuwait, Riyadh",
45
- "Africa/Nairobi": "Nairobi",
46
- "Asia/Baghdad": "Baghdad",
47
- "Asia/Tehran": "Tehran",
48
- "Asia/Dubai": "Abu Dhabi, Muscat",
49
- "Asia/Baku": "Baku, Tbilisi, Yerevan",
50
- "Asia/Kabul": "Kabul",
51
- "Asia/Yekaterinburg": "Ekaterinburg",
52
- "Asia/Karachi": "Islamabad, Karachi, Tashkent",
53
- "Asia/Kolkata": "Chennai, Kolkata, Mumbai, New Delhi",
54
- "Asia/Kathmandu": "Kathmandu",
55
- "Asia/Dhaka": "Astana, Dhaka",
56
- "Asia/Colombo": "Sri Jayawardenepura",
57
- "Asia/Almaty": "Almaty, Novosibirsk",
58
- "Asia/Rangoon": "Yangon Rangoon",
59
- "Asia/Bangkok": "Bangkok, Hanoi, Jakarta",
60
- "Asia/Krasnoyarsk": "Krasnoyarsk",
61
- "Asia/Shanghai": "Beijing, Chongqing, Hong Kong SAR, Urumqi",
62
- "Asia/Kuala_Lumpur": "Kuala Lumpur, Singapore",
63
- "Asia/Taipei": "Taipei",
64
- "Australia/Perth": "Perth",
65
- "Asia/Irkutsk": "Irkutsk, Ulaanbaatar",
66
- "Asia/Seoul": "Seoul",
67
- "Asia/Tokyo": "Osaka, Sapporo, Tokyo",
68
- "Asia/Yakutsk": "Yakutsk",
69
- "Australia/Darwin": "Darwin",
70
- "Australia/Adelaide": "Adelaide",
71
- "Australia/Sydney": "Canberra, Melbourne, Sydney",
72
- "Australia/Brisbane": "Brisbane",
73
- "Australia/Hobart": "Hobart",
74
- "Asia/Vladivostok": "Vladivostok",
75
- "Pacific/Guam": "Guam, Port Moresby",
76
- "Asia/Magadan": "Magadan, Solomon Islands, New Caledonia",
77
- "Asia/Kamchatka": "Kamchatka, Marshall Islands",
78
- "Pacific/Fiji": "Fiji Islands",
79
- "Pacific/Auckland": "Auckland, Wellington",
80
- "Pacific/Tongatapu": "Nuku'alofa",
81
- };
82
- export default allTimezones;
@@ -1 +0,0 @@
1
- import "@testing-library/jest-dom/extend-expect";
@@ -1 +0,0 @@
1
- export {};