@uxf/core 11.89.0 → 11.91.0

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/README.md CHANGED
@@ -343,6 +343,26 @@ formatBytes(17.5 * 1024);
343
343
  //=> "17.5 kB"
344
344
  ```
345
345
 
346
+ ## inArray
347
+
348
+ Type-safe helper for checking if a value exists in an array. Particularly useful with `as const` arrays where the value type is wider than the array element type.
349
+
350
+ ```tsx
351
+ import { inArray } from "@uxf/core/utils/in-array";
352
+
353
+ // Basic usage
354
+ inArray("a", ["a", "b", "c"]); /* returns true */
355
+ inArray("d", ["a", "b", "c"]); /* returns false */
356
+
357
+ // Useful with const arrays and wider value types
358
+ const statuses = ["pending", "active", "completed"] as const;
359
+ const status: string = getStatusFromApi();
360
+
361
+ if (inArray(status, statuses)) {
362
+ // status is now narrowed to the array values
363
+ }
364
+ ```
365
+
346
366
  ## isEmpty
347
367
 
348
368
  ```tsx
@@ -422,6 +442,27 @@ isNotNil([]); /* returns true */
422
442
  isNotNil("string"); /* returns true */
423
443
  ```
424
444
 
445
+ ## isPlainObject
446
+
447
+ Type guard that checks if a value is a plain object. Returns `false` for arrays, `null`, `Date`, `Map`, `Set`, `RegExp`, and other non-plain-object types.
448
+
449
+ ```tsx
450
+ import { isPlainObject } from "@uxf/core/utils/is-plain-object";
451
+
452
+ isPlainObject({}); /* returns true */
453
+ isPlainObject({ a: 1 }); /* returns true */
454
+ isPlainObject([]); /* returns false */
455
+ isPlainObject([1, 2, 3]); /* returns false */
456
+ isPlainObject(new Date()); /* returns false */
457
+ isPlainObject(new Map()); /* returns false */
458
+ isPlainObject(new Set()); /* returns false */
459
+ isPlainObject(/regex/); /* returns false */
460
+ isPlainObject(null); /* returns false */
461
+ isPlainObject(undefined); /* returns false */
462
+ isPlainObject("string"); /* returns false */
463
+ isPlainObject(123); /* returns false */
464
+ ```
465
+
425
466
  ## last
426
467
 
427
468
  ```tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "11.89.0",
3
+ "version": "11.91.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
package/types/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export type Nullish = null | undefined;
2
2
  export type Noop = () => void;
3
3
  export type AnyObject = Partial<Record<string, any>>;
4
+ export type UnknownObject = Partial<Record<string, unknown>>;
4
5
  export type AnyJSON = any;
5
6
  export interface FileResponse {
6
7
  id: number;
@@ -0,0 +1 @@
1
+ export declare function inArray<Value, Array extends Value>(value: Value, array: readonly Array[]): boolean;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inArray = inArray;
4
+ function inArray(value, array) {
5
+ return array.includes(value);
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const in_array_1 = require("./in-array");
4
+ test("in-array", () => {
5
+ expect((0, in_array_1.inArray)("a", ["a", "b", "c"])).toBeTruthy();
6
+ expect((0, in_array_1.inArray)("b", ["a", "b", "c"])).toBeTruthy();
7
+ expect((0, in_array_1.inArray)("c", ["a", "b", "c"])).toBeTruthy();
8
+ expect((0, in_array_1.inArray)("d", ["a", "b", "c"])).toBeFalsy();
9
+ expect((0, in_array_1.inArray)(1, [1, 2, 3])).toBeTruthy();
10
+ expect((0, in_array_1.inArray)(4, [1, 2, 3])).toBeFalsy();
11
+ expect((0, in_array_1.inArray)("value", [])).toBeFalsy();
12
+ });
13
+ test("in-array with const array", () => {
14
+ const statuses = ["pending", "active", "completed"];
15
+ const status = "active";
16
+ expect((0, in_array_1.inArray)(status, statuses)).toBeTruthy();
17
+ const unknownStatus = "unknown";
18
+ expect((0, in_array_1.inArray)(unknownStatus, statuses)).toBeFalsy();
19
+ });
@@ -0,0 +1,2 @@
1
+ import { UnknownObject } from "../types";
2
+ export declare function isPlainObject(value: unknown): value is UnknownObject;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPlainObject = isPlainObject;
4
+ function isPlainObject(value) {
5
+ var _a;
6
+ if (typeof value !== "object" || value === null) {
7
+ return false;
8
+ }
9
+ if (Object.prototype.toString.call(value) !== "[object Object]") {
10
+ return false;
11
+ }
12
+ const proto = Object.getPrototypeOf(value);
13
+ if (proto === null) {
14
+ return true;
15
+ }
16
+ // Handle cross-realm objects by checking if proto's constructor is named "Object"
17
+ return ((_a = proto.constructor) === null || _a === void 0 ? void 0 : _a.name) === "Object";
18
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_plain_object_1 = require("./is-plain-object");
4
+ test("is-plain-object", () => {
5
+ [{}, { a: 1 }, Object.create(null)].map((value) => expect((0, is_plain_object_1.isPlainObject)(value)).toBeTruthy());
6
+ const emptyFn = () => undefined;
7
+ [
8
+ null,
9
+ undefined,
10
+ "",
11
+ "string",
12
+ 0,
13
+ 1,
14
+ true,
15
+ false,
16
+ NaN,
17
+ Infinity,
18
+ Symbol("test"),
19
+ emptyFn,
20
+ [],
21
+ [1, 2, 3],
22
+ new Date(),
23
+ new Map(),
24
+ new Set(),
25
+ /regex/,
26
+ ].map((value) => expect((0, is_plain_object_1.isPlainObject)(value)).toBeFalsy());
27
+ });