MCPcopy Create free account
hub / github.com/ICBNetwork/web3-Wallet / makeAssert

Function makeAssert

ses.cjs:1811–1897  ·  view source on GitHub ↗
(optRaise=  undefined, unredacted=  false)

Source from the content-addressed store, hash-verified

1809 * @type {MakeAssert}
1810 */
1811const makeAssert= (optRaise= undefined, unredacted= false)=> {
1812 const details= unredacted? unredactedDetails: redactedDetails;
1813 const assertFailedDetails= details `Check failed`;
1814
1815 /** @type {AssertFail} */
1816 const fail= (
1817 optDetails= assertFailedDetails,
1818 ErrorConstructor= globalThis.Error)=>
1819 {
1820 const reason= makeError(optDetails, ErrorConstructor);
1821 if( optRaise!== undefined) {
1822 optRaise(reason);
1823 }
1824 throw reason;
1825 };
1826 freeze(fail);
1827
1828 /** @type {FailTag} */
1829 const Fail= (template, ...args)=> fail(details(template, ...args));
1830
1831 // Don't freeze or export `baseAssert` until we add methods.
1832 // TODO If I change this from a `function` function to an arrow
1833 // function, I seem to get type errors from TypeScript. Why?
1834 /** @type {BaseAssert} */
1835 function baseAssert(
1836 flag,
1837 optDetails= undefined,
1838 ErrorConstructor= undefined)
1839 {
1840 flag|| fail(optDetails, ErrorConstructor);
1841 }
1842
1843 /** @type {AssertEqual} */
1844 const equal= (
1845 actual,
1846 expected,
1847 optDetails= undefined,
1848 ErrorConstructor= undefined)=>
1849 {
1850 is(actual, expected)||
1851 fail(
1852 optDetails|| details `Expected ${actual} is same as ${expected}`,
1853 ErrorConstructor|| RangeError);
1854
1855 };
1856 freeze(equal);
1857
1858 /** @type {AssertTypeof} */
1859 const assertTypeof= (specimen, typename, optDetails)=> {
1860 // This will safely fall through if typename is not a string,
1861 // which is what we want.
1862 // eslint-disable-next-line valid-typeof
1863 if( typeof specimen=== typename) {
1864 return;
1865 }
1866 typeof typename=== 'string'|| Fail `${quote(typename)} must be a string`;
1867
1868 if( optDetails=== undefined) {

Callers 2

ses.cjsFile · 0.85
repairIntrinsicsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected