MCPcopy Create free account
hub / github.com/R-js/libRmath.js / shims

Function shims

scripts/rollup.build.mjs:18–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16const version = pkg.version;
17
18function shims() {
19 // for browser, mimic with WebApi the nodejs "crypto" https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback
20 const cryptoStub = `export function randomBytes(n) {
21 return {
22 readUInt32BE(offset = 0) {
23 if (n - offset < 4) {
24 throw new RangeError('[ERR_BUFFER_OUT_OF_BOUNDS]: Attempt to write outside buffer bounds');
25 }
26 const sampler = new Uint8Array(n);
27 globalThis.crypto.getRandomValues(sampler);
28 const dv = new DataView(sampler.buffer);
29 return dv.getUint32(offset, false);
30 },
31 };
32 }`;
33 return {
34 name: 'stubbing for browser',
35 async resolveId(source, importer) {
36 if (!importer) {
37 return null; // skip entry files
38 }
39 if (source.includes('crypto')) {
40 return source;
41 }
42 return null;
43 },
44 async load(id) {
45 if (id.includes('crypto')) {
46 return cryptoStub;
47 }
48 return null;
49 }
50 };
51}
52// see below for details on the options
53const inputOptions = {
54 input: {

Callers 1

rollup.build.mjsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected