@lumino/coreutils
Advanced tools
Comparing version 1.8.2 to 1.9.0
@@ -362,4 +362,5 @@ // Copyright (c) Jupyter Development Team. | ||
// Look up the crypto module if available. | ||
var crypto = ((typeof window !== 'undefined' && (window.crypto || window.msCrypto)) || | ||
(typeof require !== 'undefined' && require('crypto')) || null); | ||
var crypto = (typeof window !== 'undefined' && (window.crypto || window.msCrypto)) || | ||
(typeof require !== 'undefined' && require('crypto')) || | ||
null; | ||
// Modern browsers and IE 11 | ||
@@ -391,5 +392,5 @@ if (crypto && typeof crypto.getRandomValues === 'function') { | ||
if (i % 4 === 0) { | ||
value = Math.random() * 0xFFFFFFFF >>> 0; | ||
value = (Math.random() * 0xffffffff) >>> 0; | ||
} | ||
buffer[i] = value & 0xFF; | ||
buffer[i] = value & 0xff; | ||
value >>>= 8; | ||
@@ -466,5 +467,5 @@ } | ||
// Set the UUID version number to 4. | ||
bytes[6] = 0x40 | (bytes[6] & 0x0F); | ||
bytes[6] = 0x40 | (bytes[6] & 0x0f); | ||
// Set the clock sequence bit to the RFC spec. | ||
bytes[8] = 0x80 | (bytes[8] & 0x3F); | ||
bytes[8] = 0x80 | (bytes[8] & 0x3f); | ||
// Assemble the UUID string. | ||
@@ -471,0 +472,0 @@ return (lut[bytes[0]] + |
@@ -368,4 +368,5 @@ (function (global, factory) { | ||
// Look up the crypto module if available. | ||
var crypto = ((typeof window !== 'undefined' && (window.crypto || window.msCrypto)) || | ||
(typeof require !== 'undefined' && require('crypto')) || null); | ||
var crypto = (typeof window !== 'undefined' && (window.crypto || window.msCrypto)) || | ||
(typeof require !== 'undefined' && require('crypto')) || | ||
null; | ||
// Modern browsers and IE 11 | ||
@@ -397,5 +398,5 @@ if (crypto && typeof crypto.getRandomValues === 'function') { | ||
if (i % 4 === 0) { | ||
value = Math.random() * 0xFFFFFFFF >>> 0; | ||
value = (Math.random() * 0xffffffff) >>> 0; | ||
} | ||
buffer[i] = value & 0xFF; | ||
buffer[i] = value & 0xff; | ||
value >>>= 8; | ||
@@ -472,5 +473,5 @@ } | ||
// Set the UUID version number to 4. | ||
bytes[6] = 0x40 | (bytes[6] & 0x0F); | ||
bytes[6] = 0x40 | (bytes[6] & 0x0f); | ||
// Set the clock sequence bit to the RFC spec. | ||
bytes[8] = 0x80 | (bytes[8] & 0x3F); | ||
bytes[8] = 0x80 | (bytes[8] & 0x3f); | ||
// Assemble the UUID string. | ||
@@ -477,0 +478,0 @@ return (lut[bytes[0]] + |
{ | ||
"name": "@lumino/coreutils", | ||
"version": "1.8.2", | ||
"version": "1.9.0", | ||
"description": "Lumino Core Utilities", | ||
@@ -79,4 +79,3 @@ "homepage": "https://github.com/jupyterlab/lumino", | ||
"access": "public" | ||
}, | ||
"gitHead": "79b0d03a9d78fbc7055114bdafbd9d5d531490ce" | ||
} | ||
} |
150
src/json.ts
@@ -11,52 +11,44 @@ // Copyright (c) Jupyter Development Team. | ||
/** | ||
* A type alias for a JSON primitive. | ||
*/ | ||
export | ||
type JSONPrimitive = boolean | number | string | null; | ||
export type JSONPrimitive = boolean | number | string | null; | ||
/** | ||
* A type alias for a JSON value. | ||
*/ | ||
export | ||
type JSONValue = JSONPrimitive | JSONObject | JSONArray; | ||
export type JSONValue = JSONPrimitive | JSONObject | JSONArray; | ||
/** | ||
* A type definition for a JSON object. | ||
*/ | ||
export | ||
interface JSONObject { [key: string]: JSONValue; } | ||
export interface JSONObject { | ||
[key: string]: JSONValue; | ||
} | ||
/** | ||
* A type definition for a JSON array. | ||
*/ | ||
export | ||
interface JSONArray extends Array<JSONValue> { } | ||
export interface JSONArray extends Array<JSONValue> {} | ||
/** | ||
* A type definition for a readonly JSON object. | ||
*/ | ||
export | ||
interface ReadonlyJSONObject { readonly [key: string]: ReadonlyJSONValue; } | ||
export interface ReadonlyJSONObject { | ||
readonly [key: string]: ReadonlyJSONValue; | ||
} | ||
/** | ||
* A type definition for a readonly JSON array. | ||
*/ | ||
export | ||
interface ReadonlyJSONArray extends ReadonlyArray<ReadonlyJSONValue> { } | ||
export interface ReadonlyJSONArray extends ReadonlyArray<ReadonlyJSONValue> {} | ||
/** | ||
* A type alias for a readonly JSON value. | ||
*/ | ||
export | ||
type ReadonlyJSONValue = JSONPrimitive | ReadonlyJSONObject | ReadonlyJSONArray; | ||
export type ReadonlyJSONValue = | ||
| JSONPrimitive | ||
| ReadonlyJSONObject | ||
| ReadonlyJSONArray; | ||
/** | ||
@@ -67,6 +59,7 @@ * A type alias for a partial JSON value. | ||
*/ | ||
export | ||
type PartialJSONValue = JSONPrimitive | PartialJSONObject | PartialJSONArray; | ||
export type PartialJSONValue = | ||
| JSONPrimitive | ||
| PartialJSONObject | ||
| PartialJSONArray; | ||
/** | ||
@@ -77,6 +70,6 @@ * A type definition for a partial JSON object. | ||
*/ | ||
export | ||
interface PartialJSONObject { [key: string]: PartialJSONValue | undefined; } | ||
export interface PartialJSONObject { | ||
[key: string]: PartialJSONValue | undefined; | ||
} | ||
/** | ||
@@ -87,6 +80,4 @@ * A type definition for a partial JSON array. | ||
*/ | ||
export | ||
interface PartialJSONArray extends Array<PartialJSONValue> { } | ||
export interface PartialJSONArray extends Array<PartialJSONValue> {} | ||
/** | ||
@@ -97,6 +88,6 @@ * A type definition for a readonly partial JSON object. | ||
*/ | ||
export | ||
interface ReadonlyPartialJSONObject { readonly [key: string]: ReadonlyPartialJSONValue | undefined; } | ||
export interface ReadonlyPartialJSONObject { | ||
readonly [key: string]: ReadonlyPartialJSONValue | undefined; | ||
} | ||
/** | ||
@@ -107,6 +98,5 @@ * A type definition for a readonly partial JSON array. | ||
*/ | ||
export | ||
interface ReadonlyPartialJSONArray extends ReadonlyArray<ReadonlyPartialJSONValue> { } | ||
export interface ReadonlyPartialJSONArray | ||
extends ReadonlyArray<ReadonlyPartialJSONValue> {} | ||
/** | ||
@@ -117,16 +107,15 @@ * A type alias for a readonly partial JSON value. | ||
*/ | ||
export | ||
type ReadonlyPartialJSONValue = JSONPrimitive | ReadonlyPartialJSONObject | ReadonlyPartialJSONArray; | ||
export type ReadonlyPartialJSONValue = | ||
| JSONPrimitive | ||
| ReadonlyPartialJSONObject | ||
| ReadonlyPartialJSONArray; | ||
/** | ||
* The namespace for JSON-specific functions. | ||
*/ | ||
export | ||
namespace JSONExt { | ||
export namespace JSONExt { | ||
/** | ||
* A shared frozen empty JSONObject | ||
*/ | ||
export | ||
const emptyObject = Object.freeze({}) as ReadonlyJSONObject; | ||
export const emptyObject = Object.freeze({}) as ReadonlyJSONObject; | ||
@@ -136,4 +125,3 @@ /** | ||
*/ | ||
export | ||
const emptyArray = Object.freeze([]) as ReadonlyJSONArray; | ||
export const emptyArray = Object.freeze([]) as ReadonlyJSONArray; | ||
@@ -147,4 +135,5 @@ /** | ||
*/ | ||
export | ||
function isPrimitive(value: ReadonlyPartialJSONValue): value is JSONPrimitive { | ||
export function isPrimitive( | ||
value: ReadonlyPartialJSONValue | ||
): value is JSONPrimitive { | ||
return ( | ||
@@ -165,12 +154,9 @@ value === null || | ||
*/ | ||
export | ||
function isArray(value: JSONValue): value is JSONArray; | ||
export | ||
function isArray(value: ReadonlyJSONValue): value is ReadonlyJSONArray; | ||
export | ||
function isArray(value: PartialJSONValue): value is PartialJSONArray; | ||
export | ||
function isArray(value: ReadonlyPartialJSONValue): value is ReadonlyPartialJSONArray; | ||
export | ||
function isArray(value: ReadonlyPartialJSONValue): boolean { | ||
export function isArray(value: JSONValue): value is JSONArray; | ||
export function isArray(value: ReadonlyJSONValue): value is ReadonlyJSONArray; | ||
export function isArray(value: PartialJSONValue): value is PartialJSONArray; | ||
export function isArray( | ||
value: ReadonlyPartialJSONValue | ||
): value is ReadonlyPartialJSONArray; | ||
export function isArray(value: ReadonlyPartialJSONValue): boolean { | ||
return Array.isArray(value); | ||
@@ -186,12 +172,11 @@ } | ||
*/ | ||
export | ||
function isObject(value: JSONValue): value is JSONObject; | ||
export | ||
function isObject(value: ReadonlyJSONValue): value is ReadonlyJSONObject; | ||
export | ||
function isObject(value: PartialJSONValue): value is PartialJSONObject; | ||
export | ||
function isObject(value: ReadonlyPartialJSONValue): value is ReadonlyPartialJSONObject; | ||
export | ||
function isObject(value: ReadonlyPartialJSONValue): boolean { | ||
export function isObject(value: JSONValue): value is JSONObject; | ||
export function isObject( | ||
value: ReadonlyJSONValue | ||
): value is ReadonlyJSONObject; | ||
export function isObject(value: PartialJSONValue): value is PartialJSONObject; | ||
export function isObject( | ||
value: ReadonlyPartialJSONValue | ||
): value is ReadonlyPartialJSONObject; | ||
export function isObject(value: ReadonlyPartialJSONValue): boolean { | ||
return !isPrimitive(value) && !isArray(value); | ||
@@ -209,4 +194,6 @@ } | ||
*/ | ||
export | ||
function deepEqual(first: ReadonlyPartialJSONValue, second: ReadonlyPartialJSONValue): boolean { | ||
export function deepEqual( | ||
first: ReadonlyPartialJSONValue, | ||
second: ReadonlyPartialJSONValue | ||
): boolean { | ||
// Check referential and primitive equality first. | ||
@@ -233,7 +220,13 @@ if (first === second) { | ||
if (a1 && a2) { | ||
return deepArrayEqual(first as ReadonlyPartialJSONArray, second as ReadonlyPartialJSONArray); | ||
return deepArrayEqual( | ||
first as ReadonlyPartialJSONArray, | ||
second as ReadonlyPartialJSONArray | ||
); | ||
} | ||
// At this point, they must both be objects. | ||
return deepObjectEqual(first as ReadonlyPartialJSONObject, second as ReadonlyPartialJSONObject); | ||
return deepObjectEqual( | ||
first as ReadonlyPartialJSONObject, | ||
second as ReadonlyPartialJSONObject | ||
); | ||
} | ||
@@ -248,4 +241,3 @@ | ||
*/ | ||
export | ||
function deepCopy<T extends ReadonlyPartialJSONValue>(value: T): T { | ||
export function deepCopy<T extends ReadonlyPartialJSONValue>(value: T): T { | ||
// Do nothing for primitive values. | ||
@@ -268,3 +260,6 @@ if (isPrimitive(value)) { | ||
*/ | ||
function deepArrayEqual(first: ReadonlyPartialJSONArray, second: ReadonlyPartialJSONArray): boolean { | ||
function deepArrayEqual( | ||
first: ReadonlyPartialJSONArray, | ||
second: ReadonlyPartialJSONArray | ||
): boolean { | ||
// Check referential equality first. | ||
@@ -294,3 +289,6 @@ if (first === second) { | ||
*/ | ||
function deepObjectEqual(first: ReadonlyPartialJSONObject, second: ReadonlyPartialJSONObject): boolean { | ||
function deepObjectEqual( | ||
first: ReadonlyPartialJSONObject, | ||
second: ReadonlyPartialJSONObject | ||
): boolean { | ||
// Check referential equality first. | ||
@@ -297,0 +295,0 @@ if (first === second) { |
@@ -11,3 +11,2 @@ // Copyright (c) Jupyter Development Team. | ||
/** | ||
@@ -22,4 +21,3 @@ * An object which stores MIME data for general application use. | ||
*/ | ||
export | ||
class MimeData { | ||
export class MimeData { | ||
/** | ||
@@ -26,0 +24,0 @@ * Get an array of the MIME types contained within the dataset. |
@@ -11,3 +11,2 @@ // Copyright (c) Jupyter Development Team. | ||
/** | ||
@@ -20,4 +19,3 @@ * A class which wraps a promise into a delegate object. | ||
*/ | ||
export | ||
class PromiseDelegate<T> { | ||
export class PromiseDelegate<T> { | ||
/** | ||
@@ -24,0 +22,0 @@ * Construct a new promise delegate. |
@@ -13,11 +13,9 @@ // Copyright (c) Jupyter Development Team. | ||
// hard dependency on both. This package must run on node. | ||
declare var window: any; | ||
declare var require: any; | ||
declare let window: any; | ||
declare let require: any; | ||
/** | ||
* The namespace for random number related functionality. | ||
*/ | ||
export | ||
namespace Random { | ||
export namespace Random { | ||
/** | ||
@@ -40,9 +38,8 @@ * A function which generates random bytes. | ||
*/ | ||
export | ||
const getRandomValues = (() => { | ||
export const getRandomValues = (() => { | ||
// Look up the crypto module if available. | ||
const crypto: any = ( | ||
const crypto: any = | ||
(typeof window !== 'undefined' && (window.crypto || window.msCrypto)) || | ||
(typeof require !== 'undefined' && require('crypto')) || null | ||
); | ||
(typeof require !== 'undefined' && require('crypto')) || | ||
null; | ||
@@ -53,3 +50,3 @@ // Modern browsers and IE 11 | ||
return crypto.getRandomValues(buffer); | ||
} | ||
}; | ||
} | ||
@@ -61,3 +58,3 @@ | ||
return crypto.randomFillSync(buffer); | ||
} | ||
}; | ||
} | ||
@@ -72,3 +69,3 @@ | ||
} | ||
} | ||
}; | ||
} | ||
@@ -81,9 +78,9 @@ | ||
if (i % 4 === 0) { | ||
value = Math.random() * 0xFFFFFFFF >>> 0; | ||
value = (Math.random() * 0xffffffff) >>> 0; | ||
} | ||
buffer[i] = value & 0xFF; | ||
buffer[i] = value & 0xff; | ||
value >>>= 8; | ||
} | ||
} | ||
}; | ||
})(); | ||
} |
@@ -11,3 +11,2 @@ // Copyright (c) Jupyter Development Team. | ||
/** | ||
@@ -20,4 +19,3 @@ * A runtime object which captures compile-time type information. | ||
*/ | ||
export | ||
class Token<T> { | ||
export class Token<T> { | ||
/** | ||
@@ -24,0 +22,0 @@ * Construct a new token. |
@@ -10,12 +10,8 @@ // Copyright (c) Jupyter Development Team. | ||
|----------------------------------------------------------------------------*/ | ||
import { | ||
Random | ||
} from './random'; | ||
import { Random } from './random'; | ||
/** | ||
* The namespace for UUID related functionality. | ||
*/ | ||
export | ||
namespace UUID { | ||
export namespace UUID { | ||
/** | ||
@@ -33,4 +29,3 @@ * A function which generates UUID v4 identifiers. | ||
*/ | ||
export | ||
const uuid4 = (() => { | ||
export const uuid4 = (() => { | ||
// Create a 16 byte array to hold the random values. | ||
@@ -58,6 +53,6 @@ const bytes = new Uint8Array(16); | ||
// Set the UUID version number to 4. | ||
bytes[6] = 0x40 | (bytes[6] & 0x0F); | ||
bytes[6] = 0x40 | (bytes[6] & 0x0f); | ||
// Set the clock sequence bit to the RFC spec. | ||
bytes[8] = 0x80 | (bytes[8] & 0x3F); | ||
bytes[8] = 0x80 | (bytes[8] & 0x3f); | ||
@@ -70,12 +65,12 @@ // Assemble the UUID string. | ||
lut[bytes[3]] + | ||
'-' + | ||
'-' + | ||
lut[bytes[4]] + | ||
lut[bytes[5]] + | ||
'-' + | ||
'-' + | ||
lut[bytes[6]] + | ||
lut[bytes[7]] + | ||
'-' + | ||
'-' + | ||
lut[bytes[8]] + | ||
lut[bytes[9]] + | ||
'-' + | ||
'-' + | ||
lut[bytes[10]] + | ||
@@ -88,4 +83,4 @@ lut[bytes[11]] + | ||
); | ||
} | ||
}; | ||
})(); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
1944
154377
28