Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export {default as resolveEmojiUrisInHtml} from './utils/resolveEmojiUrisInHtml'
export {default as isAvatarUri, AVATAR_URI_SCHEME} from './utils/isAvatarUri';
export {default as extractAvatarParamsFromUri} from './utils/extractAvatarParamsFromUri';
export type {AvatarParams, AvatarShape, AvatarVariant} from './utils/extractAvatarParamsFromUri';
export {default as buildAvatarSpec} from './utils/buildAvatarSpec';
export {
default as generateAvatarDataUri,
deriveAvatarContent,
Expand Down
41 changes: 41 additions & 0 deletions packages/browser/src/utils/buildAvatarSpec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import type {AvatarParams} from './extractAvatarParamsFromUri';
import {AVATAR_URI_SCHEME} from './isAvatarUri';

/**
* Serializes {@link AvatarParams} into an `avatar:` URI, the inverse of
* {@link extractAvatarParamsFromUri}.
*
* @param params - The avatar parameters to serialize.
* @returns An `"avatar:shape=...,variant=...,content=...,colors=..."` spec string, with a
* trailing `,bg=...` when {@link AvatarParams.bg} is set.
*
* @example
* ```typescript
* buildAvatarSpec({shape: 'circle', variant: 'two_letter', content: 'BM', colors: 2});
* // "avatar:shape=circle,variant=two_letter,content=BM,colors=2"
* ```
*/
const buildAvatarSpec = ({shape, variant, content, colors, bg}: AvatarParams): string => {
const base = `${AVATAR_URI_SCHEME}shape=${shape},variant=${variant},content=${content},colors=${colors}`;
return bg ? `${base},bg=${bg}` : base;
};

export default buildAvatarSpec;
16 changes: 16 additions & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ export {
extractEmojiFromUri,
resolveLogoUri,
type ResolvedLogo,
isAvatarUri,
AVATAR_URI_SCHEME,
extractAvatarParamsFromUri,
type AvatarParams,
type AvatarShape,
type AvatarVariant,
buildAvatarSpec,
generateAvatarDataUri,
deriveAvatarContent,
AVATAR_GRADIENT_COUNT,
pickAnonymousAvatarName,
pickAnonymousEntityName,
ANONYMOUS_ANIMAL_ICONS,
type AnonymousAnimalIcon,
ANONYMOUS_ENTITY_ICONS,
type AnonymousEntityIcon,
resolveMeta,
resolveFlowTemplateLiterals,
countryCodeToFlagEmoji,
Expand Down
Loading