docs: improve docs

This commit is contained in:
Nolan Lawson 2020-06-14 12:09:11 -07:00
parent 6b981b9102
commit 786027fbd6
4 changed files with 48 additions and 22 deletions

View File

@ -263,10 +263,33 @@ same underlying IndexedDB connection and database.
Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`customEmoji` | CustomEmoji] | [] | Array of custom emoji |
`dataSource` | string | "https://cdn.jsdelivr.net/npm/emojibase-data@5/en/data.json" | URL to fetch the emojibase data from |
`locale` | string | "en" | Locale string |
`locale` | string | "en" | Locale string |
**Returns:** *Database*
**Returns:** *[Database*
### Accessors
#### customEmoji
**get customEmoji**(): *CustomEmoji]*
Return the custom emoji associated with this Database, or the empty array if none.
**Returns:** *[CustomEmoji]*
**set customEmoji**(`customEmoji`: [CustomEmoji]): *void*
Set the custom emoji for this database. Throws an error if custom emoji are not in the correct format.
**Parameters:**
Name | Type | Description |
------ | ------ | ------ |
`customEmoji` | [CustomEmoji] | |
**Returns:** *void*
@ -298,9 +321,10 @@ ___
#### getEmojiByGroup
**getEmojiByGroup**(`group`: number): *PromiseEmoji]*
**getEmojiByGroup**(`group`: number): *Promise[NativeEmoji]*
Returns all emoji belonging to a group, ordered by `order`.
Returns all emoji belonging to a group, ordered by `order`. Only returns native emoji;
custom emoji don't belong to a group.
Non-numbers throw an error.
@ -310,7 +334,7 @@ Name | Type | Description |
------ | ------ | ------ |
`group` | number | the group number |
**Returns:** *Promise[Emoji]*
**Returns:** *Promise[NativeEmoji]*
___
@ -354,7 +378,7 @@ ___
#### getEmojiByUnicode
**getEmojiByUnicode**(`unicode`: string): *PromiseEmoji | null*
**getEmojiByUnicode**(`unicode`: string): *PromiseNativeEmoji | null*
Return a single emoji matching the unicode string, or null if not found.
@ -366,7 +390,7 @@ Name | Type | Description |
------ | ------ | ------ |
`unicode` | string | unicode string |
**Returns:** *PromiseEmoji | null*
**Returns:** *PromiseNativeEmoji | null*
___
@ -382,7 +406,7 @@ ___
#### getTopFavoriteEmoji
**getTopFavoriteEmoji**(`n`: number): *PromiseEmoji]*
**getTopFavoriteEmoji**(`limit`: number): *PromiseEmoji]*
Get the top favorite emoji in descending order. If there are no favorite emoji yet, returns an empty array.
@ -390,7 +414,7 @@ Get the top favorite emoji in descending order. If there are no favorite emoji y
Name | Type | Description |
------ | ------ | ------ |
`n` | number | maximum number of results to return |
`limit` | number | maximum number of results to return |
**Returns:** *Promise[Emoji]*
@ -398,16 +422,17 @@ ___
#### incrementFavoriteEmojiCount
**incrementFavoriteEmojiCount**(`unicode`: string): *Promisevoid*
**incrementFavoriteEmojiCount**(`unicodeOrShortcode`: string): *Promisevoid*
Increment the favorite count for an emoji by one. The unicode string must be non-empty. It should
correspond to the base (non-skin-tone) unicode string from the emoji object.
correspond to the base (non-skin-tone) unicode string from the emoji object, or in the case of
custom emoji, it should be the shortcode.
**Parameters:**
Name | Type | Description |
------ | ------ | ------ |
`unicode` | string | unicode of the emoji to increment |
`unicodeOrShortcode` | string | unicode of the native emoji, or shortcode of a custom emoji |
**Returns:** *Promisevoid*

View File

@ -18,8 +18,8 @@
"build:rollup": "NODE_ENV=production rollup -c",
"build:css-docs": "node ./bin/generateCssDocs",
"build:i18n-docs": "node ./bin/generateI18nDocs",
"build:typedoc": "typedoc --out docs-tmp --theme markdown --excludePrivate --excludeNotExported --hideSources --hideBreadcrumbs ./src/types && node ./bin/generateTypeDocs && rm -fr docs-tmp",
"build:types": "tsc -d --outDir ./ts-tmp ./src/types/*.ts && mv ./ts-tmp/*.d.ts ./ && rm -fr ts-tmp",
"build:typedoc": "typedoc --target ES5 --out docs-tmp --theme markdown --excludePrivate --excludeNotExported --hideSources --hideBreadcrumbs ./src/types && node ./bin/generateTypeDocs && rm -fr docs-tmp",
"build:types": "tsc --target ES5 -d --outDir ./ts-tmp ./src/types/*.ts && mv ./ts-tmp/*.d.ts ./ && rm -fr ts-tmp",
"benchmark:bundlesize": "run-s build:rollup benchmark:bundle benchmark:run-bundlesize",
"benchmark:bundle": "rollup -c ./test/bundlesize/rollup.config.js",
"benchmark:memory": "run-s build:rollup benchmark:bundle && run-p --race benchmark:memory:server benchmark:memory:test",

View File

@ -1,4 +1,4 @@
import {Emoji, DatabaseConstructorOptions, SkinTone, CustomEmoji} from "./shared";
import {Emoji, DatabaseConstructorOptions, SkinTone, CustomEmoji, NativeEmoji} from "./shared";
export default class Database {
@ -31,12 +31,13 @@ export default class Database {
}
/**
* Returns all emoji belonging to a group, ordered by `order`.
* Returns all emoji belonging to a group, ordered by `order`. Only returns native emoji;
* custom emoji don't belong to a group.
*
* Non-numbers throw an error.
* @param group - the group number
*/
getEmojiByGroup(group: number): Promise<Emoji[]> {
getEmojiByGroup(group: number): Promise<NativeEmoji[]> {
return Promise.resolve([])
}
@ -69,7 +70,7 @@ export default class Database {
* Empty/null strings throw an error.
* @param unicode - unicode string
*/
getEmojiByUnicode(unicode: string): Promise<Emoji | null> {
getEmojiByUnicode(unicode: string): Promise<NativeEmoji | null> {
return Promise.resolve(null)
}
@ -111,8 +112,6 @@ export default class Database {
/**
* Set the custom emoji for this database. Throws an error if custom emoji are not in the correct format.
*
* Note that custom emoji are kept in-memory, not in IndexedDB. So they are not shared against separate
* Database instances.
*
* @param customEmoji
*/

View File

@ -7,7 +7,7 @@ export enum SkinTone {
Dark = 5
}
export interface Emoji {
export interface NativeEmoji {
annotation: string
emoticon?: string
group: number
@ -97,4 +97,6 @@ export interface EmojiPickerEventMap {
export interface CustomEmoji {
shortcode: string,
url: string
}
}
export type Emoji = NativeEmoji | CustomEmoji