@blocksuite/global
Advanced tools
Comparing version 0.4.0-20230124211050-22f6e52 to 0.4.0-20230125204655-410ba23
@@ -20,3 +20,4 @@ export { isFirefox, isWeb, caretRangeFromPoint } from './utils/web.js'; | ||
export declare function assertEquals<T extends Allowed, U extends T>(val: T, expected: U): asserts val is U; | ||
export declare function isEqual<T extends Allowed, U extends T>(val: T, expected: U): boolean; | ||
export declare function sleep(ms: number): Promise<void>; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -30,2 +30,7 @@ export { isFirefox, isWeb, caretRangeFromPoint } from './utils/web.js'; | ||
export function assertEquals(val, expected) { | ||
if (!isEqual(val, expected)) { | ||
throw new Error('val is not same as expected'); | ||
} | ||
} | ||
export function isEqual(val, expected) { | ||
const a = isPrimitive(val); | ||
@@ -35,7 +40,7 @@ const b = isPrimitive(expected); | ||
if (!Object.is(val, expected)) { | ||
throw new Error('val is not same as expected'); | ||
return false; | ||
} | ||
} | ||
else if (a !== b) { | ||
throw new Error('val is not same as expected'); | ||
return false; | ||
} | ||
@@ -45,5 +50,5 @@ else { | ||
if (val.length !== expected.length) { | ||
throw new Error('val is not same as expected'); | ||
return false; | ||
} | ||
val.every((x, i) => assertEquals(x, expected[i])); | ||
return val.every((x, i) => isEqual(x, expected[i])); | ||
} | ||
@@ -54,7 +59,8 @@ else if (typeof val === 'object' && typeof expected === 'object') { | ||
if (obj1.length !== obj2.length) { | ||
throw new Error('val is not same as expected'); | ||
return false; | ||
} | ||
obj1.every((x, i) => assertEquals(x, obj2[i])); | ||
return obj1.every((x, i) => isEqual(x, obj2[i])); | ||
} | ||
} | ||
return true; | ||
} | ||
@@ -61,0 +67,0 @@ export async function sleep(ms) { |
{ | ||
"name": "@blocksuite/global", | ||
"version": "0.4.0-20230124211050-22f6e52", | ||
"version": "0.4.0-20230125204655-410ba23", | ||
"types": "./index.d.ts", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -62,2 +62,11 @@ export { isFirefox, isWeb, caretRangeFromPoint } from './utils/web.js'; | ||
): asserts val is U { | ||
if (!isEqual(val, expected)) { | ||
throw new Error('val is not same as expected'); | ||
} | ||
} | ||
export function isEqual<T extends Allowed, U extends T>( | ||
val: T, | ||
expected: U | ||
): boolean { | ||
const a = isPrimitive(val); | ||
@@ -67,12 +76,12 @@ const b = isPrimitive(expected); | ||
if (!Object.is(val, expected)) { | ||
throw new Error('val is not same as expected'); | ||
return false; | ||
} | ||
} else if (a !== b) { | ||
throw new Error('val is not same as expected'); | ||
return false; | ||
} else { | ||
if (Array.isArray(val) && Array.isArray(expected)) { | ||
if (val.length !== expected.length) { | ||
throw new Error('val is not same as expected'); | ||
return false; | ||
} | ||
val.every((x, i) => assertEquals(x, expected[i])); | ||
return val.every((x, i) => isEqual(x, expected[i])); | ||
} else if (typeof val === 'object' && typeof expected === 'object') { | ||
@@ -82,7 +91,8 @@ const obj1 = Object.entries(val as Record<string, unknown>); | ||
if (obj1.length !== obj2.length) { | ||
throw new Error('val is not same as expected'); | ||
return false; | ||
} | ||
obj1.every((x, i) => assertEquals(x, obj2[i])); | ||
return obj1.every((x, i) => isEqual(x, obj2[i])); | ||
} | ||
} | ||
return true; | ||
} | ||
@@ -89,0 +99,0 @@ |
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
217774
54
2585