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.
boxed-out
Advanced tools
Readme
Small utility library wrapping plain Array
or Object
to extend with each, map, filter,
reduce using indeterminate ordering, left to right, right to left that operate on own properties
of array or object.
To simulate break return BREAK
or RETURN
, to simulate return
return BREAK(value)
or
RETURN(value)
both are equivalent but the one communicating the right intent should be used.
const boxOut = require('boxed-immutable').boxOut;
const boxedOut = boxOut(arg);
Used to construct a boxed-out object or array that has the extra prototype functions for iterating over own properties. Does not provide immutability or modification tracking, only prototype convenience functions. This adds ability to use the same functions on regular objects and arrays. It also enables using filter, map, reduce, etc to be used on Object properties and on Array properties, not just integer indexed properties.
argument | default | Description |
---|---|---|
arg | none | object or array to enhance with boxed-out proxy methods |
Functions available on boxed-out argument:
Method | Object Arg | Array Arg | Description |
---|---|---|---|
filteredProps | yes | yes | property extraction to new object/array using filter value, array, object or function, this is copyFiltered applied to a new instance with this as the source |
filterProps | yes | yes | .filter equivalent for objects, takes same argument: callback(value,key,object) and thisArg |
mappedProps | yes | yes | object property value mapping, similar to map for arrays except builds object with original property name and mapped value |
mapProps | yes | yes | builds an array of values returned from callback applied to array/object properties, order of property iteration given by each |
copyFiltered | yes | yes | copying of selected properties, filter provides inclusion predicate |
copyFilteredNot | yes | yes | copying of not selected properties. ie. filter provides exclusion predicate |
eachProp | yes | yes | forEach like for object and array properties. Order of property iteration not guaranteed. |
each | yes | yes | forEach like for objects with Array index type properties iterated first (in increasing order) then non-indexed properties sorted by sort() |
eachRight | yes | yes | each but properties iterated in reverse order |
cloneArrayObject | yes | yes | shallow copy array/object, but array's non-indexed properties are also copied |
deleteItems | no | yes | delete array simple (not object or array, etc) items by value, given in array or object properties |
arrayLength | yes | yes | equivalent to array length property for objects. Will find the maximum array index property of an object, for arrays it is just length |
deepClone | yes | yes | deepClone array/object, with argument for number of levels |
mergeDefaults | yes | yes | mergeDefaults, with options for levels, whether current object is immutable and whether to deepClone source when copying its values |
someProps | yes | yes | some equivalent for object properties |
everyProp | yes | yes | every equivalent for object properties |
reduceProps | yes | yes | reduce equivalent for object properties, order of iteration not guaranteed, same as eachProp |
reducePropsLeft | yes | yes | reduce equivalent with order given by each |
reducePropsRight | yes | yes | reduceRight equivalent for object properties |
hasOwnProperties | yes | yes | returns true if object array has own properties, optionally takes an argument for properties to be ignored |
filter | synonym for filterProps | Array.prototype.filter | corresponding method for object properties |
map | synonym for mapProps | Array.prototype.map | corresponding method for object properties |
forEach | synonym for each | Array.prototype.forEach | corresponding method for object properties |
some | synonym for someProps | Array.prototype.some | corresponding method for object properties |
every | synonym for everyProp | Array.prototype.every | corresponding method for object properties |
reduce | synonym for reducePropsLeft | Array.prototype.reduce | corresponding method for object properties |
reduceRight | synonym for reducePropsRight | Array.prototype.reduceRight | corresponding method for object properties |
The iteration functions all implement a mechanism for the callback
function to break out of
the loop similar to how it can be done in a regular loop. Lambda iteration is a PITA
for some
applications without the ability to cut the iteration short.
To break out of an iteration the callback can return BREAK
a value defined in the
boxedImmutable.util
library. eachProp
, each
and eachRight
also have a mechanism to return
a value which the callback can set by returning BREAK(arg)
. With these two mechanisms it is
possible to break out of an iteration and have these iterators return a value the same way it
can be done in regular looping constructs.
To prepare a default return value before invoking a callback which can potentially use the
simple BREAK
return value, you can use BREAK.setDefault(arg)
, returning BREAK
will then be
equivalent to returning BREAK(arg)
.
Some iterators define the default value that will be returned if a callback BREAKs
our of a
loop or ignore the value returned through BREAK where their return value is determined by their
operation.
Use npm to install.
npm install boxed-out --save
MIT, see LICENSE.md for details.
FAQs
wrapper for plain Array or Object extending with common each, filter, map, reduce, etc functions
The npm package boxed-out receives a total of 19 weekly downloads. As such, boxed-out popularity was classified as not popular.
We found that boxed-out 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.