Add NIP-30 module for custom emojis

This commit is contained in:
Alex Gleason
2023-07-06 13:08:38 -05:00
committed by fiatjaf_
parent 9cd4f16e45
commit 36e0de2a68
3 changed files with 87 additions and 1 deletions

32
nip30.test.ts Normal file
View File

@@ -0,0 +1,32 @@
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:',
)
})