esday 0.2.0 → 0.3.0
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type DateType = Date | string | number | EsDay;
|
|
1
|
+
type DateType = Date | string | number | EsDay | undefined;
|
|
2
2
|
type PrettyUnitType = 'date' | 'day' | 'week' | 'month' | 'year' | 'hour' | 'minute' | 'second' | 'millisecond';
|
|
3
3
|
type PrettyUnit<T extends UnitType> = T extends 'D' ? 'date' : T extends 'w' ? 'week' : T extends 'M' ? 'month' : T extends 'y' ? 'year' : T extends 'H' ? 'hour' : T extends 'm' ? 'minute' : T extends 's' ? 'second' : T extends 'ms' ? 'millisecond' : T;
|
|
4
4
|
type UnitType = 'y' | 'M' | 'D' | 'w' | 'H' | 'm' | 's' | 'ms' | PrettyUnitType;
|
|
@@ -20,10 +20,10 @@ interface AllDateFields {
|
|
|
20
20
|
second: number;
|
|
21
21
|
millisecond: number;
|
|
22
22
|
}
|
|
23
|
+
type EsDayFactoryParserFn = (d?: DateType, ...others: any[]) => EsDay;
|
|
23
24
|
interface EsDayFactory {
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
}): EsDay;
|
|
25
|
+
(...args: Parameters<EsDayFactoryParserFn>): ReturnType<EsDayFactoryParserFn>;
|
|
26
|
+
utc: EsDayFactoryParserFn;
|
|
27
27
|
extend: <T extends {}>(plugin: EsDayPlugin<T>, option?: T) => EsDayFactory;
|
|
28
28
|
}
|
|
29
29
|
type EsDayPlugin<T extends {}> = (option: T, dayTsClass: typeof EsDay, esday: EsDayFactory) => void;
|
|
@@ -41,10 +41,7 @@ declare interface EsDay {
|
|
|
41
41
|
declare class EsDay {
|
|
42
42
|
private $d;
|
|
43
43
|
private $u;
|
|
44
|
-
constructor(
|
|
45
|
-
d?: DateType;
|
|
46
|
-
utc: boolean;
|
|
47
|
-
});
|
|
44
|
+
constructor(d: Exclude<DateType, EsDay>, utc: boolean, ...others: any[]);
|
|
48
45
|
private parse;
|
|
49
46
|
utc(): EsDay;
|
|
50
47
|
isSame(that: DateType, units: UnitType): boolean;
|
|
@@ -68,4 +65,4 @@ declare class EsDay {
|
|
|
68
65
|
private $set;
|
|
69
66
|
}
|
|
70
67
|
|
|
71
|
-
export { type AllDateFields as A, type DateType as D, type EsDayFactory as E, type PrettyUnitType as P, type UnitType as U, EsDay as a, type PrettyUnit as b, type
|
|
68
|
+
export { type AllDateFields as A, type DateType as D, type EsDayFactory as E, type PrettyUnitType as P, type UnitType as U, EsDay as a, type PrettyUnit as b, type EsDayFactoryParserFn as c, type EsDayPlugin as d };
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EsDayFactory } from './EsDay-
|
|
2
|
-
export { A as AllDateFields, D as DateType, a as EsDay, c as EsDayPlugin, b as PrettyUnit, P as PrettyUnitType, U as UnitType } from './EsDay-
|
|
1
|
+
import { E as EsDayFactory } from './EsDay-CKy0jEj2.js';
|
|
2
|
+
export { A as AllDateFields, D as DateType, a as EsDay, c as EsDayFactoryParserFn, d as EsDayPlugin, b as PrettyUnit, P as PrettyUnitType, U as UnitType } from './EsDay-CKy0jEj2.js';
|
|
3
3
|
|
|
4
4
|
declare const esday: EsDayFactory;
|
|
5
5
|
|
package/index.js
CHANGED
|
@@ -15,28 +15,6 @@ var FORMAT_DEFAULT = "YYYY-MM-DDTHH:mm:ssZ";
|
|
|
15
15
|
var INVALID_DATE_STRING = "Invalid Date";
|
|
16
16
|
var REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
|
|
17
17
|
var REGEX_FORMAT = /\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
|
|
18
|
-
|
|
19
|
-
// src/core/factory.ts
|
|
20
|
-
var esday = (d, config) => {
|
|
21
|
-
if (d instanceof EsDay) {
|
|
22
|
-
return d;
|
|
23
|
-
} else {
|
|
24
|
-
return new EsDay({
|
|
25
|
-
d,
|
|
26
|
-
utc: false,
|
|
27
|
-
...config
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
esday.extend = (plugin, option) => {
|
|
32
|
-
if (!plugin.$i) {
|
|
33
|
-
plugin(option, EsDay, esday);
|
|
34
|
-
plugin.$i = true;
|
|
35
|
-
}
|
|
36
|
-
return esday;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/core/utils.ts
|
|
40
18
|
function prettyUnit(u) {
|
|
41
19
|
const special = {
|
|
42
20
|
M,
|
|
@@ -81,9 +59,9 @@ function padStart(str, length, pad) {
|
|
|
81
59
|
return `${Array.from({ length: length + 1 - str.length }).join(pad)}${str}`;
|
|
82
60
|
}
|
|
83
61
|
function wrapperInst(date, instance) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
62
|
+
const newInst = instance.clone();
|
|
63
|
+
newInst["$d"] = new Date(date);
|
|
64
|
+
return newInst;
|
|
87
65
|
}
|
|
88
66
|
|
|
89
67
|
// src/core/Impl/add.ts
|
|
@@ -113,7 +91,7 @@ function addImpl(that, number, units) {
|
|
|
113
91
|
second: 1e3
|
|
114
92
|
}[unit] || 1;
|
|
115
93
|
const nextTimeStamp = $d.getTime() + number * step;
|
|
116
|
-
return
|
|
94
|
+
return wrapperInst(new Date(nextTimeStamp), that);
|
|
117
95
|
}
|
|
118
96
|
|
|
119
97
|
// src/core/Impl/format.ts
|
|
@@ -249,19 +227,16 @@ var EsDay = class _EsDay {
|
|
|
249
227
|
$d;
|
|
250
228
|
// utc mode
|
|
251
229
|
$u = false;
|
|
252
|
-
constructor(
|
|
253
|
-
this.parse(
|
|
230
|
+
constructor(d, utc, ...others) {
|
|
231
|
+
this.parse(d, utc, ...others);
|
|
254
232
|
}
|
|
255
|
-
parse(
|
|
256
|
-
this.$d = parseDate(
|
|
257
|
-
this.$u =
|
|
233
|
+
parse(d, utc, ..._others) {
|
|
234
|
+
this.$d = parseDate(d);
|
|
235
|
+
this.$u = utc;
|
|
258
236
|
}
|
|
259
237
|
// return utc instance
|
|
260
238
|
utc() {
|
|
261
|
-
return new _EsDay(
|
|
262
|
-
d: this.toDate(),
|
|
263
|
-
utc: true
|
|
264
|
-
});
|
|
239
|
+
return new _EsDay(this.toDate(), true);
|
|
265
240
|
}
|
|
266
241
|
isSame(that, units) {
|
|
267
242
|
const other = esday(that);
|
|
@@ -284,10 +259,7 @@ var EsDay = class _EsDay {
|
|
|
284
259
|
return !(this.$d.toString() === INVALID_DATE_STRING);
|
|
285
260
|
}
|
|
286
261
|
clone() {
|
|
287
|
-
return new _EsDay(
|
|
288
|
-
d: new Date(this.$d),
|
|
289
|
-
utc: this.$u
|
|
290
|
-
});
|
|
262
|
+
return new _EsDay(this.toDate(), this.$u);
|
|
291
263
|
}
|
|
292
264
|
format(formatStr) {
|
|
293
265
|
return formatImpl(this, formatStr);
|
|
@@ -349,4 +321,27 @@ var EsDay = class _EsDay {
|
|
|
349
321
|
};
|
|
350
322
|
});
|
|
351
323
|
|
|
324
|
+
// src/core/factory.ts
|
|
325
|
+
var esday = (d, ...others) => {
|
|
326
|
+
if (d instanceof EsDay) {
|
|
327
|
+
return d.clone();
|
|
328
|
+
} else {
|
|
329
|
+
return new EsDay(d, false, ...others);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
esday.utc = (d, ...others) => {
|
|
333
|
+
if (d instanceof EsDay) {
|
|
334
|
+
return d.clone().utc();
|
|
335
|
+
} else {
|
|
336
|
+
return new EsDay(d, true, ...others);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
esday.extend = (plugin, option) => {
|
|
340
|
+
if (!plugin.$i) {
|
|
341
|
+
plugin(option, EsDay, esday);
|
|
342
|
+
plugin.$i = true;
|
|
343
|
+
}
|
|
344
|
+
return esday;
|
|
345
|
+
};
|
|
346
|
+
|
|
352
347
|
export { EsDay, esday };
|
package/package.json
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as EsDayPlugin } from '../../EsDay-CKy0jEj2.js';
|
|
2
2
|
|
|
3
|
-
declare module 'esday' {
|
|
4
|
-
interface EsDayFactory {
|
|
5
|
-
(d?: DateType, conf?: {
|
|
6
|
-
utc?: boolean;
|
|
7
|
-
format?: string;
|
|
8
|
-
}): EsDay;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
3
|
declare const customParseFormatPlugin: EsDayPlugin<{}>;
|
|
12
4
|
|
|
13
5
|
export { customParseFormatPlugin };
|
|
@@ -139,16 +139,19 @@ function parseFormattedInput(input, format, utc) {
|
|
|
139
139
|
}
|
|
140
140
|
var customParseFormatPlugin = (_, dayTsClass) => {
|
|
141
141
|
const oldParse = dayTsClass.prototype["parse"];
|
|
142
|
-
dayTsClass.prototype["parse"] = function(
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
dayTsClass.prototype["parse"] = function(d, ...others) {
|
|
143
|
+
const utc = others[0];
|
|
144
|
+
const format = others[1];
|
|
145
|
+
if (typeof d === "string" && typeof format === "string") {
|
|
146
|
+
const date = parseFormattedInput(d, format, utc);
|
|
147
|
+
if (Number.isNaN(date.getTime())) {
|
|
147
148
|
this["$d"] = /* @__PURE__ */ new Date("");
|
|
148
|
-
else
|
|
149
|
+
} else {
|
|
149
150
|
this["$d"] = date;
|
|
151
|
+
this["$u"] = utc;
|
|
152
|
+
}
|
|
150
153
|
} else {
|
|
151
|
-
oldParse.call(this,
|
|
154
|
+
oldParse.call(this, d, utc);
|
|
152
155
|
}
|
|
153
156
|
};
|
|
154
157
|
};
|