BitTags is a project mainly written in JavaScript, it's free.
Bitmasking Javascript class that is used to associate objects with tags
h1. bitTags.js
Created by "Arlo Carreon":http://www.arlocarreon.com on 2011-03-16. MIT LIcense "arlo.mit-license.org":http://arlo.mit-license.org
h1. About
Note: Tags are defined as an array of strings. e.g. ['tall','dark','handsome','male']
h2. Interface
h1. Use Cases
// Initiate Class var bt = new bitTags();// Local Objects var people = { betty : new Person('betty'), justin : new Person('justin'), erick : new Person('erick'), arlo : new Person('arlo') }
// Assign tags people.betty.tags = bt.getTagsID(['tall','chinese','female']); people.justin.tags = bt.getTagsID(['short','vietnamese','male']); people.erick.tags = bt.getTagsID(['tall','dominican','male']); people.arlo.tags = bt.getTagsID(['tall','mexican','male']);
// Find Asians var asianList = ['japanese','chinese','vietnamese','korean','thai']; for(var key in people) { // Make our comparison if( bt.matchAny( asianList,person[key].tags ) ) alert(key+' is asian.'); } // *** Above outputs: betty is asian. justin is asian.
// Find Hispanics var hispList = ['mexican','cuban','puerto rican','dominican','argentinian']; for(var key in people) { // Make our comparison if( bt.matchAny( hispList,person[key].tags ) ) alert(key+' is hispanic.'); } // *** Above outputs: arlo is hispanic. erick is hispanic.
h1. Test Cases
// Create object var bl = new bitTags();// Register initial list bt.getTagsID(['a','b','c','d','e','f','g','h','i','j','k','l']);
// Test matchAny() bt.matchAny( ['a','b','c','d'], ['k','l','e','b','f','a'] ); //returns: 2 bt.matchAny( ['a','b','c','d'], ['k','c','e','b','f','a'] ); //returns: 3 bt.matchAny( ['a','b','c','d'], ['e','f','g','h','i','j'] ); //returns: 0 bt.matchAny( ['sunshine','b','cat','z'] ); //returns: 1
// Test matchAll() bt.matchAll( ['a','b','c','d'], ['a','b','c','d'] ); //returns: true bt.matchAll( ['a','b','c','d'], ['c','b','d','a'] ); //returns: true bt.matchAll( ['a','b','c','d'], ['a','e','c','d'] ); //returns: false bt.matchAll( ['a','b','c','d'], ['a','b','c','d','e'] ); //returns: false bt.matchAll( ['a','b','c','d'] ); //returns: false
// Test matchNone() bt.matchNone( ['a','b','c','d'], ['e','f','g','h'] ); //returns: true bt.matchNone( ['a','b','c','d'], ['a','b','c'] ); //returns: false bt.matchNone( ['a','b','c','d'], ['sunshine','b','cat','z'] ); //returns: false bt.matchNone( ['small','ball','3','$'] ); //returns: true
h1. License: "arlo.mit-license.org":http://arlo.mit-license.org