Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

basic-collection

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basic-collection - npm Package Compare versions

Comparing version 0.0.11 to 0.1.0

src/filters.js

2

package.json
{
"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 ]
) );
} );
} );
} );
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc