@etsoo/shared 1.1.77 → 1.1.79

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');
@@ -371,20 +371,20 @@ export declare namespace DataTypes {
371
371
  /**
372
372
  * List item with number id type
373
373
  */
374
- export declare type ListType = DataTypes.IdLabelItem<number>;
374
+ export type ListType = DataTypes.IdLabelItem<number>;
375
375
  /**
376
376
  * List item with string id type
377
377
  */
378
- export declare type ListType1 = DataTypes.IdLabelItem<string>;
378
+ export type ListType1 = DataTypes.IdLabelItem<string>;
379
379
  /**
380
380
  * Id default type
381
381
  */
382
- export declare type IdDefaultType<T extends object> = T extends {
382
+ export type IdDefaultType<T extends object> = T extends {
383
383
  id: number | string;
384
384
  } ? DataTypes.Keys<T> & 'id' : DataTypes.Keys<T>;
385
385
  /**
386
386
  * Label default type
387
387
  */
388
- export declare type LabelDefaultType<T extends object> = T extends {
388
+ export type LabelDefaultType<T extends object> = T extends {
389
389
  label: string;
390
390
  } ? DataTypes.Keys<T, string> & 'label' : DataTypes.Keys<T, string>;
@@ -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
@@ -1,4 +1,4 @@
1
- export declare type DelayedExecutorType<P extends any[] = []> = {
1
+ export type DelayedExecutorType<P extends any[] = []> = {
2
2
  /**
3
3
  * Call the function
4
4
  * @param miliseconds Delayed miliseconds for this call
@@ -5,19 +5,6 @@ exports.EColor = void 0;
5
5
  * Etsoo implmented Color
6
6
  */
7
7
  class EColor {
8
- /**
9
- * Constructor
10
- * @param r Reg
11
- * @param g Green
12
- * @param b Blue
13
- * @param alpha Alpha
14
- */
15
- constructor(r, g, b, alpha) {
16
- this.r = r;
17
- this.g = g;
18
- this.b = b;
19
- this.alpha = alpha;
20
- }
21
8
  /**
22
9
  * Adjust value
23
10
  * @param value Current value
@@ -100,6 +87,19 @@ class EColor {
100
87
  }
101
88
  return undefined;
102
89
  }
90
+ /**
91
+ * Constructor
92
+ * @param r Reg
93
+ * @param g Green
94
+ * @param b Blue
95
+ * @param alpha Alpha
96
+ */
97
+ constructor(r, g, b, alpha) {
98
+ this.r = r;
99
+ this.g = g;
100
+ this.b = b;
101
+ this.alpha = alpha;
102
+ }
103
103
  /**
104
104
  * Clone color with adjustments
105
105
  * @param adjustR Adjust R value
@@ -11,13 +11,13 @@ interface EHistoryNavigateEventData extends EHistoryEventData {
11
11
  */
12
12
  delta: number;
13
13
  }
14
- declare type EHistoryEventDef = {
14
+ type EHistoryEventDef = {
15
15
  clear: EHistoryEventData;
16
16
  navigate: EHistoryNavigateEventData;
17
17
  push: EHistoryEventData;
18
18
  replace: EHistoryEventData;
19
19
  };
20
- declare type EHistoryEventType = Exclude<keyof EHistoryEventDef, 'navigate'>;
20
+ type EHistoryEventType = Exclude<keyof EHistoryEventDef, 'navigate'>;
21
21
  /**
22
22
  * ETSOO Extended history event
23
23
  */
@@ -21,20 +21,6 @@ exports.EHistoryNavigateEvent = EHistoryNavigateEvent;
21
21
  * ETSOO Extended abstract history class
22
22
  */
23
23
  class EHistory extends EventClass_1.EventClass {
24
- /**
25
- * Constructor
26
- * @param maxDepth Max depth of the history
27
- */
28
- constructor(maxDepth = 20) {
29
- super();
30
- this.maxDepth = maxDepth;
31
- // Index
32
- this._index = -1;
33
- /**
34
- * States
35
- */
36
- this.states = [];
37
- }
38
24
  /**
39
25
  * States length
40
26
  */
@@ -55,6 +41,20 @@ class EHistory extends EventClass_1.EventClass {
55
41
  return undefined;
56
42
  return this.states[this._index];
57
43
  }
44
+ /**
45
+ * Constructor
46
+ * @param maxDepth Max depth of the history
47
+ */
48
+ constructor(maxDepth = 20) {
49
+ super();
50
+ this.maxDepth = maxDepth;
51
+ // Index
52
+ this._index = -1;
53
+ /**
54
+ * States
55
+ */
56
+ this.states = [];
57
+ }
58
58
  /**
59
59
  * Back to the previous state
60
60
  */
@@ -40,7 +40,7 @@ interface EventOptions {
40
40
  */
41
41
  once?: boolean;
42
42
  }
43
- declare type EventClassDef = {
43
+ type EventClassDef = {
44
44
  [key: string]: object;
45
45
  };
46
46
  /**
@@ -7,17 +7,6 @@ exports.EventClass = exports.EventBase = void 0;
7
7
  * D for data
8
8
  */
9
9
  class EventBase {
10
- /**
11
- * Constructor
12
- * @param type Type
13
- */
14
- constructor(target, type, data) {
15
- this.target = target;
16
- this.type = type;
17
- this.data = data;
18
- this._propagationStopped = false;
19
- this._timeStamp = Date.now();
20
- }
21
10
  /**
22
11
  * stopImmediatePropagation called
23
12
  */
@@ -30,6 +19,17 @@ class EventBase {
30
19
  get timeStamp() {
31
20
  return this._timeStamp;
32
21
  }
22
+ /**
23
+ * Constructor
24
+ * @param type Type
25
+ */
26
+ constructor(target, type, data) {
27
+ this.target = target;
28
+ this.type = type;
29
+ this.data = data;
30
+ this._propagationStopped = false;
31
+ this._timeStamp = Date.now();
32
+ }
33
33
  /**
34
34
  * Prevent all other listeners from being called
35
35
  */
@@ -22,7 +22,7 @@ export interface IFile {
22
22
  /**
23
23
  * FormDataFieldValue like type
24
24
  */
25
- export declare type FormDataFieldValue = string | IFile;
25
+ export type FormDataFieldValue = string | IFile;
26
26
  /**
27
27
  * FormData like interface
28
28
  * https://developer.mozilla.org/en-US/docs/Web/API/FormData
@@ -371,20 +371,20 @@ export declare namespace DataTypes {
371
371
  /**
372
372
  * List item with number id type
373
373
  */
374
- export declare type ListType = DataTypes.IdLabelItem<number>;
374
+ export type ListType = DataTypes.IdLabelItem<number>;
375
375
  /**
376
376
  * List item with string id type
377
377
  */
378
- export declare type ListType1 = DataTypes.IdLabelItem<string>;
378
+ export type ListType1 = DataTypes.IdLabelItem<string>;
379
379
  /**
380
380
  * Id default type
381
381
  */
382
- export declare type IdDefaultType<T extends object> = T extends {
382
+ export type IdDefaultType<T extends object> = T extends {
383
383
  id: number | string;
384
384
  } ? DataTypes.Keys<T> & 'id' : DataTypes.Keys<T>;
385
385
  /**
386
386
  * Label default type
387
387
  */
388
- export declare type LabelDefaultType<T extends object> = T extends {
388
+ export type LabelDefaultType<T extends object> = T extends {
389
389
  label: string;
390
390
  } ? DataTypes.Keys<T, string> & 'label' : DataTypes.Keys<T, string>;
@@ -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
@@ -1,4 +1,4 @@
1
- export declare type DelayedExecutorType<P extends any[] = []> = {
1
+ export type DelayedExecutorType<P extends any[] = []> = {
2
2
  /**
3
3
  * Call the function
4
4
  * @param miliseconds Delayed miliseconds for this call
@@ -2,19 +2,6 @@
2
2
  * Etsoo implmented Color
3
3
  */
4
4
  export class EColor {
5
- /**
6
- * Constructor
7
- * @param r Reg
8
- * @param g Green
9
- * @param b Blue
10
- * @param alpha Alpha
11
- */
12
- constructor(r, g, b, alpha) {
13
- this.r = r;
14
- this.g = g;
15
- this.b = b;
16
- this.alpha = alpha;
17
- }
18
5
  /**
19
6
  * Adjust value
20
7
  * @param value Current value
@@ -97,6 +84,19 @@ export class EColor {
97
84
  }
98
85
  return undefined;
99
86
  }
87
+ /**
88
+ * Constructor
89
+ * @param r Reg
90
+ * @param g Green
91
+ * @param b Blue
92
+ * @param alpha Alpha
93
+ */
94
+ constructor(r, g, b, alpha) {
95
+ this.r = r;
96
+ this.g = g;
97
+ this.b = b;
98
+ this.alpha = alpha;
99
+ }
100
100
  /**
101
101
  * Clone color with adjustments
102
102
  * @param adjustR Adjust R value
@@ -11,13 +11,13 @@ interface EHistoryNavigateEventData extends EHistoryEventData {
11
11
  */
12
12
  delta: number;
13
13
  }
14
- declare type EHistoryEventDef = {
14
+ type EHistoryEventDef = {
15
15
  clear: EHistoryEventData;
16
16
  navigate: EHistoryNavigateEventData;
17
17
  push: EHistoryEventData;
18
18
  replace: EHistoryEventData;
19
19
  };
20
- declare type EHistoryEventType = Exclude<keyof EHistoryEventDef, 'navigate'>;
20
+ type EHistoryEventType = Exclude<keyof EHistoryEventDef, 'navigate'>;
21
21
  /**
22
22
  * ETSOO Extended history event
23
23
  */
@@ -16,20 +16,6 @@ export class EHistoryNavigateEvent extends EventBase {
16
16
  * ETSOO Extended abstract history class
17
17
  */
18
18
  export class EHistory extends EventClass {
19
- /**
20
- * Constructor
21
- * @param maxDepth Max depth of the history
22
- */
23
- constructor(maxDepth = 20) {
24
- super();
25
- this.maxDepth = maxDepth;
26
- // Index
27
- this._index = -1;
28
- /**
29
- * States
30
- */
31
- this.states = [];
32
- }
33
19
  /**
34
20
  * States length
35
21
  */
@@ -50,6 +36,20 @@ export class EHistory extends EventClass {
50
36
  return undefined;
51
37
  return this.states[this._index];
52
38
  }
39
+ /**
40
+ * Constructor
41
+ * @param maxDepth Max depth of the history
42
+ */
43
+ constructor(maxDepth = 20) {
44
+ super();
45
+ this.maxDepth = maxDepth;
46
+ // Index
47
+ this._index = -1;
48
+ /**
49
+ * States
50
+ */
51
+ this.states = [];
52
+ }
53
53
  /**
54
54
  * Back to the previous state
55
55
  */
@@ -40,7 +40,7 @@ interface EventOptions {
40
40
  */
41
41
  once?: boolean;
42
42
  }
43
- declare type EventClassDef = {
43
+ type EventClassDef = {
44
44
  [key: string]: object;
45
45
  };
46
46
  /**
@@ -4,17 +4,6 @@
4
4
  * D for data
5
5
  */
6
6
  export class EventBase {
7
- /**
8
- * Constructor
9
- * @param type Type
10
- */
11
- constructor(target, type, data) {
12
- this.target = target;
13
- this.type = type;
14
- this.data = data;
15
- this._propagationStopped = false;
16
- this._timeStamp = Date.now();
17
- }
18
7
  /**
19
8
  * stopImmediatePropagation called
20
9
  */
@@ -27,6 +16,17 @@ export class EventBase {
27
16
  get timeStamp() {
28
17
  return this._timeStamp;
29
18
  }
19
+ /**
20
+ * Constructor
21
+ * @param type Type
22
+ */
23
+ constructor(target, type, data) {
24
+ this.target = target;
25
+ this.type = type;
26
+ this.data = data;
27
+ this._propagationStopped = false;
28
+ this._timeStamp = Date.now();
29
+ }
30
30
  /**
31
31
  * Prevent all other listeners from being called
32
32
  */
@@ -22,7 +22,7 @@ export interface IFile {
22
22
  /**
23
23
  * FormDataFieldValue like type
24
24
  */
25
- export declare type FormDataFieldValue = string | IFile;
25
+ export type FormDataFieldValue = string | IFile;
26
26
  /**
27
27
  * FormData like interface
28
28
  * https://developer.mozilla.org/en-US/docs/Web/API/FormData
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.77",
3
+ "version": "1.1.79",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,17 +54,17 @@
54
54
  },
55
55
  "homepage": "https://github.com/ETSOO/Shared#readme",
56
56
  "devDependencies": {
57
- "@types/jest": "^29.2.2",
57
+ "@types/jest": "^29.2.3",
58
58
  "@types/lodash.isequal": "^4.5.6",
59
- "@typescript-eslint/eslint-plugin": "^5.42.1",
60
- "@typescript-eslint/parser": "^5.42.1",
61
- "eslint": "^8.27.0",
59
+ "@typescript-eslint/eslint-plugin": "^5.45.0",
60
+ "@typescript-eslint/parser": "^5.45.0",
61
+ "eslint": "^8.28.0",
62
62
  "eslint-config-airbnb-base": "^15.0.0",
63
63
  "eslint-plugin-import": "^2.26.0",
64
64
  "jest": "^29.3.1",
65
65
  "jest-environment-jsdom": "^29.3.1",
66
66
  "ts-jest": "^29.0.3",
67
- "typescript": "^4.8.4"
67
+ "typescript": "^4.9.3"
68
68
  },
69
69
  "dependencies": {
70
70
  "lodash.isequal": "^4.5.0"
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