@etsoo/shared 1.1.78 → 1.1.80

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.
@@ -73,6 +73,12 @@ test('Tests for formatForInput', () => {
73
73
  expect(result41).toBe('2021-06-06T20:08:45');
74
74
  });
75
75
 
76
+ test('Tests for isExpired', () => {
77
+ expect(DateUtils.isExpired(null)).toBeFalsy();
78
+ expect(DateUtils.isExpired('2020/1/1')).toBeTruthy();
79
+ expect(DateUtils.isExpired('9999/1/1')).toBeFalsy();
80
+ });
81
+
76
82
  test('Tests for substract', () => {
77
83
  const d1 = new Date('2021/1/13 12:00:00');
78
84
  const d2 = new Date('2022/1/13 12:00:00');
@@ -221,17 +221,19 @@ test('Tests for detectedCulture', () => {
221
221
  test('Tests for getCulture', () => {
222
222
  const cultures: DataTypes.CultureDefinition[] = [
223
223
  {
224
- name: 'zh-CN',
224
+ name: 'zh-Hans',
225
225
  label: '简体中文',
226
226
  resources: {},
227
- compatibleName: ['zh-SG']
227
+ compatibleNames: ['zh-CN', 'zh-SG']
228
228
  },
229
- { name: 'en-US', label: 'English', resources: {} }
229
+ { name: 'en', label: 'English', resources: {} }
230
230
  ];
231
231
 
232
- expect(DomUtils.getCulture(cultures, 'zh-CN')?.name).toBe('zh-CN');
233
- expect(DomUtils.getCulture(cultures, 'zh-SG')?.name).toBe('zh-CN');
234
- expect(DomUtils.getCulture(cultures, 'en-GB')?.name).toBe('en-US');
232
+ expect(DomUtils.getCulture(cultures, 'zh-CN')?.name).toBe('zh-Hans');
233
+ expect(DomUtils.getCulture(cultures, 'zh-Hans-CN')?.name).toBe('zh-Hans');
234
+ expect(DomUtils.getCulture(cultures, 'zh-Hans-HK')?.name).toBe('zh-Hans');
235
+ expect(DomUtils.getCulture(cultures, 'zh-SG')?.name).toBe('zh-Hans');
236
+ expect(DomUtils.getCulture(cultures, 'en-GB')?.name).toBe('en');
235
237
  });
236
238
 
237
239
  test('Tests for getLocationKey', () => {
@@ -240,7 +240,7 @@ export declare namespace DataTypes {
240
240
  /**
241
241
  * Compatible names
242
242
  */
243
- compatibleName?: string[];
243
+ compatibleNames?: string[];
244
244
  }>;
245
245
  /**
246
246
  * Dynamic interface with multiple properties
@@ -57,6 +57,12 @@ export declare namespace DateUtils {
57
57
  * @returns Days
58
58
  */
59
59
  const getDays: (year: number, month: number) => number;
60
+ /**
61
+ * Is the test date expired to now
62
+ * @param testDate Test date
63
+ * @returns Result
64
+ */
65
+ function isExpired(testDate?: Date | string | null): boolean;
60
66
  /**
61
67
  * Build JSON parser
62
68
  * @param keys Date field names
@@ -133,6 +133,21 @@ var DateUtils;
133
133
  * @returns Days
134
134
  */
135
135
  DateUtils.getDays = (year, month) => new Date(year, month + 1, 0).getDate();
136
+ /**
137
+ * Is the test date expired to now
138
+ * @param testDate Test date
139
+ * @returns Result
140
+ */
141
+ function isExpired(testDate) {
142
+ if (testDate == null)
143
+ return false;
144
+ const d = parse(testDate);
145
+ // Format error
146
+ if (d == null)
147
+ return false;
148
+ return d.valueOf() < new Date().valueOf();
149
+ }
150
+ DateUtils.isExpired = isExpired;
136
151
  /**
137
152
  * Build JSON parser
138
153
  * @param keys Date field names
@@ -73,14 +73,14 @@ export declare namespace DomUtils {
73
73
  resources: T; /**
74
74
  * Current detected culture
75
75
  */
76
- compatibleName?: string[] | undefined;
76
+ compatibleNames?: string[] | undefined;
77
77
  }>[], culture: string) => Readonly<{
78
78
  name: string;
79
79
  label: string;
80
80
  resources: T; /**
81
81
  * Current detected culture
82
82
  */
83
- compatibleName?: string[] | undefined;
83
+ compatibleNames?: string[] | undefined;
84
84
  }> | undefined;
85
85
  /**
86
86
  * Get input value depending on its type
@@ -282,7 +282,11 @@ var DomUtils;
282
282
  if (exactMatch)
283
283
  return exactMatch;
284
284
  // Compatible match
285
- const compatibleMatch = items.find((item) => { var _a; return (_a = item.compatibleName) === null || _a === void 0 ? void 0 : _a.includes(culture); });
285
+ const compatibleMatch = items.find((item) => {
286
+ var _a;
287
+ return ((_a = item.compatibleNames) === null || _a === void 0 ? void 0 : _a.includes(culture)) ||
288
+ culture.startsWith(item + '-');
289
+ });
286
290
  if (compatibleMatch)
287
291
  return compatibleMatch;
288
292
  // Same part, like zh-CN and zh-HK
@@ -240,7 +240,7 @@ export declare namespace DataTypes {
240
240
  /**
241
241
  * Compatible names
242
242
  */
243
- compatibleName?: string[];
243
+ compatibleNames?: string[];
244
244
  }>;
245
245
  /**
246
246
  * Dynamic interface with multiple properties
@@ -57,6 +57,12 @@ export declare namespace DateUtils {
57
57
  * @returns Days
58
58
  */
59
59
  const getDays: (year: number, month: number) => number;
60
+ /**
61
+ * Is the test date expired to now
62
+ * @param testDate Test date
63
+ * @returns Result
64
+ */
65
+ function isExpired(testDate?: Date | string | null): boolean;
60
66
  /**
61
67
  * Build JSON parser
62
68
  * @param keys Date field names
@@ -130,6 +130,21 @@ export var DateUtils;
130
130
  * @returns Days
131
131
  */
132
132
  DateUtils.getDays = (year, month) => new Date(year, month + 1, 0).getDate();
133
+ /**
134
+ * Is the test date expired to now
135
+ * @param testDate Test date
136
+ * @returns Result
137
+ */
138
+ function isExpired(testDate) {
139
+ if (testDate == null)
140
+ return false;
141
+ const d = parse(testDate);
142
+ // Format error
143
+ if (d == null)
144
+ return false;
145
+ return d.valueOf() < new Date().valueOf();
146
+ }
147
+ DateUtils.isExpired = isExpired;
133
148
  /**
134
149
  * Build JSON parser
135
150
  * @param keys Date field names
@@ -73,14 +73,14 @@ export declare namespace DomUtils {
73
73
  resources: T; /**
74
74
  * Current detected culture
75
75
  */
76
- compatibleName?: string[] | undefined;
76
+ compatibleNames?: string[] | undefined;
77
77
  }>[], culture: string) => Readonly<{
78
78
  name: string;
79
79
  label: string;
80
80
  resources: T; /**
81
81
  * Current detected culture
82
82
  */
83
- compatibleName?: string[] | undefined;
83
+ compatibleNames?: string[] | undefined;
84
84
  }> | undefined;
85
85
  /**
86
86
  * Get input value depending on its type
@@ -279,7 +279,11 @@ export var DomUtils;
279
279
  if (exactMatch)
280
280
  return exactMatch;
281
281
  // Compatible match
282
- const compatibleMatch = items.find((item) => { var _a; return (_a = item.compatibleName) === null || _a === void 0 ? void 0 : _a.includes(culture); });
282
+ const compatibleMatch = items.find((item) => {
283
+ var _a;
284
+ return ((_a = item.compatibleNames) === null || _a === void 0 ? void 0 : _a.includes(culture)) ||
285
+ culture.startsWith(item + '-');
286
+ });
283
287
  if (compatibleMatch)
284
288
  return compatibleMatch;
285
289
  // Same part, like zh-CN and zh-HK
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.78",
3
+ "version": "1.1.80",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -56,9 +56,9 @@
56
56
  "devDependencies": {
57
57
  "@types/jest": "^29.2.3",
58
58
  "@types/lodash.isequal": "^4.5.6",
59
- "@typescript-eslint/eslint-plugin": "^5.43.0",
60
- "@typescript-eslint/parser": "^5.43.0",
61
- "eslint": "^8.27.0",
59
+ "@typescript-eslint/eslint-plugin": "^5.45.0",
60
+ "@typescript-eslint/parser": "^5.45.0",
61
+ "eslint": "^8.29.0",
62
62
  "eslint-config-airbnb-base": "^15.0.0",
63
63
  "eslint-plugin-import": "^2.26.0",
64
64
  "jest": "^29.3.1",
package/src/DataTypes.ts CHANGED
@@ -305,7 +305,7 @@ export namespace DataTypes {
305
305
  /**
306
306
  * Compatible names
307
307
  */
308
- compatibleName?: string[];
308
+ compatibleNames?: string[];
309
309
  }>;
310
310
 
311
311
  /**
package/src/DateUtils.ts CHANGED
@@ -194,6 +194,21 @@ export namespace DateUtils {
194
194
  export const getDays = (year: number, month: number) =>
195
195
  new Date(year, month + 1, 0).getDate();
196
196
 
197
+ /**
198
+ * Is the test date expired to now
199
+ * @param testDate Test date
200
+ * @returns Result
201
+ */
202
+ export function isExpired(testDate?: Date | string | null) {
203
+ if (testDate == null) return false;
204
+ const d = parse(testDate);
205
+
206
+ // Format error
207
+ if (d == null) return false;
208
+
209
+ return d.valueOf() < new Date().valueOf();
210
+ }
211
+
197
212
  /**
198
213
  * Build JSON parser
199
214
  * @param keys Date field names
package/src/DomUtils.ts CHANGED
@@ -325,8 +325,10 @@ export namespace DomUtils {
325
325
  if (exactMatch) return exactMatch;
326
326
 
327
327
  // Compatible match
328
- const compatibleMatch = items.find((item) =>
329
- item.compatibleName?.includes(culture)
328
+ const compatibleMatch = items.find(
329
+ (item) =>
330
+ item.compatibleNames?.includes(culture) ||
331
+ culture.startsWith(item + '-')
330
332
  );
331
333
  if (compatibleMatch) return compatibleMatch;
332
334