Utilities for formatting localized names.
yarn add @shopify/name
Formats a name (given name and/or family name) according to the locale. For example:
formatName({name: {givenName: 'John', familyName: 'Smith'}, locale: 'en'})
will returnJohn
in English andSmith様
in JapaneseformatName({name: {givenName: 'John', familyName: 'Smith'}, locale: 'en', options: {full: true}})
will returnJohn Smith
in English andSmithJohn
in Japanese
Returns true
when the provided locale formats family name before given name.
For example:
hasFamilyNameGivenNameOrdering('ja')
will returntrue
hasFamilyNameGivenNameOrdering('en')
will returnfalse
Takes a name (given and family name) and returns a language appropriate abbreviated name, or will return formatName
if
it is unable to find a suitable abbreviation.
For example:
abbreviateName({name: {givenName: 'John', familyName: 'Smith'}, locale: 'en'})
will returnJS
abbreviateName({name: {givenName: '健', familyName: '田中'}, locale: 'en'})
will return田中
You may also pass an optional idealMaxLength
parameter, which gives the maximum allowable abbreviation length when
trying to abbreviate a name in the Korean language (default 3 characters). In Korean, if the given name is longer than
this length, the method will instead return the first character of the given name.
Takes a business name and returns a language appropriate abbreviated name, or will return the input name if it is unable to find a suitable abbreviation.
For example:
abbreviateBusinessName({name: 'Shopify'})
will returnSho
abbreviateBusinessName({name: 'My Store'})
will returnMS
abbreviateBusinessName({name: '任天堂'})
will return任天堂
You may also pass an optional idealMaxLength
parameter, which gives the maximum allowable abbreviation length when
trying to abbreviate a name.