@uxf/core 11.87.0 → 11.89.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 +103 -0
- package/constants/empty-object.d.ts +1 -1
- package/cookie/index.d.ts +3 -2
- package/cookie/index.js +3 -2
- package/date/to-date-string.d.ts +4 -1
- package/date/to-datetime-string.d.ts +4 -1
- package/date/to-time-string.d.ts +4 -1
- package/package.json +1 -1
- package/qr/index.d.ts +1 -1
- package/types/index.d.ts +2 -0
- package/utils/body-scroll-lock.d.ts +5 -5
- package/utils/body-scroll-lock.js +16 -12
- package/utils/cxa.d.ts +2 -1
- package/utils/deep-equal-ingoring-key-order.test.js +0 -1
- package/utils/filter-aria-and-data-attrs.d.ts +2 -1
- package/utils/filter-nullish-object-values.d.ts +4 -0
- package/utils/filter-nullish-object-values.js +7 -0
- package/utils/filter-nullish-object-values.test.d.ts +1 -0
- package/utils/filter-nullish-object-values.test.js +18 -0
- package/utils/filter-nullish.d.ts +2 -1
- package/utils/is-empty.d.ts +2 -3
- package/utils/is-even.d.ts +1 -0
- package/utils/is-even.js +6 -0
- package/utils/is-even.test.d.ts +1 -0
- package/utils/is-even.test.js +7 -0
- package/utils/is-nil.d.ts +1 -1
- package/utils/is-not-empty.d.ts +2 -3
- package/utils/is-odd.d.ts +1 -0
- package/utils/is-odd.js +7 -0
- package/utils/is-odd.test.d.ts +1 -0
- package/utils/is-odd.test.js +7 -0
- package/utils/non-empty-array-or-null.d.ts +2 -0
- package/utils/non-empty-array-or-null.js +8 -0
- package/utils/non-empty-array-or-null.test.d.ts +1 -0
- package/utils/non-empty-array-or-null.test.js +14 -0
- package/utils/non-empty-string-or-null.d.ts +2 -0
- package/utils/non-empty-string-or-null.js +6 -0
- package/utils/non-empty-string-or-null.test.d.ts +1 -0
- package/utils/non-empty-string-or-null.test.js +11 -0
- package/utils/nullish-to-empty-string.d.ts +2 -0
- package/utils/nullish-to-empty-string.js +6 -0
- package/utils/nullish-to-empty-string.test.d.ts +1 -0
- package/utils/nullish-to-empty-string.test.js +10 -0
- package/utils/number-or-null.d.ts +2 -0
- package/utils/number-or-null.js +7 -0
- package/utils/number-or-null.test.d.ts +1 -0
- package/utils/number-or-null.test.js +18 -0
- package/utils/omit.d.ts +2 -1
- package/utils/sort-object-keys.d.ts +2 -1
- package/validators/form-validator.d.ts +1 -1
package/README.md
CHANGED
|
@@ -285,6 +285,20 @@ import { filterNullish } from "@uxf/core/utils/filter-nullish";
|
|
|
285
285
|
filterNullish([0, "text", null, undefined, [], {}]); /* returns [0, "text", [], {}] */
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
+
## filterNullishObjectValues
|
|
289
|
+
|
|
290
|
+
Filters out all properties with `null` or `undefined` values from an object, returning a new object with only non-nullish values.
|
|
291
|
+
|
|
292
|
+
```tsx
|
|
293
|
+
import { filterNullishObjectValues } from "@uxf/core/utils/filter-nullish-object-values";
|
|
294
|
+
|
|
295
|
+
filterNullishObjectValues({ a: 1, b: null, c: "test", d: undefined });
|
|
296
|
+
/* returns { a: 1, c: "test" } */
|
|
297
|
+
|
|
298
|
+
filterNullishObjectValues({ a: 0, b: "", c: false });
|
|
299
|
+
/* returns { a: 0, b: "", c: false } - keeps falsy values that are not nullish */
|
|
300
|
+
```
|
|
301
|
+
|
|
288
302
|
## filterAriaAndDataAttrs
|
|
289
303
|
|
|
290
304
|
Filters an object to return only properties that start with `aria-` or `data-` prefixes. This utility is useful when you need to pass accessibility and data attributes to HTML elements while excluding other props like event handlers or component-specific props.
|
|
@@ -340,6 +354,36 @@ isEmpty(["1"]); /* returns false */
|
|
|
340
354
|
isEmpty([]); /* returns true */
|
|
341
355
|
```
|
|
342
356
|
|
|
357
|
+
## isEven
|
|
358
|
+
|
|
359
|
+
Checks if a number is even.
|
|
360
|
+
|
|
361
|
+
```tsx
|
|
362
|
+
import { isEven } from "@uxf/core/utils/is-even";
|
|
363
|
+
|
|
364
|
+
isEven(2); /* returns true */
|
|
365
|
+
isEven(4); /* returns true */
|
|
366
|
+
isEven(1); /* returns false */
|
|
367
|
+
isEven(3); /* returns false */
|
|
368
|
+
isEven(0); /* returns true */
|
|
369
|
+
isEven(-2); /* returns true */
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## isOdd
|
|
373
|
+
|
|
374
|
+
Checks if a number is odd.
|
|
375
|
+
|
|
376
|
+
```tsx
|
|
377
|
+
import { isOdd } from "@uxf/core/utils/is-odd";
|
|
378
|
+
|
|
379
|
+
isOdd(1); /* returns true */
|
|
380
|
+
isOdd(3); /* returns true */
|
|
381
|
+
isOdd(2); /* returns false */
|
|
382
|
+
isOdd(4); /* returns false */
|
|
383
|
+
isOdd(0); /* returns false */
|
|
384
|
+
isOdd(-1); /* returns true */
|
|
385
|
+
```
|
|
386
|
+
|
|
343
387
|
## isBrowser / isServer
|
|
344
388
|
|
|
345
389
|
```tsx
|
|
@@ -378,6 +422,8 @@ isNotNil([]); /* returns true */
|
|
|
378
422
|
isNotNil("string"); /* returns true */
|
|
379
423
|
```
|
|
380
424
|
|
|
425
|
+
## last
|
|
426
|
+
|
|
381
427
|
```tsx
|
|
382
428
|
import { last } from "@uxf/core/utils/last";
|
|
383
429
|
|
|
@@ -385,6 +431,63 @@ last([1, 2]); /* returns 2 */
|
|
|
385
431
|
last([]); /* returns undefined */
|
|
386
432
|
```
|
|
387
433
|
|
|
434
|
+
## nonEmptyArrayOrNull
|
|
435
|
+
|
|
436
|
+
Converts empty arrays, `null`, or `undefined` values to `null`, leaving all non-empty arrays unchanged. Useful for normalizing form inputs or API data where empty arrays should be treated as `null`.
|
|
437
|
+
|
|
438
|
+
```tsx
|
|
439
|
+
import { nonEmptyArrayOrNull } from "@uxf/core/utils/non-empty-array-or-null";
|
|
440
|
+
|
|
441
|
+
nonEmptyArrayOrNull([]); /* returns null */
|
|
442
|
+
nonEmptyArrayOrNull(null); /* returns null */
|
|
443
|
+
nonEmptyArrayOrNull(undefined); /* returns null */
|
|
444
|
+
nonEmptyArrayOrNull([1, 2, 3]); /* returns [1, 2, 3] */
|
|
445
|
+
nonEmptyArrayOrNull(["a", "b"]); /* returns ["a", "b"] */
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
## nonEmptyStringOrNull
|
|
449
|
+
|
|
450
|
+
Converts empty strings and `undefined` values to `null`, leaving all other strings unchanged. Useful for normalizing form inputs or API data where empty strings should be treated as `null`.
|
|
451
|
+
|
|
452
|
+
```tsx
|
|
453
|
+
import { nonEmptyStringOrNull } from "@uxf/core/utils/non-empty-string-or-null";
|
|
454
|
+
|
|
455
|
+
nonEmptyStringOrNull(""); /* returns null */
|
|
456
|
+
nonEmptyStringOrNull(undefined); /* returns null */
|
|
457
|
+
nonEmptyStringOrNull(null); /* returns null */
|
|
458
|
+
nonEmptyStringOrNull("test"); /* returns "test" */
|
|
459
|
+
nonEmptyStringOrNull(" "); /* returns " " - non-empty string */
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## nullishToEmptyString
|
|
463
|
+
|
|
464
|
+
Converts `null` or `undefined` values to an empty string, leaving all other strings unchanged. Useful for safely displaying nullable string values in UI components.
|
|
465
|
+
|
|
466
|
+
```tsx
|
|
467
|
+
import { nullishToEmptyString } from "@uxf/core/utils/nullish-to-empty-string";
|
|
468
|
+
|
|
469
|
+
nullishToEmptyString(null); /* returns "" */
|
|
470
|
+
nullishToEmptyString(undefined); /* returns "" */
|
|
471
|
+
nullishToEmptyString(""); /* returns "" */
|
|
472
|
+
nullishToEmptyString("hello world"); /* returns "hello world" */
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
## numberOrNull
|
|
476
|
+
|
|
477
|
+
Converts `NaN`, `null`, or `undefined` values to `null`, leaving all valid numbers unchanged. Useful for normalizing numeric inputs or API data where invalid numbers should be treated as `null`.
|
|
478
|
+
|
|
479
|
+
```tsx
|
|
480
|
+
import { numberOrNull } from "@uxf/core/utils/number-or-null";
|
|
481
|
+
|
|
482
|
+
numberOrNull(0); /* returns 0 */
|
|
483
|
+
numberOrNull(42); /* returns 42 */
|
|
484
|
+
numberOrNull(-1); /* returns -1 */
|
|
485
|
+
numberOrNull(3.14); /* returns 3.14 */
|
|
486
|
+
numberOrNull(NaN); /* returns null */
|
|
487
|
+
numberOrNull(null); /* returns null */
|
|
488
|
+
numberOrNull(undefined); /* returns null */
|
|
489
|
+
```
|
|
490
|
+
|
|
388
491
|
## slugify
|
|
389
492
|
|
|
390
493
|
```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?:
|
|
12
|
-
static create(ctx?:
|
|
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
|
}
|
package/date/to-date-string.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { DateString } from "./index";
|
|
2
|
-
|
|
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
|
-
|
|
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 {};
|
package/date/to-time-string.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { TimeString } from "./index";
|
|
2
|
-
|
|
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
package/qr/index.d.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export interface BodyScrollOptions {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export interface BodyScrollOptions<E extends HTMLElement> {
|
|
2
|
+
allowTouchMove?: (el: E) => boolean;
|
|
3
|
+
willReserveScrollBarGap?: boolean;
|
|
4
4
|
}
|
|
5
|
-
export declare const disableBodyScroll: (targetElement:
|
|
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:
|
|
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
|
|
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 (
|
|
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
|
|
53
|
+
const willReserveScrollBarGap = (options === null || options === void 0 ? void 0 : options.willReserveScrollBarGap) === true;
|
|
53
54
|
const scrollBarGap = window.innerWidth - document.documentElement.clientWidth;
|
|
54
|
-
if (
|
|
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 (!
|
|
173
|
+
if (!isDocumentListenerAdded) {
|
|
173
174
|
document.addEventListener("touchmove", preventDefault, hasPassiveEvents ? { passive: false } : undefined);
|
|
174
|
-
|
|
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 (
|
|
190
|
+
if (isDocumentListenerAdded) {
|
|
187
191
|
document.removeEventListener("touchmove", preventDefault);
|
|
188
|
-
|
|
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 (
|
|
216
|
+
if (isDocumentListenerAdded && locks.length === 0) {
|
|
213
217
|
document.removeEventListener("touchmove", preventDefault);
|
|
214
|
-
|
|
218
|
+
isDocumentListenerAdded = false;
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
221
|
if (isIosDevice) {
|
package/utils/cxa.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
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", () => {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterNullishObjectValues = filterNullishObjectValues;
|
|
4
|
+
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
5
|
+
function filterNullishObjectValues(obj) {
|
|
6
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => (0, is_not_nil_1.isNotNil)(value)));
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const filter_nullish_object_values_1 = require("./filter-nullish-object-values");
|
|
4
|
+
test("filter-nullish-object-values", () => {
|
|
5
|
+
expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: 1, b: null, c: "test", d: undefined })).toStrictEqual({
|
|
6
|
+
a: 1,
|
|
7
|
+
c: "test",
|
|
8
|
+
});
|
|
9
|
+
expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: 0, b: "", c: false, d: NaN })).toStrictEqual({
|
|
10
|
+
a: 0,
|
|
11
|
+
b: "",
|
|
12
|
+
c: false,
|
|
13
|
+
d: NaN,
|
|
14
|
+
});
|
|
15
|
+
expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: [], b: {} })).toStrictEqual({ a: [], b: {} });
|
|
16
|
+
expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({})).toStrictEqual({});
|
|
17
|
+
expect((0, filter_nullish_object_values_1.filterNullishObjectValues)({ a: null, b: undefined })).toStrictEqual({});
|
|
18
|
+
});
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { Nullish } from "../types";
|
|
2
|
+
export declare function filterNullish<T>(val: Array<T | Nullish>): T[];
|
package/utils/is-empty.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
} | string): boolean;
|
|
1
|
+
import { AnyObject } from "../types";
|
|
2
|
+
export declare function isEmpty(value: unknown[] | AnyObject | string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isEven(n: number): boolean;
|
package/utils/is-even.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const is_even_1 = require("./is-even");
|
|
4
|
+
test("is-even", () => {
|
|
5
|
+
[0, 2, 4, 10, 100, -2, -4].map((value) => expect((0, is_even_1.isEven)(value)).toBeTruthy());
|
|
6
|
+
[1, 3, 5, 11, 101, -1, -3].map((value) => expect((0, is_even_1.isEven)(value)).toBeFalsy());
|
|
7
|
+
});
|
package/utils/is-nil.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isNil(value:
|
|
1
|
+
export declare function isNil(value: unknown): value is null | undefined;
|
package/utils/is-not-empty.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
} | string): boolean;
|
|
1
|
+
import { AnyObject } from "../types";
|
|
2
|
+
export declare function isNotEmpty(value: unknown[] | AnyObject | string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isOdd(n: number): boolean;
|
package/utils/is-odd.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const is_odd_1 = require("./is-odd");
|
|
4
|
+
test("is-odd", () => {
|
|
5
|
+
[1, 3, 5, 11, 101, -1, -3].map((value) => expect((0, is_odd_1.isOdd)(value)).toBeTruthy());
|
|
6
|
+
[0, 2, 4, 10, 100, -2, -4].map((value) => expect((0, is_odd_1.isOdd)(value)).toBeFalsy());
|
|
7
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nonEmptyArrayOrNull = nonEmptyArrayOrNull;
|
|
4
|
+
const is_empty_1 = require("@uxf/core/utils/is-empty");
|
|
5
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
6
|
+
function nonEmptyArrayOrNull(value) {
|
|
7
|
+
return (0, is_nil_1.isNil)(value) || (0, is_empty_1.isEmpty)(value) ? null : value;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const non_empty_array_or_null_1 = require("./non-empty-array-or-null");
|
|
4
|
+
test("non-empty-array-or-null", () => {
|
|
5
|
+
expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([])).toBe(null);
|
|
6
|
+
expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)(undefined)).toBe(null);
|
|
7
|
+
expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)(null)).toBe(null);
|
|
8
|
+
expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([1, 2, 3])).toStrictEqual([1, 2, 3]);
|
|
9
|
+
expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)(["a", "b"])).toStrictEqual(["a", "b"]);
|
|
10
|
+
expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([0])).toStrictEqual([0]);
|
|
11
|
+
expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([false])).toStrictEqual([false]);
|
|
12
|
+
expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([null])).toStrictEqual([null]);
|
|
13
|
+
expect((0, non_empty_array_or_null_1.nonEmptyArrayOrNull)([{}])).toStrictEqual([{}]);
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const non_empty_string_or_null_1 = require("./non-empty-string-or-null");
|
|
4
|
+
test("nullish-empty-string-to-nullable", () => {
|
|
5
|
+
expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)("")).toBe(null);
|
|
6
|
+
expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)(undefined)).toBe(null);
|
|
7
|
+
expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)(null)).toBe(null);
|
|
8
|
+
expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)("test")).toBe("test");
|
|
9
|
+
expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)("hello world")).toBe("hello world");
|
|
10
|
+
expect((0, non_empty_string_or_null_1.nonEmptyStringOrNull)(" ")).toBe(" ");
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const nullish_to_empty_string_1 = require("./nullish-to-empty-string");
|
|
4
|
+
test("nullish-to-empty-string", () => {
|
|
5
|
+
expect((0, nullish_to_empty_string_1.nullishToEmptyString)(null)).toBe("");
|
|
6
|
+
expect((0, nullish_to_empty_string_1.nullishToEmptyString)(undefined)).toBe("");
|
|
7
|
+
expect((0, nullish_to_empty_string_1.nullishToEmptyString)("")).toBe("");
|
|
8
|
+
expect((0, nullish_to_empty_string_1.nullishToEmptyString)("test")).toBe("test");
|
|
9
|
+
expect((0, nullish_to_empty_string_1.nullishToEmptyString)("hello world")).toBe("hello world");
|
|
10
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.numberOrNull = numberOrNull;
|
|
4
|
+
const is_not_nil_1 = require("./is-not-nil");
|
|
5
|
+
function numberOrNull(value) {
|
|
6
|
+
return (0, is_not_nil_1.isNotNil)(value) && !isNaN(value) ? value : null;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const number_or_null_1 = require("./number-or-null");
|
|
4
|
+
test("number-or-null", () => {
|
|
5
|
+
// Valid numbers should return the number
|
|
6
|
+
expect((0, number_or_null_1.numberOrNull)(0)).toBe(0);
|
|
7
|
+
expect((0, number_or_null_1.numberOrNull)(1)).toBe(1);
|
|
8
|
+
expect((0, number_or_null_1.numberOrNull)(-1)).toBe(-1);
|
|
9
|
+
expect((0, number_or_null_1.numberOrNull)(42)).toBe(42);
|
|
10
|
+
expect((0, number_or_null_1.numberOrNull)(3.14)).toBe(3.14);
|
|
11
|
+
expect((0, number_or_null_1.numberOrNull)(-99.99)).toBe(-99.99);
|
|
12
|
+
// null should return null
|
|
13
|
+
expect((0, number_or_null_1.numberOrNull)(null)).toBe(null);
|
|
14
|
+
// undefined should return null
|
|
15
|
+
expect((0, number_or_null_1.numberOrNull)(undefined)).toBe(null);
|
|
16
|
+
// NaN should return null
|
|
17
|
+
expect((0, number_or_null_1.numberOrNull)(NaN)).toBe(null);
|
|
18
|
+
});
|
package/utils/omit.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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:
|
|
8
|
+
required: (errorMessage?: string) => (value: unknown) => string | undefined;
|
|
9
9
|
};
|