@uxf/core 11.95.0 → 11.100.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
@@ -139,6 +139,22 @@ switch(value) {
139
139
  }
140
140
  ```
141
141
 
142
+ ### ts-pattern
143
+
144
+ Re-export of the [ts-pattern](https://github.com/gvergnaud/ts-pattern) library for exhaustive pattern matching. This provides a more powerful and type-safe alternative to switch statements with support for complex patterns, guards, and exhaustiveness checking.
145
+
146
+ ```ts
147
+ import { match, Pattern } from "@uxf/core/utils/ts-pattern";
148
+
149
+ const result = match(value)
150
+ .with("a", () => "A")
151
+ .with("b", () => "B")
152
+ .with(Pattern.string, (str) => `String: ${str}`)
153
+ .exhaustive();
154
+ ```
155
+
156
+ For full documentation, see the [official ts-pattern docs](https://github.com/gvergnaud/ts-pattern).
157
+
142
158
  ## assertNotNil
143
159
 
144
160
  ```tsx
@@ -287,6 +303,18 @@ escapeQuotes('The "quick" fox');
287
303
  // Output: The \"quick\" fox
288
304
  ```
289
305
 
306
+ ## humanIndex
307
+
308
+ Converts a 0-based index to a 1-based (human-readable) index.
309
+
310
+ ```tsx
311
+ import { humanIndex } from "@uxf/core/utils/human-index";
312
+
313
+ humanIndex(0); /* returns 1 */
314
+ humanIndex(9); /* returns 10 */
315
+ humanIndex(-1); /* throws error */
316
+ ```
317
+
290
318
  ## filterNullish
291
319
 
292
320
  ```tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "11.95.0",
3
+ "version": "11.100.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
@@ -19,6 +19,9 @@
19
19
  "build": "tsc -P tsconfig.json",
20
20
  "typecheck": "tsc --noEmit --skipLibCheck"
21
21
  },
22
+ "dependencies": {
23
+ "ts-pattern": "5.9.0"
24
+ },
22
25
  "bugs": {
23
26
  "url": "https://gitlab.com/uxf-npm/core/issues"
24
27
  },
@@ -0,0 +1 @@
1
+ export declare function humanIndex(index: number): number;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.humanIndex = humanIndex;
4
+ function humanIndex(index) {
5
+ if (index < 0) {
6
+ throw Error("Negative indexes are not supported.");
7
+ }
8
+ return index + 1;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const human_index_1 = require("./human-index");
4
+ test("human-index", () => {
5
+ expect((0, human_index_1.humanIndex)(0)).toBe(1);
6
+ expect((0, human_index_1.humanIndex)(1)).toBe(2);
7
+ expect((0, human_index_1.humanIndex)(9)).toBe(10);
8
+ expect(() => (0, human_index_1.humanIndex)(-1)).toThrow();
9
+ });
@@ -0,0 +1 @@
1
+ export { NonExhaustiveError, P, Pattern, isMatching, match } from "ts-pattern";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.match = exports.isMatching = exports.Pattern = exports.P = exports.NonExhaustiveError = void 0;
4
+ var ts_pattern_1 = require("ts-pattern");
5
+ Object.defineProperty(exports, "NonExhaustiveError", { enumerable: true, get: function () { return ts_pattern_1.NonExhaustiveError; } });
6
+ Object.defineProperty(exports, "P", { enumerable: true, get: function () { return ts_pattern_1.P; } });
7
+ Object.defineProperty(exports, "Pattern", { enumerable: true, get: function () { return ts_pattern_1.Pattern; } });
8
+ Object.defineProperty(exports, "isMatching", { enumerable: true, get: function () { return ts_pattern_1.isMatching; } });
9
+ Object.defineProperty(exports, "match", { enumerable: true, get: function () { return ts_pattern_1.match; } });