Skip to content

Commit

Permalink
test: add tests for builders
Browse files Browse the repository at this point in the history
  • Loading branch information
EndBug committed Jun 7, 2022
1 parent 240d128 commit 7660a07
Show file tree
Hide file tree
Showing 3 changed files with 525 additions and 14 deletions.
16 changes: 3 additions & 13 deletions src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,19 @@ import {LIMITS} from './constants';
import {chunkString} from './internal';

export interface RichTextOptions {
type?: 'text' | 'equation'; // 'mention' is not supported
type?: 'text' | 'equation'; // 'mention' is not supported, it's quicker to just write the object
annotations?: RichText['annotations'];
url?: string;
}
export function richText(
content: string,
options: RichTextOptions = {}
): RichText[] {
const annotations: RichText['annotations'] = {
bold: false,
strikethrough: false,
underline: false,
italic: false,
code: false,
color: 'default' as const,
...((options.annotations as RichText['annotations']) || {}),
};

if (options.type === 'equation') {
return chunkString(content, LIMITS.RICH_TEXT.EQUATION_EXPRESSION).map(
expression => ({
type: 'equation',
annotations,
annotations: options.annotations,
equation: {
expression,
},
Expand All @@ -36,7 +26,7 @@ export function richText(
} else
return chunkString(content, LIMITS.RICH_TEXT.TEXT_CONTENT).map(str => ({
type: 'text',
annotations,
annotations: options.annotations,
text: {
content: str,
link: options.url
Expand Down
Loading

0 comments on commit 7660a07

Please sign in to comment.