@tim-code/my-util 0.6.0 → 0.6.2

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.
@@ -0,0 +1 @@
1
+ export { default } from "@tim-code/eslint-config"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-code/my-util",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "author": "Tim Sprowl",
@@ -21,24 +21,15 @@
21
21
  "scripts": {
22
22
  "test": "node --no-warnings --experimental-vm-modules node_modules/.bin/jest"
23
23
  },
24
- "eslintConfig": {
25
- "root": true,
26
- "extends": [
27
- "@tim-code"
28
- ]
29
- },
30
24
  "devDependencies": {
31
- "@jest/globals": "^29.7.0",
32
- "@tim-code/eslint-config": "^1.4.0",
33
- "jest": "^29.7.0"
25
+ "@jest/globals": "^30.2.0",
26
+ "@tim-code/eslint-config": "^2.0.1",
27
+ "jest": "^30.2.0"
34
28
  },
35
29
  "jest": {
36
30
  "transform": {}
37
31
  },
38
32
  "publishConfig": {
39
33
  "access": "public"
40
- },
41
- "dependencies": {
42
- "@tim-code/my-util": "^0.5.5"
43
34
  }
44
35
  }
package/src/array.js CHANGED
@@ -194,7 +194,6 @@ export function multilevel(...comparators) {
194
194
  }
195
195
 
196
196
  function siftDown(heap, i, compare, length) {
197
- // eslint-disable-next-line no-constant-condition
198
197
  while (true) {
199
198
  const left = 2 * i + 1
200
199
  const right = left + 1
package/src/find.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable complexity */
1
2
  export function findEq(array, desired, { key } = {}) {
2
3
  if (typeof key === "function") {
3
4
  for (let i = 0; i < array.length; i++) {
@@ -316,7 +317,6 @@ export function findMax(array, { key, cutoff = -Infinity } = {}) {
316
317
  * When true, changes the default values of "from", "until", "to" to `array.length - 1`, `-1`, `0`.
317
318
  * @returns {T}
318
319
  */
319
- // eslint-disable-next-line complexity
320
320
  export function findTruthy(
321
321
  array,
322
322
  {
package/src/object.js CHANGED
@@ -182,3 +182,20 @@ export function deepEqual(a, b) {
182
182
  }
183
183
  return true
184
184
  }
185
+
186
+ /**
187
+ * Checks if the argument is a class.
188
+ * Example: `isClass(class {})`
189
+ * Returns: true
190
+ * In general, this will only work for third-party or user-defined classes, not built-ins.
191
+ * @param {any} thing
192
+ * @returns {boolean}
193
+ */
194
+ export function isClass(thing) {
195
+ if (typeof thing !== "function") {
196
+ return false
197
+ }
198
+ const stringified = Function.prototype.toString.call(thing)
199
+ const result = /^class\s/u.test(stringified)
200
+ return result
201
+ }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-empty-function */
1
2
  import { jest } from "@jest/globals"
2
3
  import {
3
4
  deepCopy,
@@ -5,6 +6,7 @@ import {
5
6
  deepMerge,
6
7
  deepMergeCopy,
7
8
  deleteUndefinedValues,
9
+ isClass,
8
10
  isObject,
9
11
  like,
10
12
  mapValues,
@@ -38,7 +40,7 @@ describe("isObject", () => {
38
40
 
39
41
  it("returns false for functions", () => {
40
42
  expect(isObject(() => {})).toBe(false)
41
- // eslint-disable-next-line func-names, prefer-arrow-callback, no-empty-function
43
+ // eslint-disable-next-line func-names, prefer-arrow-callback
42
44
  expect(isObject(function () {})).toBe(false)
43
45
  })
44
46
  })
@@ -592,3 +594,33 @@ describe("deepEqual", () => {
592
594
  expect(deepEqual({}, { a: undefined })).toBe(false)
593
595
  })
594
596
  })
597
+
598
+ // --- isClass ---
599
+ describe("isClass", () => {
600
+ it("returns true for class declarations and expressions", () => {
601
+ class A {}
602
+ const B = class {}
603
+ expect(isClass(A)).toBe(true)
604
+ expect(isClass(B)).toBe(true)
605
+ })
606
+
607
+ it("returns false for non-class functions", () => {
608
+ function f() {}
609
+ const g = () => {}
610
+ async function af() {}
611
+ function* gf() {}
612
+ expect(isClass(f)).toBe(false)
613
+ expect(isClass(g)).toBe(false)
614
+ expect(isClass(af)).toBe(false)
615
+ expect(isClass(gf)).toBe(false)
616
+ })
617
+
618
+ it("returns false for built-in constructors and non-functions", () => {
619
+ // Built-ins typically stringify as 'function X() { [native code] }'
620
+ expect(isClass(Date)).toBe(false)
621
+ expect(isClass(Map)).toBe(false)
622
+ expect(isClass(123)).toBe(false)
623
+ expect(isClass({})).toBe(false)
624
+ expect(isClass(null)).toBe(false)
625
+ })
626
+ })
package/src/time.js CHANGED
@@ -45,7 +45,7 @@ export function getTime({ floorMinute, timestamp, timeZone = false } = {}) {
45
45
  }
46
46
 
47
47
  /**
48
- * Get today's date in YYYY-MM-DD format.
48
+ * Get today's date in YYYY-MM-DD format using local time.
49
49
  * @returns {string}
50
50
  */
51
51
  export function today() {