@bbn/bbn 2.0.7 → 2.0.9
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/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/date.d.ts +3 -3
- package/dist/date.js +43 -42
- package/dist/fn/datetime/calendar.js +0 -5
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -37
- package/package.json +15 -18
package/dist/date.d.ts
CHANGED
|
@@ -27,9 +27,9 @@ declare class bbnDateTool {
|
|
|
27
27
|
year(v?: number): number | bbnDateTool;
|
|
28
28
|
month(v?: number): number | bbnDateTool;
|
|
29
29
|
day(v?: number): number | bbnDateTool;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
hour(v?: number): number | bbnDateTool;
|
|
31
|
+
minute(v?: number): number | bbnDateTool;
|
|
32
|
+
second(v?: number): number | bbnDateTool;
|
|
33
33
|
weekday(v?: number, past?: boolean): number | bbnDateTool;
|
|
34
34
|
/**
|
|
35
35
|
* Returns the ISO-8601 week number of this date.
|
package/dist/date.js
CHANGED
|
@@ -17,6 +17,7 @@ import isNumber from './fn/type/isNumber.js';
|
|
|
17
17
|
import isDate from './fn/type/isDate.js';
|
|
18
18
|
import isPrimitive from './fn/type/isPrimitive.js';
|
|
19
19
|
import extend from './fn/object/extend.js';
|
|
20
|
+
import getRow from './fn/object/getRow.js';
|
|
20
21
|
const patterns = [
|
|
21
22
|
// MariaDB DATETIME "YYYY-MM-DD HH:MM:SS"
|
|
22
23
|
{
|
|
@@ -26,9 +27,9 @@ const patterns = [
|
|
|
26
27
|
year: +m[1],
|
|
27
28
|
month: +m[2],
|
|
28
29
|
day: +m[3],
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
hour: +m[4],
|
|
31
|
+
minute: +m[5],
|
|
32
|
+
second: +m[6],
|
|
32
33
|
})
|
|
33
34
|
},
|
|
34
35
|
// MariaDB DATETIME without seconds "YYYY-MM-DD HH:MM"
|
|
@@ -39,9 +40,9 @@ const patterns = [
|
|
|
39
40
|
year: +m[1],
|
|
40
41
|
month: +m[2],
|
|
41
42
|
day: +m[3],
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
hour: +m[4],
|
|
44
|
+
minute: +m[5],
|
|
45
|
+
second: 0,
|
|
45
46
|
})
|
|
46
47
|
},
|
|
47
48
|
// MariaDB DATE "YYYY-MM-DD"
|
|
@@ -52,9 +53,9 @@ const patterns = [
|
|
|
52
53
|
year: +m[1],
|
|
53
54
|
month: +m[2],
|
|
54
55
|
day: +m[3],
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
hour: 0,
|
|
57
|
+
minute: 0,
|
|
58
|
+
second: 0,
|
|
58
59
|
})
|
|
59
60
|
},
|
|
60
61
|
// ISO / JS-style "YYYY-MM-DDTHH:MM[:SS][.sss][Z or ±HH:MM]"
|
|
@@ -65,9 +66,9 @@ const patterns = [
|
|
|
65
66
|
year: +m[1],
|
|
66
67
|
month: +m[2],
|
|
67
68
|
day: +m[3],
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
hour: +m[4],
|
|
70
|
+
minute: +m[5],
|
|
71
|
+
second: m[6] !== undefined ? +m[6] : 0,
|
|
71
72
|
})
|
|
72
73
|
},
|
|
73
74
|
// Simple slash date "YYYY/MM/DD"
|
|
@@ -78,9 +79,9 @@ const patterns = [
|
|
|
78
79
|
year: +m[3],
|
|
79
80
|
month: +m[2],
|
|
80
81
|
day: +m[1],
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
hour: 0,
|
|
83
|
+
minute: 0,
|
|
84
|
+
second: 0,
|
|
84
85
|
})
|
|
85
86
|
},
|
|
86
87
|
// Slash datetime "YYYY/MM/DD HH:MM:SS"
|
|
@@ -91,9 +92,9 @@ const patterns = [
|
|
|
91
92
|
year: +m[3],
|
|
92
93
|
month: +m[2],
|
|
93
94
|
day: +m[1],
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
hour: +m[4],
|
|
96
|
+
minute: +m[5],
|
|
97
|
+
second: +m[6],
|
|
97
98
|
})
|
|
98
99
|
},
|
|
99
100
|
];
|
|
@@ -247,7 +248,7 @@ class bbnDateDuration {
|
|
|
247
248
|
throw new Error('Invalid unit for duration: ' + unit);
|
|
248
249
|
}
|
|
249
250
|
__classPrivateFieldSet(this, _bbnDateDuration_unit, realUnit, "f");
|
|
250
|
-
const row =
|
|
251
|
+
const row = getRow(units, d => d[0] === realUnit);
|
|
251
252
|
if (!row) {
|
|
252
253
|
throw new Error('Invalid unit for duration: ' + realUnit);
|
|
253
254
|
}
|
|
@@ -317,7 +318,7 @@ class bbnDateDuration {
|
|
|
317
318
|
const targetUnit = unit
|
|
318
319
|
? (unitsCorrespondence[unit] || unit)
|
|
319
320
|
: __classPrivateFieldGet(this, _bbnDateDuration_unit, "f");
|
|
320
|
-
const row =
|
|
321
|
+
const row = getRow(units, d => d[0] === targetUnit);
|
|
321
322
|
if (!row) {
|
|
322
323
|
throw new Error('Invalid unit for duration: ' + (unit !== null && unit !== void 0 ? unit : targetUnit));
|
|
323
324
|
}
|
|
@@ -331,7 +332,7 @@ class bbnDateDuration {
|
|
|
331
332
|
}
|
|
332
333
|
}
|
|
333
334
|
_bbnDateDuration_durationMs = new WeakMap(), _bbnDateDuration_unit = new WeakMap(), _bbnDateDuration_instances = new WeakSet(), _bbnDateDuration_getUnitRowByName = function _bbnDateDuration_getUnitRowByName(name) {
|
|
334
|
-
const row =
|
|
335
|
+
const row = getRow(units, d => d[1] === name);
|
|
335
336
|
if (!row) {
|
|
336
337
|
throw new Error('Unit name not found: ' + name);
|
|
337
338
|
}
|
|
@@ -798,8 +799,8 @@ class bbnDateTool {
|
|
|
798
799
|
for (const p of patterns) {
|
|
799
800
|
const m = value.match(p.re);
|
|
800
801
|
if (m) {
|
|
801
|
-
const { year, month, day,
|
|
802
|
-
__classPrivateFieldSet(this, _bbnDateTool_value, new Date(year, month - 1, day,
|
|
802
|
+
const { year, month, day, hour, minute, second } = p.map(m);
|
|
803
|
+
__classPrivateFieldSet(this, _bbnDateTool_value, new Date(year, month - 1, day, hour, minute, second, 0), "f");
|
|
803
804
|
}
|
|
804
805
|
}
|
|
805
806
|
if (!__classPrivateFieldGet(this, _bbnDateTool_value, "f")) {
|
|
@@ -849,7 +850,7 @@ class bbnDateTool {
|
|
|
849
850
|
}
|
|
850
851
|
return __classPrivateFieldGet(this, _bbnDateTool_value, "f").getDate();
|
|
851
852
|
}
|
|
852
|
-
|
|
853
|
+
hour(v) {
|
|
853
854
|
if (0 in arguments) {
|
|
854
855
|
const d = this.copy();
|
|
855
856
|
d.setHours(v);
|
|
@@ -857,7 +858,7 @@ class bbnDateTool {
|
|
|
857
858
|
}
|
|
858
859
|
return __classPrivateFieldGet(this, _bbnDateTool_value, "f").getHours();
|
|
859
860
|
}
|
|
860
|
-
|
|
861
|
+
minute(v) {
|
|
861
862
|
if (0 in arguments) {
|
|
862
863
|
const d = this.copy();
|
|
863
864
|
d.setMinutes(v);
|
|
@@ -865,7 +866,7 @@ class bbnDateTool {
|
|
|
865
866
|
}
|
|
866
867
|
return __classPrivateFieldGet(this, _bbnDateTool_value, "f").getMinutes();
|
|
867
868
|
}
|
|
868
|
-
|
|
869
|
+
second(v) {
|
|
869
870
|
if (0 in arguments) {
|
|
870
871
|
const d = this.copy();
|
|
871
872
|
d.setSeconds(v);
|
|
@@ -960,25 +961,25 @@ class bbnDateTool {
|
|
|
960
961
|
return this.day().toString();
|
|
961
962
|
}
|
|
962
963
|
get HH() {
|
|
963
|
-
const h = parseInt(this.
|
|
964
|
+
const h = parseInt(this.hour().toString());
|
|
964
965
|
return h < 10 ? '0' + h.toString() : h.toString();
|
|
965
966
|
}
|
|
966
967
|
get H() {
|
|
967
|
-
return this.
|
|
968
|
+
return this.hour().toString();
|
|
968
969
|
}
|
|
969
970
|
get II() {
|
|
970
|
-
const i = parseInt(this.
|
|
971
|
+
const i = parseInt(this.minute().toString());
|
|
971
972
|
return i < 10 ? '0' + i.toString() : i.toString();
|
|
972
973
|
}
|
|
973
974
|
get I() {
|
|
974
|
-
return this.
|
|
975
|
+
return this.minute().toString();
|
|
975
976
|
}
|
|
976
977
|
get SS() {
|
|
977
|
-
const s = parseInt(this.
|
|
978
|
+
const s = parseInt(this.second().toString());
|
|
978
979
|
return s < 10 ? '0' + s.toString() : s.toString();
|
|
979
980
|
}
|
|
980
981
|
get S() {
|
|
981
|
-
return this.
|
|
982
|
+
return this.second().toString();
|
|
982
983
|
}
|
|
983
984
|
get WW() {
|
|
984
985
|
const y = parseInt(this.year().toString());
|
|
@@ -1150,7 +1151,7 @@ class bbnDateTool {
|
|
|
1150
1151
|
const order = ['y', 'm', 'd', 'h', 'i', 's'];
|
|
1151
1152
|
// Compare step by step until the requested precision
|
|
1152
1153
|
for (const u of order) {
|
|
1153
|
-
const key = (_a =
|
|
1154
|
+
const key = (_a = getRow(units, un => un[0] === u)) === null || _a === void 0 ? void 0 : _a[1];
|
|
1154
1155
|
const a = this[key]();
|
|
1155
1156
|
const b = d[key]();
|
|
1156
1157
|
if (a < b) {
|
|
@@ -1187,7 +1188,7 @@ class bbnDateTool {
|
|
|
1187
1188
|
const diff = this.diff(date, chosenUnit);
|
|
1188
1189
|
const rtf = new Intl.RelativeTimeFormat([bbn.env.lang, ...navigator.languages], { numeric: "auto" });
|
|
1189
1190
|
// FORCED UNIT MODE
|
|
1190
|
-
const match =
|
|
1191
|
+
const match = getRow(units, d => d[0] === chosenUnit);
|
|
1191
1192
|
if (!match) {
|
|
1192
1193
|
throw new Error('Invalid unit for fromDate: ' + unit);
|
|
1193
1194
|
}
|
|
@@ -1217,7 +1218,7 @@ class bbnDateTool {
|
|
|
1217
1218
|
return diff;
|
|
1218
1219
|
}
|
|
1219
1220
|
const realUnit = unitsCorrespondence[unit];
|
|
1220
|
-
const match =
|
|
1221
|
+
const match = getRow(units, d => d[0] === realUnit);
|
|
1221
1222
|
if (!match) {
|
|
1222
1223
|
throw new Error('Invalid unit for diff: ' + unit);
|
|
1223
1224
|
}
|
|
@@ -1359,7 +1360,7 @@ class bbnDateTool {
|
|
|
1359
1360
|
case "w": {
|
|
1360
1361
|
// Week starting Monday:
|
|
1361
1362
|
// JS getDay(): 0 (Sun) .. 6 (Sat)
|
|
1362
|
-
const current = new Date(this.year(), this.month() - 1, this.day(), this.
|
|
1363
|
+
const current = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), this.second(), 0);
|
|
1363
1364
|
const wd = current.getDay(); // 0..6
|
|
1364
1365
|
const diffToMonday = (wd + 6) % 7; // 0 for Monday, 6 for Sunday
|
|
1365
1366
|
d = new Date(current.getFullYear(), current.getMonth(), current.getDate() - diffToMonday, 0, 0, 0, 0);
|
|
@@ -1369,13 +1370,13 @@ class bbnDateTool {
|
|
|
1369
1370
|
d = new Date(this.year(), this.month() - 1, this.day(), 0, 0, 0, 0);
|
|
1370
1371
|
break;
|
|
1371
1372
|
case "h":
|
|
1372
|
-
d = new Date(this.year(), this.month() - 1, this.day(), this.
|
|
1373
|
+
d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), 0, 0, 0);
|
|
1373
1374
|
break;
|
|
1374
1375
|
case "i":
|
|
1375
|
-
d = new Date(this.year(), this.month() - 1, this.day(), this.
|
|
1376
|
+
d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), 0, 0);
|
|
1376
1377
|
break;
|
|
1377
1378
|
case "s":
|
|
1378
|
-
d = new Date(this.year(), this.month() - 1, this.day(), this.
|
|
1379
|
+
d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), this.second(), 0);
|
|
1379
1380
|
break;
|
|
1380
1381
|
default:
|
|
1381
1382
|
throw new Error('Invalid unit for startOf: ' + unit);
|
|
@@ -1413,13 +1414,13 @@ class bbnDateTool {
|
|
|
1413
1414
|
d = new Date(this.year(), this.month() - 1, this.day(), 23, 59, 59, 999);
|
|
1414
1415
|
break;
|
|
1415
1416
|
case "hour":
|
|
1416
|
-
d = new Date(this.year(), this.month() - 1, this.day(), this.
|
|
1417
|
+
d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), 59, 59, 999);
|
|
1417
1418
|
break;
|
|
1418
1419
|
case "minute":
|
|
1419
|
-
d = new Date(this.year(), this.month() - 1, this.day(), this.
|
|
1420
|
+
d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), 59, 999);
|
|
1420
1421
|
break;
|
|
1421
1422
|
case "second":
|
|
1422
|
-
d = new Date(this.year(), this.month() - 1, this.day(), this.
|
|
1423
|
+
d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), this.second(), 999);
|
|
1423
1424
|
break;
|
|
1424
1425
|
default:
|
|
1425
1426
|
d = new Date(this.mtst);
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
2
|
-
import isLeapYear from 'dayjs/plugin/isLeapYear.js';
|
|
3
|
-
import dayjs_plugin_calendar from 'dayjs/plugin/calendar.js';
|
|
4
1
|
import date from '../../date.js';
|
|
5
2
|
import isString from '../type/isString.js';
|
|
6
3
|
const bbn = {
|
|
7
4
|
_: st => st
|
|
8
5
|
};
|
|
9
|
-
dayjs.extend(dayjs_plugin_calendar);
|
|
10
|
-
dayjs.extend(isLeapYear);
|
|
11
6
|
/**
|
|
12
7
|
* Returns a date relative to the current day.
|
|
13
8
|
*
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
2
|
-
import calendar from 'dayjs/plugin/calendar.js';
|
|
3
|
-
import customParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
4
|
-
import dayOfYear from 'dayjs/plugin/dayOfYear.js';
|
|
5
|
-
import duration from 'dayjs/plugin/duration.js';
|
|
6
|
-
import isBetween from 'dayjs/plugin/isBetween.js';
|
|
7
|
-
import isLeapYear from 'dayjs/plugin/isLeapYear.js';
|
|
8
|
-
import isoWeek from 'dayjs/plugin/isoWeek.js';
|
|
9
|
-
import localeData from 'dayjs/plugin/localeData.js';
|
|
10
|
-
import localizedFormat from 'dayjs/plugin/localizedFormat.js';
|
|
11
|
-
import minMax from 'dayjs/plugin/minMax.js';
|
|
12
|
-
import quarterOfYear from 'dayjs/plugin/quarterOfYear.js';
|
|
13
|
-
import relativeTime from 'dayjs/plugin/relativeTime.js';
|
|
14
|
-
import timezone from 'dayjs/plugin/timezone.js';
|
|
15
|
-
import updateLocale from 'dayjs/plugin/updateLocale.js';
|
|
16
|
-
import utc from 'dayjs/plugin/utc.js';
|
|
17
|
-
import weekday from 'dayjs/plugin/weekday.js';
|
|
18
|
-
import weekOfYear from 'dayjs/plugin/weekOfYear.js';
|
|
19
|
-
dayjs.extend(calendar);
|
|
20
|
-
dayjs.extend(customParseFormat);
|
|
21
|
-
dayjs.extend(dayOfYear);
|
|
22
|
-
dayjs.extend(duration);
|
|
23
|
-
dayjs.extend(isBetween);
|
|
24
|
-
dayjs.extend(isLeapYear);
|
|
25
|
-
dayjs.extend(isoWeek);
|
|
26
|
-
dayjs.extend(localeData);
|
|
27
|
-
dayjs.extend(localizedFormat);
|
|
28
|
-
dayjs.extend(minMax);
|
|
29
|
-
dayjs.extend(quarterOfYear);
|
|
30
|
-
dayjs.extend(relativeTime);
|
|
31
|
-
dayjs.extend(timezone);
|
|
32
|
-
dayjs.extend(updateLocale);
|
|
33
|
-
dayjs.extend(utc);
|
|
34
|
-
dayjs.extend(weekday);
|
|
35
|
-
dayjs.extend(weekOfYear);
|
|
36
1
|
import _ from './_.js';
|
|
37
2
|
import $ from './$.js';
|
|
38
3
|
import lng from './lng.js';
|
|
@@ -127,7 +92,6 @@ const bbn = {
|
|
|
127
92
|
]
|
|
128
93
|
};
|
|
129
94
|
if ('undefined' !== typeof window) {
|
|
130
|
-
window.dayjs = dayjs;
|
|
131
95
|
window.bbn = bbn;
|
|
132
96
|
}
|
|
133
|
-
export
|
|
97
|
+
export default bbn;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bbn/bbn",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "Javascript toolkit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,30 +24,27 @@
|
|
|
24
24
|
"author": "Thomas Nabet <thomas.nabet@gmail.com>",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
28
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
29
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
30
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
31
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
32
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
33
|
+
"chai": "^6.2.1",
|
|
34
|
+
"jsdom": "27.2.0",
|
|
29
35
|
"jsdom-global": "3.0.2",
|
|
30
|
-
"mocha": "^11.
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
36
|
+
"mocha": "^11.0.0",
|
|
37
|
+
"rollup": "^4.53.2",
|
|
38
|
+
"ts-loader": "^9.5.4",
|
|
39
|
+
"tslib": "^2.8.1",
|
|
40
|
+
"typescript": "^5.9.3",
|
|
41
|
+
"webpack": "^5.102.1",
|
|
34
42
|
"webpack-cli": "^6.0.1"
|
|
35
43
|
},
|
|
36
44
|
"bugs": {
|
|
37
45
|
"url": "https://github.com/nabab/bbn-js/issues"
|
|
38
46
|
},
|
|
39
47
|
"homepage": "https://github.com/nabab/bbn-js#readme",
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"@rollup/plugin-commonjs": "^28.0.6",
|
|
42
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
43
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
44
|
-
"@rollup/plugin-replace": "^6.0.2",
|
|
45
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
46
|
-
"@rollup/plugin-typescript": "^12.1.4",
|
|
47
|
-
"dayjs": "^1.11.13",
|
|
48
|
-
"rollup": "^4.46.1",
|
|
49
|
-
"tslib": "^2.8.1"
|
|
50
|
-
},
|
|
51
48
|
"directories": {
|
|
52
49
|
"doc": "doc",
|
|
53
50
|
"test": "test"
|