CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lumino--coreutils

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
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Lumino Core Utilities

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.

Package Information

  • Package Name: @lumino/coreutils
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @lumino/coreutils

Core Imports

import { 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";

Basic Usage

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"

Architecture

Lumino Core Utilities is designed with a modular, cross-platform architecture:

  • JSON System: Complete type-safe JSON handling with readonly and partial variants
  • MIME Management: Generic data storage system organized by MIME types
  • Promise Utilities: Separation of promise creation from resolution logic
  • Token System: Type-safe runtime tokens for dependency injection and object identity
  • Cross-Platform Abstraction: Unified APIs with platform-optimized implementations
  • Fallback Strategy: Graceful degradation when crypto APIs are unavailable

Capabilities

JSON Utilities

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;
}

JSON Utilities

MIME Data Management

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;
}

MIME Data Management

Promise Delegation

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;
}

Promise Delegation

Token System

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;
}

Token System

Random Number Generation

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;

Random Number Generation

UUID Generation

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;

UUID Generation

Types

// 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> {}

docs

index.md

json-utilities.md

mime-data.md

promise-delegation.md

random-generation.md

token-system.md

uuid-generation.md

tile.json