Skip to content

Commit 38bcd4c

Browse files
feat: add nuxt-emoji
1 parent 928f3ca commit 38bcd4c

File tree

8 files changed

+111
-14
lines changed

8 files changed

+111
-14
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
3030
},
3131
"dependencies": {
32-
"@nuxt/kit": "^3.14.1592"
32+
"@nuxt/kit": "^3.14.1592",
33+
"node-emoji": "^2.2.0"
3334
},
3435
"devDependencies": {
3536
"@nuxt/devtools": "^1.6.4",

playground/app.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<template>
22
<div>
3-
Nuxt module playground!
3+
{{ $emoji.emojify("I :heart: :coffee:!") }}
44
</div>
55
</template>
66

77
<script setup>
8+
const emoji = useEmojify('I :heart: :coffee:!')
9+
console.log(emoji)
10+
const unemojify = useUnemojify(emoji)
11+
console.log(unemojify)
812
</script>

pnpm-lock.yaml

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/module.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1-
import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'
1+
import { defineNuxtModule, addPlugin, createResolver, addImports } from '@nuxt/kit'
22

33
export default defineNuxtModule({
44
meta: {
5-
name: 'my-module',
6-
configKey: 'myModule',
5+
name: 'nuxt-emoji',
6+
configKey: 'emoji',
77
},
8-
// Default configuration options of the Nuxt module
9-
defaults: {},
10-
setup(_options, _nuxt) {
11-
const resolver = createResolver(import.meta.url)
8+
setup(_options, nuxt) {
9+
const { resolve } = createResolver(import.meta.url)
1210

13-
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
14-
addPlugin(resolver.resolve('./runtime/plugin'))
11+
const runtimeDir = resolve('runtime')
12+
13+
addPlugin({
14+
src: resolve(runtimeDir, 'plugin.ts'),
15+
})
16+
17+
nuxt.options.alias['#emoji'] = resolve(runtimeDir, 'composables/emoji')
18+
19+
const composables = [{
20+
name: 'useEmoji',
21+
as: 'useEmoji',
22+
from: resolve(runtimeDir, 'composables/emoji'),
23+
}, {
24+
name: 'useEmojify',
25+
as: 'useEmojify',
26+
from: resolve(runtimeDir, 'composables/emojify'),
27+
}, {
28+
name: 'useUnemojify',
29+
as: 'useUnemojify',
30+
from: resolve(runtimeDir, 'composables/unemojify'),
31+
}]
32+
addImports(composables)
1533
},
1634
})

src/runtime/composables/emoji.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { find, get, has, random, replace, search, strip, which, emojify, unemojify } from 'node-emoji'
2+
3+
export const useEmoji = () => {
4+
return {
5+
find, get, has, random, replace, search, strip, which, emojify, unemojify,
6+
}
7+
}

src/runtime/composables/emojify.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { EmojifyOptions } from 'node-emoji'
2+
import { emojify } from 'node-emoji'
3+
4+
export const useEmojify = (input: string, opts?: EmojifyOptions) => {
5+
return emojify(input, opts)
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { unemojify } from 'node-emoji'
2+
3+
export const useUnemojify = (input: string) => {
4+
return unemojify(input)
5+
}

src/runtime/plugin.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
import * as emoji from 'node-emoji'
12
import { defineNuxtPlugin } from '#app'
23

3-
export default defineNuxtPlugin((_nuxtApp) => {
4-
console.log('Plugin injected by my-module!')
5-
})
4+
declare module '#app' {
5+
interface NuxtApp {
6+
$emoji: typeof emoji
7+
}
8+
}
9+
10+
declare module 'vue' {
11+
interface ComponentCustomProperties {
12+
$emoji: typeof emoji
13+
}
14+
}
15+
16+
export default defineNuxtPlugin(async nuxtApp => nuxtApp.provide('emoji', emoji))

0 commit comments

Comments
 (0)