pull-stream
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -45,2 +45,13 @@ # Throughs | ||
## unique (prop) | ||
Filter items that have a repeated value for `prop()`, | ||
by default, `prop = function (it) {return it }`, if prop is a string, | ||
it will filter nodes which have repeated values for that property. | ||
## nonUnique (prop) | ||
filter unique items -- get the duplicates. | ||
The inverse of `unique` | ||
## take (test) | ||
@@ -47,0 +58,0 @@ |
{ | ||
"name": "pull-stream", | ||
"description": "minimal pull stream", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"homepage": "https://github.com/dominictarr/pull-stream", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -0,1 +1,13 @@ | ||
function prop (map) { | ||
if('string' == typeof map) { | ||
var key = map | ||
return function (data) { return data[key] } | ||
} | ||
return map | ||
} | ||
function id (item) { | ||
return item | ||
} | ||
var k = 0 | ||
@@ -5,7 +17,3 @@ var map = exports.map = | ||
var _k = k++ | ||
if('string' == typeof map) { | ||
var key = map | ||
map = function (data) { return data[key] } | ||
} | ||
map = map || function (e) {return e} | ||
map = prop(map) || id | ||
return function (end, cb) { | ||
@@ -25,3 +33,3 @@ read(end, function (end, data) { | ||
test = test.test.bind(test) | ||
test = test || function (data) {return !!data} | ||
test = prop(test) || id | ||
return function next (end, cb) { | ||
@@ -75,2 +83,17 @@ read(end, function (end, data) { | ||
var unique = exports.unique = function (read, field, invert) { | ||
field = prop(field) || id | ||
var seen = {} | ||
return filter(read, function (data) { | ||
var key = field(data) | ||
if(seen[key]) return !!invert //false, by default | ||
else seen[key] = true | ||
return !invert //true by default | ||
}) | ||
} | ||
var nonUnique = exports.nonUnique = function (read, field) { | ||
return unique(read, field, true) | ||
} | ||
var nextTick = process.nextTick | ||
@@ -77,0 +100,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25786
18
595