react-timezone-select 1.5.3 → 1.5.5

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/dist/index.cjs CHANGED
@@ -129,48 +129,47 @@ var TimezoneSelect = ({
129
129
  onChange,
130
130
  labelStyle = "original",
131
131
  timezones,
132
+ maxAbbrLength = 4,
132
133
  ...props
133
134
  }) => {
134
135
  if (!timezones)
135
136
  timezones = timezone_list_default;
136
137
  const getOptions = React.useMemo(() => {
137
138
  return Object.entries(timezones).reduce((selectOptions, zone) => {
138
- const now = import_spacetime.default.now(zone[0]);
139
- const tz = now.timezone();
140
- const tzStrings = (0, import_timezone_soft.default)(zone[0]);
141
- let label = "";
142
- let abbr = now.isDST() ? (
143
- // @ts-expect-error
144
- tzStrings[0].daylight?.abbr
145
- ) : (
146
- // @ts-expect-error
147
- tzStrings[0].standard?.abbr
148
- );
149
- let altName = now.isDST() ? tzStrings[0].daylight?.name : tzStrings[0].standard?.name;
150
- const min = tz.current.offset * 60;
151
- const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
152
- const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
153
- switch (labelStyle) {
154
- case "original":
155
- label = prefix;
156
- break;
157
- case "altName":
158
- label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
159
- break;
160
- case "abbrev":
161
- label = `${prefix} ${abbr?.length < 5 ? `(${abbr})` : ""}`;
162
- break;
163
- default:
164
- label = `${prefix}`;
139
+ try {
140
+ const now = import_spacetime.default.now(zone[0]);
141
+ const tz = now.timezone();
142
+ const tzStrings = (0, import_timezone_soft.default)(zone[0]);
143
+ let label = "";
144
+ let abbr = now.isDST() ? tzStrings[0].daylight.abbr : tzStrings[0].standard.abbr;
145
+ let altName = now.isDST() ? tzStrings[0].daylight.name : tzStrings[0].standard.name;
146
+ const min = tz.current.offset * 60;
147
+ const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
148
+ const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
149
+ switch (labelStyle) {
150
+ case "original":
151
+ label = prefix;
152
+ break;
153
+ case "altName":
154
+ label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
155
+ break;
156
+ case "abbrev":
157
+ label = `${prefix} (${abbr.substring(0, maxAbbrLength)})`;
158
+ break;
159
+ default:
160
+ label = `${prefix}`;
161
+ }
162
+ selectOptions.push({
163
+ value: tz.name,
164
+ label,
165
+ offset: tz.current.offset,
166
+ abbrev: abbr,
167
+ altName
168
+ });
169
+ return selectOptions;
170
+ } catch {
171
+ return selectOptions;
165
172
  }
166
- selectOptions.push({
167
- value: tz.name,
168
- label,
169
- offset: tz.current.offset,
170
- abbrev: abbr,
171
- altName
172
- });
173
- return selectOptions;
174
173
  }, []).sort((a, b) => a.offset - b.offset);
175
174
  }, [labelStyle, timezones]);
176
175
  const handleChange = (tz) => {
package/dist/index.d.ts CHANGED
@@ -12,15 +12,25 @@ interface ITimezoneOption {
12
12
  altName?: string
13
13
  }
14
14
  declare type ITimezone = ITimezoneOption | string
15
- interface Props extends Omit<Props$1, 'onChange'> {
15
+ interface Props
16
+ extends Omit<Props$1<ITimezone, false>, 'onChange'> {
16
17
  value: ITimezone
17
18
  labelStyle?: ILabelStyle
18
19
  onChange?: (timezone: ITimezoneOption) => void
19
20
  timezones?: ICustomTimezone
21
+ maxAbbrLength?: number
20
22
  }
21
23
 
22
24
  declare const allTimezones: ICustomTimezone;
23
25
 
24
- declare const TimezoneSelect: ({ value, onBlur, onChange, labelStyle, timezones, ...props }: Props) => JSX.Element;
26
+ declare const TimezoneSelect: ({
27
+ value,
28
+ onBlur,
29
+ onChange,
30
+ labelStyle,
31
+ timezones,
32
+ maxAbbrLength,
33
+ ...props
34
+ }: Props) => JSX.Element
25
35
 
26
36
  export { ILabelStyle, ITimezone, ITimezoneOption, Props, allTimezones, TimezoneSelect as default };
package/dist/index.js CHANGED
@@ -95,48 +95,47 @@ var TimezoneSelect = ({
95
95
  onChange,
96
96
  labelStyle = "original",
97
97
  timezones,
98
+ maxAbbrLength = 4,
98
99
  ...props
99
100
  }) => {
100
101
  if (!timezones)
101
102
  timezones = timezone_list_default;
102
103
  const getOptions = React.useMemo(() => {
103
104
  return Object.entries(timezones).reduce((selectOptions, zone) => {
104
- const now = spacetime.now(zone[0]);
105
- const tz = now.timezone();
106
- const tzStrings = soft(zone[0]);
107
- let label = "";
108
- let abbr = now.isDST() ? (
109
- // @ts-expect-error
110
- tzStrings[0].daylight?.abbr
111
- ) : (
112
- // @ts-expect-error
113
- tzStrings[0].standard?.abbr
114
- );
115
- let altName = now.isDST() ? tzStrings[0].daylight?.name : tzStrings[0].standard?.name;
116
- const min = tz.current.offset * 60;
117
- const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
118
- const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
119
- switch (labelStyle) {
120
- case "original":
121
- label = prefix;
122
- break;
123
- case "altName":
124
- label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
125
- break;
126
- case "abbrev":
127
- label = `${prefix} ${abbr?.length < 5 ? `(${abbr})` : ""}`;
128
- break;
129
- default:
130
- label = `${prefix}`;
105
+ try {
106
+ const now = spacetime.now(zone[0]);
107
+ const tz = now.timezone();
108
+ const tzStrings = soft(zone[0]);
109
+ let label = "";
110
+ let abbr = now.isDST() ? tzStrings[0].daylight.abbr : tzStrings[0].standard.abbr;
111
+ let altName = now.isDST() ? tzStrings[0].daylight.name : tzStrings[0].standard.name;
112
+ const min = tz.current.offset * 60;
113
+ const hr = `${min / 60 ^ 0}:` + (min % 60 === 0 ? "00" : Math.abs(min % 60));
114
+ const prefix = `(GMT${hr.includes("-") ? hr : `+${hr}`}) ${zone[1]}`;
115
+ switch (labelStyle) {
116
+ case "original":
117
+ label = prefix;
118
+ break;
119
+ case "altName":
120
+ label = `${prefix} ${altName?.length ? `(${altName})` : ""}`;
121
+ break;
122
+ case "abbrev":
123
+ label = `${prefix} (${abbr.substring(0, maxAbbrLength)})`;
124
+ break;
125
+ default:
126
+ label = `${prefix}`;
127
+ }
128
+ selectOptions.push({
129
+ value: tz.name,
130
+ label,
131
+ offset: tz.current.offset,
132
+ abbrev: abbr,
133
+ altName
134
+ });
135
+ return selectOptions;
136
+ } catch {
137
+ return selectOptions;
131
138
  }
132
- selectOptions.push({
133
- value: tz.name,
134
- label,
135
- offset: tz.current.offset,
136
- abbrev: abbr,
137
- altName
138
- });
139
- return selectOptions;
140
139
  }, []).sort((a, b) => a.offset - b.offset);
141
140
  }, [labelStyle, timezones]);
142
141
  const handleChange = (tz) => {
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "react-timezone-select",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "description": "Usable, dynamic React Timezone Select",
5
5
  "scripts": {
6
- "dev": "concurrently \"rollup -cw\" \"cd example && npm run dev\"",
7
- "prepublish": "npm run build",
8
- "postpublish": "npm run build:example && npm run deploy",
6
+ "dev": "concurrently \"tsup src/index.tsx --format esm --watch\" \"cd example && npm run dev\"",
7
+ "prepublishOnly": "pnpm run build",
8
+ "postpublish": "pnpm run build:example && npm run deploy",
9
9
  "build": "tsup src/index.tsx --format cjs,esm --dts",
10
- "build:example": "cd example && npm run build",
10
+ "build:example": "cd example && pnpm run build",
11
11
  "deploy": "gh-pages -d example/dist",
12
+ "pretest": "pnpm run build",
12
13
  "test": "jest",
13
14
  "test:watch": "jest --watch",
14
- "test:ci": "jest --ci ",
15
+ "test:ci": "pnpm run build && jest --ci ",
15
16
  "tsc": "tsc"
16
17
  },
17
18
  "author": "Nico Domino <yo@ndo.dev>",
@@ -51,8 +52,8 @@
51
52
  },
52
53
  "dependencies": {
53
54
  "react-select": "^5.7.0",
54
- "spacetime": "^7.1.4",
55
- "timezone-soft": "^1.3.1"
55
+ "spacetime": "^7.4.1",
56
+ "timezone-soft": "^1.4.1"
56
57
  },
57
58
  "devDependencies": {
58
59
  "@babel/core": "^7.20.7",