Skip to content

Commit

Permalink
v0.0.18: ArrayTome.indexOf and lastIndexOf now do a valueOf on the va…
Browse files Browse the repository at this point in the history
…lue to be searched for.
  • Loading branch information
Bjorn Stromberg committed Nov 20, 2013
1 parent 185e627 commit c4e402e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion component.json
Expand Up @@ -2,7 +2,7 @@
"name": "tomes",
"repo": "Wizcorp/node-tomes",
"description": "Evented Storage Agnostic Data API",
"version": "0.0.17",
"version": "0.0.18",
"keywords": [ "data", "events" ],
"dependencies": {
"component/emitter": "*"
Expand Down
8 changes: 6 additions & 2 deletions index.js
Expand Up @@ -1407,8 +1407,10 @@ ArrayTome.prototype.unshift = function () {
return this._arr.length;
};

ArrayTome.prototype.indexOf = function (searchElement) {
ArrayTome.prototype.indexOf = function (s) {
// straight from MDN, Tomes have to do valueOf instead of ===
var searchElement = s ? s.valueOf() : s;

var t = this._arr;
var len = t.length;

Expand Down Expand Up @@ -1442,8 +1444,10 @@ ArrayTome.prototype.indexOf = function (searchElement) {
return -1;
};

ArrayTome.prototype.lastIndexOf = function (searchElement) {
ArrayTome.prototype.lastIndexOf = function (s) {
// straight from MDN, Tomes have to do valueOf instead of ===
var searchElement = s ? s.valueOf() : s;

var t = this._arr;
var len = t.length;

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "tomes",
"description": "Evented Storage Agnostic Data API",
"version": "0.0.17",
"version": "0.0.18",
"author": "Wizcorp, Inc. <info@wizcorp.jp>",
"maintainers": [
{ "name": "Bjorn Stromberg", "email": "bstromberg@wizcorp.jp" }
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint-all.sh
Expand Up @@ -17,7 +17,7 @@ then
exit 0
fi

jshint $files --config ./scripts/jshint.cfg
node_modules/.bin/jshint $files --config ./scripts/jshint.cfg
exitCode=$?

cd "$path"
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint-staged.sh
Expand Up @@ -25,7 +25,7 @@ do
# ignore non-existing files (caused by renames or removal)
if [[ -e $file ]]
then
jshint $file --config ./scripts/jshint.cfg
node_modules/.bin/jshint $file --config ./scripts/jshint.cfg
if [[ $? != 0 ]]
then
exitCode=1
Expand Down
38 changes: 38 additions & 0 deletions test/modules/array.js
Expand Up @@ -560,6 +560,44 @@ exports.testArrayIndexOf = function (test) {
test.done();
};

exports.testArrayIndexOfTome = function (test) {
var a = [ '24df74c9-dc07-431e-8eec-cb575bf062e6', 'asdf', null, undefined, 17, '*', false, 0, true, 9, true, false, null, undefined, 'asdf', 17 ];
var b = Tome.conjure(a);

test.expect(a.length * 2);

var i;

for (i = 0; i < a.length; i += 1) {
test.strictEqual(a.indexOf(b[i].valueOf()), b.indexOf(b[i]));
}

for (i = 0; i < a.length; i += 1) {
test.strictEqual(a.indexOf(a[i]), b.indexOf(a[i]));
}

test.done();
};

exports.testArrayIndexOfTome = function (test) {
var a = [ '24df74c9-dc07-431e-8eec-cb575bf062e6', 'asdf', null, undefined, 17, '*', false, 0, true, 9, true, false, null, undefined, 'asdf', 17 ];
var b = Tome.conjure(a);

test.expect(a.length * 2);

var i;

for (i = 0; i < a.length; i += 1) {
test.strictEqual(a.lastIndexOf(b[i].valueOf()), b.lastIndexOf(b[i]));
}

for (i = 0; i < a.length; i += 1) {
test.strictEqual(a.lastIndexOf(a[i]), b.lastIndexOf(a[i]));
}

test.done();
};

exports.testArrayLastIndexOf = function (test) {
test.expect(7);

Expand Down

0 comments on commit c4e402e

Please sign in to comment.