@lumino/coreutils

  • Version 2.1.2
  • Published
  • 259 kB
  • No dependencies
  • BSD-3-Clause license

Install

npm i @lumino/coreutils
yarn add @lumino/coreutils
pnpm add @lumino/coreutils

Overview

coreutils

Index

Classes

class MimeData

class MimeData {}
  • An object which stores MIME data for general application use.

    #### Notes This class does not attempt to enforce "correctness" of MIME types and their associated data. Since this class is designed to transfer arbitrary data and objects within the same application, it assumes that the user provides correct and accurate data.

method clear

clear: () => void;
  • Remove all data entries from the dataset.

method clearData

clearData: (mime: string) => void;
  • Remove the data entry for the given MIME type.

    Parameter mime

    The MIME type of interest.

    #### Notes This is a no-op if there is no entry for the given MIME type.

method getData

getData: (mime: string) => any | undefined;
  • Get the data value for the given MIME type.

    Parameter mime

    The MIME type of interest.

    Returns

    The value for the given MIME type, or undefined if the dataset does not contain a value for the type.

method hasData

hasData: (mime: string) => boolean;
  • Test whether the dataset has an entry for the given type.

    Parameter mime

    The MIME type of interest.

    Returns

    true if the dataset contains a value for the given MIME type, false otherwise.

method setData

setData: (mime: string, data: unknown) => void;
  • Set the data value for the given MIME type.

    Parameter mime

    The MIME type of interest.

    Parameter data

    The data value for the given MIME type.

    #### Notes This will overwrite any previous entry for the MIME type.

method types

types: () => string[];
  • Get an array of the MIME types contained within the dataset.

    Returns

    A new array of the MIME types, in order of insertion.

class PromiseDelegate

class PromiseDelegate<T> {}
  • A class which wraps a promise into a delegate object.

    #### Notes This class is useful when the logic to resolve or reject a promise cannot be defined at the point where the promise is created.

constructor

constructor();
  • Construct a new promise delegate.

property promise

readonly promise: Promise<T>;
  • The promise wrapped by the delegate.

method reject

reject: (reason: unknown) => void;
  • Reject the wrapped promise with the given value.

    - The reason for rejecting the promise.

method resolve

resolve: (value: T | PromiseLike<T>) => void;
  • Resolve the wrapped promise with the given value.

    Parameter value

    The value to use for resolving the promise.

class Token

class Token<T> {}
  • A runtime object which captures compile-time type information.

    #### Notes A token captures the compile-time type of an interface or class in an object which can be used at runtime in a type-safe fashion.

constructor

constructor(name: string, description?: string);
  • Construct a new token.

    Parameter name

    A human readable name for the token.

    Parameter description

    Token purpose description for documentation.

property description

readonly description?: string;
  • Token purpose description.

property name

readonly name: string;
  • The human readable name for the token.

    #### Notes This can be useful for debugging and logging.

Interfaces

interface JSONArray

interface JSONArray extends Array<JSONValue> {}
  • A type definition for a JSON array.

interface JSONObject

interface JSONObject {}
  • A type definition for a JSON object.

index signature

[key: string]: JSONValue;

    interface PartialJSONArray

    interface PartialJSONArray extends Array<PartialJSONValue> {}
    • A type definition for a partial JSON array.

      Note: Partial here means that JSON object attributes can be undefined.

    interface PartialJSONObject

    interface PartialJSONObject {}
    • A type definition for a partial JSON object.

      Note: Partial here means that the JSON object attributes can be undefined.

    index signature

    [key: string]: PartialJSONValue | undefined;

      interface ReadonlyJSONArray

      interface ReadonlyJSONArray extends ReadonlyArray<ReadonlyJSONValue> {}
      • A type definition for a readonly JSON array.

      interface ReadonlyJSONObject

      interface ReadonlyJSONObject {}
      • A type definition for a readonly JSON object.

      index signature

      readonly [key: string]: ReadonlyJSONValue;

        interface ReadonlyPartialJSONArray

        interface ReadonlyPartialJSONArray extends ReadonlyArray<ReadonlyPartialJSONValue> {}
        • A type definition for a readonly partial JSON array.

          Note: Partial here means that JSON object attributes can be undefined.

        interface ReadonlyPartialJSONObject

        interface ReadonlyPartialJSONObject {}
        • A type definition for a readonly partial JSON object.

          Note: Partial here means that JSON object attributes can be undefined.

        index signature

        readonly [key: string]: ReadonlyPartialJSONValue | undefined;

          Type Aliases

          type JSONPrimitive

          type JSONPrimitive = boolean | number | string | null;
          • A type alias for a JSON primitive.

          type JSONValue

          type JSONValue = JSONPrimitive | JSONObject | JSONArray;
          • A type alias for a JSON value.

          type PartialJSONValue

          type PartialJSONValue = JSONPrimitive | PartialJSONObject | PartialJSONArray;
          • A type alias for a partial JSON value.

            Note: Partial here means that JSON object attributes can be undefined.

          type ReadonlyJSONValue

          type ReadonlyJSONValue = JSONPrimitive | ReadonlyJSONObject | ReadonlyJSONArray;
          • A type alias for a readonly JSON value.

          type ReadonlyPartialJSONValue

          type ReadonlyPartialJSONValue =
          | JSONPrimitive
          | ReadonlyPartialJSONObject
          | ReadonlyPartialJSONArray;
          • A type alias for a readonly partial JSON value.

            Note: Partial here means that JSON object attributes can be undefined.

          Namespaces

          namespace JSONExt

          namespace JSONExt {}
          • The namespace for JSON-specific functions.

          variable emptyArray

          const emptyArray: ReadonlyJSONArray;
          • A shared frozen empty JSONArray

          variable emptyObject

          const emptyObject: ReadonlyJSONObject;
          • A shared frozen empty JSONObject

          function deepCopy

          deepCopy: <T extends ReadonlyPartialJSONValue>(value: T) => T;
          • Create a deep copy of a JSON value.

            Parameter value

            The JSON value to copy.

            Returns

            A deep copy of the given JSON value.

          function deepEqual

          deepEqual: (
          first: ReadonlyPartialJSONValue,
          second: ReadonlyPartialJSONValue
          ) => boolean;
          • Compare two JSON values for deep equality.

            Parameter first

            The first JSON value of interest.

            Parameter second

            The second JSON value of interest.

            Returns

            true if the values are equivalent, false otherwise.

          function isArray

          isArray: {
          (value: JSONValue): value is JSONArray;
          (value: ReadonlyJSONValue): value is ReadonlyJSONArray;
          (value: PartialJSONValue): value is PartialJSONArray;
          (value: ReadonlyPartialJSONValue): value is ReadonlyPartialJSONArray;
          };
          • Test whether a JSON value is an array.

            Parameter value

            The JSON value of interest.

            Returns

            true if the value is a an array, false otherwise.

          function isObject

          isObject: {
          (value: JSONValue): value is JSONObject;
          (value: ReadonlyJSONValue): value is ReadonlyJSONObject;
          (value: PartialJSONValue): value is PartialJSONObject;
          (value: ReadonlyPartialJSONValue): value is ReadonlyPartialJSONObject;
          };
          • Test whether a JSON value is an object.

            Parameter value

            The JSON value of interest.

            Returns

            true if the value is a an object, false otherwise.

          function isPrimitive

          isPrimitive: (value: ReadonlyPartialJSONValue) => value is JSONPrimitive;
          • Test whether a JSON value is a primitive.

            Parameter value

            The JSON value of interest.

            Returns

            true if the value is a primitive,false otherwise.

          namespace Random

          namespace Random {}
          • The namespace for random number related functionality.

          variable getRandomValues

          const getRandomValues: (buffer: Uint8Array) => void;
          • A function which generates random bytes.

            Parameter buffer

            The Uint8Array to fill with random bytes.

            #### Notes A cryptographically strong random number generator will be used if available. Otherwise, Math.random will be used as a fallback for randomness.

            The following RNGs are supported, listed in order of precedence: - window.crypto.getRandomValues - window.msCrypto.getRandomValues - `require('crypto').randomFillSync - `require('crypto').randomBytes - Math.random

          namespace UUID

          namespace UUID {}
          • The namespace for UUID related functionality.

          function uuid4

          uuid4: () => string;
          • A function which generates UUID v4 identifiers.

            Returns

            A new UUID v4 string.

            #### Notes This implementation complies with RFC 4122.

            This uses Random.getRandomValues() for random bytes, which in turn will use the underlying crypto module of the platform if it is available. The fallback for randomness is Math.random.

          Package Files (7)

          Dependencies (0)

          No dependencies.

          Dev Dependencies (23)

          Peer Dependencies (0)

          No peer dependencies.

          Badge

          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@lumino/coreutils.

          • Markdown
            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@lumino/coreutils)
          • HTML
            <a href="https://www.jsdocs.io/package/@lumino/coreutils"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>