@zelgadis87/utils-core 4.6.0 → 4.6.1

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.
Files changed (59) hide show
  1. package/dist/Logger.d.ts +21 -0
  2. package/dist/Optional.d.ts +70 -0
  3. package/dist/async/CancelableDeferred.d.ts +17 -0
  4. package/dist/async/Deferred.d.ts +34 -0
  5. package/dist/async/RateThrottler.d.ts +13 -0
  6. package/dist/async/Semaphore.d.ts +17 -0
  7. package/dist/async/index.d.ts +4 -0
  8. package/dist/index.d.ts +8 -0
  9. package/dist/lazy/Lazy.d.ts +22 -0
  10. package/dist/lazy/LazyAsync.d.ts +24 -0
  11. package/dist/lazy/index.d.ts +2 -0
  12. package/dist/sorting/ComparisonChain.d.ts +57 -0
  13. package/dist/sorting/Sorter.d.ts +100 -0
  14. package/dist/sorting/index.d.ts +4 -0
  15. package/dist/sorting/types.d.ts +5 -0
  16. package/dist/time/RandomTimeDuration.d.ts +9 -0
  17. package/dist/time/TimeBase.d.ts +38 -0
  18. package/dist/time/TimeDuration.d.ts +81 -0
  19. package/dist/time/TimeFrequency.d.ts +10 -0
  20. package/dist/time/TimeInstant.d.ts +175 -0
  21. package/dist/time/TimeInstantBuilder.d.ts +77 -0
  22. package/dist/time/TimeRange.d.ts +11 -0
  23. package/dist/time/TimeUnit.d.ts +17 -0
  24. package/dist/time/index.d.ts +7 -0
  25. package/dist/time/types.d.ts +26 -0
  26. package/dist/tsconfig.tsbuildinfo +1 -0
  27. package/dist/upgrade/DataUpgrader.d.ts +22 -0
  28. package/dist/upgrade/errors.d.ts +12 -0
  29. package/dist/upgrade/getTransitionsPath.d.ts +3 -0
  30. package/dist/upgrade/index.d.ts +2 -0
  31. package/dist/upgrade/types.d.ts +31 -0
  32. package/dist/utils/arrays/groupBy.d.ts +9 -0
  33. package/dist/utils/arrays/indexBy.d.ts +7 -0
  34. package/dist/utils/arrays/statistics.d.ts +8 -0
  35. package/dist/utils/arrays/uniqBy.d.ts +4 -0
  36. package/dist/utils/arrays.d.ts +57 -0
  37. package/dist/utils/booleans.d.ts +2 -0
  38. package/dist/utils/empties.d.ts +17 -0
  39. package/dist/utils/errors/withTryCatch.d.ts +3 -0
  40. package/dist/utils/errors.d.ts +3 -0
  41. package/dist/utils/functions/constant.d.ts +10 -0
  42. package/dist/utils/functions/iff.d.ts +8 -0
  43. package/dist/utils/functions.d.ts +31 -0
  44. package/dist/utils/index.d.ts +13 -0
  45. package/dist/utils/json.d.ts +11 -0
  46. package/dist/utils/nulls.d.ts +8 -0
  47. package/dist/utils/numbers/round.d.ts +8 -0
  48. package/dist/utils/numbers.d.ts +34 -0
  49. package/dist/utils/primitives.d.ts +3 -0
  50. package/dist/utils/promises.d.ts +6 -0
  51. package/dist/utils/random.d.ts +7 -0
  52. package/dist/utils/records/entries.d.ts +4 -0
  53. package/dist/utils/records.d.ts +31 -0
  54. package/dist/utils/strings/StringParts.d.ts +32 -0
  55. package/dist/utils/strings.d.ts +17 -0
  56. package/package.json +2 -2
  57. package/esbuild/index.cjs +0 -2836
  58. package/esbuild/index.js +0 -2658
  59. package/esbuild/package.json +0 -39
@@ -0,0 +1,31 @@
1
+ export * from './functions/constant.js';
2
+ export * from './functions/iff.js';
3
+ export type TFunction<A, R> = (a: A) => R;
4
+ export type TTransformer<A, R> = TFunction<A, R>;
5
+ export type TVoidFunction = TFunction<void, void>;
6
+ export type TProducer<R> = TFunction<void, R>;
7
+ export type TConsumer<T> = TFunction<T, void>;
8
+ export type TPredicate<T> = TFunction<T, boolean>;
9
+ export type TTypePredicate<T, R extends T> = (t: T) => t is R;
10
+ export type TIdentityFunction<T> = TFunction<T, T>;
11
+ export type TBiFunction<A, B, R> = (a: A, b: B) => R;
12
+ export type TBiConsumer<A, B> = TBiFunction<A, B, void>;
13
+ export type TBiPredicate<T> = TBiFunction<T, T, boolean>;
14
+ export type TAccumulator<A, B> = TBiFunction<A, B, A>;
15
+ export type TAsyncFunction<A, R> = TFunction<A, Promise<R>>;
16
+ export type TAsyncVoidFunction = TAsyncFunction<void, void>;
17
+ export type TAsyncProducer<R> = TAsyncFunction<void, R>;
18
+ export type TAsyncConsumer<T> = TAsyncFunction<T, void>;
19
+ export type TAsyncPredicate<T> = TAsyncFunction<T, boolean>;
20
+ export type TAsyncBiFunction<A, B, R> = TBiFunction<A, B, Promise<R>>;
21
+ export type TAsyncBiConsumer<A, B> = TAsyncBiFunction<A, B, void>;
22
+ export type TAsyncBiPredicate<T> = TAsyncBiFunction<T, T, boolean>;
23
+ export type TAnyFunction<R> = (...args: unknown[]) => R;
24
+ export type TAsyncAnyFunction<R> = (...args: unknown[]) => Promise<R>;
25
+ export declare function isFunction(t: unknown): t is Function;
26
+ export declare function noop(): void;
27
+ export declare function filterWithTypePredicate<T, R extends T>(filter: TPredicate<T>): TTypePredicate<T, R>;
28
+ export declare function not<T>(predicate: TPredicate<T>): TPredicate<T>;
29
+ export declare function and<T>(a: TPredicate<T>, b: TPredicate<T>): TPredicate<T>;
30
+ export declare function or<T>(a: TPredicate<T>, b: TPredicate<T>): TPredicate<T>;
31
+ export declare function xor<T>(a: TPredicate<T>, b: TPredicate<T>): TPredicate<T>;
@@ -0,0 +1,13 @@
1
+ export * from './arrays.js';
2
+ export * from './booleans.js';
3
+ export * from './empties.js';
4
+ export * from './errors.js';
5
+ export * from './functions.js';
6
+ export * from './json.js';
7
+ export * from './nulls.js';
8
+ export * from './numbers.js';
9
+ export * from './primitives.js';
10
+ export * from './promises.js';
11
+ export * from './random.js';
12
+ export * from './records.js';
13
+ export * from './strings.js';
@@ -0,0 +1,11 @@
1
+ export type TJsonPrimitive = string | number | boolean | null | undefined;
2
+ export type TJsonArray = Array<TJsonSerializable> | ReadonlyArray<TJsonSerializable>;
3
+ export type TJsonObject = {
4
+ [key: string]: TJsonSerializable;
5
+ };
6
+ export type TJsonSerializable = TJsonPrimitive | TJsonArray | TJsonObject;
7
+ export declare function tryToParseJson<T extends TJsonSerializable>(jsonContent: string): [T, undefined] | [undefined, Error];
8
+ export declare function jsonCloneDeep<A extends TJsonSerializable>(a: A): A;
9
+ export declare function omitFromJsonObject<T extends TJsonObject, K extends keyof T>(o: T, ...keys: K[]): Omit<T, K>;
10
+ /** @deprecated[2024-12-23]: Use {@link omitFromJsonObject} instead. */
11
+ export declare const omit: typeof omitFromJsonObject;
@@ -0,0 +1,8 @@
1
+ import { TConsumer, TFunction } from "./functions.js";
2
+ export type TMaybe<T> = T | null;
3
+ export declare function ensureDefined<T>(v: T, name?: string): T;
4
+ export declare function isDefined<T>(x: T | null | undefined): x is T;
5
+ export declare function isNullOrUndefined(x: unknown): x is null | undefined;
6
+ export declare function ifDefined<R>(source: TMaybe<R>, callback: TConsumer<R>): void;
7
+ export declare function mapDefined<R, S>(source: TMaybe<R>, mapper: TFunction<R, S>): TMaybe<S>;
8
+ export declare function ifNullOrUndefined(source: TMaybe<unknown>, callback: TConsumer<void>): void;
@@ -0,0 +1,8 @@
1
+ type TRoundMode = 'toNearest' | 'toLower' | 'toUpper' | 'towardsZero' | 'awayFromZero';
2
+ export declare function round(n: number, precision?: number, mode?: TRoundMode): number;
3
+ export default round;
4
+ export declare const roundToNearest: (n: number, precision?: number) => number;
5
+ export declare const roundToLower: (n: number, precision?: number) => number;
6
+ export declare const roundToUpper: (n: number, precision?: number) => number;
7
+ export declare const roundTowardsZero: (n: number, precision?: number) => number;
8
+ export declare const roundAwayFromZero: (n: number, precision?: number) => number;
@@ -0,0 +1,34 @@
1
+ import type { TFunction } from "./functions.js";
2
+ export * from './numbers/round.js';
3
+ export type TNumericString = `${number}`;
4
+ export type TNumericFloatingPointString = `${number}.${number}`;
5
+ export type TPositiveNumber = number;
6
+ export type TNegativeNumber = number;
7
+ export type TZero = 0;
8
+ export type TDigit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
9
+ export type TDigit1_9 = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
10
+ export type TNumber0_100 = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100;
11
+ export type TNumber0_1000 = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999;
12
+ export type TNumber0_5 = 0 | 1 | 2 | 3 | 4 | 5;
13
+ export type TNumber0_10 = TNumber0_5 | 6 | 7 | 8 | 9 | 10;
14
+ export type TNumber0_15 = TNumber0_10 | 11 | 12 | 13 | 14 | 15;
15
+ export type TNumber0_20 = TNumber0_15 | 16 | 17 | 18 | 19 | 20;
16
+ export type TNumber1_10 = Exclude<TNumber0_10, 0>;
17
+ export type TParseInt<T> = T extends `${infer N extends number}` ? N : never;
18
+ export type TParseableInt<T> = T extends `${number}` ? T : never;
19
+ export declare function ensurePositiveNumber(v: number, name?: string): number;
20
+ export declare function ensureNonNegativeNumber(v: number, name?: string): number;
21
+ export declare function ensureNonPositiveNumber(v: number, name?: string): number;
22
+ export declare function ensureNegativeNumber(v: number, name?: string): number;
23
+ export declare function incrementBy(n: number): TFunction<number, number>;
24
+ export declare function multiplyBy(n: number): TFunction<number, number>;
25
+ export declare function divideBy(n: number): TFunction<number, number>;
26
+ export declare const increment: TFunction<number, number>;
27
+ export declare const decrement: TFunction<number, number>;
28
+ export declare const decrementBy: (n: number) => TFunction<number, number>;
29
+ export declare function isNumber(v: unknown): v is number;
30
+ export declare function isPositiveNumber(v: number): v is TPositiveNumber;
31
+ export declare function isNegativeNumber(v: number): v is TNegativeNumber;
32
+ export declare function isZero(v: number): v is TZero;
33
+ export declare function clamp(n: number, min: number, max: number): number;
34
+ export declare function tryToParseNumber(numberStr: string): [undefined, Error] | [number, undefined];
@@ -0,0 +1,3 @@
1
+ export type TTimeoutHandle = ReturnType<typeof setTimeout>;
2
+ export type TIntervalHandle = ReturnType<typeof setInterval>;
3
+ export type TPrimitive = string | number | boolean | null;
@@ -0,0 +1,6 @@
1
+ import TimeDuration from "../time/TimeDuration.js";
2
+ import { TAsyncFunction, TFunction } from "./functions.js";
3
+ export type TPromisable<T> = T | Promise<T>;
4
+ export declare function asPromise<T>(promisable: TPromisable<T>): Promise<T>;
5
+ export declare function promiseSequence<R>(...fns: TFunction<void, Promise<R>>[]): TFunction<void, Promise<R[]>>;
6
+ export declare function delayPromise<T>(duration: TimeDuration): TAsyncFunction<T, T>;
@@ -0,0 +1,7 @@
1
+ import { TPositiveNumber } from "./numbers.ts";
2
+ /** @deprecated[2025-01-14]: Use {@link randomNumberInInterval} instead. */
3
+ export declare const randomInterval: (min: number, max: number) => number;
4
+ /** @deprecated[2025-01-14]: Use {@link randomNumberInInterval} / 100 instead. */
5
+ export declare const randomPercentage: (min: number, max: number) => number;
6
+ export declare function randomNumberInInterval(min: number, max: number): number;
7
+ export declare const randomId: (length: TPositiveNumber) => string;
@@ -0,0 +1,4 @@
1
+ import { TFunction } from "..";
2
+ export declare function dictToEntries<V, K extends string = string>(obj: Record<K, V>): [K, V][];
3
+ export declare function entriesToDict<V, K extends string = string>(entries: [K, V][]): Record<K, V>;
4
+ export declare function mapEntries<K1 extends string, V1, K2 extends string, V2>(dict: Record<K1, V1>, mapper: TFunction<[K1, V1], [K2, V2]>): Record<K2, V2>;
@@ -0,0 +1,31 @@
1
+ export * from './records/entries.js';
2
+ export type TEmpty = Record<string, never>;
3
+ export type TKeysOfType<T, V> = {
4
+ [K in keyof T]-?: T[K] extends V ? K : never;
5
+ }[keyof T];
6
+ export declare function dictToList<T>(obj: Record<string | number, T>): T[];
7
+ export declare function pick<T extends object, K extends keyof T>(o: T, keys: K[]): Pick<T, K>;
8
+ export type TOptionsWithoutDefaults<T, R> = Partial<T> & Required<Omit<T, keyof R>>;
9
+ export type TOptionalKeysForType<T> = {
10
+ [K in keyof T]-?: {} extends Pick<T, K> ? K : never;
11
+ }[keyof T];
12
+ export type TRequiredKeysForType<T> = Exclude<keyof T, TOptionalKeysForType<T>>;
13
+ export type TAllKeysOptional<T> = TRequiredKeysForType<T> extends never ? true : false;
14
+ export type TConditionalParameter<T> = TAllKeysOptional<T> extends true ? T | undefined : T;
15
+ export type TConditionalParameterOptions<T, R> = TConditionalParameter<TOptionsWithoutDefaults<T, R>>;
16
+ /**
17
+ * Given a type T, replaces all fields of type From to fields of type To.
18
+ */
19
+ export type TReplaceType<T, From, To> = {
20
+ [K in keyof T]: T[K] extends From ? To : T[K];
21
+ };
22
+ /**
23
+ * Given a type T, make field K required instead of optional.
24
+ */
25
+ export type TWithRequiredProperty<T, K extends keyof T> = T & {
26
+ [Property in K]-?: T[Property];
27
+ };
28
+ /**
29
+ * Given a type T, make all fields required instead of optional.
30
+ */
31
+ export type TWithRequiredProperties<T> = Required<T>;
@@ -0,0 +1,32 @@
1
+ import { TReadableArray } from "../arrays.js";
2
+ import { TMaybe } from "../nulls.js";
3
+ export declare class StringParts {
4
+ private readonly _parts;
5
+ private constructor();
6
+ toUpperCase(): StringParts;
7
+ toLowerCase(): StringParts;
8
+ capitalizeFirst(): StringParts;
9
+ capitalizeEach(): StringParts;
10
+ get parts(): string[];
11
+ get tail(): string[];
12
+ get first(): TMaybe<string>;
13
+ get last(): TMaybe<string>;
14
+ get length(): number;
15
+ trim(): StringParts;
16
+ toSnakeCase(): string;
17
+ toCamelCase(): string;
18
+ toKebabCase(): string;
19
+ toPascalCase(): string;
20
+ toHumanCase(): string;
21
+ join(separator: string): string;
22
+ mergeWith({ parts: otherParts }: {
23
+ parts: TReadableArray<string>;
24
+ }): StringParts;
25
+ slice(start: number, end?: number): StringParts;
26
+ splice(start: number, deleteCount: number, ...items: string[]): StringParts;
27
+ push(part: string): StringParts;
28
+ shift(part: string): StringParts;
29
+ reverse(): StringParts;
30
+ static fromString: (s: string, separator?: string | RegExp) => StringParts;
31
+ static fromParts: (...parts: string[]) => StringParts;
32
+ }
@@ -0,0 +1,17 @@
1
+ export * from './strings/StringParts.js';
2
+ export type THtmlString = string;
3
+ export type TUrl = string;
4
+ export type TRelativeUrl = string;
5
+ export declare function hashCode(str: string): number;
6
+ export declare function repeat(char: string, times: number): string;
7
+ export declare function capitalizeWord(word: string): string;
8
+ export declare function splitWords(text: string, regEx?: RegExp): string[];
9
+ export declare function stringToNumber(s: string | null | undefined): number | null;
10
+ export declare function pad(str: string, n: number, char: string, where?: 'left' | 'right'): string;
11
+ export declare function padLeft(str: string, n: number, char: string): string;
12
+ export declare function padRight(str: string, n: number, char: string): string;
13
+ export declare function ellipsis(str: string, maxLength: number): string;
14
+ export declare function pluralize(n: number, singular: string, plural?: string): string;
15
+ export declare function wrapWithString(str: string, delimiter: string): string;
16
+ /** @deprecated[2024-12-23]: Use {@link wrapWithString} instead. */
17
+ export declare const wrap: typeof wrapWithString;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@zelgadis87/utils-core",
4
- "version": "4.6.0",
4
+ "version": "4.6.1",
5
5
  "author": "Zelgadis87",
6
6
  "license": "ISC",
7
7
  "private": false,
@@ -29,7 +29,7 @@
29
29
  "nx": "20.3.2",
30
30
  "rimraf": "6.0.1",
31
31
  "typescript": "5.7.3",
32
- "typescript-eslint": "^8.20.0",
32
+ "typescript-eslint": "8.20.0",
33
33
  "vitest": "2.1.8"
34
34
  },
35
35
  "dependencies": {