feat: add stripMentionTag utils in tailchat-client-sdk

pull/90/head
moonrailgun 2 years ago
parent 0c02849775
commit 14255b6804

@ -0,0 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};

@ -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": {

@ -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,2 +1,3 @@
export * from './openapi';
export * from './plugins/simplenotify';
export * from './utils';

@ -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();
}

@ -457,9 +457,18 @@ importers:
specifier: ^1.3.2
version: 1.3.2
devDependencies:
'@types/jest':
specifier: ^29.5.1
version: 29.5.1
'@types/node':
specifier: ^18.16.1
version: 18.16.1
jest:
specifier: 27.5.1
version: 27.5.1(ts-node@10.9.1)
ts-jest:
specifier: 27.1.4
version: 27.1.4(@babel/core@7.21.0)(@types/jest@29.5.1)(esbuild@0.15.18)(jest@27.5.1)(typescript@4.9.5)
typescript:
specifier: ^4.9.5
version: 4.9.5
@ -2365,6 +2374,7 @@ packages:
/@babel/compat-data@7.18.13:
resolution: {integrity: sha512-5yUzC5LqyTFp2HLmDoxGQelcdYgSpP9xsnMWBphAscOdFrHSAVbLNzWiy32sVNDqJRDiJK6klfDnAgu6PAGSHw==}
engines: {node: '>=6.9.0'}
dev: true
/@babel/compat-data@7.21.0:
resolution: {integrity: sha512-gMuZsmsgxk/ENC3O/fRw5QY8A9/uxQbbCEypnLIiYYc/qVJtEV7ouxC3EllIIwNzMqAQee5tanFabWsUOutS7g==}
@ -2505,10 +2515,10 @@ packages:
peerDependencies:
'@babel/core': ^7.0.0
dependencies:
'@babel/compat-data': 7.18.13
'@babel/compat-data': 7.21.0
'@babel/core': 7.18.13
'@babel/helper-validator-option': 7.18.6
browserslist: 4.21.3
'@babel/helper-validator-option': 7.21.0
browserslist: 4.21.5
semver: 6.3.0
/@babel/helper-compilation-targets@7.18.9(@babel/core@7.21.0):
@ -2740,7 +2750,7 @@ packages:
dependencies:
'@babel/helper-environment-visitor': 7.18.9
'@babel/helper-module-imports': 7.18.6
'@babel/helper-simple-access': 7.18.6
'@babel/helper-simple-access': 7.20.2
'@babel/helper-split-export-declaration': 7.18.6
'@babel/helper-validator-identifier': 7.19.1
'@babel/template': 7.20.7
@ -2819,12 +2829,6 @@ packages:
transitivePeerDependencies:
- supports-color
/@babel/helper-simple-access@7.18.6:
resolution: {integrity: sha512-iNpIgTgyAvDQpDj76POqg+YEt8fPxx3yaNBg3S30dxNKm2SWfYhD0TGrK/Eu9wHpUW63VQU894TsTg+GLbUa1g==}
engines: {node: '>=6.9.0'}
dependencies:
'@babel/types': 7.21.2
/@babel/helper-simple-access@7.20.2:
resolution: {integrity: sha512-+0woI/WPq59IrqDYbVGfshjT5Dmk/nnbdpcF8SnMhhXObpTq2KNBdLFRFrkVdbDOyUmHBCxzm5FHV1rACIkIbA==}
engines: {node: '>=6.9.0'}
@ -2854,6 +2858,7 @@ packages:
/@babel/helper-validator-option@7.18.6:
resolution: {integrity: sha512-XO7gESt5ouv/LRJdrVjkShckw6STTaB7l9BrpBaAHDeF5YZT+01PCwmR0SJHnkW6i8OwW/EVWRShfi4j2x+KQw==}
engines: {node: '>=6.9.0'}
dev: true
/@babel/helper-validator-option@7.21.0:
resolution: {integrity: sha512-rmL/B8/f0mKS2baE9ZpyTcTavvEuWhTTW8amjzXNvYG4AwBsqTLikfXsEofsJEfKHf+HQVQbFOHy6o+4cnC/fQ==}
@ -11137,7 +11142,7 @@ packages:
util-deprecate: 1.0.2
watchpack: 2.4.0
webpack: 5.75.0(esbuild@0.12.29)(webpack-cli@4.10.0)
ws: 8.11.0
ws: 8.12.1
x-default-browser: 0.4.0
transitivePeerDependencies:
- '@storybook/mdx2-csf'
@ -12616,7 +12621,7 @@ packages:
resolution: {integrity: sha512-tEuVcHrpaixS36w7hpsfLBLpjtMRJUE09/MHXn923LOVojDwyC14cWcfc0rDs0VEfUyYmt/+iX1kxxp+gZMcaQ==}
dependencies:
expect: 29.4.3
pretty-format: 29.4.3
pretty-format: 29.5.0
dev: true
/@types/js-cookie@2.2.7:
@ -15211,6 +15216,7 @@ packages:
electron-to-chromium: 1.4.310
node-releases: 2.0.10
update-browserslist-db: 1.0.10(browserslist@4.21.3)
dev: true
/browserslist@4.21.5:
resolution: {integrity: sha512-tUkiguQGW7S3IhB7N+c2MV/HZPSCPAAiYBZXLsBhFB/PCy6ZKKsZrmBayHV9fdGV/ARIfJ14NkxKzRDjvp7L6w==}
@ -19323,7 +19329,7 @@ packages:
jest-get-type: 29.4.3
jest-matcher-utils: 29.4.3
jest-message-util: 29.4.3
jest-util: 29.4.3
jest-util: 29.5.0
dev: true
/express-handlebars@6.0.6:
@ -22960,7 +22966,7 @@ packages:
pretty-format: 27.5.1
slash: 3.0.0
strip-json-comments: 3.1.1
ts-node: 10.9.1(@types/node@18.15.12)(typescript@4.9.5)
ts-node: 10.9.1(@types/node@18.16.1)(typescript@4.9.5)
transitivePeerDependencies:
- bufferutil
- canvas
@ -23376,18 +23382,6 @@ packages:
picomatch: 2.3.1
dev: true
/jest-util@29.4.3:
resolution: {integrity: sha512-ToSGORAz4SSSoqxDSylWX8JzkOQR7zoBtNRsA7e+1WUX5F8jrOwaNpuh1YfJHJKDHXLHmObv5eOjejUd+/Ws+Q==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dependencies:
'@jest/types': 29.5.0
'@types/node': 18.16.1
chalk: 4.1.2
ci-info: 3.8.0
graceful-fs: 4.2.10
picomatch: 2.3.1
dev: true
/jest-util@29.5.0:
resolution: {integrity: sha512-RYMgG/MTadOr5t8KdhejfvUU82MxsCu5MF6KuDUHl+NuwzUt+Sm6jJWxTJVrDR1j5M/gJVCPKQEpWXY+yIQ6lQ==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
@ -34113,6 +34107,42 @@ packages:
yargs-parser: 20.2.9
dev: true
/ts-jest@27.1.4(@babel/core@7.21.0)(@types/jest@29.5.1)(esbuild@0.15.18)(jest@27.5.1)(typescript@4.9.5):
resolution: {integrity: sha512-qjkZlVPWVctAezwsOD1OPzbZ+k7zA5z3oxII4dGdZo5ggX/PL7kvwTM0pXTr10fAtbiVpJaL3bWd502zAhpgSQ==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
hasBin: true
peerDependencies:
'@babel/core': '>=7.0.0-beta.0 <8'
'@types/jest': ^27.0.0
babel-jest: '>=27.0.0 <28'
esbuild: '*'
jest: ^27.0.0
typescript: '>=3.8 <5.0'
peerDependenciesMeta:
'@babel/core':
optional: true
'@types/jest':
optional: true
babel-jest:
optional: true
esbuild:
optional: true
dependencies:
'@babel/core': 7.21.0
'@types/jest': 29.5.1
bs-logger: 0.2.6
esbuild: 0.15.18
fast-json-stable-stringify: 2.1.0
jest: 27.5.1(ts-node@10.9.1)
jest-util: 27.5.1
json5: 2.2.1
lodash.memoize: 4.1.2
make-error: 1.3.6
semver: 7.3.7
typescript: 4.9.5
yargs-parser: 20.2.9
dev: true
/ts-morph@16.0.0:
resolution: {integrity: sha512-jGNF0GVpFj0orFw55LTsQxVYEUOCWBAbR5Ls7fTYE5pQsbW18ssTb/6UXx/GYAEjS+DQTp8VoTw0vqYMiaaQuw==}
dependencies:
@ -34938,6 +34968,7 @@ packages:
browserslist: 4.21.3
escalade: 3.1.1
picocolors: 1.0.0
dev: true
/update-browserslist-db@1.0.10(browserslist@4.21.5):
resolution: {integrity: sha512-OztqDenkfFkbSG+tRxBeAnCVPckDBcvibKd35yDONx6OU8N7sqgwc7rCbkJ/WcYtVRZ4ba68d6byhC21GFh7sQ==}
@ -36283,6 +36314,7 @@ packages:
optional: true
utf-8-validate:
optional: true
dev: false
/ws@8.12.1:
resolution: {integrity: sha512-1qo+M9Ba+xNhPB+YTWUlK6M17brTut5EXbcBaMRN5pH5dFrXz7lzz1ChFSUq3bOUl8yEvSenhHmYUNJxFzdJew==}

Loading…
Cancel
Save