wip: code formatting nits continued

This commit is contained in:
jdalton
2023-09-16 22:59:56 -07:00
parent 0b28b7f7b6
commit b5c59317ea
421 changed files with 7354 additions and 9005 deletions

View File

@@ -25,7 +25,7 @@ function cloneBuffer(buffer, isDeep) {
return buffer.slice()
}
const length = buffer.length
const result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length)
const result = allocUnsafe ? allocUnsafe(length) : buffer.constructor.alloc(length)
buffer.copy(result)
return result

View File

@@ -15,12 +15,13 @@
* forEach(saves, type => asyncSave({ 'type': type, 'complete': done }))
* // => Logs 'done saving!' after the two async saves have completed.
*/
function after(n, func) {
function after(n, func: Function) {
if (typeof func !== 'function') {
throw new TypeError('Expected a function');
}
n = n || 0;
return function (...args) {
// eslint-disable-next-line consistent-return
return function (this: any, ...args: any[]) {
if (--n < 1) {
return func.apply(this, args);
}

View File

@@ -15,7 +15,7 @@
* clamp(10, -5, 5)
* // => 5
*/
function clamp(number, lower, upper) {
function clamp(number: number, lower: number, upper: number) {
number = +number;
lower = +lower;
upper = +upper;

View File

@@ -27,19 +27,19 @@ import map from './map.js';
* func({ 'a': '1', 'b': '2' })
* // => 'no match'
*/
function cond(pairs) {
function cond(pairs: any[]) {
const length = pairs == null ? 0 : pairs.length;
pairs = !length
? []
: map(pairs, (pair) => {
: map(pairs, (pair: any[]) => {
if (typeof pair[1] !== 'function') {
throw new TypeError('Expected a function');
}
return [pair[0], pair[1]];
});
return (...args) => {
// eslint-disable-next-line consistent-return
return function (this: any, ...args: any[]) {
for (const pair of pairs) {
if (pair[0].apply(this, args)) {
return pair[1].apply(this, args);

View File

@@ -63,8 +63,12 @@ import root from './.internal/root.js';
* const status = debounced.pending() ? "Pending..." : "Ready"
*/
function debounce(func, wait, options) {
let lastArgs, lastThis, maxWait, result, timerId, lastCallTime;
let lastArgs;
let lastThis;
let maxWait;
let result;
let timerId;
let lastCallTime;
let lastInvokeTime = 0;
let leading = false;
let maxing = false;

View File

@@ -23,6 +23,7 @@ const rsCombo = `[${rsComboRange}]`;
* Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
* [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
*/
// eslint-disable-next-line no-misleading-character-class
const reComboMark = RegExp(rsCombo, 'g');
/**

View File

@@ -12,10 +12,11 @@
* defer(text => console.log(text), 'deferred')
* // => Logs 'deferred' after one millisecond.
*/
function defer(func, ...args) {
function defer(func: Function, ...args: any[]) {
if (typeof func !== 'function') {
throw new TypeError('Expected a function');
}
// eslint-disable-next-line @typescript-eslint/no-implied-eval
return setTimeout(func, 1, ...args);
}

View File

@@ -13,10 +13,11 @@
* delay(text => console.log(text), 1000, 'later')
* // => Logs 'later' after one second.
*/
function delay(func, wait, ...args) {
function delay(func: Function, wait: number, ...args: any[]) {
if (typeof func !== 'function') {
throw new TypeError('Expected a function');
}
// eslint-disable-next-line @typescript-eslint/no-implied-eval
return setTimeout(func, +wait || 0, ...args);
}

View File

@@ -1 +1,2 @@
// eslint-disable-next-line no-restricted-exports
export { default } from './forEach.js';

View File

@@ -1 +1,2 @@
// eslint-disable-next-line no-restricted-exports
export { default } from './forEachRight.js';

View File

@@ -21,18 +21,18 @@
* // => 'barney' (iteration order is not guaranteed)
*/
function findKey(object, predicate) {
let result;
if (object == null) {
return result;
return undefined;
}
Object.keys(object).some((key) => {
const keys = Object.keys(object);
for (let i = 0, { length } = keys; i < length; i += 1) {
const key = keys[i];
const value = object[key];
if (predicate(value, key, object)) {
result = key;
return true;
return key;
}
});
return result;
}
return undefined;
}
export default findKey;

View File

@@ -1 +1,2 @@
// eslint-disable-next-line no-restricted-exports
export { default } from './head.js';

View File

@@ -20,19 +20,19 @@
* addSquare(1, 2)
* // => 9
*/
function flow(...funcs) {
function flow(...funcs: Function[]) {
const length = funcs.length;
let index = length;
while (index--) {
if (typeof funcs[index] !== 'function') {
let i = length;
while (i--) {
if (typeof funcs[i] !== 'function') {
throw new TypeError('Expected a function');
}
}
return function (...args) {
let index = 0;
let result = length ? funcs[index].apply(this, args) : args[0];
while (++index < length) {
result = funcs[index].call(this, result);
return function (this: any, ...args: any[]) {
let j = 0;
let result = length ? funcs[j].apply(this, args) : args[0];
while (++j < length) {
result = funcs[j].call(this, result);
}
return result;
};

View File

@@ -12,7 +12,7 @@ const nativeIsBuffer = root?.Buffer?.isBuffer;
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
* @example
*
* isBuffer(new Buffer(2))
* isBuffer(Buffer.alloc(2))
* // => true
*
* isBuffer(new Uint8Array(2))

View File

@@ -23,10 +23,13 @@ import reduce from './reduce.js';
* keyBy(array, ({ code }) => String.fromCharCode(code))
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
*/
function keyBy(collection, iteratee) {
function keyBy(collection: any, iteratee: Function) {
return reduce(
collection,
(result, value, key) => (baseAssignValue(result, iteratee(value), value), result),
(result: object, value: any) => {
baseAssignValue(result, iteratee(value), value);
return result;
},
{},
);
}

View File

@@ -19,12 +19,13 @@ import isIndex from './.internal/isIndex.js';
* nth(array, -2)
* // => 'c'
*/
function nth(array, n) {
function nth(array: any[], n: number) {
const length = array == null ? 0 : array.length;
if (!length) {
return;
}
n += n < 0 ? length : 0;
// eslint-disable-next-line consistent-return
return isIndex(n, length) ? array[n] : undefined;
}

View File

@@ -26,7 +26,10 @@ import reduce from './reduce.js';
function partition(collection, predicate) {
return reduce(
collection,
(result, value, key) => (result[predicate(value) ? 0 : 1].push(value), result),
(result, value) => {
result[predicate(value) ? 0 : 1].push(value);
return result;
},
[[], []],
);
}

View File

@@ -48,8 +48,8 @@ function transform(object, iteratee, accumulator) {
accumulator = {};
}
}
(isArrLike ? arrayEach : baseForOwn)(object, (value, index, object) =>
iteratee(accumulator, value, index, object),
(isArrLike ? arrayEach : baseForOwn)(object, (value, index, _object) =>
iteratee(accumulator, value, index, _object),
);
return accumulator;
}

View File

@@ -20,7 +20,7 @@ import stringToArray from './.internal/stringToArray.js';
* trim('-_-abc-_-', '_-')
* // => 'abc'
*/
function trim(string, chars) {
function trim(string: string, chars: string) {
if (string && chars === undefined) {
return string.trim();
}

View File

@@ -17,7 +17,7 @@ import isArrayLikeObject from './isArrayLikeObject.js';
* union([2, 3], [1, 2])
* // => [2, 3, 1]
*/
function union(...arrays) {
function union(...arrays: any[]) {
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
}

View File

@@ -26,6 +26,7 @@ function unzip(array) {
return [];
}
let length = 0;
// eslint-disable-next-line consistent-return
array = filter(array, (group) => {
if (isArrayLikeObject(group)) {
length = Math.max(group.length, length);

View File

@@ -5,6 +5,7 @@ const hasUnicodeWord = RegExp.prototype.test.bind(
);
/** Used to match words composed of alphanumeric characters. */
// eslint-disable-next-line no-control-regex
const reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
function asciiWords(string) {