@uxf/core 10.0.0 → 10.10.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
@@ -328,86 +328,6 @@ queryParamToNumber(ctx.query.id);
328
328
  queryParamToString(ctx.query.name);
329
329
  ```
330
330
 
331
- ## Utils
332
- ```tsx
333
- import { cameCaseToDash } from "@uxf/core/utils/cameCaseToDash";
334
-
335
- const example = cameCaseToDash("fooBar") /* returns "foo-bar" */
336
- ```
337
- ```tsx
338
- import { composeRefs } from "@uxf/core/utils/composeRefs";
339
-
340
- const firstRef = useRef<HTMLDivElement>(null);
341
- const secondRef = useRef<HTMLDivElement>(null);
342
-
343
- const example = <div ref={composeRefs(firstRef, secondRef)} />;
344
- ```
345
- ```tsx
346
- import { cx } from "@uxf/core/utils/cx";
347
-
348
- /* fork of https://github.com/lukeed/clsx */
349
- const example = cx("foo", true && "bar", "baz", false && "bam", undefined) /* returns "foo bar baz" */
350
- ```
351
- ```tsx
352
- import { forwardRef } from "@uxf/core/utils/forwardRef";
353
-
354
- interface Props {
355
- className?: string;
356
- }
357
-
358
- // will enforce 'displayName'
359
- export const ExampleComponent = forwardRef<HTMLDivElement, Props>("ExampleComponent", (props, ref) => {
360
- return <div className={props.className} ref={ref} />;
361
- });
362
- ```
363
- ```tsx
364
- import { isBrowser } from "@uxf/core/utils/isBrowser";
365
- import { isServer } from "@uxf/core/utils/isServer";
366
-
367
- const browserExample = isBrowser; /* returns true if DOM is available */
368
- const serverExample = isServer; /* returns true if DOM is NOT available */
369
- ```
370
- ```tsx
371
- import { slugify } from "@uxf/core/utils/slugify";
372
-
373
- const example = slugify("Jak se dnes máte?") /* returns "jak-se-dnes-mate" */
374
- ```
375
- ```tsx
376
- import { trimTrailingZeros } from "@uxf/core/utils/trimTrailingZeros";
377
-
378
- const example = trimTrailingZeros("120,450") /* returns "120,45" */
379
- ```
380
-
381
- ```tsx
382
- import { filterNullish } from "@uxf/core/utils/filter-nullish";
383
-
384
- filterNullish([0, "text", null, undefined, [], {}]) /* returns [0, "text", [], {}] */
385
- ```
386
-
387
- ```tsx
388
- import { isNil } from "@uxf/core/utils/is-nil";
389
-
390
- isNil(null) /* returns true */
391
- isNil(undefined) /* returns true */
392
- isNil(true) /* returns false */
393
- isNil(1) /* returns false */
394
- isNil(0) /* returns false */
395
- isNil([]) /* returns false */
396
- isNil("string") /* returns false */
397
- ```
398
-
399
- ```tsx
400
- import { isNotNil } from "@uxf/core/utils/is-not-nil";
401
-
402
- isNotNil(null) /* returns false */
403
- isNotNil(undefined) /* returns false */
404
- isNotNil(true) /* returns true */
405
- isNotNil(1) /* returns true */
406
- isNotNil(0) /* returns true */
407
- isNotNil([]) /* returns true */
408
- isNotNil("string") /* returns true */
409
- ```
410
-
411
331
  ## Validators
412
332
  ```tsx
413
333
  import { Validator } from "@uxf/core";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "10.0.0",
3
+ "version": "10.10.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
@@ -0,0 +1,2 @@
1
+ import { Nullish } from "../types";
2
+ export declare function assertNotNil<T>(value: T | Nullish, errorMessage?: string): asserts value is T;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertNotNil = void 0;
4
+ const is_nil_1 = require("./is-nil");
5
+ function assertNotNil(value, errorMessage = "Value is nil.") {
6
+ if ((0, is_nil_1.isNil)(value)) {
7
+ throw new Error(errorMessage);
8
+ }
9
+ }
10
+ exports.assertNotNil = assertNotNil;
@@ -0,0 +1 @@
1
+ export declare function isEmpty(value: any[] | string): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEmpty = void 0;
4
+ function isEmpty(value) {
5
+ if (Array.isArray(value)) {
6
+ return value.length === 0;
7
+ }
8
+ return value === "";
9
+ }
10
+ exports.isEmpty = isEmpty;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_empty_1 = require("./is-empty");
4
+ test("is-empty", () => {
5
+ expect((0, is_empty_1.isEmpty)(["1"])).toBeFalsy();
6
+ expect((0, is_empty_1.isEmpty)([])).toBeTruthy();
7
+ expect((0, is_empty_1.isEmpty)("not-empty")).toBeFalsy();
8
+ expect((0, is_empty_1.isEmpty)("")).toBeTruthy();
9
+ });
@@ -0,0 +1 @@
1
+ export declare function last<T>(value: T[]): T | undefined;
package/utils/last.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.last = void 0;
4
+ function last(value) {
5
+ if (value.length === 0) {
6
+ return undefined;
7
+ }
8
+ return value[value.length - 1];
9
+ }
10
+ exports.last = last;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const last_1 = require("./last");
4
+ test("last", () => {
5
+ expect((0, last_1.last)(["1"])).toStrictEqual("1");
6
+ expect((0, last_1.last)(["1", "2", "3"])).toStrictEqual("3");
7
+ expect((0, last_1.last)([])).toBeUndefined();
8
+ });