mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
33 lines
741 B
TypeScript
33 lines
741 B
TypeScript
import {matchAll, replaceAll} from './nip30.ts'
|
|
|
|
test('matchAll', () => {
|
|
const result = matchAll('Hello :blobcat: :disputed: ::joy:joy:')
|
|
|
|
expect([...result]).toEqual([
|
|
{
|
|
name: 'blobcat',
|
|
shortcode: ':blobcat:',
|
|
start: 6,
|
|
end: 15
|
|
},
|
|
{
|
|
name: 'disputed',
|
|
shortcode: ':disputed:',
|
|
start: 16,
|
|
end: 26
|
|
}
|
|
])
|
|
})
|
|
|
|
test('replaceAll', () => {
|
|
const content = 'Hello :blobcat: :disputed: ::joy:joy:'
|
|
|
|
const result = replaceAll(content, ({name}) => {
|
|
return `<img src="https://ditto.pub/emoji/${name}.png" />`
|
|
})
|
|
|
|
expect(result).toEqual(
|
|
'Hello <img src="https://ditto.pub/emoji/blobcat.png" /> <img src="https://ditto.pub/emoji/disputed.png" /> ::joy:joy:',
|
|
)
|
|
})
|