0.2.1 • Published 5 years ago

@pakal/get-global v0.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

@pakal/get-global

Source Code Version MIT License Bundle Size TypeScript

Get Global is package from Pakal library

Install

$ yarn add @pakal/get-global

Or

$ npm install --save @pakal/get-global

Use

Module

import {
  default as getGlobal
} from '@pakal/get-global';

Browser

<script src="https://unpkg.com/@pakal/get-global/bundle.umd.min.js"></script>
let {
  getGlobal
} = _;

Examples

 // browser
 getGlobal() === window; // => true
 // worker
 getGlobal() === self; // => true
 // nodejs
 getGlobal() === global; // => true

 getGlobal('Object') === Object; // => true
 getGlobal('NaN'); // => NaN
 getGlobal('String.prototype') === String.prototype; // => true
 getGlobal('Math.foo', 'bar'); // => 'bar'
 getGlobal('Math.zero', 0, true); // => 0
 getGlobal('Math').zero; // => 0
 getGlobal('color'); // => undefined
 typeof color; // => undefined
 getGlobal('color', 'green'); // => 'green'
 typeof color; // => undefined
 getGlobal('color', 'blue', true); // => 'blue'
 color === 'blue'; // => true
 getGlobal('color', 'red', true); // => 'blue'
 color === 'blue'; // => true
 color = 'yellow';
 getGlobal('color', 'black', true); // => 'yellow'
 getGlobal('data'); // => undefined
 getGlobal('data', {name: 'bob'}).name; // => 'bob'
 getGlobal('data'); // => undefined
 getGlobal('data.name', 'david', true); // => 'david'
 getGlobal('data'); // => 'undefined'
 getGlobal('data', {name: 'alice'}, true).name; // => 'alice'
 getGlobal('data.name'); // => 'alice'
 getGlobal('data.name', 'john', true).name; // => 'alice'
 getGlobal('data').name; // => 'alice'
 getGlobal('data').name = 'moshe';
 getGlobal('data.name', 'steve', true); // => 'moshe'

License

Copyright © Yisrael Eliev, Licensed under the MIT license.