Essential utility functions and classes for TypeScript/JavaScript applications including JSON handling, MIME data management, promise delegation, secure tokens, and cross-platform random number generation.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Lumino Core Utilities provides essential utility functions and classes for TypeScript/JavaScript applications, particularly those building rich desktop-like web applications. It includes comprehensive JSON type definitions and utilities, MIME data management, promise delegation, secure token generation, and cross-platform random number generation with UUID support.
npm install @lumino/coreutilsimport { JSONExt, MimeData, PromiseDelegate, Token, Random, UUID } from "@lumino/coreutils";For CommonJS:
const { JSONExt, MimeData, PromiseDelegate, Token, Random, UUID } = require("@lumino/coreutils");Individual imports:
import { JSONValue, JSONObject, JSONExt } from "@lumino/coreutils";
import { MimeData } from "@lumino/coreutils";
import { PromiseDelegate } from "@lumino/coreutils";
import { Token } from "@lumino/coreutils";
import { Random } from "@lumino/coreutils";
import { UUID } from "@lumino/coreutils";import { JSONExt, MimeData, PromiseDelegate, Token, Random, UUID } from "@lumino/coreutils";
// JSON utilities
const data = { name: "Alice", age: 30 };
const copy = JSONExt.deepCopy(data);
const isEmpty = JSONExt.deepEqual(data, JSONExt.emptyObject);
// MIME data handling
const mimeData = new MimeData();
mimeData.setData("text/plain", "Hello, World!");
mimeData.setData("application/json", JSON.stringify(data));
// Promise delegation
const delegate = new PromiseDelegate<string>();
delegate.resolve("Task completed");
await delegate.promise; // "Task completed"
// Secure tokens
const userToken = new Token<User>("user-token");
const configToken = new Token<Config>("config");
// Random number generation (cross-platform)
const buffer = new Uint8Array(16);
Random.getRandomValues(buffer);
// UUID generation
const id = UUID.uuid4(); // "f47ac10b-58cc-4372-a567-0e02b2c3d479"Lumino Core Utilities is designed with a modular, cross-platform architecture:
Comprehensive type system and utilities for type-safe JSON data manipulation with deep equality, copying, and type checking functions.
namespace JSONExt {
const emptyObject: ReadonlyJSONObject;
const emptyArray: ReadonlyJSONArray;
function isPrimitive(value: ReadonlyPartialJSONValue): value is JSONPrimitive;
function isArray(value: ReadonlyPartialJSONValue): boolean;
function isObject(value: ReadonlyPartialJSONValue): boolean;
function deepEqual(first: ReadonlyPartialJSONValue, second: ReadonlyPartialJSONValue): boolean;
function deepCopy<T extends ReadonlyPartialJSONValue>(value: T): T;
}Storage and management system for arbitrary data organized by MIME types, ideal for data transfer within applications.
class MimeData {
types(): string[];
hasData(mime: string): boolean;
getData(mime: string): any | undefined;
setData(mime: string, data: any): void;
clearData(mime: string): void;
clear(): void;
}Promise wrapper that separates promise creation from resolution logic, useful for complex asynchronous workflows.
class PromiseDelegate<T> {
readonly promise: Promise<T>;
resolve(value: T | PromiseLike<T>): void;
reject(reason: any): void;
}Runtime tokens that capture compile-time type information for type-safe object identity and dependency injection.
class Token<T> {
constructor(name: string);
readonly name: string;
}Cross-platform random number generation with cryptographically strong fallbacks and unified API across browser and Node.js environments.
namespace Random {
const getRandomValues: (buffer: Uint8Array) => void;
}
function fallbackRandomValues(buffer: Uint8Array): void;RFC 4122 compliant UUID v4 generation with cryptographically strong randomness and cross-platform support.
namespace UUID {
const uuid4: () => string;
}
function uuid4Factory(
getRandomValues: (bytes: Uint8Array) => void
): () => string;// JSON Types
type JSONPrimitive = boolean | number | string | null;
type JSONValue = JSONPrimitive | JSONObject | JSONArray;
interface JSONObject {
[key: string]: JSONValue;
}
interface JSONArray extends Array<JSONValue> {}
// Readonly JSON Types
type ReadonlyJSONValue = JSONPrimitive | ReadonlyJSONObject | ReadonlyJSONArray;
interface ReadonlyJSONObject {
readonly [key: string]: ReadonlyJSONValue;
}
interface ReadonlyJSONArray extends ReadonlyArray<ReadonlyJSONValue> {}
// Partial JSON Types (allows undefined)
type PartialJSONValue = JSONPrimitive | PartialJSONObject | PartialJSONArray;
interface PartialJSONObject {
[key: string]: PartialJSONValue | undefined;
}
interface PartialJSONArray extends Array<PartialJSONValue> {}
// Readonly Partial JSON Types
type ReadonlyPartialJSONValue = JSONPrimitive | ReadonlyPartialJSONObject | ReadonlyPartialJSONArray;
interface ReadonlyPartialJSONObject {
readonly [key: string]: ReadonlyPartialJSONValue | undefined;
}
interface ReadonlyPartialJSONArray extends ReadonlyArray<ReadonlyPartialJSONValue> {}