@tstdl/base 0.92.118 → 0.92.119

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.
Files changed (3) hide show
  1. package/formats.d.ts +13 -11
  2. package/formats.js +4 -7
  3. package/package.json +1 -1
package/formats.d.ts CHANGED
@@ -26,20 +26,22 @@ export declare function formatDate(dateOrTimestamp: number | Date): string;
26
26
  export declare function formatNumericDate(numericDate: number): string;
27
27
  export declare function formatEuro(value: number): string;
28
28
  export declare function formatPercent(value: number): string;
29
- export type FormatPersonNameOptions = {
29
+ export type FormatPersonNameOptions<F = unknown> = {
30
30
  lastNameFirst?: boolean;
31
- nullOnMissing?: boolean;
31
+ fallback?: F;
32
32
  };
33
+ export declare function formatPersonName<F>(person: {
34
+ firstName?: string | null;
35
+ lastName?: string | null;
36
+ } | null | undefined, options: FormatPersonNameOptions<F> & {
37
+ fallback: F;
38
+ }): string | F;
33
39
  export declare function formatPersonName(person: {
34
- firstName: string;
35
- lastName: string | null;
36
- } | null | undefined, options: FormatPersonNameOptions & {
37
- nullOnMissing: true;
38
- }): string | null;
39
- export declare function formatPersonName(person: {
40
- firstName: string;
41
- lastName: string | null;
42
- } | null | undefined, options?: FormatPersonNameOptions): string;
40
+ firstName?: string | null;
41
+ lastName?: string | null;
42
+ } | null | undefined, options?: FormatPersonNameOptions & {
43
+ fallback?: undefined;
44
+ }): string;
43
45
  /**
44
46
  * @deprecated use {@link formatPersonName} instead
45
47
  */
package/formats.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { numericDateToTimestamp } from './utils/date-time.js';
2
2
  import { memoize, memoizeSingle } from './utils/function/memoize.js';
3
- import { isNull, isNullOrUndefined, isUndefined } from './utils/type-guards.js';
3
+ import { isNullOrUndefined, isUndefined } from './utils/type-guards.js';
4
4
  export let locale = 'de-DE';
5
5
  export function configureFormats(options) {
6
6
  locale = options.locale ?? locale;
@@ -120,12 +120,9 @@ export function formatEuro(value) {
120
120
  export function formatPercent(value) {
121
121
  return percentFormatter(locale).format(value);
122
122
  }
123
- export function formatPersonName(person, { lastNameFirst = false, nullOnMissing = false } = {}) {
124
- if (isNullOrUndefined(person)) {
125
- return nullOnMissing ? null : '-';
126
- }
127
- if (isNull(person.lastName)) {
128
- return person.firstName;
123
+ export function formatPersonName(person, { lastNameFirst = false, fallback = '-' } = {}) {
124
+ if (isNullOrUndefined(person?.firstName) || isNullOrUndefined(person.lastName)) {
125
+ return person?.firstName ?? person?.lastName ?? fallback;
129
126
  }
130
127
  if (lastNameFirst) {
131
128
  return `${person.lastName}, ${person.firstName}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.118",
3
+ "version": "0.92.119",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"