@pii/scope

A library to create new global scopes

Usage no npm install needed!

<script type="module">
  import piiScope from 'https://cdn.skypack.dev/@pii/scope';
</script>

README

Pii Scope

Pii Scope is library to create new global scopes

js-standard-style Build Status (linux, Mac) Build status (Windows) Coverage Status

NPM

Installation

npm i -S @pii/scope

Requirements

  • NodeJS version >= 6

Documentation

Examples

Here is a simple example to get you started:

index.js

import scope from '@pii/scope'
// or require for ES5 
// const scope = require('@pii/scope').default

const Test1 = scope.New(require.resolve('./test'))

const t1 = new Test1()
t1.set()
t1.log()

const list = [1,2,3,4,5,6,7,8,9]
list.forEach(_ => {
  const Test2 = scope.New(require.resolve('./test'))
  const t2 = new Test2()
  t2.log()
})

test.js

class Test {
  set() {
    global.testVar = 3.1415
  }
  log() {
    console.log(global.testVar || Math.random())
  }
}

module.exports = Test

License

This project is MIT licensed.

js-standard-style