Skip to content

Commit

Permalink
upgrading underscore string and deprecating functions that are now pa…
Browse files Browse the repository at this point in the history
…rt of underscore or underscore.string
  • Loading branch information
rdy committed Dec 17, 2012
1 parent 853cd9e commit 617fbaa
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .rvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rvm 1.9.3-p125-perf@underscore_extensions --create
rvm 1.9.3-p327-perf@underscore_extensions --create
56 changes: 0 additions & 56 deletions lib/assets/javascripts/underscore.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,7 @@
}, obj);
}

function mergeSort(array, comparison) {
function merge(left, right, comparison) {
var result = [];
while ((left.length > 0) && (right.length > 0)) {
if (comparison(left[0], right[0]) <= 0) {
result.push(left.shift());
} else {
result.push(right.shift());
}
}
while (left.length > 0) {
result.push(left.shift());
}
while (right.length > 0) {
result.push(right.shift());
}
return result;
}

if (array.length < 2) {
return array;
}
var middle = Math.ceil(array.length / 2);
return merge(mergeSort(array.slice(0, middle), comparison), mergeSort(array.slice(middle), comparison), comparison);
}

_.mixin({
classify: function(str) {
var s = _(str).trim().replace(/(\-|_|\s)+(.)?/g, function(match, separator, chr) {
return chr ? chr.toUpperCase() : '';
});
return s.charAt(0).toUpperCase() + s.substring(1);
},
namespace: function(obj, ns) {
if (arguments.length === 2) {
if (_(ns).isArray()) {
Expand All @@ -56,30 +24,6 @@
} else {
return namespace(obj, Array.prototype.slice.call(arguments, 1));
}
},
stableSortBy: function(obj, val, context) {
var iterator = _.isFunction(val) ? val : function(obj) {
return obj[val];
};
var toSort = _.map(obj, function(value, index, list) {
return {
value: value,
criteria: iterator.call(context, value, index, list)
};
});
var comparator = function(left, right) {
var a = left.criteria, b = right.criteria;
if (a === void 0) {
return 1;
}
if (b === void 0) {
return -1;
}
return a < b ? -1 : a > b ? 1 : 0;
};

toSort = mergeSort(toSort, comparator);
return _.pluck(toSort, 'value');
}
});

Expand Down
2 changes: 1 addition & 1 deletion lib/underscore_extensions/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module UnderscoreExtensions
VERSION = '0.2.0'
VERSION = '0.2.1'
UNDERSCORE_VERSION = '1.4.2'
UNDERSCORE_STRING_VERSION = '2.3.0'
end
8 changes: 0 additions & 8 deletions spec/javascripts/underscore.extensions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,4 @@ describe('_', function() {
expect(_('foos').singularize({skip: 'foos'})).toEqual('foos');
});
});

describe("#stableSortBy", function() {
it("should sort the items by the provided iterator, through a stable sort", function() {
var toSort = [{a: 1}, {b: 1}, {c: 1}, {d: 1}, {e: 2}, {f:1}, {g: 1}];
var sorted = _(toSort).stableSortBy(function(obj) { return _(obj).values()[0]; });
expect(sorted).toEqual([{a: 1}, {b: 1}, {c: 1}, {d: 1}, {f:1}, {g: 1}, {e: 2}]);
});
});
});
4 changes: 2 additions & 2 deletions vendor/assets/javascripts/underscore.string.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
slugify: function(str) {
if (str == null) return '';

var from = "ąàáäâãåæćęèéëêìíïîłńòóöôõøùúüûñçżź",
var from = "ąà áäâãåæćęèéëêìíïîłńòóöôõøùúüûñçżź",
to = "aaaaaaaaceeeeeiiiilnoooooouuuunczz",
regex = new RegExp(defaultToWhiteSpace(from), 'g');

Expand Down Expand Up @@ -597,4 +597,4 @@
root._.string = root._.str = _s;
}

}(this, String);
}(this, String);

0 comments on commit 617fbaa

Please sign in to comment.