arc-object
Advanced tools
Comparing version 1.0.3 to 1.1.0
35
index.js
@@ -47,3 +47,3 @@ "use strict"; | ||
//Declare | ||
var $this,keys,key,length,eachBreak; | ||
var $this,keys,key,length; | ||
@@ -66,2 +66,31 @@ //Our context | ||
returnEach(_f,_returnArg,_falseBreak){ | ||
if(is(_f) !== 'function'){ | ||
throw new TypeError('ArcObject.each first argument must be a valid function'); | ||
} | ||
_falseBreak = (_falseBreak === false ? false : true); | ||
//Declare | ||
var $this,keys,key,length,cbReturn; | ||
//Our context | ||
$this = this; | ||
//Etc | ||
keys = Object.keys(this); | ||
length = keys.length; | ||
//Iterate | ||
for(let i=0;i<length;i++){ | ||
key = keys[i]; | ||
cbReturn = _f.call($this,key,this[key],_returnArg); | ||
if(cbReturn === false && _falseBreak){ | ||
break; | ||
} | ||
_returnArg = cbReturn || _returnArg; | ||
} | ||
return _returnArg; | ||
} | ||
//Lazy | ||
@@ -83,3 +112,3 @@ count(){ | ||
keys.sort(); | ||
keys.each(function(_key){ | ||
keys.each(function(_index,_key){ | ||
copy[_key] = $this[_key]; | ||
@@ -158,3 +187,3 @@ delete $this[_key]; | ||
var keys = $this.keys(); | ||
keys.each(function(_key){ | ||
keys.each(function(_index,_key){ | ||
if(_Check.val(_key)){ | ||
@@ -161,0 +190,0 @@ delete $this[_key]; |
{ | ||
"name": "arc-object", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "An object convenience subclass", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
"test": "tap test/*.js --coverage --coverage-report=html" | ||
}, | ||
@@ -24,3 +24,3 @@ "repository": { | ||
"dependencies": { | ||
"arc-array": "^2.0.3", | ||
"arc-array": "3.2.0", | ||
"arc-check": "^1.0.2", | ||
@@ -27,0 +27,0 @@ "arc-is": "^1.0.3" |
@@ -72,2 +72,20 @@ # arc-object [![Build Status](https://travis-ci.org/anyuzer/arc-object.svg?branch=master)](https://travis-ci.org/anyuzer/arc-object) | ||
### .returnEach(callback:Function,returnArg:Mixed[,falseBreak:Boolean]) | ||
Like .each except takes in an argument, passes it into each callback, and mutates it accordingly based on whether or not anything was returned. | ||
By default, returning false breaks the iteration, but this can be optionally switched off by passing in false as the third argument. | ||
```js | ||
//Example of returning returnEach | ||
var users = new ArcObject({'a':'aardvark','b':'brad','c':'documents are boring','d':'Andy'}); | ||
var aUsers = users.returnEach(function(_key,_val,_aUsers){ | ||
if(_val.charAt(0) === 'a'){ | ||
_aUsers.push(_val); | ||
} | ||
return _aUsers; | ||
},[]); | ||
//aUsers contains ['aardvark','Andy'] | ||
``` | ||
### .ksort() | ||
@@ -74,0 +92,0 @@ Rebuild an object by keys (alphabetical) |
21999
13
463
189
+ Addedarc-array@3.2.0(transitive)
- Removedarc-array@2.1.0(transitive)
Updatedarc-array@3.2.0