@bbn/bbn 1.0.458 → 1.0.460

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
@@ -43,6 +43,7 @@ declare class bbnDateTool {
43
43
  guessUnit(valueInMs: number): string | null;
44
44
  diff(date: any, unit?: string, abs?: boolean): number;
45
45
  calendar(format: string): string;
46
+ getWeekDay(n: 0 | 1 | 2 | 3 | 4 | 5 | 6, mode?: string, locale?: string): any;
46
47
  get daysInMonth(): number;
47
48
  }
48
49
  declare function generatorFunction(value: any, inputFormat?: null | String): bbnDateTool;
package/dist/date.js CHANGED
@@ -495,6 +495,41 @@ class bbnDateTool {
495
495
  }
496
496
  return str;
497
497
  }
498
+ getWeekDay(n, mode = 'long', locale) {
499
+ if (!mode) {
500
+ const letter = this.getWeekDay(n, 'narrow', locale);
501
+ const abbr = this.getWeekDay(n, 'short', locale);
502
+ const full = this.getWeekDay(n, 'long', locale);
503
+ return {
504
+ letter,
505
+ abbr,
506
+ full,
507
+ long: full,
508
+ short: abbr,
509
+ narrow: letter
510
+ };
511
+ }
512
+ let m;
513
+ if (mode === 'letter') {
514
+ m = 'narrow';
515
+ }
516
+ else if (mode === 'abbr') {
517
+ m = 'short';
518
+ }
519
+ else if (mode === 'full') {
520
+ m = 'long';
521
+ }
522
+ else if (!['long', 'short', 'narrow'].includes(mode)) {
523
+ throw new Error('Invalid mode for getWeekDay: ' + mode + '. Allowed values are "long", "short", "narrow", "letter", "abbr", "full".');
524
+ }
525
+ else {
526
+ m = mode;
527
+ }
528
+ // Create a date with the right weekday
529
+ // 2023-01-01 was a Sunday → base for offset
530
+ const base = new Date(2023, 0, 1 + n);
531
+ return base.toLocaleDateString([locale || bbn.env.lang, ...navigator.languages], { weekday: m });
532
+ }
498
533
  get daysInMonth() {
499
534
  if (this.isValid && !__classPrivateFieldGet(this, _bbnDateTool_daysInMonth, "f")) {
500
535
  switch (__classPrivateFieldGet(this, _bbnDateTool_value, "f").getMonth()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "1.0.458",
3
+ "version": "1.0.460",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",