-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add stripMentionTag utils in tailchat-client-sdk
- Loading branch information
1 parent
0c02849
commit 14255b6
Showing
6 changed files
with
100 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
client/packages/tailchat-client-sdk/src/__tests__/utils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { stripMentionTag } from '../utils'; | ||
|
||
describe('stripMentionTag', () => { | ||
test('simple', () => { | ||
expect( | ||
stripMentionTag('[at=6448e822834c12425646f473]Robot[/at] Hello') | ||
).toBe('Hello'); | ||
}); | ||
|
||
test('not remove other message', () => { | ||
expect( | ||
stripMentionTag( | ||
'[at=6448e822834c12425646f473]Robot[/at] Hello [at=6448e822834c12425646f4732]Robot[/at]' | ||
) | ||
).toBe('Hello [at=6448e822834c12425646f4732]Robot[/at]'); | ||
}); | ||
|
||
test('also can remove mention ', () => { | ||
expect(stripMentionTag('@Robot Hello')).toBe('Hello'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './openapi'; | ||
export * from './plugins/simplenotify'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* remove first [at=xxx]xxx[/at] in message first | ||
*/ | ||
export function stripMentionTag(message: string): string { | ||
return message | ||
.trim() | ||
.replace(/^\[at=.*?\[\/at\]/, '') | ||
.replace(/^@\S*\s?/, '') | ||
.trimStart(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.