Core utilities shared across @webgogol packages.
npm install @webgogol/core-shareCore utilities shared across @webgogol packages.
This package provides a collection of utility functions and types designed to be used across multiple projects within the @webgogol ecosystem. It includes modules for handling Base64 conversions, managing contracts, data manipulation, event handling, file operations, and more.
``bash`
pnpm add @webgogol/core-share
`ts
import { uuid, shortenPath, truncateString } from "@webgogol/core-share";
const id = uuid();
const short = shortenPath("c:/very/long/path/to/file.txt");
const preview = truncateString("Some very long text...", 80);
`
- arrayBufferToBase64(buffer: ArrayBuffer): string: Converts an ArrayBuffer to a Base64 string.base64ToArrayBuffer(base64: string): ArrayBuffer
- : Converts a Base64 string to an ArrayBuffer.uint8ArrayToBase64(a: Uint8Array): string
- : Converts a Uint8Array to a Base64 string.
- Types: Contract, BriefContract, FlowContract, ProcessorContract, StatusFlowContract, StepStatusProcessorContract, VaultId.brief(contract: Contract): BriefContract
- : Creates a brief version of a contract.checkContract(contract: Contract): Contract
- : Validates a contract.emptyContract()
- : Returns an empty contract object.emptyBriefContract()
- : Returns an empty brief contract object.emptyVaultId()
- : Returns an empty vault ID object.
- Types: ContentType, Data, Format.data(source: string, contentType: ContentType, format: Format = "base64"): Data
- : Creates a data URL.
- AppErrorEvent: Custom error event class.emit(event: Event)
- : Dispatches an event.handleEvent(event: Event, handler: HandlerEvent)
- : Handles a specific event.rwl(message: string, level: "log" | "warn" | "error" = "log")
- : A simple event logger.HandlerEvent
- Type: .
- replaceExt(path: string, ext: string): string: Replaces the extension of a file path.replaceName(path: string, name: string): string
- : Replaces the name of a file in a path.
- fingerprint(): Promise: Generates a browser fingerprint.
- akey(parts: string[]): string: Assembles a key from parts.removeFirstKey(key: string): string
- : Removes the first segment of a key.removePagination(key: string): string
- : Removes pagination from a key.rkey(key: string): string[]
- : Splits a key into its component parts.
- shortenPath(path: string, maxLength = 50): string: Shortens a file path to a maximum length.
- truncate(value: unknown, maxLength = 100): unknown: Truncates strings in primitives, arrays, and objects to a max length.truncateObject
- : Safely truncates all string fields within an object.truncateString(text: string, maxLength = 100): string
- : Truncates a string to a max length with an ellipsis.
- Type: Prefix.getPrefix(text: string): Prefix | undefined
- : Extracts a prefix from a string.hasAnyPrefix(text: string): boolean
- : Checks if a string has any known prefix.hasPrefix(text: string, prefix: Prefix): boolean
- : Checks if a string has a specific prefix.noPrefix(text: string): string
- : Removes any known prefix from a string.prefix(text: string, prefix: Prefix): string
- : Adds a prefix to a string.
- fromSqliteValue(value: any, type: string): any: Converts a value from its SQLite representation.getSqliteType(value: any): string
- : Determines the SQLite type of a value.toSqliteValue(value: any): any
- : Converts a value to its SQLite representation.SQLITE_TYPE_MAP
- : A map of JavaScript types to SQLite types.
- contractId(id: string): string: Formats a contract ID.objectId(): string
- : Generates a new object ID.parsedJsonOrSame(json: string): any
- : Safely parses a JSON string.uuid(): string`: Generates a UUID.
-