Skip to content

dandre3000/sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@dandre3000/sandbox

Run code with a temporary globalThis.

Install

npm i @dandre3000/sandbox

Usage

import { createRestrictedGlobalProxy, createSandboxFunction } from '@dandre3000/sandbox'

const sandbox = createRestrictedGlobalProxy()
sandbox.foo = 'bar'

const fn = createSandboxFunction(() => console.log(foo, window, process, userAgent, navigator), sandbox)

fn() // bar undefined undefined undefined undefined

Exports

type RestrictedGlobalProxy = Pick<'Infinity' | 'NaN' | 'undefined' | 'isFinite' |
'isNaN' | 'parseFloat' | 'parseInt' | 'decodeURI' | 'decodeURIComponent' |
'encodeURI' | 'encodeURIComponent' | 'Object' | 'Function' | 'Boolean' | 'Symbol' | 'Error' |
'AggregateError' | 'RangeError' | 'ReferenceError' | 'SyntaxError' | 'TypeError' | 'URIError' |
'Number' | 'BigInt' | 'Math' | 'String' | 'RegExp' | 'Array' | 'Int8Array' | 'Uint8Array' |
'Uint8ClampedArray' | 'Int16Array' | 'Uint16Array' | 'Int32Array' | 'Uint32Array' |
'BigInt64Array' | 'BigUint64Array' | 'Float16Array' | 'Float32Array' | 'Float64Array' | 'Map' |
'Set' | 'WeakMap' | 'WeakSet' | 'ArrayBuffer' | 'DataView' | 'JSON' | 'Iterator' | 'Promise' |
'Reflect' | 'Proxy' | 'Intl' | 'console'> & {
 global: RestrictedGlobalProxy;
 globalThis: RestrictedGlobalProxy;
}

createRestrictedGlobalProxy: () => RestrictedGlobalProxy

createSandboxFunction: createSandboxFunction: (fn: Function, context: any) => Function

License

MIT

About

Run code with a temporary globalThis.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors