Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add JSDoc comments from DefinitelyTyped pull request #203

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading