0.1.0 • Published 7 years ago

lazy-some v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

lazy-some

Lazy Array some. Once fun returns non falsy value, that value is returned and search is suspended

extending npm-version downloads build coverage climate dependencies qa-control

language: English also available in: Spanish

Install

$ npm install lazy-some

Usage

require('lazy-some')(Array);

var lines=[
    'Line without mail',
    'Line with one mail: name@host.dom',
    'This line is not searches',
    'Another line with mail: other@mail.dom. Not searched'
];

var firstMail=lines.lazySome(function(line){
    var match = line.match(/\w+@(?:\w+\.)+\w+/)
    return match && match[0];
});

console.log(firstMail); // name@host.dom

arr.lazySome(fun , thisArg)

Calls fun with each array element until a non falsy value was obtained. Then that value was returned by lazySome.

If only falsy values were obtained then false was returned.

License

MIT