Skip to content

Commit

Permalink
Merge pull request #203 from ikelax/docs/add-JSDoc-comments-from-DT-p…
Browse files Browse the repository at this point in the history
…r-issue-136

docs: add JSDoc comments from DefinitelyTyped pull request
  • Loading branch information
JoshuaKGoldberg authored Oct 8, 2024
2 parents 7ef3b06 + 38151bc commit 9e46292
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/emojify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ export type EmojifyFormat = (
) => string

export interface EmojifyOptions {
/**
* The string to fallback to if an emoji was not found.
*/
fallback?: ((part: string) => string) | string

/**
* Adds a middleware layer to modify each matched emoji after parsing.
*/
format?: EmojifyFormat
}

/**
* Parse all markdown-encoded emojis in a string.
*/
export const emojify = (
input: string,
{ fallback, format = name => name }: EmojifyOptions = {},
Expand Down
3 changes: 3 additions & 0 deletions src/find.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { findByCode } from './findByCode.js'
import { findByName } from './findByName.js'

/**
* Get the name and character of an emoji.
*/
export const find = (codeOrName: string) => {
return findByCode(codeOrName) ?? findByName(codeOrName)
}
3 changes: 3 additions & 0 deletions src/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { assert } from '@sindresorhus/is'
import { emojiCodesByName } from './data.js'
import { normalizeName } from './utils.js'

/**
* Get an emoji from an emoji name.
*/
export const get = (codeOrName: string) => {
assert.string(codeOrName)

Expand Down
3 changes: 3 additions & 0 deletions src/has.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { assert } from '@sindresorhus/is'
import { emojiCodesByName, emojiNamesByCode } from './data.js'
import { normalizeCode, normalizeName } from './utils.js'

/**
* Check if this library supports a specific emoji.
*/
export const has = (codeOrName: string) => {
assert.string(codeOrName)

Expand Down
3 changes: 3 additions & 0 deletions src/random.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { emojiData } from './data.js'
import { randomItem } from './utils.js'

/**
* Get a random emoji.
*/
export const random = () => {
const [name, emoji] = randomItem(emojiData)
return { emoji, name }
Expand Down
3 changes: 3 additions & 0 deletions src/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export type ReplaceReplacement = (
string: string,
) => string

/**
* Replace the emojis in a string.
*/
export const replace = (
input: string,
replacement: ReplaceReplacement | string,
Expand Down
3 changes: 3 additions & 0 deletions src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { assert } from '@sindresorhus/is'
import { emojiData } from './data.js'
import { normalizeName } from './utils.js'

/**
* Search for emojis containing the provided name in their name.
*/
export const search = (keyword: string) => {
assert.string(keyword)

Expand Down
6 changes: 6 additions & 0 deletions src/strip.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { replace } from './replace.js'

export interface StripOptions {
/**
* Whether to keep the extra space after a stripped emoji.
*/
preserveSpaces?: boolean
}

/**
* Remove all the emojis from a string.
*/
export const strip = (input: string, { preserveSpaces }: StripOptions = {}) =>
replace(input, '', { preserveSpaces })
3 changes: 3 additions & 0 deletions src/unemojify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { assert } from '@sindresorhus/is'
import { charRegexMatcher } from './utils.js'
import { which } from './which.js'

/**
* Convert all emojis in a string to their markdown-encoded counterparts.
*/
export const unemojify = (input: string) => {
assert.string(input)

Expand Down
3 changes: 3 additions & 0 deletions src/which.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export interface WhichOptions {
markdown?: boolean
}

/**
* Get an emoji name from an emoji.
*/
export const which = (
emoji: string,
{ markdown = false }: WhichOptions = {},
Expand Down

0 comments on commit 9e46292

Please sign in to comment.