@bbn/bbn 2.0.6 → 2.0.8

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/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
- hours(v?: number): number | bbnDateTool;
31
- minutes(v?: number): number | bbnDateTool;
32
- seconds(v?: number): number | bbnDateTool;
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
@@ -16,6 +16,8 @@ import substr from './fn/string/substr.js';
16
16
  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
+ import extend from './fn/object/extend.js';
20
+ import getRow from './fn/object/getRow.js';
19
21
  const patterns = [
20
22
  // MariaDB DATETIME "YYYY-MM-DD HH:MM:SS"
21
23
  {
@@ -25,9 +27,9 @@ const patterns = [
25
27
  year: +m[1],
26
28
  month: +m[2],
27
29
  day: +m[3],
28
- hours: +m[4],
29
- minutes: +m[5],
30
- seconds: +m[6],
30
+ hour: +m[4],
31
+ minute: +m[5],
32
+ second: +m[6],
31
33
  })
32
34
  },
33
35
  // MariaDB DATETIME without seconds "YYYY-MM-DD HH:MM"
@@ -38,9 +40,9 @@ const patterns = [
38
40
  year: +m[1],
39
41
  month: +m[2],
40
42
  day: +m[3],
41
- hours: +m[4],
42
- minutes: +m[5],
43
- seconds: 0,
43
+ hour: +m[4],
44
+ minute: +m[5],
45
+ second: 0,
44
46
  })
45
47
  },
46
48
  // MariaDB DATE "YYYY-MM-DD"
@@ -51,9 +53,9 @@ const patterns = [
51
53
  year: +m[1],
52
54
  month: +m[2],
53
55
  day: +m[3],
54
- hours: 0,
55
- minutes: 0,
56
- seconds: 0,
56
+ hour: 0,
57
+ minute: 0,
58
+ second: 0,
57
59
  })
58
60
  },
59
61
  // ISO / JS-style "YYYY-MM-DDTHH:MM[:SS][.sss][Z or ±HH:MM]"
@@ -64,9 +66,9 @@ const patterns = [
64
66
  year: +m[1],
65
67
  month: +m[2],
66
68
  day: +m[3],
67
- hours: +m[4],
68
- minutes: +m[5],
69
- seconds: m[6] !== undefined ? +m[6] : 0,
69
+ hour: +m[4],
70
+ minute: +m[5],
71
+ second: m[6] !== undefined ? +m[6] : 0,
70
72
  })
71
73
  },
72
74
  // Simple slash date "YYYY/MM/DD"
@@ -77,9 +79,9 @@ const patterns = [
77
79
  year: +m[3],
78
80
  month: +m[2],
79
81
  day: +m[1],
80
- hours: 0,
81
- minutes: 0,
82
- seconds: 0,
82
+ hour: 0,
83
+ minute: 0,
84
+ second: 0,
83
85
  })
84
86
  },
85
87
  // Slash datetime "YYYY/MM/DD HH:MM:SS"
@@ -90,9 +92,9 @@ const patterns = [
90
92
  year: +m[3],
91
93
  month: +m[2],
92
94
  day: +m[1],
93
- hours: +m[4],
94
- minutes: +m[5],
95
- seconds: +m[6],
95
+ hour: +m[4],
96
+ minute: +m[5],
97
+ second: +m[6],
96
98
  })
97
99
  },
98
100
  ];
@@ -235,7 +237,7 @@ const buildLocaleFromIntl = () => {
235
237
  weekdaysShort,
236
238
  };
237
239
  };
238
- const locales = buildLocaleFromIntl();
240
+ const locales = {};
239
241
  class bbnDateDuration {
240
242
  constructor(len, unit, fromMs = false) {
241
243
  _bbnDateDuration_instances.add(this);
@@ -246,7 +248,7 @@ class bbnDateDuration {
246
248
  throw new Error('Invalid unit for duration: ' + unit);
247
249
  }
248
250
  __classPrivateFieldSet(this, _bbnDateDuration_unit, realUnit, "f");
249
- const row = bbn.fn.getRow(units, d => d[0] === realUnit);
251
+ const row = getRow(units, d => d[0] === realUnit);
250
252
  if (!row) {
251
253
  throw new Error('Invalid unit for duration: ' + realUnit);
252
254
  }
@@ -316,7 +318,7 @@ class bbnDateDuration {
316
318
  const targetUnit = unit
317
319
  ? (unitsCorrespondence[unit] || unit)
318
320
  : __classPrivateFieldGet(this, _bbnDateDuration_unit, "f");
319
- const row = bbn.fn.getRow(units, d => d[0] === targetUnit);
321
+ const row = getRow(units, d => d[0] === targetUnit);
320
322
  if (!row) {
321
323
  throw new Error('Invalid unit for duration: ' + (unit !== null && unit !== void 0 ? unit : targetUnit));
322
324
  }
@@ -330,7 +332,7 @@ class bbnDateDuration {
330
332
  }
331
333
  }
332
334
  _bbnDateDuration_durationMs = new WeakMap(), _bbnDateDuration_unit = new WeakMap(), _bbnDateDuration_instances = new WeakSet(), _bbnDateDuration_getUnitRowByName = function _bbnDateDuration_getUnitRowByName(name) {
333
- const row = bbn.fn.getRow(units, d => d[1] === name);
335
+ const row = getRow(units, d => d[1] === name);
334
336
  if (!row) {
335
337
  throw new Error('Unit name not found: ' + name);
336
338
  }
@@ -373,6 +375,9 @@ class bbnDateTool {
373
375
  */
374
376
  static parse(input, format, locale) {
375
377
  var _a, _b, _c, _d;
378
+ if (!('monthsLong' in locales)) {
379
+ extend(locales, buildLocaleFromIntl());
380
+ }
376
381
  const loc = {
377
382
  monthsLong: (_a = locale === null || locale === void 0 ? void 0 : locale.monthsLong) !== null && _a !== void 0 ? _a : locales.monthsLong,
378
383
  monthsShort: (_b = locale === null || locale === void 0 ? void 0 : locale.monthsShort) !== null && _b !== void 0 ? _b : locales.monthsShort,
@@ -794,8 +799,8 @@ class bbnDateTool {
794
799
  for (const p of patterns) {
795
800
  const m = value.match(p.re);
796
801
  if (m) {
797
- const { year, month, day, hours, minutes, seconds } = p.map(m);
798
- __classPrivateFieldSet(this, _bbnDateTool_value, new Date(year, month - 1, day, hours, minutes, seconds, 0), "f");
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");
799
804
  }
800
805
  }
801
806
  if (!__classPrivateFieldGet(this, _bbnDateTool_value, "f")) {
@@ -845,7 +850,7 @@ class bbnDateTool {
845
850
  }
846
851
  return __classPrivateFieldGet(this, _bbnDateTool_value, "f").getDate();
847
852
  }
848
- hours(v) {
853
+ hour(v) {
849
854
  if (0 in arguments) {
850
855
  const d = this.copy();
851
856
  d.setHours(v);
@@ -853,7 +858,7 @@ class bbnDateTool {
853
858
  }
854
859
  return __classPrivateFieldGet(this, _bbnDateTool_value, "f").getHours();
855
860
  }
856
- minutes(v) {
861
+ minute(v) {
857
862
  if (0 in arguments) {
858
863
  const d = this.copy();
859
864
  d.setMinutes(v);
@@ -861,7 +866,7 @@ class bbnDateTool {
861
866
  }
862
867
  return __classPrivateFieldGet(this, _bbnDateTool_value, "f").getMinutes();
863
868
  }
864
- seconds(v) {
869
+ second(v) {
865
870
  if (0 in arguments) {
866
871
  const d = this.copy();
867
872
  d.setSeconds(v);
@@ -956,25 +961,25 @@ class bbnDateTool {
956
961
  return this.day().toString();
957
962
  }
958
963
  get HH() {
959
- const h = parseInt(this.hours().toString());
964
+ const h = parseInt(this.hour().toString());
960
965
  return h < 10 ? '0' + h.toString() : h.toString();
961
966
  }
962
967
  get H() {
963
- return this.hours().toString();
968
+ return this.hour().toString();
964
969
  }
965
970
  get II() {
966
- const i = parseInt(this.minutes().toString());
971
+ const i = parseInt(this.minute().toString());
967
972
  return i < 10 ? '0' + i.toString() : i.toString();
968
973
  }
969
974
  get I() {
970
- return this.minutes().toString();
975
+ return this.minute().toString();
971
976
  }
972
977
  get SS() {
973
- const s = parseInt(this.seconds().toString());
978
+ const s = parseInt(this.second().toString());
974
979
  return s < 10 ? '0' + s.toString() : s.toString();
975
980
  }
976
981
  get S() {
977
- return this.seconds().toString();
982
+ return this.second().toString();
978
983
  }
979
984
  get WW() {
980
985
  const y = parseInt(this.year().toString());
@@ -1146,7 +1151,7 @@ class bbnDateTool {
1146
1151
  const order = ['y', 'm', 'd', 'h', 'i', 's'];
1147
1152
  // Compare step by step until the requested precision
1148
1153
  for (const u of order) {
1149
- const key = (_a = bbn.fn.getRow(units, un => un[0] === u)) === null || _a === void 0 ? void 0 : _a[1];
1154
+ const key = (_a = getRow(units, un => un[0] === u)) === null || _a === void 0 ? void 0 : _a[1];
1150
1155
  const a = this[key]();
1151
1156
  const b = d[key]();
1152
1157
  if (a < b) {
@@ -1183,7 +1188,7 @@ class bbnDateTool {
1183
1188
  const diff = this.diff(date, chosenUnit);
1184
1189
  const rtf = new Intl.RelativeTimeFormat([bbn.env.lang, ...navigator.languages], { numeric: "auto" });
1185
1190
  // FORCED UNIT MODE
1186
- const match = bbn.fn.getRow(units, d => d[0] === chosenUnit);
1191
+ const match = getRow(units, d => d[0] === chosenUnit);
1187
1192
  if (!match) {
1188
1193
  throw new Error('Invalid unit for fromDate: ' + unit);
1189
1194
  }
@@ -1213,7 +1218,7 @@ class bbnDateTool {
1213
1218
  return diff;
1214
1219
  }
1215
1220
  const realUnit = unitsCorrespondence[unit];
1216
- const match = bbn.fn.getRow(units, d => d[0] === realUnit);
1221
+ const match = getRow(units, d => d[0] === realUnit);
1217
1222
  if (!match) {
1218
1223
  throw new Error('Invalid unit for diff: ' + unit);
1219
1224
  }
@@ -1355,7 +1360,7 @@ class bbnDateTool {
1355
1360
  case "w": {
1356
1361
  // Week starting Monday:
1357
1362
  // JS getDay(): 0 (Sun) .. 6 (Sat)
1358
- const current = new Date(this.year(), this.month() - 1, this.day(), this.hours(), this.minutes(), this.seconds(), 0);
1363
+ const current = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), this.second(), 0);
1359
1364
  const wd = current.getDay(); // 0..6
1360
1365
  const diffToMonday = (wd + 6) % 7; // 0 for Monday, 6 for Sunday
1361
1366
  d = new Date(current.getFullYear(), current.getMonth(), current.getDate() - diffToMonday, 0, 0, 0, 0);
@@ -1365,13 +1370,13 @@ class bbnDateTool {
1365
1370
  d = new Date(this.year(), this.month() - 1, this.day(), 0, 0, 0, 0);
1366
1371
  break;
1367
1372
  case "h":
1368
- d = new Date(this.year(), this.month() - 1, this.day(), this.hours(), 0, 0, 0);
1373
+ d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), 0, 0, 0);
1369
1374
  break;
1370
1375
  case "i":
1371
- d = new Date(this.year(), this.month() - 1, this.day(), this.hours(), this.minutes(), 0, 0);
1376
+ d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), 0, 0);
1372
1377
  break;
1373
1378
  case "s":
1374
- d = new Date(this.year(), this.month() - 1, this.day(), this.hours(), this.minutes(), this.seconds(), 0);
1379
+ d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), this.second(), 0);
1375
1380
  break;
1376
1381
  default:
1377
1382
  throw new Error('Invalid unit for startOf: ' + unit);
@@ -1409,13 +1414,13 @@ class bbnDateTool {
1409
1414
  d = new Date(this.year(), this.month() - 1, this.day(), 23, 59, 59, 999);
1410
1415
  break;
1411
1416
  case "hour":
1412
- d = new Date(this.year(), this.month() - 1, this.day(), this.hours(), 59, 59, 999);
1417
+ d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), 59, 59, 999);
1413
1418
  break;
1414
1419
  case "minute":
1415
- d = new Date(this.year(), this.month() - 1, this.day(), this.hours(), this.minutes(), 59, 999);
1420
+ d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), 59, 999);
1416
1421
  break;
1417
1422
  case "second":
1418
- d = new Date(this.year(), this.month() - 1, this.day(), this.hours(), this.minutes(), this.seconds(), 999);
1423
+ d = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), this.second(), 999);
1419
1424
  break;
1420
1425
  default:
1421
1426
  d = new Date(this.mtst);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",