From c695a6ff1df051cc276c41577ca4918d41609cb1 Mon Sep 17 00:00:00 2001 From: Whitney Young Date: Sun, 9 Nov 2014 08:59:21 -0800 Subject: [PATCH] Strict option to fix #174. --- lib/underscore.string.js | 8 ++++++-- test/strings.js | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/underscore.string.js b/lib/underscore.string.js index 5ce1e3f7..224f05e3 100644 --- a/lib/underscore.string.js +++ b/lib/underscore.string.js @@ -550,11 +550,15 @@ else return str; }, - exports: function() { + exports: function(options) { var result = {}; + var opts = options || {}; + var regex = opts.strict ? + /^(?:include|contains|reverse|join)$/ : + /^(?:include|contains|reverse)$/; for (var prop in this) { - if (!this.hasOwnProperty(prop) || prop.match(/^(?:include|contains|reverse)$/)) continue; + if (!this.hasOwnProperty(prop) || prop.match(regex)) continue; result[prop] = this[prop]; } diff --git a/test/strings.js b/test/strings.js index e57ec224..71d2276a 100644 --- a/test/strings.js +++ b/test/strings.js @@ -5,6 +5,11 @@ $(document).ready(function() { module('String extensions'); + test('Strings: exports', function() { + equal(_.has(_.str.exports(), 'join'), true); + equal(_.has(_.str.exports({ strict: true }), 'join'), false); + }); + test('Strings: naturalSort', function() { var arr = ['foo2', 'foo1', 'foo10', 'foo30', 'foo100', 'foo10bar'], sorted = ['foo1', 'foo2', 'foo10', 'foo10bar', 'foo30', 'foo100'];