import { KbqUsernameModule } from '@koobiq/components/username';

KbqUsername

componentCopy link to KbqUsername

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');
}
userInfoinputCopy link to userInfoKbqUserInfo

User profile data used for display.

isCompactinputCopy link to isCompactboolean

Enables compact display mode

fullNameFormatinputCopy link to fullNameFormatstring

Format string for rendering the user's full name.

modeinputCopy link to modeKbqUsernameMode

Display mode of the username. Defaults to 'inline'.

typeinputCopy link to typeKbqUsernameStyle

Visual style of the username. Defaults to 'default'.

KbqUsernameCustomView

directiveCopy link to KbqUsernameCustomView

Custom content for KbqUsername, overrides default view.

@Directive({
    selector: 'kbq-username-custom-view, [kbq-username-custom-view]',
    exportAs: 'kbqUsernameCustomView'
})
class KbqUsernameCustomView {}

KbqUsernamePrimary

directiveCopy link to KbqUsernamePrimary

Styles the primary part of the username (e.g. full name).

@Directive({ selector: '[kbqUsernamePrimary]', exportAs: 'kbqUsernamePrimary' })
class KbqUsernamePrimary {}

KbqUsernameSecondary

directiveCopy link to KbqUsernameSecondary

Styles the secondary part.

@Directive({
    selector: '[kbqUsernameSecondary]',
    exportAs: 'kbqUsernameSecondary'
})
class KbqUsernameSecondary {}

KbqUsernameSecondaryHint

directiveCopy link to KbqUsernameSecondaryHint

Styles a secondary hint.

@Directive({
    selector: '[kbqUsernameSecondaryHint]',
    exportAs: 'kbqUsernameSecondaryHint'
})
class KbqUsernameSecondaryHint {}

KbqUsernameCustomPipe

pipeCopy link to KbqUsernameCustomPipe

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()Copy link to transform()string

Builds a formatted name string from the user profile using the provided format and mapping.

KbqUsernamePipe

pipeCopy link to KbqUsernamePipe

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()Copy link to transform()string

Builds a formatted name string from the user profile using the provided format and mapping.

kbqBuildUsernameText

functionCopy link to kbqBuildUsernameText

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;

kbqFormatUsername

functionCopy link to kbqFormatUsername

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;
Parameters
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.

kbqFormatUsernameCustom

functionCopy link to kbqFormatUsernameCustom

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;
Parameters
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.

kbqInjectUsernameFormatter

functionCopy link to kbqInjectUsernameFormatter

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;

KbqFormatKeyToProfileMapping

typeCopy link to KbqFormatKeyToProfileMapping

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;
};

KbqFormatKeyToProfileMappingExtended

typeCopy link to KbqFormatKeyToProfileMappingExtended

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;
};

KbqUserInfo

typeCopy link to KbqUserInfo

Basic user info rendered by kbq-username.

type KbqUserInfo = {
    firstName?: string;
    lastName?: string;
    middleName?: string;
    login?: string;
    site?: string;
};
firstNameoptionalCopy link to firstNamestring

Given name.

lastNameoptionalCopy link to lastNamestring

Family name.

middleNameoptionalCopy link to middleNamestring

Middle name or patronymic.

loginoptionalCopy link to loginstring

Account name, rendered as the secondary part.

siteoptionalCopy link to sitestring

Site the account belongs to, rendered in parentheses after the login.

KbqUsernameMode

typeCopy link to KbqUsernameMode

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';

KbqUsernameStyle

typeCopy link to KbqUsernameStyle

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';

KbqUsernameTextOptions

interfaceCopy link to KbqUsernameTextOptions
interface KbqUsernameTextOptions {
    formatLogin?: (login: string) => string;
    formatSite?: (site: string) => string;
    bidiIsolate?: boolean;
}
formatLoginoptionalCopy link to formatLogin(login: string) => string

Formats the login segment. Defaults to identity.

formatSiteoptionalCopy link to formatSite(site: string) => string

Formats the site segment. Defaults to wrapping in parentheses, matching kbq-username display.

bidiIsolateoptionalCopy link to 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.

KbqUsernameFormatKey

enumCopy link to KbqUsernameFormatKey

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 = '.'
}
FirstNameShortCopy link to FirstNameShort'f'

First name, abbreviated by KbqUsernameCustomPipe.

FirstNameFullCopy link to FirstNameFull'F'

First name, rendered in full by KbqUsernameCustomPipe.

MiddleNameShortCopy link to MiddleNameShort'm'

Middle name, abbreviated by KbqUsernameCustomPipe.

MiddleNameFullCopy link to MiddleNameFull'M'

Middle name, rendered in full by KbqUsernameCustomPipe.

LastNameShortCopy link to LastNameShort'l'

Last name, abbreviated by KbqUsernameCustomPipe.

LastNameFullCopy link to LastNameFull'L'

Last name, rendered in full by KbqUsernameCustomPipe.

DotCopy link to Dot'.'

Abbreviation mark. KbqUsernamePipe abbreviates the key it follows; never maps to a field.

KBQ_PROFILE_MAPPING

constCopy link to KBQ_PROFILE_MAPPING

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>;

KBQ_USERNAME_DEFAULT_LOCALE_CONFIGURATION

constCopy link to KBQ_USERNAME_DEFAULT_LOCALE_CONFIGURATION

Default localized strings of kbq-username.

const KBQ_USERNAME_DEFAULT_LOCALE_CONFIGURATION: KbqUsernameLocaleConfiguration;

KBQ_USERNAME_LOCALE_CONFIGURATION

constCopy link to KBQ_USERNAME_LOCALE_CONFIGURATION

Localization configuration provider for kbq-username.

const KBQ_USERNAME_LOCALE_CONFIGURATION: InjectionToken<KbqUsernameLocaleConfiguration>;

kbqDefaultFullNameFormat

constCopy link to kbqDefaultFullNameFormat

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;

kbqDefaultFullNameFormatCustom

constCopy link to kbqDefaultFullNameFormatCustom

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;

kbqDefaultProfileMapping

constCopy link to kbqDefaultProfileMapping

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; };

kbqUsernameLocaleConfigurationProvider

constCopy link to kbqUsernameLocaleConfigurationProvider

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;
Suggestions for improvement
If you found a mistake or want to improve the article, create an issue on GitHub.