From c4e402e5fc2a53185512f4ed50ba88d472eb3a05 Mon Sep 17 00:00:00 2001 From: Bjorn Stromberg Date: Wed, 20 Nov 2013 19:10:31 +0900 Subject: [PATCH] v0.0.18: ArrayTome.indexOf and lastIndexOf now do a valueOf on the value to be searched for. --- component.json | 2 +- index.js | 8 ++++++-- package.json | 2 +- scripts/lint-all.sh | 2 +- scripts/lint-staged.sh | 2 +- test/modules/array.js | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/component.json b/component.json index 8c1cd8a..6c86fc9 100644 --- a/component.json +++ b/component.json @@ -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": "*" diff --git a/index.js b/index.js index 4ed85ae..fbb5001 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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; diff --git a/package.json b/package.json index 4349115..80fed69 100755 --- a/package.json +++ b/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. ", "maintainers": [ { "name": "Bjorn Stromberg", "email": "bstromberg@wizcorp.jp" } diff --git a/scripts/lint-all.sh b/scripts/lint-all.sh index e51999f..60b21fa 100755 --- a/scripts/lint-all.sh +++ b/scripts/lint-all.sh @@ -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" diff --git a/scripts/lint-staged.sh b/scripts/lint-staged.sh index 610e2ce..55ac719 100755 --- a/scripts/lint-staged.sh +++ b/scripts/lint-staged.sh @@ -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 diff --git a/test/modules/array.js b/test/modules/array.js index 2b349a2..85177c5 100755 --- a/test/modules/array.js +++ b/test/modules/array.js @@ -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);