mybase 1.1.36 → 1.1.38

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": "mybase",
3
- "version": "1.1.36",
3
+ "version": "1.1.38",
4
4
  "description": "",
5
5
  "main": "mybase.js",
6
6
  "scripts": {
package/ts/index.ts CHANGED
@@ -31,3 +31,5 @@ export * from "./funcs/ensureFolder"
31
31
  export * from "./models/Unixtime"
32
32
  export * from "./models/Timespan"
33
33
  export * from "./models/IPAddress"
34
+
35
+
@@ -15,4 +15,8 @@ export declare class Timespan {
15
15
  static days(days: number): Timespan;
16
16
  static weeks(weeks: number): Timespan;
17
17
  static months(months: number): Timespan;
18
+ toJSON(): {
19
+ __type: string;
20
+ value: number;
21
+ };
18
22
  }
@@ -47,6 +47,12 @@ class Timespan {
47
47
  static months(months) {
48
48
  return new Timespan(months * 30 * 24 * 60 * 60 * 1000);
49
49
  }
50
+ toJSON() {
51
+ return {
52
+ __type: 'Timespan',
53
+ value: this.ms
54
+ };
55
+ }
50
56
  }
51
57
  exports.Timespan = Timespan;
52
58
  //# sourceMappingURL=Timespan.js.map
@@ -59,5 +59,10 @@ export class Timespan {
59
59
  }
60
60
 
61
61
 
62
-
62
+ toJSON() {
63
+ return {
64
+ __type:'Timespan',
65
+ value:this.ms
66
+ }
67
+ }
63
68
  }
@@ -8,6 +8,10 @@ export declare class Unixtime {
8
8
  isEmpty(): boolean;
9
9
  lessThan(other: Unixtime): boolean;
10
10
  get elapsed(): Timespan;
11
+ toJSON(): {
12
+ __type: string;
13
+ value: number;
14
+ };
11
15
  constructor(value: Date | string | number);
12
16
  addTimespan(timespan: Timespan): Unixtime;
13
17
  subtractTimespan(timespan: Timespan): Unixtime;
@@ -28,5 +32,6 @@ export declare class Unixtime {
28
32
  toISOString(): string;
29
33
  elapsedSeconds(): number;
30
34
  elapsedMinutes(): number;
35
+ clone(): Unixtime;
31
36
  static try(value: Date | string | number): Unixtime | null;
32
37
  }
@@ -22,6 +22,12 @@ class Unixtime {
22
22
  get elapsed() {
23
23
  return new Timespan_1.Timespan(Date.now() - this.toLongUnixtime());
24
24
  }
25
+ toJSON() {
26
+ return {
27
+ __type: 'Unixtime',
28
+ value: this.toLongUnixtime()
29
+ };
30
+ }
25
31
  constructor(value) {
26
32
  if (typeof value === 'string') {
27
33
  this.value = new Date(value);
@@ -123,6 +129,9 @@ class Unixtime {
123
129
  elapsedMinutes() {
124
130
  return Math.round(this.elapsedSeconds() / 60);
125
131
  }
132
+ clone() {
133
+ return new Unixtime(this.toLongUnixtime());
134
+ }
126
135
  static try(value) {
127
136
  try {
128
137
  return new Unixtime(value);
@@ -99,4 +99,11 @@ describe('Unixtime', () => {
99
99
  const addedUnixtime = unixtime.addYears(1);
100
100
  expect(addedUnixtime.toDate()).toEqual(new Date(date.setFullYear(date.getFullYear() + 1)));
101
101
  });
102
+
103
+ it('clone should create brand new object', () => {
104
+ const unixtime0 = new Unixtime(new Date())
105
+ const unixtime1 = unixtime0.clone();
106
+ expect(unixtime1).not.toBe(unixtime0);
107
+ expect(unixtime0.toDate()).toEqual(unixtime1.toDate());
108
+ });
102
109
  });
@@ -31,6 +31,13 @@ export class Unixtime {
31
31
  return new Timespan(Date.now() - this.toLongUnixtime())
32
32
  }
33
33
 
34
+ toJSON() {
35
+ return {
36
+ __type:'Unixtime',
37
+ value:this.toLongUnixtime()
38
+ }
39
+ }
40
+
34
41
 
35
42
  constructor(value: Date | string | number) {
36
43
  if (typeof value === 'string') {
@@ -153,6 +160,10 @@ export class Unixtime {
153
160
  return Math.round(this.elapsedSeconds() / 60)
154
161
  }
155
162
 
163
+ clone():Unixtime {
164
+ return new Unixtime(this.toLongUnixtime())
165
+ }
166
+
156
167
 
157
168
  static try(value: Date | string | number): Unixtime | null {
158
169
  try {