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

KbqUsername

componentСкопировать ссылку на 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');
}
userInfoinputСкопировать ссылку на userInfoKbqUserInfo

User profile data used for display.

isCompactinputСкопировать ссылку на isCompactboolean

Enables compact display mode

fullNameFormatinputСкопировать ссылку на fullNameFormatstring

Format string for rendering the user's full name.

modeinputСкопировать ссылку на modeKbqUsernameMode

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

typeinputСкопировать ссылку на typeKbqUsernameStyle

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

KbqUsernameCustomView

directiveСкопировать ссылку на KbqUsernameCustomView

Custom content for KbqUsername, overrides default view.

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

KbqUsernamePrimary

directiveСкопировать ссылку на KbqUsernamePrimary

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

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

KbqUsernameSecondary

directiveСкопировать ссылку на KbqUsernameSecondary

Styles the secondary part.

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

KbqUsernameSecondaryHint

directiveСкопировать ссылку на KbqUsernameSecondaryHint

Styles a secondary hint.

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

KbqUsernameCustomPipe

pipeСкопировать ссылку на 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()Скопировать ссылку на transform()string

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

KbqUsernamePipe

pipeСкопировать ссылку на 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()Скопировать ссылку на transform()string

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

kbqBuildUsernameText

functionСкопировать ссылку на 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

functionСкопировать ссылку на 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

functionСкопировать ссылку на 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

functionСкопировать ссылку на 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

typeСкопировать ссылку на 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

typeСкопировать ссылку на 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

typeСкопировать ссылку на KbqUserInfo

Basic user info rendered by kbq-username.

type KbqUserInfo = {
    firstName?: string;
    lastName?: string;
    middleName?: string;
    login?: string;
    site?: string;
};
firstNameoptionalСкопировать ссылку на firstNamestring

Given name.

lastNameoptionalСкопировать ссылку на lastNamestring

Family name.

middleNameoptionalСкопировать ссылку на middleNamestring

Middle name or patronymic.

loginoptionalСкопировать ссылку на loginstring

Account name, rendered as the secondary part.

siteoptionalСкопировать ссылку на sitestring

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

KbqUsernameMode

typeСкопировать ссылку на 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

typeСкопировать ссылку на 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

interfaceСкопировать ссылку на KbqUsernameTextOptions
interface KbqUsernameTextOptions {
    formatLogin?: (login: string) => string;
    formatSite?: (site: string) => string;
    bidiIsolate?: boolean;
}
formatLoginoptionalСкопировать ссылку на formatLogin(login: string) => string

Formats the login segment. Defaults to identity.

formatSiteoptionalСкопировать ссылку на formatSite(site: string) => string

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

bidiIsolateoptionalСкопировать ссылку на 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

enumСкопировать ссылку на 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 = '.'
}
FirstNameShortСкопировать ссылку на FirstNameShort'f'

First name, abbreviated by KbqUsernameCustomPipe.

FirstNameFullСкопировать ссылку на FirstNameFull'F'

First name, rendered in full by KbqUsernameCustomPipe.

MiddleNameShortСкопировать ссылку на MiddleNameShort'm'

Middle name, abbreviated by KbqUsernameCustomPipe.

MiddleNameFullСкопировать ссылку на MiddleNameFull'M'

Middle name, rendered in full by KbqUsernameCustomPipe.

LastNameShortСкопировать ссылку на LastNameShort'l'

Last name, abbreviated by KbqUsernameCustomPipe.

LastNameFullСкопировать ссылку на LastNameFull'L'

Last name, rendered in full by KbqUsernameCustomPipe.

DotСкопировать ссылку на Dot'.'

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

KBQ_PROFILE_MAPPING

constСкопировать ссылку на 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

constСкопировать ссылку на KBQ_USERNAME_DEFAULT_LOCALE_CONFIGURATION

Default localized strings of kbq-username.

const KBQ_USERNAME_DEFAULT_LOCALE_CONFIGURATION: KbqUsernameLocaleConfiguration;

KBQ_USERNAME_LOCALE_CONFIGURATION

constСкопировать ссылку на KBQ_USERNAME_LOCALE_CONFIGURATION

Localization configuration provider for kbq-username.

const KBQ_USERNAME_LOCALE_CONFIGURATION: InjectionToken<KbqUsernameLocaleConfiguration>;

kbqDefaultFullNameFormat

constСкопировать ссылку на 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

constСкопировать ссылку на 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

constСкопировать ссылку на 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

constСкопировать ссылку на 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;
Предложения по улучшению
Если вы нашли ошибку или хотите доработать статью, создайте запрос на GitHub.