Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
jquery-extendext
Advanced tools
Readme
jQuery.extend with configurable behaviour for arrays.
Well, it's actually pretty good, and is generally sufficient, but it merges arrays in a strange way depending of what you want. Example:
var DEFAULTS = {
operators: ['AND', 'OR', 'XOR']
};
var config = {
operators: ['OR', 'XOR']
};
config = $.extend(true, {}, DEFAULTS, config);
When executing this code, one will expects to get config.operators = ['OR', 'XOR']
, but instead you get ['OR', 'XOR', 'XOR]
, because $.extend
merges arrays like objects as per spec.
Other deep merging utilities I found either have the same behaviour or perform both merge and append on array values (nrf110/deepmerge for example).
jQuery.extendext.js contains a new $.extendext
function with the exact same behaviour as $.extend
if not additional config is provided.
The difference is that it accepts a optional second string argument to specify how arrays should be merged.
jQuery.extendext([deep ,][arrayMode ,] target, object1 [, objectN ] )
replace
, concat
, extend
or default
In this mode, every Array values in target
is replaced by a copy of the same value found in objectN
. The copy is recursive if deep
is true.
var DEFAULTS = {
operators: ['AND', 'OR', 'XOR']
};
var config = {
operators: ['OR', 'XOR']
};
config = $.extendext(true, 'replace', {}, DEFAULTS, config);
assert.deepEqual(config, {
operators: ['OR', 'XOR']
}) // true;
In this mode, Arrays found in both target
and objectN
are always concatenated. If deep
is true, a recursive copy of each value if concatenated instead of the value itself.
var DEFAULTS = {
operators: ['AND', 'OR', 'XOR']
};
var config = {
operators: ['OR', 'XOR']
};
config = $.extendext(true, 'concat', {}, DEFAULTS, config);
assert.deepEqual(config, {
operators: ['AND', 'OR', 'XOR', 'OR', 'XOR']
}) // true;
This is how nrf110/deepmerge works. In this mode, Arrays values are treated a bit differently:
target
and objectN
they are merged recursively or not (depending on deep
option).objectN
is not found in target
, it is pushed at the end of the array.var DEFAULTS = {
operators: ['AND', 'OR', 'XOR']
};
var config = {
operators: ['XOR', 'NAND']
};
config = $.extendext(true, 'extend', {}, DEFAULTS, config);
assert.deepEqual(config, {
operators: ['AND', 'OR', 'XOR', 'NAND']
}) // true;
Same as $.extend
.
var DEFAULTS = {
operators: ['AND', 'OR', 'XOR']
};
var config = {
operators: ['OR', 'XOR']
};
config = $.extendext(true, 'default', {}, DEFAULTS, config);
assert.deepEqual(config, {
operators: ['OR', 'XOR', 'XOR']
}) // true;
A jest test suite is provided in tests
directory.
$.extendext
is tested against core jQuery tests for $.extend
and nrf110/deepmerge
tests (with the difference that extendext, like extend, modifies the first argument where deepmerge does not touch it).
FAQs
jQuery.extend with configurable behaviour for arrays
The npm package jquery-extendext receives a total of 17,606 weekly downloads. As such, jquery-extendext popularity was classified as popular.
We found that jquery-extendext 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.