Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
can-globals
Advanced tools
This module provides a dependency injection container. Modules may define a key and specify a default value (which can be static, cached lazy, or dynamic lazy), but other code can set and reset the value as needed. There is also an event system, for alert
This module provides a dependency injection container. Modules may define
a key and specify a default value (which can be static, cached lazy, or dynamic lazy), but other code can set
and reset
the value as needed. There is also an event system, for alerting on value changes, both specific to a key and for any key.
params
String
- The key value to create.Any
|| Function
- The default value. If this is a function, its return value will be used.Boolean
(optional) - True to cache the result of the value function.Defines a new global called key
, who's value defaults to value
(if it is not a function), or lazily to the return of value
(if it is a function). If value is a function and cache
is truthy, the the value function will only be called once, and that result used for all future calls.
params
String
- The key value to access.Returns the current value at key
. If no value has been set, it will return the default value (if it is not a function). If the default value is a function, it will return the output of the function. This execution is cached if the cache flag was set on initialization.
get
ting a key which was not previously define
d will result in an error.
params
String
- The key value to access.Any
- The new value.Sets the new value at key
. Will override previously set values, but preserves the default (see delete
).
set
ting a key which was not previously define
d will result in an error.
params
String
- The key value to access.Deletes the current value at key
. Future get
s will use the default value.
reset
ting a key which was not previously define
d will result in an error.
params
String
- The key value to observe.Function
- The observer callback.Calls observer
each time the value of key
is set
or reset
. For no key, observer
will be called each time any value is set
or reset
.
on
ing a key which was not previously define
d will result in an error. Will not trigger for changes to the return value of lazy defaults.
params
String
- The key value to observe.Function
- The observer callback.Removes observer
from future change events for key
. For no key, removes observer
from future change events for all keys (must have called on
with no key).
off
ing a key which was not previously define
d will result in an error. off
ing an observer which was not previously on
ed for a key will be silently ignored.
params
String
- The key value to access.Creates an export, for preserving legacy functionality. Returns a function which is get
(no arguments), set
(one non-unidentified argument), and reset
(one unidentified argument).
makeExport
ing a key which was not previously define
d will result in an error.
// Define the global key's default value to the window object
globals.define('global', window);
globals.get('window');
// To make the value lazy you can set it to a function
globals.define('isBrowserWindow', function() {
return typeof window !== 'undefined' &&
typeof document !== 'undefined' && typeof SimpleDOM === 'undefined';
});
globals.get('isBrowserWindow'); // will call the provided function every time
// A third argument of true is passed to enable caching
// The function is called once and the returned value is cached for the next use
globals.define('isWebkit', function() {
var div = document.createElement('div');
return 'WebkitTransition' in div.style;
}, true);
globals.get('isWebkit'); // will call the provided function only the first time
// To make the value a method, it must lazily return a function.
globals.define('isRoot', function() {
return function(pathname) {
return (pathname || window.location.pathname) === '/';
};
});
globals.get('isRoot')();
globals.define('global', window);
globals.set('global', {}); // Overwrite global with an empty object
globals.reset('global'); // Restore to default
globals.get('global') === window;
FAQs
This module provides a dependency injection container. Modules may define a key and specify a default value (which can be static, cached lazy, or dynamic lazy), but other code can set and reset the value as needed. There is also an event system, for alert
The npm package can-globals receives a total of 609 weekly downloads. As such, can-globals popularity was classified as not popular.
We found that can-globals demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.