import { KbqUsernameModule } from '@koobiq/components/username';Displays a user's name based on profile data.
Supports different display modes and visual styles.
A custom view can be provided via <kbq-username-custom-view> for full control over the output.
Accepts input profile data and optional formatting options.
@Component({ selector: 'kbq-username', exportAs: 'kbqUsername' })
class KbqUsername {
readonly userInfo = input<KbqUserInfo>();
readonly isCompact = input<boolean>(false);
readonly fullNameFormat = input<string>(kbqDefaultFullNameFormat);
readonly mode = input<KbqUsernameMode>('inline');
readonly type = input<KbqUsernameStyle>('default');
}userInfoKbqUserInfo User profile data used for display.
isCompactboolean Enables compact display mode
fullNameFormatstring Format string for rendering the user's full name.
modeKbqUsernameMode Display mode of the username. Defaults to 'inline'.
typeKbqUsernameStyle Visual style of the username. Defaults to 'default'.
Custom content for KbqUsername, overrides default view.
@Directive({
selector: 'kbq-username-custom-view, [kbq-username-custom-view]',
exportAs: 'kbqUsernameCustomView'
})
class KbqUsernameCustomView {}Styles the primary part of the username (e.g. full name).
@Directive({ selector: '[kbqUsernamePrimary]', exportAs: 'kbqUsernamePrimary' })
class KbqUsernamePrimary {}Styles the secondary part.
@Directive({
selector: '[kbqUsernameSecondary]',
exportAs: 'kbqUsernameSecondary'
})
class KbqUsernameSecondary {}Styles a secondary hint.
@Directive({
selector: '[kbqUsernameSecondaryHint]',
exportAs: 'kbqUsernameSecondaryHint'
})
class KbqUsernameSecondaryHint {}Formats a user profile into a name string.
A lowercase key renders an initial and an uppercase one the full value; every character with no mapped field is emitted verbatim, so the format carries its own separators.
KbqUsernamePipe derives the form from a following . instead.
@Pipe({ name: 'kbqUsernameCustom' })
class KbqUsernameCustomPipe<T = unknown> implements PipeTransform {
transform(
profile: T,
format?: string,
customMapping?: KbqFormatKeyToProfileMappingExtended<T>
): string;
}transform()string Builds a formatted name string from the user profile using the provided format and mapping.
Formats a user profile into a name string.
A key followed by . renders an initial and any other key renders the full value; the separating
spaces are inserted by the pipe, so a character that is neither a mapped key nor . is dropped.
KbqUsernameCustomPipe derives the form from the key's case instead, and keeps the format's own
punctuation.
@Pipe({ name: 'kbqUsername' })
class KbqUsernamePipe<T = unknown> implements PipeTransform {
transform(
profile: T,
format?: string,
customMapping?: KbqFormatKeyToProfileMapping
): string;
}transform()string Builds a formatted name string from the user profile using the provided format and mapping.
Builds a full username string from a pre-formatted name plus optional login and site,
mirroring the text rendered by kbq-username.
Provide custom formatLogin / formatSite to tailor the output.
function kbqBuildUsernameText(
data: { name: string } & Partial<Pick<KbqUserInfo, 'login' | 'site'>>,
options?: KbqUsernameTextOptions
): string;Formats a profile the way KbqUsernamePipe and kbq-username do: a key followed by
KbqUsernameFormatKey.Dot renders an initial, any other key renders the full value, and the
parts are joined with single spaces — a character that is neither a mapped key nor . is dropped.
Fields the profile does not carry are skipped one by one, so a partial profile still renders whatever it has.
function kbqFormatUsername<T = unknown>(
profile: T,
format: string,
mapping: KbqFormatKeyToProfileMapping | KbqFormatKeyToProfileMappingExtended
): string;profileT Profile to format. Anything that is not a record — null, a primitive, an array — formats as an empty string.
formatstring Format string, e.g. kbqDefaultFullNameFormat.
mappingKbqFormatKeyToProfileMapping | KbqFormatKeyToProfileMappingExtended Format key to profile field mapping, e.g. kbqDefaultProfileMapping. Resolve it
from your own injection context — inject(KBQ_PROFILE_MAPPING) — to honour a scoped override.
Formats a profile the way KbqUsernameCustomPipe does: a lowercase key renders an initial, an
uppercase one the full value, and every character with no mapped field — the separators — is emitted
verbatim, which is what lets the format carry its own punctuation.
function kbqFormatUsernameCustom<T = unknown>(
profile: T,
format: string,
mapping: KbqFormatKeyToProfileMapping | KbqFormatKeyToProfileMappingExtended
): string;profileT Profile to format. Anything that is not a record — null, a primitive, an array — formats as an empty string.
formatstring Format string, e.g. kbqDefaultFullNameFormatCustom.
mappingKbqFormatKeyToProfileMapping | KbqFormatKeyToProfileMappingExtended Format key to profile field mapping, e.g. kbqDefaultProfileMapping. Resolve it
from your own injection context — inject(KBQ_PROFILE_MAPPING) — to honour a scoped override.
Returns the formatter kbq-username renders with, bound to the KBQ_PROFILE_MAPPING visible at the
call site. Use it wherever the displayed string is needed outside a template — a search filter, an
option label — so that a scoped mapping applies to both paths.
Must run in an injection context.
function kbqInjectUsernameFormatter(): <T>(profile: T, format?: string) => string;Maps each format key to a property name in the user profile object. Allows flexible formatting regardless of profile field names.
Excludes the uppercase keys: KbqUsernamePipe decides shortness from a following
KbqUsernameFormatKey.Dot, so a case pair would carry no meaning for it. The mapping that does
carry them is KbqFormatKeyToProfileMappingExtended.
type KbqFormatKeyToProfileMapping<T = any> = {
[
key in Exclude<
KbqUsernameFormatKey,
KbqUsernameFormatKey.FirstNameFull | KbqUsernameFormatKey.MiddleNameFull | KbqUsernameFormatKey.LastNameFull
>
]: keyof T | undefined;
};Maps each format key to a property name in the user profile object. Allows flexible formatting regardless of profile field names.
Covers the uppercase keys as well, which is the pair KbqUsernameCustomPipe derives the form from.
type KbqFormatKeyToProfileMappingExtended<T = any> = {
[key in KbqUsernameFormatKey]: keyof T | undefined;
};Basic user info rendered by kbq-username.
type KbqUserInfo = {
firstName?: string;
lastName?: string;
middleName?: string;
login?: string;
site?: string;
};firstNamestring Given name.
lastNamestring Family name.
middleNamestring Middle name or patronymic.
loginstring Account name, rendered as the secondary part.
sitestring Site the account belongs to, rendered in parentheses after the login.
Layout mode for displaying a username and applying text-ellipsis.
stacked: Elements shown vertically.inline: Elements shown in one line. Text ellipsis is applied to both parts.text: display: inline, so the username flows inside a sentence; nothing clips it, hence no title.type KbqUsernameMode = 'stacked' | 'inline' | 'text';Visual style of the username.
default: standard styling with primary and secondary colors.error: error colors (e.g., red).accented: no color theming; emphasizes via typography only.inherit: inherits parent styles, no theming. For example, useful when using inside links.type KbqUsernameStyle = 'default' | 'error' | 'accented' | 'inherit';interface KbqUsernameTextOptions {
formatLogin?: (login: string) => string;
formatSite?: (site: string) => string;
bidiIsolate?: boolean;
}formatLogin(login: string) => string Formats the login segment. Defaults to identity.
formatSite(site: string) => string Formats the site segment. Defaults to wrapping in parentheses, matching kbq-username display.
bidiIsolateboolean Wraps every segment in U+2068/U+2069 so that a right-to-left name keeps its order next to a
left-to-right login, and the parentheses around the site stay attached to it.
Off by default: the isolates are invisible but real characters, and this string is commonly fed to
an includes() filter that would stop matching.
Keys naming the profile field a format character stands for.
The key identifies the field only. Whether it renders in full or as an initial is decided by the
pipe that reads the format: KbqUsernamePipe abbreviates a key that is followed by Dot,
KbqUsernameCustomPipe abbreviates the lowercase keys. The two upper/lower pairs therefore exist so
that a single mapping serves both rules.
enum KbqUsernameFormatKey {
FirstNameShort = 'f',
FirstNameFull = 'F',
MiddleNameShort = 'm',
MiddleNameFull = 'M',
LastNameShort = 'l',
LastNameFull = 'L',
Dot = '.'
}FirstNameShort'f' First name, abbreviated by KbqUsernameCustomPipe.
FirstNameFull'F' First name, rendered in full by KbqUsernameCustomPipe.
MiddleNameShort'm' Middle name, abbreviated by KbqUsernameCustomPipe.
MiddleNameFull'M' Middle name, rendered in full by KbqUsernameCustomPipe.
LastNameShort'l' Last name, abbreviated by KbqUsernameCustomPipe.
LastNameFull'L' Last name, rendered in full by KbqUsernameCustomPipe.
Dot'.' Abbreviation mark. KbqUsernamePipe abbreviates the key it follows; never maps to a field.
Injection token for providing a global username format-to-profile mapping.
Resolved where the kbq-username component or the pipe lives, so a component-level or route-level
provider applies to that subtree. Outside a template, resolve it from your own injection context —
kbqInjectUsernameFormatter() does exactly that.
const KBQ_PROFILE_MAPPING: InjectionToken<KbqFormatKeyToProfileMapping | KbqFormatKeyToProfileMappingExtended>;Default localized strings of kbq-username.
const KBQ_USERNAME_DEFAULT_LOCALE_CONFIGURATION: KbqUsernameLocaleConfiguration;Localization configuration provider for kbq-username.
const KBQ_USERNAME_LOCALE_CONFIGURATION: InjectionToken<KbqUsernameLocaleConfiguration>;Default format of KbqUsernamePipe and of the kbq-username component: full last name, first and
middle names as initials.
Written in that pipe's own syntax — a key followed by . renders an initial, any other key renders
the full value, and the separating spaces are inserted by the pipe rather than by the format.
const kbqDefaultFullNameFormat: string;Default format of KbqUsernameCustomPipe: full last name, first and middle names as initials.
Written in that pipe's own syntax — uppercase keys render the full value, lowercase ones an initial, and every other character is copied verbatim, which is where the spaces and the dots come from.
const kbqDefaultFullNameFormatCustom: string;Mapping of every format key onto a field of KbqUserInfo. Backs KBQ_PROFILE_MAPPING
and is the fallback of both pipes, so a profile shaped like KbqUserInfo needs no mapping at all.
Covers the uppercase keys as well, which is what makes kbqDefaultFullNameFormatCustom work out of
the box; spread it to map extra fields without losing the defaults.
const kbqDefaultProfileMapping: { f: "firstName"; F: "firstName"; m: "middleName"; M: "middleName"; l: "lastName"; L: "lastName"; ".": undefined; };Utility provider. Only the strings you pass are overridden; the rest keep following the active locale.
Provides KBQ_USERNAME_LOCALE_CONFIGURATION.
const kbqUsernameLocaleConfigurationProvider: (
configuration: KbqDeepPartial<KbqUsernameLocaleConfiguration>
) => Provider;