@phosphor/coreutils
- Version 1.3.1
- Published
- 25.8 kB
- No dependencies
- BSD-3-Clause license
Install
npm i @phosphor/coreutils
yarn add @phosphor/coreutils
pnpm add @phosphor/coreutils
Overview
PhosphorJS - Core Utilities
Index
Classes
Interfaces
Type Aliases
Namespaces
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: any) => 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: any) => 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);
Construct a new token.
Parameter name
A human readable name for the token.
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 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;
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 ReadonlyJSONValue
type ReadonlyJSONValue = JSONPrimitive | ReadonlyJSONObject | ReadonlyJSONArray;
A type alias for a readonly JSON value.
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 ReadonlyJSONValue>(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: ReadonlyJSONValue, second: ReadonlyJSONValue) => 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;};
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;};
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: ReadonlyJSONValue) => 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.
function getRandomValues
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 underlyingcrypto
module of the platform if it is available. The fallback for randomness isMath.random
.
Package Files (7)
Dependencies (0)
No dependencies.
Dev Dependencies (15)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto 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/@phosphor/coreutils
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@phosphor/coreutils)
- HTML<a href="https://www.jsdocs.io/package/@phosphor/coreutils"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4204 ms. - Missing or incorrect documentation? Open an issue for this package.