@uxf/core 11.88.0 → 11.90.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
@@ -422,6 +422,27 @@ isNotNil([]); /* returns true */
422
422
  isNotNil("string"); /* returns true */
423
423
  ```
424
424
 
425
+ ## isPlainObject
426
+
427
+ 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.
428
+
429
+ ```tsx
430
+ import { isPlainObject } from "@uxf/core/utils/is-plain-object";
431
+
432
+ isPlainObject({}); /* returns true */
433
+ isPlainObject({ a: 1 }); /* returns true */
434
+ isPlainObject([]); /* returns false */
435
+ isPlainObject([1, 2, 3]); /* returns false */
436
+ isPlainObject(new Date()); /* returns false */
437
+ isPlainObject(new Map()); /* returns false */
438
+ isPlainObject(new Set()); /* returns false */
439
+ isPlainObject(/regex/); /* returns false */
440
+ isPlainObject(null); /* returns false */
441
+ isPlainObject(undefined); /* returns false */
442
+ isPlainObject("string"); /* returns false */
443
+ isPlainObject(123); /* returns false */
444
+ ```
445
+
425
446
  ## last
426
447
 
427
448
  ```tsx
@@ -1 +1 @@
1
- export declare const EMPTY_OBJECT: Record<string, never>;
1
+ export declare const EMPTY_OBJECT: Partial<Record<string, never>>;
package/cookie/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { AnyObject } from "../types";
1
2
  interface CookieOptions {
2
3
  domain?: string;
3
4
  httpOnly?: boolean;
@@ -8,8 +9,8 @@ interface CookieOptions {
8
9
  }
9
10
  export declare class Cookie {
10
11
  private ctx;
11
- constructor(ctx?: any | null);
12
- static create(ctx?: any): Cookie;
12
+ constructor(ctx?: AnyObject | null);
13
+ static create(ctx?: AnyObject | null): Cookie;
13
14
  has(name: string): boolean;
14
15
  set(name: string, value: string, ttl?: number, options?: CookieOptions): Cookie;
15
16
  get(cookieName: string): string;
package/cookie/index.js CHANGED
@@ -14,6 +14,7 @@ class Cookie {
14
14
  return (0, is_not_empty_1.isNotEmpty)(this.get(name));
15
15
  }
16
16
  set(name, value, ttl = 3600, options = {}) {
17
+ var _a, _b;
17
18
  const date = new Date();
18
19
  date.setTime(date.getTime() + ttl * 1000);
19
20
  const cookieParts = [`${name}=${encodeURIComponent(value)}`, `expires=${date.toUTCString()}`];
@@ -38,9 +39,9 @@ class Cookie {
38
39
  document.cookie = cookie;
39
40
  }
40
41
  else {
41
- const existsCookies = (this.ctx.res.getHeader("Set-Cookie") || []).slice(0);
42
+ const existsCookies = (((_a = this.ctx) === null || _a === void 0 ? void 0 : _a.res.getHeader("Set-Cookie")) || []).slice(0);
42
43
  existsCookies.push(cookie);
43
- this.ctx.res.setHeader("Set-Cookie", existsCookies);
44
+ (_b = this.ctx) === null || _b === void 0 ? void 0 : _b.res.setHeader("Set-Cookie", existsCookies);
44
45
  }
45
46
  return this;
46
47
  }
@@ -1,2 +1,5 @@
1
1
  import { DateString } from "./index";
2
- export declare function toDateString<T extends Date | null>(value: T): T extends null ? DateString | null : DateString;
2
+ type InputType = Date | null;
3
+ type ReturnType<T extends InputType> = T extends null ? DateString | null : DateString;
4
+ export declare function toDateString<T extends InputType>(value: T): ReturnType<T>;
5
+ export {};
@@ -1,2 +1,5 @@
1
1
  import { DatetimeString } from "./index";
2
- export declare function toDatetimeString<T extends Date | null>(value: T): T extends null ? DatetimeString | null : DatetimeString;
2
+ type InputType = Date | null;
3
+ type ReturnType<T extends InputType> = T extends null ? DatetimeString | null : DatetimeString;
4
+ export declare function toDatetimeString<T extends InputType>(value: T): ReturnType<T>;
5
+ export {};
@@ -1,2 +1,5 @@
1
1
  import { TimeString } from "./index";
2
- export declare function toTimeString<T extends Date | null>(value: T): T extends null ? TimeString | null : TimeString;
2
+ type InputType = Date | null;
3
+ type ReturnType<T extends InputType> = T extends null ? TimeString | null : TimeString;
4
+ export declare function toTimeString<T extends InputType>(value: T): ReturnType<T>;
5
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "11.88.0",
3
+ "version": "11.90.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/qr/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  interface Config {
2
- width?: number;
3
2
  errorCorrectionLevel?: "L" | "M" | "Q" | "H";
4
3
  margin?: number;
4
+ width?: number;
5
5
  }
6
6
  export declare function qrCodeUrl(url: string, config?: Config): string;
7
7
  export {};
package/types/index.d.ts CHANGED
@@ -1,6 +1,8 @@
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>>;
5
+ export type AnyJSON = any;
4
6
  export interface FileResponse {
5
7
  id: number;
6
8
  name: string;
@@ -1,7 +1,7 @@
1
- export interface BodyScrollOptions {
2
- reserveScrollBarGap?: boolean;
3
- allowTouchMove?: (el: any) => boolean;
1
+ export interface BodyScrollOptions<E extends HTMLElement> {
2
+ allowTouchMove?: (el: E) => boolean;
3
+ willReserveScrollBarGap?: boolean;
4
4
  }
5
- export declare const disableBodyScroll: (targetElement: any, options?: BodyScrollOptions) => void;
5
+ export declare const disableBodyScroll: <E extends HTMLElement = HTMLElement>(targetElement: E | null, options?: BodyScrollOptions<E>) => void;
6
6
  export declare const clearAllBodyScrollLocks: () => void;
7
- export declare const enableBodyScroll: (targetElement: any) => void;
7
+ export declare const enableBodyScroll: <E extends HTMLElement = HTMLElement>(targetElement: E | null) => void;
@@ -2,6 +2,7 @@
2
2
  // Forked from "body-scroll-lock" https://github.com/willmcpo/body-scroll-lock
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.enableBodyScroll = exports.clearAllBodyScrollLocks = exports.disableBodyScroll = void 0;
5
+ const is_nil_1 = require("./is-nil");
5
6
  const noop_1 = require("./noop");
6
7
  // Older browsers don't support event options, feature detect it.
7
8
  let hasPassiveEvents = false;
@@ -21,7 +22,7 @@ const isIosDevice = typeof window !== "undefined" &&
21
22
  (/iP(ad|hone|od)/.test(window.navigator.platform) ||
22
23
  (window.navigator.platform === "MacIntel" && window.navigator.maxTouchPoints > 1));
23
24
  let locks = [];
24
- let documentListenerAdded = false;
25
+ let isDocumentListenerAdded = false;
25
26
  let initialClientY = -1;
26
27
  let previousBodyOverflowSetting;
27
28
  let previousBodyPosition;
@@ -34,11 +35,11 @@ const preventDefault = (rawEvent) => {
34
35
  // Recall that we do document.addEventListener('touchmove', preventDefault, { passive: false })
35
36
  // in disableBodyScroll - so if we provide this opportunity to allowTouchMove, then
36
37
  // the touchmove event on document will break.
37
- if ((e === null || e === void 0 ? void 0 : e.target) && allowTouchMove(e.target)) {
38
+ if ((e === null || e === void 0 ? void 0 : e.target) && e.target instanceof HTMLElement && allowTouchMove(e.target)) {
38
39
  return true;
39
40
  }
40
41
  // Do not prevent if the event has more than one touch (usually meaning this is a multi touch gesture like pinch to zoom).
41
- if ((e === null || e === void 0 ? void 0 : e.touches.length) > 1) {
42
+ if (e instanceof TouchEvent && e.touches.length > 1) {
42
43
  return true;
43
44
  }
44
45
  if (e === null || e === void 0 ? void 0 : e.preventDefault) {
@@ -49,9 +50,9 @@ const preventDefault = (rawEvent) => {
49
50
  const setOverflowHidden = (options) => {
50
51
  // If previousBodyPaddingRight is already set, don't set it again.
51
52
  if (previousBodyPaddingRight === undefined) {
52
- const reserveScrollBarGap = (options === null || options === void 0 ? void 0 : options.reserveScrollBarGap) === true;
53
+ const willReserveScrollBarGap = (options === null || options === void 0 ? void 0 : options.willReserveScrollBarGap) === true;
53
54
  const scrollBarGap = window.innerWidth - document.documentElement.clientWidth;
54
- if (reserveScrollBarGap && scrollBarGap > 0) {
55
+ if (willReserveScrollBarGap && scrollBarGap > 0) {
55
56
  const computedBodyPaddingRight = parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"), 10);
56
57
  previousBodyPaddingRight = document.body.style.paddingRight;
57
58
  document.body.style.paddingRight = `${computedBodyPaddingRight + scrollBarGap}px`;
@@ -119,7 +120,7 @@ const isTargetElementTotallyScrolled = (targetElement) => targetElement ? target
119
120
  const handleScroll = (event, targetElement) => {
120
121
  var _a, _b;
121
122
  const clientY = (_b = (_a = event.targetTouches.item(0)) === null || _a === void 0 ? void 0 : _a.clientY) !== null && _b !== void 0 ? _b : 0 - initialClientY;
122
- if (event.target && allowTouchMove(event.target)) {
123
+ if (event.target && event.target instanceof HTMLElement && allowTouchMove(event.target)) {
123
124
  return false;
124
125
  }
125
126
  if (targetElement && targetElement.scrollTop === 0 && clientY > 0) {
@@ -169,9 +170,9 @@ const disableBodyScroll = (targetElement, options) => {
169
170
  handleScroll(event, targetElement);
170
171
  }
171
172
  };
172
- if (!documentListenerAdded) {
173
+ if (!isDocumentListenerAdded) {
173
174
  document.addEventListener("touchmove", preventDefault, hasPassiveEvents ? { passive: false } : undefined);
174
- documentListenerAdded = true;
175
+ isDocumentListenerAdded = true;
175
176
  }
176
177
  }
177
178
  };
@@ -180,12 +181,15 @@ const clearAllBodyScrollLocks = () => {
180
181
  if (isIosDevice) {
181
182
  // Clear all locks ontouchstart/ontouchmove handlers, and the references.
182
183
  locks.forEach((lock) => {
184
+ if ((0, is_nil_1.isNil)(lock.targetElement)) {
185
+ return;
186
+ }
183
187
  lock.targetElement.ontouchstart = null;
184
188
  lock.targetElement.ontouchmove = null;
185
189
  });
186
- if (documentListenerAdded) {
190
+ if (isDocumentListenerAdded) {
187
191
  document.removeEventListener("touchmove", preventDefault);
188
- documentListenerAdded = false;
192
+ isDocumentListenerAdded = false;
189
193
  }
190
194
  // Reset initial clientY.
191
195
  initialClientY = -1;
@@ -209,9 +213,9 @@ const enableBodyScroll = (targetElement) => {
209
213
  if (isIosDevice) {
210
214
  targetElement.ontouchstart = null;
211
215
  targetElement.ontouchmove = null;
212
- if (documentListenerAdded && locks.length === 0) {
216
+ if (isDocumentListenerAdded && locks.length === 0) {
213
217
  document.removeEventListener("touchmove", preventDefault);
214
- documentListenerAdded = false;
218
+ isDocumentListenerAdded = false;
215
219
  }
216
220
  }
217
221
  if (isIosDevice) {
package/utils/cxa.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export type CxaClassValue = CxaClassArray | Record<string, any> | string | number | null | boolean | undefined;
1
+ import { AnyObject } from "../types";
2
+ export type CxaClassValue = CxaClassArray | AnyObject | string | number | null | boolean | undefined;
2
3
  export type CxaClassArray = CxaClassValue[];
3
4
  export declare function cxa(...classes: CxaClassValue[]): string;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // packages/core/utils/deep-equal-ingoring-key-order.test.ts
4
3
  const deep_equal_ingoring_key_order_1 = require("./deep-equal-ingoring-key-order");
5
4
  describe("deepEqualIgnoringKeyOrder", () => {
6
5
  it("returns true for objects with same keys in different orders", () => {
@@ -1,3 +1,4 @@
1
- export declare function filterAriaAndDataAttrs<P extends Record<string, any>>(props: P): {
1
+ import { AnyObject } from "../types";
2
+ export declare function filterAriaAndDataAttrs<P extends AnyObject>(props: P): {
2
3
  [k: string]: any;
3
4
  };
@@ -1,3 +1,4 @@
1
- export declare function filterNullishObjectValues(obj: Record<string, any>): {
1
+ import { AnyObject } from "../types";
2
+ export declare function filterNullishObjectValues(obj: AnyObject): {
2
3
  [k: string]: any;
3
4
  };
@@ -1,3 +1,2 @@
1
- export declare function isEmpty(value: any[] | {
2
- [key: string]: any;
3
- } | string): boolean;
1
+ import { AnyObject } from "../types";
2
+ export declare function isEmpty(value: unknown[] | AnyObject | string): boolean;
package/utils/is-nil.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function isNil(value: any): value is null | undefined;
1
+ export declare function isNil(value: unknown): value is null | undefined;
@@ -1,3 +1,2 @@
1
- export declare function isNotEmpty(value: any[] | {
2
- [key: string]: any;
3
- } | string): boolean;
1
+ import { AnyObject } from "../types";
2
+ export declare function isNotEmpty(value: unknown[] | AnyObject | string): boolean;
@@ -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
+ });
package/utils/omit.d.ts CHANGED
@@ -1 +1,2 @@
1
- export declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
1
+ import { AnyObject } from "../types";
2
+ export declare function omit<T extends AnyObject, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
@@ -1 +1,2 @@
1
- export declare function sortObjectKeys<T extends Record<string, any>>(object: T): T;
1
+ import { AnyObject } from "../types";
2
+ export declare function sortObjectKeys<T extends AnyObject>(object: T): T;
@@ -5,5 +5,5 @@ export declare const FormValidator: {
5
5
  isLessOrEqualThan: (maxValue: number, errorMessage?: string) => (value: string) => string | undefined;
6
6
  isLessThan: (maxValue: number, errorMessage?: string) => (value: string) => string | undefined;
7
7
  isPhone: (errorMessage?: string) => (value: string) => string | undefined;
8
- required: (errorMessage?: string) => (value: any) => string | undefined;
8
+ required: (errorMessage?: string) => (value: unknown) => string | undefined;
9
9
  };