mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Preserve sign of 0 in _.toString.
This commit is contained in:
committed by
John-David Dalton
parent
9c342eb432
commit
cd371ac66f
@@ -9760,6 +9760,10 @@
|
||||
* @returns {string} Returns the string.
|
||||
*/
|
||||
function toString(value) {
|
||||
// Preserve sign of `0`.
|
||||
if (value === 0) {
|
||||
return (1 / value) == INFINITY ? '0' : '-0';
|
||||
}
|
||||
// Exit early for strings to avoid a performance hit in some environments.
|
||||
if (typeof value == 'string') {
|
||||
return value;
|
||||
|
||||
75
test/test.js
75
test/test.js
@@ -19423,6 +19423,44 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.toString');
|
||||
|
||||
(function() {
|
||||
QUnit.test('should treat nullish values as empty strings', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var values = [, null, undefined],
|
||||
expected = lodashStable.map(values, lodashStable.constant(''));
|
||||
|
||||
var actual = lodashStable.map(values, function(value, index) {
|
||||
return index ? _.toString(value) : _.toString();
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should preserve sign of `0`', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
assert.strictEqual(_.toString(0), '0');
|
||||
assert.strictEqual(_.toString(-0), '-0');
|
||||
});
|
||||
|
||||
QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
if (!isNpm) {
|
||||
var wrapped = _([1, 2, 3]);
|
||||
assert.strictEqual(wrapped.toString(), '1,2,3');
|
||||
}
|
||||
else {
|
||||
skipTest(assert);
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.transform');
|
||||
|
||||
(function() {
|
||||
@@ -21526,43 +21564,6 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash(...).toString');
|
||||
|
||||
(function() {
|
||||
QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
if (!isNpm) {
|
||||
var wrapped = _([1, 2, 3]);
|
||||
assert.strictEqual(String(wrapped), '1,2,3');
|
||||
}
|
||||
else {
|
||||
skipTest(assert);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('should treat nullish values as empty strings', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
if (!isNpm) {
|
||||
var values = [, null, undefined],
|
||||
expected = lodashStable.map(values, lodashStable.constant(''));
|
||||
|
||||
var actual = lodashStable.map(values, function(value, index) {
|
||||
var wrapped = index ? _(value) : _();
|
||||
return String(wrapped);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
}
|
||||
else {
|
||||
skipTest(assert);
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash(...).value');
|
||||
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user