Skip to content

Commit

Permalink
feat: add stripMentionTag utils in tailchat-client-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Apr 27, 2023
1 parent 0c02849 commit 14255b6
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 28 deletions.
5 changes: 5 additions & 0 deletions client/packages/tailchat-client-sdk/jest.config.js
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',
};
7 changes: 5 additions & 2 deletions client/packages/tailchat-client-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"name": "tailchat-client-sdk",
"version": "1.0.3",
"version": "1.0.5",
"description": "",
"main": "lib/index.js",
"scripts": {
"prepare": "tsc",
"release": "npm publish --registry https://registry.npmjs.com/",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},
"keywords": [],
"author": "moonrailgun <moonrailgun@gmail.com>",
"license": "MIT",
"devDependencies": {
"@types/jest": "^29.5.1",
"@types/node": "^18.16.1",
"jest": "27.5.1",
"ts-jest": "27.1.4",
"typescript": "^4.9.5"
},
"dependencies": {
Expand Down
21 changes: 21 additions & 0 deletions client/packages/tailchat-client-sdk/src/__tests__/utils.spec.ts
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');
});
});
1 change: 1 addition & 0 deletions client/packages/tailchat-client-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './openapi';
export * from './plugins/simplenotify';
export * from './utils';
10 changes: 10 additions & 0 deletions client/packages/tailchat-client-sdk/src/utils.ts
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();
}
84 changes: 58 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 14255b6

Please sign in to comment.