@shopify/name
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -6,2 +6,3 @@ 'use strict'; | ||
var constants = require('./constants.js'); | ||
var nonEmptyOrUndefined = require('./utilities/nonEmptyOrUndefined.js'); | ||
var languageFromLocale = require('./utilities/languageFromLocale.js'); | ||
@@ -15,19 +16,23 @@ | ||
}) { | ||
if (!name.givenName) { | ||
return name.familyName || ''; | ||
const givenName = nonEmptyOrUndefined.nonEmptyOrUndefined(name === null || name === void 0 ? void 0 : name.givenName); | ||
const familyName = nonEmptyOrUndefined.nonEmptyOrUndefined(name === null || name === void 0 ? void 0 : name.familyName); | ||
if (familyName && !givenName) { | ||
return familyName; | ||
} | ||
if (!name.familyName) { | ||
return name.givenName; | ||
if (givenName && !familyName) { | ||
return givenName; | ||
} | ||
const isFullName = Boolean(options && options.full); | ||
const customNameFormatter = constants.FAMILY_NAME_GIVEN_NAME_ORDERING_INDEXED_BY_LANGUAGE.get(languageFromLocale.languageFromLocale(locale)); | ||
if (customNameFormatter) { | ||
return customNameFormatter(name.givenName, name.familyName, isFullName); | ||
if (givenName && familyName) { | ||
const isFullName = Boolean(options && options.full); | ||
const customNameFormatter = constants.FAMILY_NAME_GIVEN_NAME_ORDERING_INDEXED_BY_LANGUAGE.get(languageFromLocale.languageFromLocale(locale)); | ||
if (customNameFormatter) { | ||
return customNameFormatter(givenName, familyName, isFullName); | ||
} | ||
if (isFullName) { | ||
return `${givenName} ${familyName}`; | ||
} | ||
} | ||
if (isFullName) { | ||
return `${name.givenName} ${name.familyName}`; | ||
} | ||
return name.givenName; | ||
return givenName; | ||
} | ||
exports.formatName = formatName; |
@@ -10,3 +10,3 @@ export declare function abbreviateName({ name, locale, options, }: { | ||
}; | ||
}): string; | ||
}): string | undefined; | ||
export declare function tryAbbreviateName({ givenName, familyName, idealMaxLength, }: { | ||
@@ -13,0 +13,0 @@ givenName?: string; |
export declare function formatName({ name, locale, options, }: { | ||
name: { | ||
givenName?: string; | ||
familyName?: string; | ||
givenName?: string | null; | ||
familyName?: string | null; | ||
}; | ||
@@ -10,3 +10,3 @@ locale: string; | ||
}; | ||
}): string; | ||
}): string | undefined; | ||
//# sourceMappingURL=formatName.d.ts.map |
{ | ||
"name": "@shopify/name", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Name-related utilities", |
# `@shopify/name` | ||
> [!CAUTION] | ||
> | ||
> `@shopify/name` is deprecated. | ||
> | ||
> Shopifolk, see | ||
> [Shopify/quilt-internal](https://github.com/shopify/quilt-internal) for | ||
> information on the latest packages available for use internally. | ||
[](https://github.com/Shopify/quilt/actions?query=workflow%3ANode-CI) | ||
@@ -4,0 +12,0 @@ [](https://github.com/Shopify/quilt/actions?query=workflow%3ARuby-CI) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
53229
57
603
66