Add documentation.
This commit is contained in:
parent
03d737b9cf
commit
009ff2e424
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* Keys of feature names used in WebExtension storage.
|
||||
*/
|
||||
export enum Feature {
|
||||
AnonymizeUsernames = "anonymize-usernames",
|
||||
Autocomplete = "autocomplete",
|
||||
|
@ -11,6 +14,9 @@ export enum Feature {
|
|||
UsernameColors = "username-colors",
|
||||
}
|
||||
|
||||
/**
|
||||
* Keys of miscellaneous data stored in WebExtension storage.
|
||||
*/
|
||||
export enum Data {
|
||||
EnabledFeatures = "enabled-features",
|
||||
KnownGroups = "known-groups",
|
||||
|
|
|
@ -8,6 +8,9 @@ export * from "./enums.js";
|
|||
export * from "./username-color.js";
|
||||
export * from "./user-label.js";
|
||||
|
||||
/**
|
||||
* The data stored for the Hide Votes feature.
|
||||
*/
|
||||
export type HideVotesData = {
|
||||
otherComments: boolean;
|
||||
otherTopics: boolean;
|
||||
|
@ -15,6 +18,9 @@ export type HideVotesData = {
|
|||
ownTopics: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* All storage {@link Value}s stored in WebExtension storage.
|
||||
*/
|
||||
export const storageValues = {
|
||||
[Data.EnabledFeatures]: createValue({
|
||||
deserialize: (input) => new Set(JSON.parse(input) as Feature[]),
|
||||
|
@ -65,8 +71,15 @@ export const storageValues = {
|
|||
[Feature.UsernameColors]: collectUsernameColors(),
|
||||
};
|
||||
|
||||
/**
|
||||
* Shorthand for the inferred shape of {@link storageValues}.
|
||||
*/
|
||||
type StorageValues = typeof storageValues;
|
||||
|
||||
/**
|
||||
* Return the {@link Value}-wrapped data associated with a particular key.
|
||||
* @param key The key of the value to get from {@link storageValues}.
|
||||
*/
|
||||
export async function fromStorage<K extends keyof StorageValues>(
|
||||
key: K,
|
||||
): Promise<StorageValues[K]> {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* The deserialize data function from version 1.1.2 and before.
|
||||
*/
|
||||
export function v112DeserializeData(data: Record<string, any>): {
|
||||
userLabels: V112Settings["data"]["userLabels"];
|
||||
usernameColors: V112Settings["data"]["usernameColors"];
|
||||
|
@ -22,6 +25,9 @@ export function v112DeserializeData(data: Record<string, any>): {
|
|||
return deserialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Settings data structure from version 1.1.2 and before.
|
||||
*/
|
||||
export type V112Settings = {
|
||||
[index: string]: any;
|
||||
data: {
|
||||
|
@ -61,6 +67,9 @@ export type V112Settings = {
|
|||
version: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* A sample of the version 1.1.2 Settings data to use in testing.
|
||||
*/
|
||||
export const v112Sample: V112Settings = {
|
||||
data: {
|
||||
hideVotes: {
|
||||
|
|
|
@ -2,6 +2,9 @@ import {createValue, type Value} from "@holllo/webextension-storage";
|
|||
import browser from "webextension-polyfill";
|
||||
import {Feature} from "./enums.js";
|
||||
|
||||
/**
|
||||
* The data structure for a user label.
|
||||
*/
|
||||
export type UserLabel = {
|
||||
color: string;
|
||||
id: number;
|
||||
|
@ -10,6 +13,9 @@ export type UserLabel = {
|
|||
username: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Shorthand for an array of {@link Value}-wrapped {@link UserLabel}s.
|
||||
*/
|
||||
export type UserLabelsData = Array<Value<UserLabel>>;
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,12 +2,18 @@ import {type Value, createValue} from "@holllo/webextension-storage";
|
|||
import browser from "webextension-polyfill";
|
||||
import {Feature} from "./enums.js";
|
||||
|
||||
/**
|
||||
* The data structure for a username color.
|
||||
*/
|
||||
export type UsernameColor = {
|
||||
color: string;
|
||||
id: number;
|
||||
username: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Shorthand for an array of {@link Value}-wrapped {@link UsernameColor}s.
|
||||
*/
|
||||
export type UsernameColorsData = Array<Value<UsernameColor>>;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue