Content-Length: 781485 | pFad | https://github.com/josemx/lodash/commit/bb7c95947914d12af5f79e7369dd59ce29bc61a8

18 Remove coercion method use. · josemx/lodash@bb7c959 · GitHub
Skip to content

Commit bb7c959

Browse files
committed
Remove coercion method use.
1 parent 2f281c6 commit bb7c959

33 files changed

+59
-194
lines changed

.internal/baseRepeat.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

.internal/createRound.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import toInteger from '../toInteger.js'
2-
import toNumber from '../toNumber.js'
3-
import toString from '../toString.js'
4-
51
/**
62
* Creates a function like `round`.
73
*
@@ -12,15 +8,14 @@ import toString from '../toString.js'
128
function createRound(methodName) {
139
const func = Math[methodName]
1410
return (number, precision) => {
15-
number = toNumber(number)
16-
precision = precision == null ? 0 : Math.min(toInteger(precision), 292)
11+
precision = precision == null ? 0 : Math.min(precision, 292)
1712
if (precision) {
1813
// Shift with exponential notation to avoid floating-point issues.
1914
// See [MDN](https://mdn.io/round#Examples) for more details.
20-
let pair = `${ toString(number) }e`.split('e')
15+
let pair = `${ number }e`.split('e')
2116
const value = func(`${ pair[0] }e${ +pair[1] + precision }`)
2217

23-
pair = `${ toString(value) }e`.split('e')
18+
pair = `${ value }e`.split('e')
2419
return +`${ pair[0] }e${ +pair[1] - precision }`
2520
}
2621
return func(number)

after.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import toInteger from './toInteger.js'
2-
31
/**
42
* The opposite of `before`his method creates a function that invokes
53
* `func` once it's called `n` or more times.
@@ -21,7 +19,6 @@ function after(n, func) {
2119
if (typeof func != 'function') {
2220
throw new TypeError('Expected a function')
2321
}
24-
n = toInteger(n)
2522
return function(...args) {
2623
if (--n < 1) {
2724
return func.apply(this, args)

before.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import toInteger from './toInteger.js'
2-
31
/**
42
* Creates a function that invokes `func`, with the `this` binding and arguments
53
* of the created function, while it's called less than `n` times. Subsequent
@@ -20,7 +18,6 @@ function before(n, func) {
2018
if (typeof func != 'function') {
2119
throw new TypeError('Expected a function')
2220
}
23-
n = toInteger(n)
2421
return function(...args) {
2522
if (--n > 0) {
2623
result = func.apply(this, args)

chunk.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
import baseSlice from './.internal/baseSlice.js'
2-
import toInteger from './toInteger.js'
3-
4-
/* Built-in method references for those with the same name as other `lodash` methods. */
5-
const nativeCeil = Math.ceil
6-
const nativeMax = Math.max
72

83
/**
94
* Creates an array of elements split into groups the length of `size`.
@@ -24,14 +19,14 @@ const nativeMax = Math.max
2419
* // => [['a', 'b', 'c'], ['d']]
2520
*/
2621
function chunk(array, size) {
27-
size = nativeMax(toInteger(size), 0)
22+
size = Math.max(size, 0)
2823
const length = array == null ? 0 : array.length
2924
if (!length || size < 1) {
3025
return []
3126
}
3227
let index = 0
3328
let resIndex = 0
34-
const result = new Array(nativeCeil(length / size))
29+
const result = new Array(Math.ceil(length / size))
3530

3631
while (index < length) {
3732
result[resIndex++] = baseSlice(array, index, (index += size))

clamp.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import toNumber from './toNumber.js'
2-
31
/**
42
* Clamps `number` within the inclusive `lower` and `upper` bounds.
53
*
@@ -18,10 +16,9 @@ import toNumber from './toNumber.js'
1816
* // => 5
1917
*/
2018
function clamp(number, lower, upper) {
21-
number = toNumber(number)
22-
lower = toNumber(lower)
23-
upper = toNumber(upper)
24-
19+
number = +number
20+
lower = +lower
21+
upper = +upper
2522
lower = lower === lower ? lower : 0
2623
upper = upper === upper ? upper : 0
2724
if (number === number) {

debounce.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
import isObject from './isObject.js'
2-
import toNumber from './toNumber.js'
3-
4-
/* Built-in method references for those with the same name as other `lodash` methods. */
5-
const nativeMax = Math.max
6-
const nativeMin = Math.min
72

83
/**
94
* Creates a debounced function that delays invoking `func` until after `wait`
@@ -73,11 +68,11 @@ function debounce(func, wait, options) {
7368
if (typeof func != 'function') {
7469
throw new TypeError('Expected a function')
7570
}
76-
wait = toNumber(wait) || 0
71+
wait = +wait || 0
7772
if (isObject(options)) {
7873
leading = !!options.leading
7974
maxing = 'maxWait' in options
80-
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait
75+
maxWait = maxing ? Math.max(+options.maxWait || 0, wait) : maxWait
8176
trailing = 'trailing' in options ? !!options.trailing : trailing
8277
}
8378

@@ -105,7 +100,7 @@ function debounce(func, wait, options) {
105100
const timeSinceLastInvoke = time - lastInvokeTime
106101
const result = wait - timeSinceLastCall
107102

108-
return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result
103+
return maxing ? Math.min(result, maxWait - timeSinceLastInvoke) : result
109104
}
110105

111106
function shouldInvoke(time) {

delay.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import toNumber from './toNumber.js'
2-
31
/**
42
* Invokes `func` after `wait` milliseconds. Any additional arguments are
53
* provided to `func` when it's invoked.
@@ -19,7 +17,7 @@ function delay(func, wait, ...args) {
1917
if (typeof func != 'function') {
2018
throw new TypeError('Expected a function')
2119
}
22-
return setTimeout(func, toNumber(wait) || 0, ...args)
20+
return setTimeout(func, +wait || 0, ...args)
2321
}
2422

2523
export default delay

drop.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import baseSlice from './.internal/baseSlice.js'
2-
import toInteger from './toInteger.js'
32

43
/**
54
* Creates a slice of `array` with `n` elements dropped from the beginning.
@@ -25,11 +24,9 @@ import toInteger from './toInteger.js'
2524
*/
2625
function drop(array, n=1) {
2726
const length = array == null ? 0 : array.length
28-
if (!length) {
29-
return []
30-
}
31-
n = toInteger(n)
32-
return baseSlice(array, n < 0 ? 0 : n, length)
27+
return length
28+
? baseSlice(array, n < 0 ? 0 : n, length)
29+
: []
3330
}
3431

3532
export default drop

dropRight.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import baseSlice from './.internal/baseSlice.js'
2-
import toInteger from './toInteger.js'
32

43
/**
54
* Creates a slice of `array` with `n` elements dropped from the end.
@@ -28,7 +27,6 @@ function dropRight(array, n=1) {
2827
if (!length) {
2928
return []
3029
}
31-
n = toInteger(n)
3230
n = length - n
3331
return baseSlice(array, 0, n < 0 ? 0 : n)
3432
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/josemx/lodash/commit/bb7c95947914d12af5f79e7369dd59ce29bc61a8

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy