Skip to content

Commit

Permalink
Update @types/nlcst, unified, utilities, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 6, 2023
1 parent 3cbadde commit 8de7eeb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
38 changes: 20 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,24 @@ init()
*
* @type {import('unified').Plugin<[Options?], Root>}
*/
export default function retextEmoji(options = {}) {
const Parser = this.Parser
// Hush.
/* c8 ignore next */
if (!Parser) throw new Error('Expected parser')
const convert = options.convert
export default function retextEmoji(options) {
const convert = (options || {}).convert
/** @type {fns[keyof fns]|undefined} */
let fn
// Hush.
// type-coverage:ignore-next-line
const proto = Parser.prototype
// Hush.
// type-coverage:ignore-next-line
proto.useFirst('tokenizeSentence', emoticonModifier)
// Hush.
// type-coverage:ignore-next-line
proto.useFirst('tokenizeSentence', emojiModifier)
// Hush.
// type-coverage:ignore-next-line
proto.useFirst('tokenizeParagraph', affixEmoticonModifier)

let sentence = this.data('nlcstSentenceExtensions')
let paragraph = this.data('nlcstParagraphExtensions')

if (!sentence) {
this.data('nlcstSentenceExtensions', (sentence = []))
}

if (!paragraph) {
this.data('nlcstParagraphExtensions', (paragraph = []))
}

sentence.push(emojiModifier, emoticonModifier)
paragraph.push(affixEmoticonModifier)

if (convert !== null && convert !== undefined) {
if (!Object.keys(fns).includes(convert)) {
Expand All @@ -108,9 +106,13 @@ export default function retextEmoji(options = {}) {

const info = emoji2info[emoji]
const data = node.data || (node.data = {})
// @ts-expect-error: to do: register extra data.
data.emoji = info.emoji
// @ts-expect-error: to do: register extra data.
data.description = info.description
// @ts-expect-error: to do: register extra data.
data.names = info.names.concat()
// @ts-expect-error: to do: register extra data.
data.tags = info.tags.concat()
})
}
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@
"index.js"
],
"dependencies": {
"@types/nlcst": "^1.0.0",
"@types/nlcst": "^2.0.0",
"emoticon": "^4.0.0",
"gemoji": "^7.0.0",
"nlcst-affix-emoticon-modifier": "^2.0.0",
"nlcst-emoji-modifier": "^5.0.0",
"nlcst-emoticon-modifier": "^2.0.0",
"nlcst-to-string": "^3.0.0",
"unified": "^10.0.0",
"unist-util-visit": "^4.0.0"
"gemoji": "^8.0.0",
"nlcst-affix-emoticon-modifier": "^3.0.0",
"nlcst-emoji-modifier": "^6.0.0",
"nlcst-emoticon-modifier": "^3.0.0",
"nlcst-to-string": "^4.0.0",
"unified": "^11.0.0",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@types/tape": "^5.0.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"retext": "^8.0.0",
"retext": "^9.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unist-builder": "^3.0.0",
"unist-builder": "^4.0.0",
"xo": "^0.56.0"
},
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ test('retext-emoji', (t) => {
.process(fixture, (error, file) => {
t.deepEqual(
[error, String(file)],
[null, fixture],
[undefined, fixture],
'should not transform without `convert`'
)
})
Expand All @@ -215,7 +215,7 @@ test('retext-emoji', (t) => {
.process(fixture, (error, file) => {
t.deepEqual(
[error, String(file)],
[null, 'It’s raining 🐱s and 🐶s. Now 👨.'],
[undefined, 'It’s raining 🐱s and 🐶s. Now 👨.'],
'should encode'
)
})
Expand All @@ -225,7 +225,7 @@ test('retext-emoji', (t) => {
.process(fixture, (error, file) => {
t.deepEqual(
[error, String(file)],
[null, 'It’s raining :cat:s and :dog:s. Now :man:.'],
[undefined, 'It’s raining :cat:s and :dog:s. Now :man:.'],
'should decode'
)
})
Expand All @@ -246,7 +246,7 @@ test('retext-emoji', (t) => {
.process(fixture, (error, file) => {
t.deepEqual(
[error, String(file)],
[null, fixture],
[undefined, fixture],
'should not overwrite existing data'
)
})
Expand All @@ -256,7 +256,7 @@ test('retext-emoji', (t) => {
.process('Zap! ⚡️', (error, file) => {
t.deepEqual(
[error, String(file)],
[null, 'Zap! :zap:'],
[undefined, 'Zap! :zap:'],
'should support a superfluous variant selector 16'
)
})
Expand Down

0 comments on commit 8de7eeb

Please sign in to comment.