Implement isPlainObject, isArrayLike, isIterable, and isThenable
A logging library accepts almost anything: config objects, arrays, DOM lists, Maps, promises. Before it serializes a value, it needs to know what shape the value has. typeof says 'object' for nearly all of these, so you will write sharper checks.
Implement an object named shapeChecks with four methods. Each one takes any value and returns true or false.
shapeChecks.isPlainObject(value) // => boolean
shapeChecks.isArrayLike(value) // => boolean
shapeChecks.isIterable(value) // => boolean
shapeChecks.isThenable(value) // => boolean
true or false), never a truthy or falsy value.false: null, undefined, numbers, strings, booleans, bigints and symbols. This is true even though strings have a length and can be iterated. Boxed values such as new String('ab') are objects, not primitives.Proxy). In that case, return false.isPlainObject: an object (not a function) whose prototype is exactly Object.prototype or null. Object literals, new Object(), JSON.parse results and Object.create(null) qualify. Arrays, dates, maps, regular expressions, class instances and Object.create({}) do not.isArrayLike: an object (not a function) whose length is an integer from 0 to Number.MAX_SAFE_INTEGER. Arrays, arguments, typed arrays, NodeLists and { length: 2, 0: 'a', 1: 'b' } qualify. Functions have a numeric length too, but they do not count.isIterable: an object or function whose [Symbol.iterator] property is a function. Arrays, maps, sets, generator objects and custom iterables qualify.isThenable: an object or function whose then property is a function, whether it is an own property or inherited. Read value.then only once: it can be a getter.shapeChecks.isPlainObject({ retries: 3 }); // true
shapeChecks.isPlainObject(Object.create(null)); // true
shapeChecks.isPlainObject(new Date()); // false
shapeChecks.isArrayLike({ length: 2, 0: 'a', 1: 'b' }); // true
shapeChecks.isArrayLike({ length: 1.5 }); // false
shapeChecks.isArrayLike('abc'); // false (primitive)
shapeChecks.isIterable(new Map()); // true
shapeChecks.isIterable({ length: 2 }); // false
shapeChecks.isThenable(Promise.resolve(1)); // true
shapeChecks.isThenable({ then: true }); // false
shapeChecks.isThenable({ get then() { throw new Error('nope'); } }); // false