Package Exports
- easy-loop
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (easy-loop) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
easy-loop
쉬운 동기식 반복 처리:) (easy sync loop processing)
Comment
1) Method
: 모두 같은 동작이며 편리한 방법을 사용하세요.(All same)
var loop = require('../lib/easy-loop');
loop() == loop.for() == loop.while() == loop.loop()
2) Arguments
(1) Array or Object - require
(2) process function - require
(3) callback function - option
Examples
var loop = require('easy-loop');
var arr = [1,2,3,4,5];
console.log("Case1 Start => Array");
loop(arr, function(key, value, next){
console.log(key, "=>", value);
next(); //require
}, function(err){
console.log("err : ", err);
console.log("Case 1 result");
});
console.log("Case1 End => Array\n");
/* 결과(Result)
Case1 Start => Array
0 '=>' 1
1 '=>' 2
2 '=>' 3
3 '=>' 4
4 '=>' 5
err : undefined
Case 1 result
Case1 End => Array
*/
arr = [1,2,3,4,5];
console.log("Case2 Start => Array and 2 arguments");
loop.for(arr, function(key, value, next){
console.log(key, "=>", value);
next();
});
console.log("Case2 End => Array and 2 arguments\n");
/* 결과(Result)
Case2 Start => Array and 2 arguments
0 '=>' 1
1 '=>' 2
2 '=>' 3
3 '=>' 4
4 '=>' 5
Case2 End => Array and 2 arguments
*/
arr = [1,2,3,4,5];
console.log("Case3 Start => Array and error(or break)");
loop.while(arr, function(key, value, next){
console.log(key, "=>", value);
if(key === 2) next("error or break");
else next();
}, function(err){
console.log("err : ", err);
console.log("Case 3 result");
});
console.log("Case3 End => Array and error(or break)\n");
/* 결과(Result)
Case3 Start => Array and error(or break)
0 '=>' 1
1 '=>' 2
2 '=>' 3
err : error or break
Case 3 result
Case3 End => Array and error(or break)
*/
var obj = {a:1,b:2,c:3,d:4,e:5};
console.log("Case4 Start => object");
loop.loop(obj, function(key, value, next){
console.log(key, "=>", value);
next();
}, function(err){
console.log("err : ", err);
console.log("Case 4 result");
});
console.log("Case4 End => object\n");
/* 결과(Result)
Case4 Start => object
a => 1
b => 2
c => 3
d => 4
e => 5
err : undefined
Case 4 result
Case4 End => object
*/