@tim-code/my-util 0.5.13 → 0.5.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-code/my-util",
3
- "version": "0.5.13",
3
+ "version": "0.5.14",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "author": "Tim Sprowl",
package/src/array.js CHANGED
@@ -4,23 +4,24 @@
4
4
  * If the iterable has no elements, returns an empty array since there are no chunks.
5
5
  * @param {Iterable} iterable
6
6
  * @param {number=} chunkSize If not provided, returns an array consisting of one chunk, which has all the elements of input iterable.
7
+ * This has the same effect as passing a chunk size that is greater than the number of elements in the iterable.
7
8
  * @returns {Array}
8
9
  */
9
10
  export function chunk(iterable, chunkSize = Infinity) {
10
- if (chunkSize !== Infinity && (chunkSize <= 0 || chunkSize % 1 !== 0)) {
11
+ if (chunkSize !== Infinity && (chunkSize <= 0 || !Number.isInteger(chunkSize))) {
11
12
  throw new Error("chunkSize must be a positive integer or Infinity")
12
13
  }
13
14
  const chunks = []
14
- let currentChunk = []
15
+ let current = []
15
16
  for (const element of iterable) {
16
- currentChunk.push(element)
17
- if (currentChunk.length >= chunkSize) {
18
- chunks.push(currentChunk)
19
- currentChunk = []
17
+ current.push(element)
18
+ if (current.length >= chunkSize) {
19
+ chunks.push(current)
20
+ current = []
20
21
  }
21
22
  }
22
- if (currentChunk.length) {
23
- chunks.push(currentChunk)
23
+ if (current.length) {
24
+ chunks.push(current)
24
25
  }
25
26
  return chunks
26
27
  }
@@ -240,7 +241,7 @@ export function sortN(
240
241
  array,
241
242
  { N, compare = ascending(), unsorted = false, force = false, mutate = false }
242
243
  ) {
243
- if (!(N >= 0) || N % 1 !== 0) {
244
+ if (!(N >= 0) || !Number.isInteger(N)) {
244
245
  throw new Error("N must be a nonnegative integer")
245
246
  }
246
247
  if (N === 0) {
package/src/math.js CHANGED
@@ -166,7 +166,7 @@ export function isNumber(number) {
166
166
  * @returns {Object|undefined} Returns undefined is array is empty
167
167
  */
168
168
  export function quantiles(array, { N, key, method = Math.round }) {
169
- if (!(N > 0) || N % 1 !== 0) {
169
+ if (!(N > 0) || !Number.isInteger(N)) {
170
170
  throw new Error("N must be a positive integer")
171
171
  }
172
172
  if (!array.length) {