diff --git a/.eslintrc.json b/.eslintrc.json index ce77254..9ad7041 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,6 +5,9 @@ "rules": { "jsdoc/require-jsdoc": "warn", "one-var": "off", + "no-param-reassign": "off", + "no-return-assign": "off", + "no-unused-expressions": "off", "jsdoc/check-tag-names": [ "error", { "jsxTags": true, "definedTags": [ @@ -26,6 +29,9 @@ "files": [ "./tests/*" ], + "rules": { + "consistent-return": "off" + }, "extends": "@twipped/eslint-config/node-esm" }, { diff --git a/package.json b/package.json index 4eeae10..f6e69a8 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "build:types": "tsc" }, "engines": { - "node": ">=14.10.0" + "node": ">=18.18.0" }, "author": "Jocelyn Badgley (http://twipped.com)", "license": "MIT", diff --git a/src/assert.js b/src/assert.js index 4bff029..18b4ccc 100644 --- a/src/assert.js +++ b/src/assert.js @@ -40,7 +40,7 @@ export default function assert (ok, message, ...substitutions) { * * @category Errors */ -export const fail = /* #__PURE__ */(...args) => assert(false, ...args); +export const fail = /* #__PURE__ */(...args) => assert(false, ...args); /** @@ -54,7 +54,7 @@ export const fail = /* #__PURE__ */(...args) => assert(false, ... * @throws Error * @category Errors */ -export const assertIsArray = /* #__PURE__ */(ok, ...args) => assert(isArray(ok), ...args); +export const assertIsArray = /* #__PURE__ */(ok, ...args) => assert(isArray(ok), ...args); /** * Tests if the first argument is object like, and throws the passed message if it is not. @@ -67,7 +67,7 @@ export const assertIsArray = /* #__PURE__ */(ok, ...args) => assert(isArra * @throws Error * @category Errors */ -export const assertIsObject = /* #__PURE__ */(ok, ...args) => assert(isObject(ok), ...args); +export const assertIsObject = /* #__PURE__ */(ok, ...args) => assert(isObject(ok), ...args); /** * Tests if the first argument is a plain object, and throws the passed message if it is not. @@ -93,7 +93,7 @@ export const assertIsPlainObject = /* #__PURE__ */(ok, ...args) => assert(isObje * @throws Error * @category Errors */ -export const assertIsString = /* #__PURE__ */(ok, ...args) => assert(isString(ok), ...args); +export const assertIsString = /* #__PURE__ */(ok, ...args) => assert(isString(ok), ...args); /** * Tests if the first argument is a number, and throws the passed message if it is not. @@ -106,4 +106,4 @@ export const assertIsString = /* #__PURE__ */(ok, ...args) => assert(isStri * @throws Error * @category Errors */ -export const assertIsNumber = /* #__PURE__ */(ok, ...args) => assert(isNumber(ok), ...args); +export const assertIsNumber = /* #__PURE__ */(ok, ...args) => assert(isNumber(ok), ...args); diff --git a/src/clamp.js b/src/clamp.js index 164f31b..f88723e 100644 --- a/src/clamp.js +++ b/src/clamp.js @@ -12,7 +12,7 @@ import { isDate } from './types.js'; * @returns {number|Date} * @category Math */ -export default function clamp (value, minv = -Infinity, maxv = Infinity, nearest) { +export default function clamp (value, minv = -Infinity, maxv = Infinity, nearest = undefined) { if (value === undefined || value === null || value === '') return null; if (minv === undefined || minv === null || minv === '') minv = -Infinity; if (maxv === undefined || maxv === null || maxv === '') maxv = Infinity; diff --git a/src/clr.js b/src/clr.js index 0abcb49..5826984 100644 --- a/src/clr.js +++ b/src/clr.js @@ -5,7 +5,7 @@ * * @function clr * @param {string|Array} input - * @param {Object} classMap + * @param {object} classMap * * @returns {string} * @category Text diff --git a/src/collect.js b/src/collect.js index 64b18f2..69b0e14 100644 --- a/src/collect.js +++ b/src/collect.js @@ -18,7 +18,7 @@ import hasOwn from './hasOwn.js'; * Supports using wildcards in paths to iterate over all keys of an * object or array. * - * @param {Object|Array} target Structure to get a value from. + * @param {object | Array} target Structure to get a value from. * @param {string|Array} path Property Key, dot-notation path, * or array of key names which describes the target value. * @@ -45,7 +45,7 @@ export default function collect (target, path) { /** * Object Descender * - * @param {Object|Array} res Structure to get a value from. + * @param {object | Array} res Structure to get a value from. * @param {string|Array} level Property Key, dot-notation path, * or array of key names which describes the target value. * @private diff --git a/src/convert.js b/src/convert.js index c2ccb06..79d97e5 100644 --- a/src/convert.js +++ b/src/convert.js @@ -2,7 +2,7 @@ import assert from './assert.js'; /** - * @typedef {Object} Unit + * @typedef {object} Unit * @property {Array} names * @property {number} ratio */ diff --git a/src/dom.js b/src/dom.js index ca18525..3cb9243 100644 --- a/src/dom.js +++ b/src/dom.js @@ -1,3 +1,4 @@ +/* eslint-disable no-param-reassign */ /* global Predicate */ import iteratee from './iteratee.js'; diff --git a/src/faccimilate.js b/src/faccimilate.js index 656160d..5adf1d1 100644 --- a/src/faccimilate.js +++ b/src/faccimilate.js @@ -22,13 +22,13 @@ import nullIterator from './nullIterator.js'; */ export default function faccimilate (collection, strict) { switch (isString(collection) ? collection : mapMode(collection, strict)) { - case MAPMODE_ARRAY: return []; - case MAPMODE_SET: return new Set(); - case MAPMODE_MAP: return new Map(); - case MAPMODE_OBJECT: return {}; + case MAPMODE_ARRAY: return []; + case MAPMODE_SET: return new Set(); + case MAPMODE_MAP: return new Map(); + case MAPMODE_OBJECT: return {}; case MAPMODE_ITERABLE: return { [Symbol.iterator]: nullIterator }; case MAPMODE_ITERATOR: return nullIterator(); - case MAPMODE_STRING: return ''; - default: return undefined; + case MAPMODE_STRING: return ''; + default: return undefined; } } diff --git a/src/findIndex.js b/src/findIndex.js index b5e5fc3..523cff8 100644 --- a/src/findIndex.js +++ b/src/findIndex.js @@ -38,4 +38,5 @@ export default function findIndex (collection, predicate) { return false; // no default } + return undefined; } diff --git a/src/fromPairs.js b/src/fromPairs.js index 61021cd..64d337d 100644 --- a/src/fromPairs.js +++ b/src/fromPairs.js @@ -12,7 +12,7 @@ import mapReduce from './mapReduce.js'; * Produces a collection from an array of key/value tuples. * * @param {Array>} pairs - * @param {Object} options + * @param {object} options * @param {MAPMODE} [options.mode] Type of collection to produce. Defaults to Object. * * @returns {Collection} @@ -36,4 +36,5 @@ export default function fromPairs (pairs, { mode = MAPMODE_OBJECT } = {}) { // no default } + return undefined; } diff --git a/src/fs.js b/src/fs.js index fce4328..c7e8822 100644 --- a/src/fs.js +++ b/src/fs.js @@ -24,7 +24,7 @@ export async function isWritable (file) { return true; } catch (err) { if (err.code === 'ENOENT') { - return await fs.access(dirname(file), fsConstants.F_OK | fsConstants.W_OK).then(() => true, () => false); + return fs.access(dirname(file), fsConstants.F_OK | fsConstants.W_OK).then(() => true, () => false); } return false; } @@ -35,6 +35,7 @@ export async function isWritable (file) { * If the file already exists, its modification time will be updated. * * @param {string} file + * @returns {Promise} * * @category File System */ @@ -42,7 +43,8 @@ export async function touch (file) { const stats = await linkStat(file); if (stats) { if (stats.isDirectory()) return; // nothing to do - return await fs.utimes(file, new Date, new Date); + fs.utimes(file, new Date, new Date); + return; } if (!await exists(dirname(file))) await mkdir(dirname(file)); @@ -54,12 +56,13 @@ export async function touch (file) { * Deletes the file at the given path, if it exists. * * @param {string} file + * @returns {Promise} * * @category File System */ export async function remove (file) { const stats = await linkStat(file); - if (!stats) return; + if (!stats) return undefined; if (stats.isDirectory()) return fs.rmdir(file, { recursive: true }); return fs.unlink(file); } @@ -68,8 +71,8 @@ export async function remove (file) { * Write the passed data structure to a file as JSON. * * @param {string} file - * @param {Object|Array} object - * @param {Object} [options] Options for fs.writeFile + * @param {object | Array} object + * @param {object} [options] Options for fs.writeFile * @param {string} [options.encoding] File encoding for the data, defaults to utf8 * * @alias writeJSON @@ -88,12 +91,12 @@ export const writeJSON = writeJson; * Reads a JSON file from disk and parses its contents. * * @param {string} file - * @param {Object} [options] Options for fs.readFile + * @param {object} [options] Options for fs.readFile * @param {Function} [options.reviver] * @param {boolean} [options.quiet] * @param {string} [options.encoding] File encoding for the data, defaults to utf8 * - * @returns {Object|Array|string|number|boolean} + * @returns {object | Array | string | number | boolean} * @alias readJSON * @category File System */ diff --git a/src/get.js b/src/get.js index dc637f9..19d415a 100644 --- a/src/get.js +++ b/src/get.js @@ -13,7 +13,7 @@ const NOT_FOUND = Symbol('NOT_FOUND'); /** * Deeply extracts a value from a nested object structure. * - * @param {Object|Array} target Structure to get a value from. + * @param {object | Array} target Structure to get a value from. * @param {string|Array} path Property Key, dot-notation path, * or array of key names which describes the target value. * @param {any} [defaultValue] The value to return if the path diff --git a/src/has.js b/src/has.js index fc75661..81b6e7f 100644 --- a/src/has.js +++ b/src/has.js @@ -12,7 +12,7 @@ import parsePath from './parsePath.js'; * Deeply searches for a value in a nested object structure and returns true * if a value is found. * - * @param {Object|Array} target Structure to get a value from. + * @param {object | Array} target Structure to get a value from. * @param {string|Array} path Property Key, dot-notation path, * or array of key names which describes the target value. * diff --git a/src/hasOwn.js b/src/hasOwn.js index 23e3347..690d0d3 100644 --- a/src/hasOwn.js +++ b/src/hasOwn.js @@ -1,12 +1,12 @@ /** * Shorthand, prototype safe way to test if an object's property is its own * - * @param {Object} target Object to check + * @param {object} target Object to check * @param {string} key Property key to check * * @returns {boolean} * @category Data */ export default function hasOwn (target, key) { - return Object.prototype.hasOwnProperty.call(target, key); + return Object.hasOwn(target, key); } diff --git a/src/hash.js b/src/hash.js index 7bebe14..3e7428e 100644 --- a/src/hash.js +++ b/src/hash.js @@ -27,8 +27,8 @@ export default function hash (input) { } let h = 0; for (let i = 0; i < input.length; i += 1) { - const chr = input.charCodeAt(i); - h = ((h << 5) - h) + chr; + const chr = input.charCodeAt(i); + h = ((h << 5) - h) + chr; h |= 0; // Convert to 32bit integer } return h; diff --git a/src/is.js b/src/is.js index 6e779a7..80e42d5 100644 --- a/src/is.js +++ b/src/is.js @@ -28,17 +28,17 @@ export const isa = (constructor) => (input) => input instanceof constructor; const IS_LOOKUP = new Map([ - [ Array, isArray ], - [ Number, isNumber ], - [ String, isString ], - [ Boolean, isBoolean ], - [ Map, isMap ], - [ Set, isSet ], - [ Date, isDate ], - [ RegExp, isRegExp ], + [ Array, isArray ], + [ Number, isNumber ], + [ String, isString ], + [ Boolean, isBoolean ], + [ Map, isMap ], + [ Set, isSet ], + [ Date, isDate ], + [ RegExp, isRegExp ], [ undefined, isUndefined ], - [ true, isTruthy ], - [ false, isFalsey ], + [ true, isTruthy ], + [ false, isFalsey ], ]); /** diff --git a/src/isArrayOf.js b/src/isArrayOf.js index 3f63f46..f6ff435 100644 --- a/src/isArrayOf.js +++ b/src/isArrayOf.js @@ -38,42 +38,42 @@ export function isArrayOf (...args) { * * @returns {boolean} Returns true if all items in the array are arrays. */ -export const isArrayOfArrays = /* #__PURE__*/isArrayOf(isArray); +export const isArrayOfArrays = /* #__PURE__*/isArrayOf(isArray); /** * @function isArrayOfStrings * * @returns {boolean} Returns true if all items in the array are strings. */ -export const isArrayOfStrings = /* #__PURE__*/isArrayOf(isString); +export const isArrayOfStrings = /* #__PURE__*/isArrayOf(isString); /** * @function isArrayOfNumbers * * @returns {boolean} Returns true if all items in the array are numbers. */ -export const isArrayOfNumbers = /* #__PURE__*/isArrayOf(isNumber); +export const isArrayOfNumbers = /* #__PURE__*/isArrayOf(isNumber); /** * @function isArrayOfBooleans * * @returns {boolean} Returns true if all items in the array are booleans. */ -export const isArrayOfBooleans = /* #__PURE__*/isArrayOf(isBoolean); +export const isArrayOfBooleans = /* #__PURE__*/isArrayOf(isBoolean); /** * @function isArrayOfObjects * * @returns {boolean} Returns true if all items in the array are objects. */ -export const isArrayOfObjects = /* #__PURE__*/isArrayOf(isObject); +export const isArrayOfObjects = /* #__PURE__*/isArrayOf(isObject); /** * @function isArrayOfMappables * * @returns {boolean} Returns true if all items in the array are mappable items. */ -export const isArrayOfMappables = /* #__PURE__*/isArrayOf(isMappable); +export const isArrayOfMappables = /* #__PURE__*/isArrayOf(isMappable); /** * @function isArrayOfPrimatives @@ -87,28 +87,28 @@ export const isArrayOfPrimatives = /* #__PURE__*/isArrayOf(isPrimitive); * * @returns {boolean} Returns true if all items in the array are functions. */ -export const isArrayOfFunctions = /* #__PURE__*/isArrayOf(isFunction); +export const isArrayOfFunctions = /* #__PURE__*/isArrayOf(isFunction); /** * @function isArrayOfRegEx * * @returns {boolean} Returns true if all items in the array are Regular Expressions. */ -export const isArrayOfRegEx = /* #__PURE__*/isArrayOf(isRegExp); +export const isArrayOfRegEx = /* #__PURE__*/isArrayOf(isRegExp); /** * @function isArrayOfTruthy * * @returns {boolean} Returns true if all items in the array are truthy. */ -export const isArrayOfTruthy = /* #__PURE__*/isArrayOf(isTruthy); +export const isArrayOfTruthy = /* #__PURE__*/isArrayOf(isTruthy); /** * @function isArrayOfFalsey * * @returns {boolean} Returns true if all items in the array are falsey. */ -export const isArrayOfFalsey = /* #__PURE__*/isArrayOf(isFalsey); +export const isArrayOfFalsey = /* #__PURE__*/isArrayOf(isFalsey); /** * Produces a function which evaluates a set of functions against @@ -136,7 +136,7 @@ export function contains (...args) { * @returns {boolean} Returns true if any items in the array are arrays. * @category Collections */ -export const containsArrays = /* #__PURE__*/contains(isArray); +export const containsArrays = /* #__PURE__*/contains(isArray); /** * @function containsStrings @@ -144,7 +144,7 @@ export const containsArrays = /* #__PURE__*/contains(isArray); * @returns {boolean} Returns true if any items in the array are strings. * @category Collections */ -export const containsStrings = /* #__PURE__*/contains(isString); +export const containsStrings = /* #__PURE__*/contains(isString); /** * @function containsNumbers @@ -152,7 +152,7 @@ export const containsStrings = /* #__PURE__*/contains(isString); * @returns {boolean} Returns true if any items in the array are numbers. * @category Collections */ -export const containsNumbers = /* #__PURE__*/contains(isNumber); +export const containsNumbers = /* #__PURE__*/contains(isNumber); /** * @function containsBooleans @@ -160,7 +160,7 @@ export const containsNumbers = /* #__PURE__*/contains(isNumber); * @returns {boolean} Returns true if any items in the array are booleans. * @category Collections */ -export const containsBooleans = /* #__PURE__*/contains(isBoolean); +export const containsBooleans = /* #__PURE__*/contains(isBoolean); /** * @function containsObjects @@ -168,7 +168,7 @@ export const containsBooleans = /* #__PURE__*/contains(isBoolean); * @returns {boolean} Returns true if any items in the array are object like. * @category Collections */ -export const containsObjects = /* #__PURE__*/contains(isObject); +export const containsObjects = /* #__PURE__*/contains(isObject); /** * @function containsMappables @@ -176,7 +176,7 @@ export const containsObjects = /* #__PURE__*/contains(isObject); * @returns {boolean} Returns true if any items in the array are mappable collections. * @category Collections */ -export const containsMappables = /* #__PURE__*/contains(isMappable); +export const containsMappables = /* #__PURE__*/contains(isMappable); /** * @function containsPrimatives @@ -192,7 +192,7 @@ export const containsPrimatives = /* #__PURE__*/contains(isPrimitive); * @returns {boolean} Returns true if any items in the array are functions. * @category Collections */ -export const containsFunctions = /* #__PURE__*/contains(isFunction); +export const containsFunctions = /* #__PURE__*/contains(isFunction); /** * @function containsRegEx @@ -200,7 +200,7 @@ export const containsFunctions = /* #__PURE__*/contains(isFunction); * @returns {boolean} Returns true if any items in the array are Regular Expressions. * @category Collections */ -export const containsRegEx = /* #__PURE__*/contains(isRegExp); +export const containsRegEx = /* #__PURE__*/contains(isRegExp); /** * @function containsTruthy @@ -208,7 +208,7 @@ export const containsRegEx = /* #__PURE__*/contains(isRegExp); * @returns {boolean} Returns true if any items in the array are truthy. * @category Collections */ -export const containsTruthy = /* #__PURE__*/contains(isTruthy); +export const containsTruthy = /* #__PURE__*/contains(isTruthy); /** * @function containsFalsey @@ -216,5 +216,5 @@ export const containsTruthy = /* #__PURE__*/contains(isTruthy); * @returns {boolean} Returns true if any items in the array are falsey. * @category Collections */ -export const containsFalsey = /* #__PURE__*/contains(isFalsey); +export const containsFalsey = /* #__PURE__*/contains(isFalsey); diff --git a/src/iterateObject.js b/src/iterateObject.js index 611f92d..f3dc276 100644 --- a/src/iterateObject.js +++ b/src/iterateObject.js @@ -5,7 +5,7 @@ import hasOwn from './hasOwn.js'; /** @constant **/export const ITERATE_ENTRIES = 'ENTRIES'; /** @constant **/export const ITERATE_VALUES = 'VALUES'; /** @constant **/export const ITERATE_KEYS = 'KEYS'; -/** @enum {Object} **/const ITERATE_MODE = { +/** @enum {object} **/const ITERATE_MODE = { [ITERATE_ENTRIES]: ITERATE_ENTRIES, [ITERATE_VALUES]: ITERATE_VALUES, [ITERATE_KEYS]: ITERATE_KEYS, @@ -22,12 +22,12 @@ import hasOwn from './hasOwn.js'; */ export default function* iterateObject (collection, mode = ITERATE_ENTRIES) { for (const key in collection) { // eslint-disable-line no-restricted-syntax - if (!hasOwn(collection, key)) continue; - if (mode === ITERATE_ENTRIES) yield [ key, collection[key] ]; - else if (mode === ITERATE_KEYS) yield key; - else if (mode === ITERATE_VALUES) yield collection[key]; + if (!hasOwn(collection, key)) continue; + if (mode === ITERATE_ENTRIES) yield [ key, collection[key] ]; + else if (mode === ITERATE_KEYS) yield key; + else if (mode === ITERATE_VALUES) yield collection[key]; } } iterateObject.ENTRIES = ITERATE_ENTRIES; -iterateObject.VALUES = ITERATE_VALUES; -iterateObject.KEYS = ITERATE_KEYS; +iterateObject.VALUES = ITERATE_VALUES; +iterateObject.KEYS = ITERATE_KEYS; diff --git a/src/iteratee.js b/src/iteratee.js index da0ebc6..c4602eb 100644 --- a/src/iteratee.js +++ b/src/iteratee.js @@ -89,7 +89,7 @@ import get from './get.js'; * Object: get(iValue, key) === value * Map: iValue.get(key) === value * - * @typedef {Object} ObjectPredicate + * @typedef {object} ObjectPredicate * @global */ diff --git a/src/keyBy.js b/src/keyBy.js index 9c4cabd..0c4294d 100644 --- a/src/keyBy.js +++ b/src/keyBy.js @@ -8,7 +8,7 @@ import mapReduce from './mapReduce.js'; * @param {Collection} collection * @param {Predicate} predicate * - * @returns {Object} + * @returns {object} */ export default function keyBy (collection, predicate) { predicate = iteratee(predicate); diff --git a/src/last.js b/src/last.js index 67f061e..29ecc2c 100644 --- a/src/last.js +++ b/src/last.js @@ -11,7 +11,7 @@ import { /** * Returns the last iterate values in the collection. * - * @param {Array|Set|Object|Map|string} input + * @param {Array | Set | object | Map | string} input * @param {number} [count=1] * @returns {any|Array} */ diff --git a/src/mapMode.js b/src/mapMode.js index dd7d28a..efa171d 100644 --- a/src/mapMode.js +++ b/src/mapMode.js @@ -9,9 +9,9 @@ import { isIterable, } from './types.js'; -/** @constant */ export const MAPMODE_ARRAY = 'ARRAY'; -/** @constant */ export const MAPMODE_SET = 'SET'; -/** @constant */ export const MAPMODE_MAP = 'MAP'; +/** @constant */ export const MAPMODE_ARRAY = 'ARRAY'; +/** @constant */ export const MAPMODE_SET = 'SET'; +/** @constant */ export const MAPMODE_MAP = 'MAP'; /** @constant */ export const MAPMODE_OBJECT = 'OBJECT'; /** @constant */ export const MAPMODE_ITERABLE = 'ITERABLE'; /** @constant */ export const MAPMODE_ITERATOR = 'ITERATOR'; diff --git a/src/mapReduce.js b/src/mapReduce.js index 59eac59..cdbb08e 100644 --- a/src/mapReduce.js +++ b/src/mapReduce.js @@ -12,7 +12,7 @@ import entries from './entries.js'; * * @param {Collection} collection * @param {Function} predicate - * @returns {Object} + * @returns {object} */ export default function mapReduce (collection, predicate) { if (!collection) return {}; diff --git a/src/mapValues.js b/src/mapValues.js index a61fa35..1c069ce 100644 --- a/src/mapValues.js +++ b/src/mapValues.js @@ -10,10 +10,10 @@ import entries from './entries.js'; /** * Iterates over an object's properties, transforming the values with a predicate * - * @param {Object} collection + * @param {object} collection * @param {Predicate} predicate * - * @returns {Object} + * @returns {object} */ export default function mapValues (collection, predicate) { assert(isMap(collection) || isObject(collection, true), 'mapValues only works for simple objects, use mapReduce.'); diff --git a/src/marshal.js b/src/marshal.js index 69d6a84..9a369b1 100644 --- a/src/marshal.js +++ b/src/marshal.js @@ -39,7 +39,7 @@ const isMarshalMap = (input) => { * @param {Predicate} predicate * @param {string} rest * - * @returns {Object} + * @returns {object} * @category Data */ export default function marshal (collection, predicate, rest = 'UNKNOWN') { diff --git a/src/memoize.js b/src/memoize.js index a25ddf0..e5cfc19 100644 --- a/src/memoize.js +++ b/src/memoize.js @@ -10,10 +10,10 @@ import { * and will self-invalidate if a promise rejects. * * @param {Function} fn - * @param {Object} [options] + * @param {object} [options] * @param {number} [options.maxAge] Duration the cache should survive, * in microseconds. Default is 0 (infinite) - * @param {Object} [options.context] + * @param {object} [options.context] * * @returns {any|Promise} * @category Functional diff --git a/src/merge.js b/src/merge.js index 0a50cc7..76513dd 100644 --- a/src/merge.js +++ b/src/merge.js @@ -5,9 +5,9 @@ import { /** * Combines multiple objects into one, recursively. * - * @param {...Object} sources Objects to copy. + * @param {...object} sources Objects to copy. * - * @returns {Object} + * @returns {object} * @category Data */ export default function merge (...sources) { diff --git a/src/multimap.js b/src/multimap.js index 333a5f4..b6d9c28 100644 --- a/src/multimap.js +++ b/src/multimap.js @@ -2,9 +2,9 @@ import DEFAULT from './default.js'; const /** @constant {string} */ MODE_ENTRIES = 'ENTRIES'; -const /** @constant {string} */ MODE_VALUES = 'VALUES'; -const /** @constant {string} */ MODE_KEYS = 'KEYS'; -const /** @constant {string} */ MODE_LEAVES = 'LEAVES'; +const /** @constant {string} */ MODE_VALUES = 'VALUES'; +const /** @constant {string} */ MODE_KEYS = 'KEYS'; +const /** @constant {string} */ MODE_LEAVES = 'LEAVES'; const /** @constant {Symbol} */ EMPTY_KEY = Symbol('EMPTY_KEY'); /** @enum {string} */ export const ITERATOR_MODE = { [MODE_ENTRIES]: MODE_ENTRIES, @@ -126,7 +126,7 @@ class Limb { } climb (key, ...grips) { - if (!this._limbs.has(key)) return; + if (!this._limbs.has(key)) return undefined; const limb = this._limbs.get(key); if (!grips.length) return limb._leaf; return limb.climb(...grips); diff --git a/src/nullIterator.js b/src/nullIterator.js index bbf206b..54698a7 100644 --- a/src/nullIterator.js +++ b/src/nullIterator.js @@ -1,3 +1,4 @@ +/* eslint-disable no-empty-function */ /** * Generator that does nothing diff --git a/src/omit.js b/src/omit.js index 3a19102..b4de813 100644 --- a/src/omit.js +++ b/src/omit.js @@ -6,7 +6,7 @@ import mapReduce from './mapReduce.js'; /** * Produce a collection without certain values * - * @param {Object|Array} collection + * @param {object | Array} collection * @param {Predicate} predicate * * @returns {Collection} diff --git a/src/pCoalesce.js b/src/pCoalesce.js index 75d21ae..251b846 100644 --- a/src/pCoalesce.js +++ b/src/pCoalesce.js @@ -13,7 +13,10 @@ export default async function pCoalesce (...promises) { let count = promises.length; return new Promise((resolve, reject) => { const fin = (res) => { - if (isTruthy(res) || count <= 0) return resolve(res); + if (isTruthy(res) || count <= 0) { + resolve(res); + return; + } count--; }; diff --git a/src/pDebounce.js b/src/pDebounce.js index b7ff170..bfd6551 100644 --- a/src/pDebounce.js +++ b/src/pDebounce.js @@ -7,7 +7,7 @@ import { isFunction } from './types.js'; * * @param {Function} func * @param {number} wait - * @param {Object} options + * @param {object} options * @param {boolean} options.leading * @param {number} options.maxWait * @param {*} options.context diff --git a/src/pDefer.js b/src/pDefer.js index 619baec..eeebf36 100644 --- a/src/pDefer.js +++ b/src/pDefer.js @@ -5,7 +5,7 @@ import AbortError from './abort-error-exception.js'; * Generates a promise which resolves on the next animation frame. * * @function pDefer - * @param {Object} [options] Options + * @param {object} [options] Options * @param {AbortSignal} [options.signal] Signal from an AbortController * * @returns {Promise} diff --git a/src/pDelay.js b/src/pDelay.js index 9728e2f..7afb7b7 100644 --- a/src/pDelay.js +++ b/src/pDelay.js @@ -6,7 +6,7 @@ import AbortError from './abort-error-exception.js'; * * @function pDelay * @param {number} duration Delay duration in milliseconds - * @param {Object} [options] Options + * @param {object} [options] Options * @param {AbortSignal} [options.signal] Signal from an AbortController * * @returns {Promise} diff --git a/src/pMap.js b/src/pMap.js index ea00451..da834c6 100644 --- a/src/pMap.js +++ b/src/pMap.js @@ -12,7 +12,7 @@ import fromPairs from './fromPairs.js'; * * @param {Collection} collection * @param {Predicate} predicate - * @param {Object} [options] + * @param {object} [options] * @param {number} [options.concurrency=Infinity] * * @returns {Promise} diff --git a/src/pick.js b/src/pick.js index aedbeda..7d91c6a 100644 --- a/src/pick.js +++ b/src/pick.js @@ -6,7 +6,7 @@ import mapReduce from './mapReduce.js'; /** * Produce a collection containing only certain values * - * @param {Object|Array} collection + * @param {object | Array} collection * @param {Predicate} predicate * * @returns {Collection} diff --git a/src/set.js b/src/set.js index 793f05d..d3408ee 100644 --- a/src/set.js +++ b/src/set.js @@ -13,11 +13,11 @@ import parsePath from './parsePath.js'; * Follows the given path through an object structure to set the given value, * creating objects within the structure as needed. * - * @param {Object} target + * @param {object} target * @param {string|Array} path * @param {any} value Value to set * - * @returns {Object} + * @returns {object} * @category Data */ export default function set (target, path, value) { diff --git a/src/slugify.js b/src/slugify.js index 7b11801..9cbd0f8 100644 --- a/src/slugify.js +++ b/src/slugify.js @@ -3,7 +3,7 @@ * Generates a url safe string from the given input * * @param {string} input - * @param {Object} [options] + * @param {object} [options] * @param {string} [options.delimiter] * @param {boolean} [options.separators] * @@ -13,11 +13,11 @@ export default function slugify (input, { delimiter = '-', separators = false } = {}) { var i = separators && separators.length; var slug = input; - var regexEscape = new RegExp(/[[/\\^$*+?.()|{}\]]/g); + var regexEscape = /[[/\\^$*+?.()|{}\]]/g; var regexDelimiter = delimiter.replace(regexEscape, '\\$&'); - var prohibited = new RegExp('([^a-z0-9' + regexDelimiter + '])', 'g'); - var consecutive = new RegExp('(' + regexDelimiter + '+)', 'g'); - var trim = new RegExp('^' + regexDelimiter + '*(.*?)' + regexDelimiter + '*$'); + var prohibited = new RegExp(`([^a-z0-9${regexDelimiter}])`, 'g'); + var consecutive = new RegExp(`(${regexDelimiter}+)`, 'g'); + var trim = new RegExp(`^${regexDelimiter}*(.*?)${regexDelimiter}*$`); var sanitizer = { // common latin 'รก': 'a', diff --git a/src/suspend.js b/src/suspend.js index af083b1..9c4cf3f 100644 --- a/src/suspend.js +++ b/src/suspend.js @@ -5,6 +5,7 @@ import { isPromise } from './types.js'; * * @param {Function} fn * @param {...any} args + * @returns {Promise} * @private */ async function wrapPromise (fn, ...args) { diff --git a/src/types.js b/src/types.js index b90b86f..a866362 100644 --- a/src/types.js +++ b/src/types.js @@ -15,7 +15,7 @@ * @returns {boolean} * @category Types */ -export const isArray = Array.isArray; +export const isArray = Array.isArray; /** * Tests if a given value is a Number @@ -25,7 +25,7 @@ export const isArray = Array.isArray; * @returns {boolean} * @category Types */ -export const isNumber = (input) => typeof input === 'number' && !Number.isNaN(input); +export const isNumber = (input) => typeof input === 'number' && !Number.isNaN(input); /** * Tests if a given value is a Boolean @@ -35,7 +35,7 @@ export const isNumber = (input) => typeof input === 'number' && !Nu * @returns {boolean} * @category Types */ -export const isBoolean = (input) => typeof input === 'boolean'; +export const isBoolean = (input) => typeof input === 'boolean'; /** * Tests if a given value is a String @@ -45,7 +45,7 @@ export const isBoolean = (input) => typeof input === 'boolean'; * @returns {boolean} * @category Types */ -export const isString = (input) => typeof input === 'string'; +export const isString = (input) => typeof input === 'string'; /** * Tests if a given value is a Function @@ -55,7 +55,7 @@ export const isString = (input) => typeof input === 'string'; * @returns {boolean} * @category Types */ -export const isFunction = (input) => typeof input === 'function'; +export const isFunction = (input) => typeof input === 'function'; /** * Tests if a given value is Null @@ -65,7 +65,7 @@ export const isFunction = (input) => typeof input === 'function'; * @returns {boolean} * @category Types */ -export const isNull = (input) => input === null; +export const isNull = (input) => input === null; /** * Tests if a given value is Undefined @@ -75,7 +75,7 @@ export const isNull = (input) => input === null; * @returns {boolean} * @category Types */ -export const isUndefined = (input) => typeof input === 'undefined'; +export const isUndefined = (input) => typeof input === 'undefined'; /** * Tests if a given value is Undefined or Null @@ -85,7 +85,7 @@ export const isUndefined = (input) => typeof input === 'undefined'; * @returns {boolean} * @category Types */ -export const isUndefinedOrNull = (input) => input === null || typeof input === 'undefined'; +export const isUndefinedOrNull = (input) => input === null || typeof input === 'undefined'; /** * Tests if a given value is NOT Undefined or Null @@ -95,7 +95,7 @@ export const isUndefinedOrNull = (input) => input === null || typeof input = * @returns {boolean} * @category Types */ -export const isNotUndefinedOrNull = (input) => input !== null && typeof input !== 'undefined'; +export const isNotUndefinedOrNull = (input) => input !== null && typeof input !== 'undefined'; /** * Tests if a given value is an ECMA Map @@ -105,7 +105,7 @@ export const isNotUndefinedOrNull = (input) => input !== null && typeof input ! * @returns {boolean} * @category Types */ -export const isMap = (input) => input instanceof Map; +export const isMap = (input) => input instanceof Map; /** * Tests if a given value is an ECMA Set @@ -115,7 +115,7 @@ export const isMap = (input) => input instanceof Map; * @returns {boolean} * @category Types */ -export const isSet = (input) => input instanceof Set; +export const isSet = (input) => input instanceof Set; /** * Tests if a given value is an ECMA Date object @@ -125,7 +125,7 @@ export const isSet = (input) => input instanceof Set; * @returns {boolean} * @category Types */ -export const isDate = (input) => input instanceof Date; +export const isDate = (input) => input instanceof Date; /** * Tests if a given value is a Regular Expression object @@ -135,7 +135,7 @@ export const isDate = (input) => input instanceof Date; * @returns {boolean} * @category Types */ -export const isRegExp = (input) => input instanceof RegExp; +export const isRegExp = (input) => input instanceof RegExp; /** * Tests if a given value is strictly true @@ -145,7 +145,7 @@ export const isRegExp = (input) => input instanceof RegExp; * @returns {boolean} * @category Types */ -export const isTrue = (input) => input === true; +export const isTrue = (input) => input === true; /** * Tests if a given value is strictly false @@ -155,7 +155,7 @@ export const isTrue = (input) => input === true; * @returns {boolean} * @category Types */ -export const isFalse = (input) => input === false; +export const isFalse = (input) => input === false; /** * Tests if a given value is an Array or Set @@ -165,7 +165,7 @@ export const isFalse = (input) => input === false; * @returns {boolean} * @category Types */ -export const isList = (input) => isArray(input) || isSet(input); +export const isList = (input) => isArray(input) || isSet(input); /** * Tests if a given value is an Object or Map @@ -175,7 +175,7 @@ export const isList = (input) => isArray(input) || isSet(input); * @returns {boolean} * @category Types */ -export const isDict = (input) => isObject(input) || isMap(input); +export const isDict = (input) => isObject(input) || isMap(input); /** * Tests if a given value meets the Iterator interface @@ -185,7 +185,7 @@ export const isDict = (input) => isObject(input) || isMap(input); * @returns {boolean} * @category Types */ -export const isIterator = (input) => isObject(input) && isFunction(input.next); +export const isIterator = (input) => isObject(input) && isFunction(input.next); /** * Tests if a given value meets the Promise interface @@ -195,7 +195,7 @@ export const isIterator = (input) => isObject(input) && isFunction(in * @returns {boolean} * @category Types */ -export const isPromise = (input) => isObject(input) && isFunction(input.then); +export const isPromise = (input) => isObject(input) && isFunction(input.then); const GeneratorFunction = (function* G () { yield undefined; }).constructor; diff --git a/tests/empty.js b/tests/empty.js index 5ed5752..16d9bb7 100644 --- a/tests/empty.js +++ b/tests/empty.js @@ -9,22 +9,22 @@ tap.test('empty()', async (t) => { [ true, null, false ], [ false, null, true ], [ true, 'a' / 1 ], - [ true, '' ], + [ true, '' ], [ false, '0' ], [ false, '1' ], [ false, 'a' ], [ false, false, false ], // boolean false strict - [ true, false, true ], // boolean false loose - [ false, true, false ], // boolean true strict - [ false, true, true ], // boolean true loose + [ true, false, true ], // boolean false loose + [ false, true, false ], // boolean true strict + [ false, true, true ], // boolean true loose [ false, 0 ], - [ true, 0, true ], + [ true, 0, true ], [ false, 1 ], [ false, 1, true ], [ false, new Date ], [ false, new Date, true ], [ false, new Date('invalid') ], - [ true, new Date('invalid'), true ], + [ true, new Date('invalid'), true ], [ true, [] ], [ true, [], true ], [ false, [ 0 ] ], @@ -36,21 +36,21 @@ tap.test('empty()', async (t) => { [ true, {} ], [ true, {}, true ], [ false, { a: undefined } ], - [ true, { a: undefined }, true ], + [ true, { a: undefined }, true ], [ false, Object.create({ a: undefined }) ], - [ true, Object.create({ a: undefined }), true ], + [ true, Object.create({ a: undefined }), true ], [ false, Object.create({ a: true }), true ], [ false, Object.assign(Object.create({ a: undefined }), { b: undefined }) ], - [ true, Object.assign(Object.create({ a: undefined }), { b: undefined }), true ], + [ true, Object.assign(Object.create({ a: undefined }), { b: undefined }), true ], [ false, Object.assign(Object.create({ a: undefined }), { b: true }), true ], [ true, new Map() ], [ false, new Map([ [ 'a', undefined ] ]), false ], - [ true, new Map([ [ 'a', undefined ] ]), true ], + [ true, new Map([ [ 'a', undefined ] ]), true ], [ false, new Map([ [ 'a', 'a' ] ]) ], [ false, new Map([ [ 'a', '' ] ]) ], [ true, new Set() ], [ false, new Set([ undefined ]), false ], - [ true, new Set([ undefined ]), true ], + [ true, new Set([ undefined ]), true ], [ false, new Set([ 'a' ]) ], [ false, new Set([ 0 ]) ], [ false, new Set([ [ ] ]) ], diff --git a/tests/first.js b/tests/first.js index e9152a0..93fab0c 100644 --- a/tests/first.js +++ b/tests/first.js @@ -25,8 +25,8 @@ tap.test('first', async (t) => { ]; for (const input of inputs) { - t.same(first(input ), 1, 'single value' + input); - t.same(first(input, 2), [ 1, 2 ], 'multiple values' + input); + t.same(first(input ), 1, `single value${input}`); + t.same(first(input, 2), [ 1, 2 ], `multiple values${input}`); } }); diff --git a/tests/map.js b/tests/map.js index 26ed58c..9c37c14 100644 --- a/tests/map.js +++ b/tests/map.js @@ -21,10 +21,10 @@ tap.test('map object', async (t) => { tap.test('map map', async (t) => { const targets = [ - [ '1', 1 ], - [ '2', '2' ], - [ '3', [ 3 ] ], - [ '4', { four: 4 } ], + [ '1', 1 ], + [ '2', '2' ], + [ '3', [ 3 ] ], + [ '4', { four: 4 } ], ]; const m = new Map(targets); diff --git a/tests/memoize.js b/tests/memoize.js index 3828880..b60f9e2 100644 --- a/tests/memoize.js +++ b/tests/memoize.js @@ -120,7 +120,7 @@ tap.test('multiple arguments', async (t) => { t.equal(fn('B', arr2, 1), 3, 'Fourth call invokes'); t.equal(fn('A', arr1, 1), 1, 'Fifth call w/original arguments returns original'); t.equal(fn('B', arr2, 2), 4, 'Sixth call invokes'); - t.equal(fn('A', obj, 1), 5, 'Seventh call invokes'); + t.equal(fn('A', obj, 1), 5, 'Seventh call invokes'); fn.purge('B', arr2, 1); t.equal(fn('B', arr2, 1), 6, 'Purged arguments re-invoke'); diff --git a/tests/pdebounce.js b/tests/pdebounce.js index 0dd47c6..e9ffb16 100644 --- a/tests/pdebounce.js +++ b/tests/pdebounce.js @@ -3,7 +3,7 @@ import tap from 'tap'; import { pDebounce } from '../src/index.js'; function sleep (ms) { - return new Promise((resolve) => setTimeout(resolve, ms)); + return new Promise((resolve) => { setTimeout(resolve, ms); }); } tap.test('pDebounce', async (s) => {