basic-collection
Advanced tools
Comparing version 0.0.11 to 0.1.0
{ | ||
"name" : "basic-collection", | ||
"version" : "0.0.11", | ||
"version" : "0.1.0", | ||
"keywords" : [ "map", "data", "collection" ], | ||
@@ -5,0 +5,0 @@ "description" : "A generic collection class to contain array-like data", |
@@ -59,3 +59,3 @@ # basic-collection | ||
} | ||
} | ||
}; | ||
@@ -62,0 +62,0 @@ let Collection = new MyCollection; |
"use strict"; | ||
const filter = require( "./filters.js" ); | ||
/** | ||
@@ -109,2 +111,42 @@ * Basic data collection. | ||
/** | ||
* Returns keys that match a pattern. | ||
* | ||
* @param string pattern | ||
* @return array | ||
* @access public | ||
*/ | ||
filterByKey( pattern ) { | ||
let expression = filter.replace( pattern ); | ||
let filtered = []; | ||
for ( let key of this.keys ) { | ||
if ( `${key}`.match( expression ) ) { | ||
filtered.push( key ); | ||
} | ||
} | ||
return filtered; | ||
} | ||
/** | ||
* Returns valyes that match a pattern. | ||
* | ||
* @param string pattern | ||
* @return array | ||
* @access public | ||
*/ | ||
filterByValue( pattern ) { | ||
let expression = filter.replace( pattern ); | ||
let filtered = []; | ||
for ( let key of this.values ) { | ||
if ( `${key}`.match( expression ) ) { | ||
filtered.push( key ); | ||
} | ||
} | ||
return filtered; | ||
} | ||
/** | ||
* Counts parameters. | ||
@@ -111,0 +153,0 @@ * |
@@ -6,2 +6,13 @@ "use strict"; | ||
function arraysEqual( arr1, arr2 ) { | ||
if(arr1.length !== arr2.length) | ||
return false; | ||
for(var i = arr1.length; i--;) { | ||
if(arr1[i] !== arr2[i]) | ||
return false; | ||
} | ||
return true; | ||
} | ||
let Collection = new BasicCollection; | ||
@@ -76,2 +87,46 @@ | ||
} ); | ||
describe( "#filterByValue", function () { | ||
it( "should count elements", function () { | ||
Collection.clear(); | ||
Collection.set( "val_1", 1 ); | ||
Collection.set( "val_2", 2 ); | ||
Collection.set( "val_3", 3 ); | ||
Collection.set( 1, "a" ); | ||
Collection.set( 2, "b" ); | ||
Collection.set( 3, "c" ); | ||
assert.equal( true, arraysEqual( | ||
Collection.filterByValue( "[digit]" ), | ||
[ 1, 2, 3 ] | ||
) ); | ||
assert.equal( true, arraysEqual( | ||
Collection.filterByValue( "[alpah]" ), | ||
[ "a", "b", "c" ] | ||
) ); | ||
} ); | ||
} ); | ||
describe( "#filterByKey", function () { | ||
it( "should count elements", function () { | ||
Collection.clear(); | ||
Collection.set( "val_1", 1 ); | ||
Collection.set( "val_2", 2 ); | ||
Collection.set( "val_3", 3 ); | ||
Collection.set( 1, "a" ); | ||
Collection.set( 2, "b" ); | ||
Collection.set( 3, "c" ); | ||
assert.equal( true, arraysEqual( | ||
Collection.filterByKey( "val_[all]" ), | ||
[ "val_1", "val_2", "val_3" ] | ||
) ); | ||
assert.equal( true, arraysEqual( | ||
Collection.filterByKey( "[digit]" ), | ||
[ 1, 2, 3 ] | ||
) ); | ||
} ); | ||
} ); | ||
} ); |
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
14491
7
310