An object crawler/property search library that works on nearly all JavaScript platforms1.
Spotlight.js is part of the BestieJS "Best in Class" module collection. This means we promote solid browser/environment support, ES5 precedents, unit testing, and plenty of documentation.
The documentation for Spotlight.js can be viewed here: /doc/README.md
For a list of upcoming features, check out our roadmap.
In a browser:
<script src="spotlight.js"></script>
Via npm:
npm install spotlight
In Narwhal, Node.js, and RingoJS:
var spotlight = require('spotlight');
In Rhino:
load('spotlight.js');
In an AMD loader like RequireJS:
require({
'paths': {
'spotlight': 'path/to/spotlight'
}
},
['spotlight'], function(spotlight) {
spotlight.byKind('constructor');
});
Usage example:
// find all "length" properties
spotlight.byName('length');
// or find all "map" properties on jQuery
spotlight.byName('map', { 'object': jQuery, 'path': '$' });
// or all properties with `jQuery` objects
spotlight.byKind(jQuery);
// or all properties with `RegExp` values
spotlight.byKind('RegExp');
// or all properties with `null` values
spotlight.byKind('null');
// or all properties with `undefined` values
spotlight.byKind('undefined');
// or all constructors
spotlight.byKind('constructor');
// or all properties with the value `0`
spotlight.byValue(0);
// or all properties containing "oo" in their name
spotlight.custom(function(value, key) { return key.indexOf('oo') > -1; });
// or all properties with falsey values
spotlight.custom(function(value) { return !value; });
To clone this repository including all submodules, using Git 1.6.5 or later:
git clone --recursive https://github.com/bestiejs/spotlight.js.git
cd spotlight.js
For older Git versions, just use:
git clone https://github.com/bestiejs/spotlight.js.git
cd spotlight.js
git submodule update --init
Feel free to fork and send pull requests if you see improvements!
- Spotlight.js has been tested in at least Chrome 5/8/12/14, Firefox 1.5-4, IE 6-10, Opera 9.25-12, Safari 2-5, Node.js 0.4.2, Narwhal 0.3.2, Ringo 0.7, and Rhino 1.7RC3. ↩