@blocksuite/global
Advanced tools
Comparing version 0.4.0-20230114163139-bef702b to 0.4.0-20230115125610-fb61886
@@ -10,2 +10,5 @@ export declare const SYS_KEYS: Set<string>; | ||
}, expected: Key[]): boolean; | ||
type Allowed = null | undefined | boolean | number | string | Record<string, unknown> | unknown[]; | ||
export declare function assertEquals<T extends Allowed, U extends T>(val: T, expected: U): asserts val is U; | ||
export {}; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -19,2 +19,30 @@ export const SYS_KEYS = new Set(['id', 'flavour', 'children']); | ||
} | ||
export function assertEquals(val, expected) { | ||
const a = isPrimitive(val); | ||
const b = isPrimitive(expected); | ||
if (a && b) { | ||
if (!Object.is(a, b)) { | ||
throw new Error('val is not same as expected'); | ||
} | ||
} | ||
else if (a !== b) { | ||
throw new Error('val is not same as expected'); | ||
} | ||
else { | ||
if (Array.isArray(val) && Array.isArray(expected)) { | ||
if (val.length !== expected.length) { | ||
throw new Error('val is not same as expected'); | ||
} | ||
val.every((x, i) => assertEquals(x, expected[i])); | ||
} | ||
else if (typeof val === 'object' && typeof expected === 'object') { | ||
const obj1 = Object.entries(val); | ||
const obj2 = Object.entries(expected); | ||
if (obj1.length !== obj2.length) { | ||
throw new Error('val is not same as expected'); | ||
} | ||
obj1.every((x, i) => assertEquals(x, obj2[i])); | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=utils.js.map |
@@ -22,2 +22,3 @@ declare module 'quill' { | ||
enable_drag_handle: boolean; | ||
enable_surface: boolean; | ||
readonly: Record<string, boolean>; | ||
@@ -24,0 +25,0 @@ }; |
{ | ||
"name": "@blocksuite/global", | ||
"version": "0.4.0-20230114163139-bef702b", | ||
"version": "0.4.0-20230115125610-fb61886", | ||
"types": "./index.d.ts", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -31,1 +31,38 @@ export const SYS_KEYS = new Set(['id', 'flavour', 'children']); | ||
} | ||
type Allowed = | ||
| null | ||
| undefined | ||
| boolean | ||
| number | ||
| string | ||
| Record<string, unknown> | ||
| unknown[]; | ||
export function assertEquals<T extends Allowed, U extends T>( | ||
val: T, | ||
expected: U | ||
): asserts val is U { | ||
const a = isPrimitive(val); | ||
const b = isPrimitive(expected); | ||
if (a && b) { | ||
if (!Object.is(a, b)) { | ||
throw new Error('val is not same as expected'); | ||
} | ||
} else if (a !== b) { | ||
throw new Error('val is not same as expected'); | ||
} else { | ||
if (Array.isArray(val) && Array.isArray(expected)) { | ||
if (val.length !== expected.length) { | ||
throw new Error('val is not same as expected'); | ||
} | ||
val.every((x, i) => assertEquals(x, expected[i])); | ||
} else if (typeof val === 'object' && typeof expected === 'object') { | ||
const obj1 = Object.entries(val as Record<string, unknown>); | ||
const obj2 = Object.entries(expected as Record<string, unknown>); | ||
if (obj1.length !== obj2.length) { | ||
throw new Error('val is not same as expected'); | ||
} | ||
obj1.every((x, i) => assertEquals(x, obj2[i])); | ||
} | ||
} | ||
} |
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
54699
247
35