Socket
Socket
Sign inDemoInstall

boxed-out

Package Overview
Dependencies
5
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    boxed-out

wrapper for plain Array or Object extending with common each, filter, map, reduce, etc functions


Version published
Weekly downloads
43
decreased by-17.31%
Maintainers
1
Install size
81.7 kB
Created
Weekly downloads
 

Readme

Source

boxed-out

experimental

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.

boxOut(array|object)
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.

argumentdefaultDescription
argnoneobject or array to enhance with boxed-out proxy methods

Functions available on boxed-out argument:

MethodObject ArgArray ArgDescription
filteredPropsyesyesproperty 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
filterPropsyesyes.filter equivalent for objects, takes same argument: callback(value,key,object) and thisArg
mappedPropsyesyesobject property value mapping, similar to map for arrays except builds object with original property name and mapped value
mapPropsyesyesbuilds an array of values returned from callback applied to array/object properties, order of property iteration given by each
copyFilteredyesyescopying of selected properties, filter provides inclusion predicate
copyFilteredNotyesyescopying of not selected properties. ie. filter provides exclusion predicate
eachPropyesyesforEach like for object and array properties. Order of property iteration not guaranteed.
eachyesyesforEach like for objects with Array index type properties iterated first (in increasing order) then non-indexed properties sorted by sort()
eachRightyesyeseach but properties iterated in reverse order
cloneArrayObjectyesyesshallow copy array/object, but array's non-indexed properties are also copied
deleteItemsnoyesdelete array simple (not object or array, etc) items by value, given in array or object properties
arrayLengthyesyesequivalent to array length property for objects. Will find the maximum array index property of an object, for arrays it is just length
deepCloneyesyesdeepClone array/object, with argument for number of levels
mergeDefaultsyesyesmergeDefaults, with options for levels, whether current object is immutable and whether to deepClone source when copying its values
somePropsyesyessome equivalent for object properties
everyPropyesyesevery equivalent for object properties
reducePropsyesyesreduce equivalent for object properties, order of iteration not guaranteed, same as eachProp
reducePropsLeftyesyesreduce equivalent with order given by each
reducePropsRightyesyesreduceRight equivalent for object properties
hasOwnPropertiesyesyesreturns true if object array has own properties, optionally takes an argument for properties to be ignored
filtersynonym for filterPropsArray.prototype.filtercorresponding method for object properties
mapsynonym for mapPropsArray.prototype.mapcorresponding method for object properties
forEachsynonym for eachArray.prototype.forEachcorresponding method for object properties
somesynonym for somePropsArray.prototype.somecorresponding method for object properties
everysynonym for everyPropArray.prototype.everycorresponding method for object properties
reducesynonym for reducePropsLeftArray.prototype.reducecorresponding method for object properties
reduceRightsynonym for reducePropsRightArray.prototype.reduceRightcorresponding method for object properties

Iteration over 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.

Install

Use npm to install.

npm install boxed-out --save

Usage

NPM

License

MIT, see LICENSE.md for details.

Keywords

FAQs

Last updated on 05 Apr 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc