Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
jpex-defaults
Advanced tools
Core factories for Jpex
This package contains a number of injectable factories for Jpex.
Install via npm
npm install jpex-defaults --save
Node:
const Jpex = require('jpex');
const defaults = require('jpex-defaults');
Jpex.use(defaults);
// Default factories are now available
const t = Jpex.$resolve('$timeout');
Webpack/Browserify:
var Jpex = require('jpex');
var defaults = require('jpex-defaults');
Jpex.use(defaults);
or...
var Jpex = require('jpex');
var defaults = require('jpex-defaults/dist/jpex-defaults');
Jpex.use(defaults);
HTML/Javascript
<script src="node_modules/jpex/dist/jpex.js"></script>
<script src="node_modules/jpex-defaults/dist/jpex-defaults.js"></script>
<script>
// jpex-defaults is automatically registered when imported via script tags
var t = Jpex.$resolve('$timeout');
</script>
$timeout(callback, delay)
$timeout
is the equivalent of the setTimeout
function. The callback function is called after the value of delay has passed. The callback function is only called once.
$interval(callback, delay)
$interval
is the equivalent of the setInterval
function. $interval
will be called repeatedly at the interval set by delay.
$immediate(callback)
$immediate
calls the callback function on the next available event loop. This is the equivalent of setImmediate
in NodeJs or setTimeout(fn, 0)
in a browser.
$log(message, [message2, message3...])
This is a wrapper for the console functions
$log('I am console.log');
$log.log('I am also console.log');
$log.warn('I am console.warn');
$log.error('I am console.error');
$promise(callback)
This wraps up the native Promise
class, without the need for the new
keyword. If using $promise in a browser that doesn't support the Promise object, a polyfill must be attached to the window object. The plugin jpex-web (which also includes this package) automatically sets a polyfill if needed.
Calling $promise will create a new Promise with the provided constructor function.
The function takes two parameters: resolve and reject.
return $promise(function(resolve, reject){
resolve(123);
});
Returns a resolved promise.
return $promise.resolve(123);
Returns a rejected promise.
return $promise.reject().catch(...);
Accepts an array of promises and resolves once all promises have been resolved. If any of the promises is rejected, $promise.all
will be rejected.
$promise.all([$promise(...), $promise.resolve(), 123]);
Accepts an array of promises and resolves when any of the promises has been resolved. If any of the promises is rejected, $promise.all
will be rejected.
$promise.race([$promise(...), $promise.resolve(), 123]);
$typeof(any)
$typeof
provides a function that returns the type of any object. The possible return values are:
var t = $typeof(/a/); // 'regexp'
$copy(object)
The $copy factory allows you to create a copy any object. It can be used as a function, or as an object which contains shallow and deep copy functions.
The shallow copy will copy an object but will not create copies of its properties. So if an object has a property x
which is an object itself, the copied object will have the exact same instance of x.
var obj = { x : [1, 2, 3] };
var shallow = $copy(obj);
$copy.shallow(object)
var obj = { x : [1, 2, 3] };
var shallow = $copy.shallow(obj);
$copy.deep(object)
The deep copy will copy an object and then copy all of that object's properties.
var obj = { x : [1, 2, 3] };
var deep = $copy.deep(obj);
$copy.extend(target, [obj1, obj2...])
The extend method takes any number of arguments and will deep copy the properties of the last arguments onto the first argument. i.e. $copy.extend(a, b, c)
will copy the properties of b
onto a
and then c
onto a
. If b
and c
have the same property, c
's property wins.
There are a couple of rules to keep in mind:
If two objects have the same property, and the type of that property is an object, its properties will be combined. i.e. if b.x.foo
is set and c.x.bah
is set, then a.x
will get both properties foo
and bah
.
If two objects have the same property, and the type of that property is an array, its elements will be overwritten. i.e. if b.x = [1, 2, 3]
and c.x = [4, 5]
then a.x
will be [4,5]
.
var obj = { x : [1, 2, 3] };
var extended = $copy.extend(0, 1); // 1
extended = $copy.extend({}, obj); // { x : [1,2,3] }
extended = $copy.extend({}, obj, {y : 'why'}); // { x : [1,2,3], y : 'why' }
extended = $copy.extend({}, {x : 'first'}, {x : 'second'}); // { x : 'second' }
extended = $copy.extend({}, {x : [1, 2, 3]}, {x : [4, 5, 6]}); // { x : [1, 2, 3, 4, 5, 6]}
FAQs
Core factories for Jpex
The npm package jpex-defaults receives a total of 989 weekly downloads. As such, jpex-defaults popularity was classified as not popular.
We found that jpex-defaults demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.