UNPKG

@4players/odin-foundation

Version:

A set of classes defining a standard protocol for messaging and user data built on top of the Odin protocol.

76 lines (75 loc) 2.79 kB
import { IChatMessage, IUser } from "./model"; import { IMessageTransferFormat, IUserData } from "./datastructures"; /** * A set of utility functions used to serialize and deserialize data. */ export declare class Utilities { /** * @summary Capitalizes the first letter of a string * @param string The string to capitalize */ static capitalize(string: string): string; /** * @summary Converts a string to a base64url string * @param string The string to convert */ static base64url(string: string): string; /** * @summary URL encodes a string * @param string The string to encode */ static urlencode(string: string): string; /** * @summary Converts a decimal number to a hex string * @param dec The number to convert to hex string */ static dec2hex(dec: number): string; /** * Parses a JWT token and returns the payload * @param token The JWT token to parse */ static parseJwt(token: string): any; /** * @summary Function to filter out duplicate values in an array * @param value * @param index * @param self */ static uniqueFilter(value: any, index: any, self: any[]): boolean; /** * @summary Parses a string for URLs and returns an array of URLs * @param text The text to parse */ static parseLinks(text: string): string[]; /** * @summary Builds a chat message from a user and a message transfer message * @param user The user who sent the message * @param message The message transfer message */ static buildMessage(user: IUserData, message: IMessageTransferFormat): IChatMessage | null; /** * @summary Creates a user from user data. * Deprecated fields are still filled in for backwards compatibility. Use `data` field for storing user data instead. * @param userData The user data to create a user from * @param peerId The peer ID of the user */ static createUserFromUserData(userData: IUserData, peerId: number): IUser; /** * @summary Creates user data from a user. * @deprecated Use IUser.data instead of duplicating data all the time back and forth * @param user The user to create user data from */ static userDataFromUser(user: IUser): IUserData; /** * @summary Encodes an object to a Uint8Array * Use this function to encode objects to send them over the network * @param data The object to encode */ static encodeObjToUint8Array(data: object): Uint8Array; /** * @summary Decodes a Uint8Array to an object * Use this function to encode objects to send them over the network * @param data */ static decodeUint8ArrayToObject<T>(data: Uint8Array): T | null; }