@depup/type-fest 5.5.0-depup.0 → 5.10.0-depup.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.
Files changed (120) hide show
  1. package/README.md +2 -2
  2. package/changes.json +1 -1
  3. package/index.d.ts +17 -8
  4. package/package.json +9 -6
  5. package/readme.md +75 -61
  6. package/source/absolute.d.ts +52 -0
  7. package/source/all-extend.d.ts +9 -5
  8. package/source/all-union-fields.d.ts +18 -18
  9. package/source/and.d.ts +1 -1
  10. package/source/array-reverse.d.ts +17 -15
  11. package/source/array-splice.d.ts +24 -24
  12. package/source/array-tail.d.ts +7 -7
  13. package/source/camel-case.d.ts +38 -5
  14. package/source/camel-cased-properties-deep.d.ts +11 -4
  15. package/source/camel-cased-properties.d.ts +5 -1
  16. package/source/conditional-keys.d.ts +1 -1
  17. package/source/delimiter-case.d.ts +11 -9
  18. package/source/delimiter-cased-properties-deep.d.ts +8 -1
  19. package/source/delimiter-cased-properties.d.ts +5 -1
  20. package/source/empty-object.d.ts +1 -1
  21. package/source/entries.d.ts +1 -1
  22. package/source/entry.d.ts +1 -1
  23. package/source/exclude-exactly.d.ts +11 -11
  24. package/source/exclude-rest-element.d.ts +4 -4
  25. package/source/exclusify-union.d.ts +4 -4
  26. package/source/extends-strict.d.ts +129 -22
  27. package/source/extract-exactly.d.ts +56 -0
  28. package/source/get.d.ts +1 -1
  29. package/source/greater-than.d.ts +3 -2
  30. package/source/has-optional-keys.d.ts +1 -1
  31. package/source/has-readonly-keys.d.ts +1 -1
  32. package/source/has-required-keys.d.ts +1 -1
  33. package/source/has-writable-keys.d.ts +1 -1
  34. package/source/int-closed-range.d.ts +5 -4
  35. package/source/int-range.d.ts +57 -12
  36. package/source/internal/array.d.ts +22 -21
  37. package/source/internal/keys.d.ts +9 -9
  38. package/source/internal/numeric.d.ts +19 -65
  39. package/source/internal/object.d.ts +44 -6
  40. package/source/internal/string.d.ts +1 -76
  41. package/source/internal/tuple.d.ts +2 -2
  42. package/source/internal/type.d.ts +16 -10
  43. package/source/is-boolean-literal.d.ts +39 -0
  44. package/source/is-integer.d.ts +8 -8
  45. package/source/is-literal.d.ts +43 -267
  46. package/source/is-numeric-literal.d.ts +50 -0
  47. package/source/is-string-literal.d.ts +72 -0
  48. package/source/is-symbol-literal.d.ts +39 -0
  49. package/source/is-tuple.d.ts +3 -3
  50. package/source/is-union.d.ts +12 -12
  51. package/source/iterable-element.d.ts +5 -5
  52. package/source/jsonify.d.ts +5 -9
  53. package/source/kebab-case.d.ts +1 -0
  54. package/source/kebab-cased-properties-deep.d.ts +7 -0
  55. package/source/kebab-cased-properties.d.ts +5 -1
  56. package/source/keys-of-union.d.ts +2 -2
  57. package/source/last-array-element.d.ts +66 -13
  58. package/source/less-than-or-equal.d.ts +1 -1
  59. package/source/literal-to-primitive.d.ts +1 -1
  60. package/source/literal-union.d.ts +1 -1
  61. package/source/merge-deep.d.ts +3 -3
  62. package/source/merge-exclusive.d.ts +3 -3
  63. package/source/multidimensional-array.d.ts +1 -1
  64. package/source/multidimensional-readonly-array.d.ts +1 -1
  65. package/source/non-nullable-deep.d.ts +102 -0
  66. package/source/numeric.d.ts +3 -3
  67. package/source/object-merge.d.ts +21 -16
  68. package/source/omit-deep.d.ts +22 -22
  69. package/source/or.d.ts +1 -1
  70. package/source/package-json.d.ts +7 -7
  71. package/source/partial-deep.d.ts +3 -1
  72. package/source/pascal-case.d.ts +1 -0
  73. package/source/pascal-cased-properties-deep.d.ts +7 -0
  74. package/source/pascal-cased-properties.d.ts +5 -1
  75. package/source/pick-deep.d.ts +2 -0
  76. package/source/readonly-deep.d.ts +5 -3
  77. package/source/remove-prefix.d.ts +16 -34
  78. package/source/remove-suffix.d.ts +114 -0
  79. package/source/rename-keys.d.ts +163 -0
  80. package/source/replace.d.ts +2 -2
  81. package/source/require-all-or-none.d.ts +5 -5
  82. package/source/require-at-least-one.d.ts +9 -11
  83. package/source/require-exactly-one.d.ts +7 -7
  84. package/source/require-one-or-none.d.ts +5 -5
  85. package/source/required-deep.d.ts +3 -1
  86. package/source/schema.d.ts +16 -8
  87. package/source/screaming-snake-case.d.ts +1 -0
  88. package/source/set-non-nullable-deep.d.ts +8 -4
  89. package/source/set-non-nullable.d.ts +1 -1
  90. package/source/set-optional.d.ts +5 -5
  91. package/source/set-readonly.d.ts +3 -3
  92. package/source/set-required-deep.d.ts +3 -2
  93. package/source/set-required.d.ts +13 -12
  94. package/source/shared-union-fields-deep.d.ts +6 -4
  95. package/source/shared-union-fields.d.ts +9 -9
  96. package/source/snake-case.d.ts +1 -0
  97. package/source/snake-cased-properties-deep.d.ts +7 -0
  98. package/source/snake-cased-properties.d.ts +5 -1
  99. package/source/some-extend.d.ts +9 -5
  100. package/source/split-on-rest-element.d.ts +20 -17
  101. package/source/split.d.ts +22 -11
  102. package/source/string-length.d.ts +38 -0
  103. package/source/string-repeat.d.ts +48 -21
  104. package/source/string-slice.d.ts +1 -1
  105. package/source/string-to-array.d.ts +97 -0
  106. package/source/string-to-number.d.ts +67 -0
  107. package/source/subtract.d.ts +4 -3
  108. package/source/sum.d.ts +5 -4
  109. package/source/tagged.d.ts +3 -5
  110. package/source/tsconfig-json.d.ts +40 -8
  111. package/source/tuple-of.d.ts +42 -8
  112. package/source/typed-array.d.ts +6 -0
  113. package/source/union-length.d.ts +27 -0
  114. package/source/union-max.d.ts +56 -0
  115. package/source/union-to-intersection.d.ts +1 -1
  116. package/source/union-to-tuple.d.ts +8 -4
  117. package/source/unwrap-required.d.ts +37 -0
  118. package/source/words.d.ts +30 -4
  119. package/source/writable.d.ts +14 -14
  120. package/source/xor.d.ts +1 -1
@@ -1,7 +1,6 @@
1
1
  import type {If} from './if.d.ts';
2
2
  import type {IsArrayReadonly} from './internal/array.d.ts';
3
3
  import type {IfNotAnyOrNever, IsExactOptionalPropertyTypesEnabled} from './internal/type.d.ts';
4
- import type {IsOptionalKeyOf} from './is-optional-key-of.d.ts';
5
4
  import type {UnknownArray} from './unknown-array.d.ts';
6
5
 
7
6
  /**
@@ -51,12 +50,13 @@ type E = ArrayReverse<[string?, number?, ...boolean[]]>;
51
50
 
52
51
  @category Array
53
52
  */
54
- export type ArrayReverse<TArray extends UnknownArray> = IfNotAnyOrNever<TArray,
55
- TArray extends unknown // For distributing `TArray`
53
+ export type ArrayReverse<TArray extends UnknownArray> = IfNotAnyOrNever<TArray, {
54
+ ifNot: TArray extends unknown // For distributing `TArray`
56
55
  ? _ArrayReverse<TArray> extends infer Result
57
56
  ? If<IsArrayReadonly<TArray>, Readonly<Result>, Result>
58
57
  : never // Should never happen
59
- : never>; // Should never happen
58
+ : never; // Should never happen
59
+ }>;
60
60
 
61
61
  type _ArrayReverse<
62
62
  TArray extends UnknownArray,
@@ -64,21 +64,23 @@ type _ArrayReverse<
64
64
  AfterRestAcc extends UnknownArray = [],
65
65
  Result extends UnknownArray = never,
66
66
  > =
67
- keyof TArray & `${number}` extends never
68
- // Enters this branch, if `TArray` is empty (e.g., `[]`),
69
- // or `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
70
- ? TArray extends readonly [...infer Rest, infer Last]
71
- ? _ArrayReverse<Rest, BeforeRestAcc, [...AfterRestAcc, Last], Result> // Accumulate elements that are present after the rest element in reverse order.
72
- : Result | [...AfterRestAcc, ...TArray, ...BeforeRestAcc] // Add the rest element between the accumulated elements.
73
- : TArray extends readonly [(infer First)?, ...infer Rest]
74
- ? IsOptionalKeyOf<TArray, '0'> extends true
75
- ? _ArrayReverse<
67
+ '0' extends keyof TArray
68
+ // Enters this branch, if `TArray` starts with a non-rest element (e.g., `[string, number]` or `[string, ...number[]]`).
69
+ ? TArray extends readonly [(infer First)?, ...infer Rest]
70
+ // A tuple allows fewer than one element only when its first element is optional. Written in exactly this shape because equivalent ones, such as `[] extends TArray`, are several times slower.
71
+ ? TArray extends readonly [unknown, ...unknown[]]
72
+ ? _ArrayReverse<Rest, [First, ...BeforeRestAcc], AfterRestAcc, Result>
73
+ : _ArrayReverse<
76
74
  Rest,
77
75
  [First | (If<IsExactOptionalPropertyTypesEnabled, never, undefined>), ...BeforeRestAcc], // Add `| undefined` for optional elements, if `exactOptionalPropertyTypes` is disabled.
78
76
  AfterRestAcc,
79
77
  Result | BeforeRestAcc
80
78
  >
81
- : _ArrayReverse<Rest, [First, ...BeforeRestAcc], AfterRestAcc, Result>
82
- : never; // Should never happen, since `readonly [(infer First)?, ...infer Rest]` is a top-type for arrays.
79
+ : never // Should never happen, since `readonly [(infer First)?, ...infer Rest]` is a top-type for arrays.
80
+ // Enters this branch, if `TArray` is empty (e.g., `[]`),
81
+ // or `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
82
+ : TArray extends readonly [...infer Rest, infer Last]
83
+ ? _ArrayReverse<Rest, BeforeRestAcc, [...AfterRestAcc, Last], Result> // Accumulate elements that are present after the rest element in reverse order.
84
+ : Result | [...AfterRestAcc, ...TArray, ...BeforeRestAcc]; // Add the rest element between the accumulated elements.
83
85
 
84
86
  export {};
@@ -8,13 +8,13 @@ import type {TupleOf} from './tuple-of.d.ts';
8
8
  The implementation of `SplitArrayByIndex` for fixed length arrays.
9
9
  */
10
10
  type SplitFixedArrayByIndex<T extends UnknownArray, SplitIndex extends number> =
11
- SplitIndex extends 0
12
- ? [[], T]
13
- : T extends readonly [...TupleOf<SplitIndex>, ...infer V]
14
- ? T extends readonly [...infer U, ...V]
15
- ? [U, V]
16
- : [never, never]
17
- : [never, never];
11
+ SplitIndex extends 0
12
+ ? [[], T]
13
+ : T extends readonly [...TupleOf<SplitIndex>, ...infer V]
14
+ ? T extends readonly [...infer U, ...V]
15
+ ? [U, V]
16
+ : [never, never]
17
+ : [never, never];
18
18
 
19
19
  /**
20
20
  The implementation of `SplitArrayByIndex` for variable length arrays.
@@ -26,23 +26,23 @@ type SplitVariableArrayByIndex<T extends UnknownArray,
26
26
  ? TupleOf<GreaterThanOrEqual<T1, 0> extends true ? T1 : number, VariablePartOfArray<T>[number]>
27
27
  : [],
28
28
  > =
29
- SplitIndex extends 0
30
- ? [[], T]
31
- : GreaterThanOrEqual<StaticPartOfArray<T>['length'], SplitIndex> extends true
32
- ? [
33
- SplitFixedArrayByIndex<StaticPartOfArray<T>, SplitIndex>[0],
34
- [
35
- ...SplitFixedArrayByIndex<StaticPartOfArray<T>, SplitIndex>[1],
36
- ...VariablePartOfArray<T>,
37
- ],
38
- ]
39
- : [
40
- [
41
- ...StaticPartOfArray<T>,
42
- ...(T2 extends UnknownArray ? T2 : []),
43
- ],
44
- VariablePartOfArray<T>,
45
- ];
29
+ SplitIndex extends 0
30
+ ? [[], T]
31
+ : GreaterThanOrEqual<StaticPartOfArray<T>['length'], SplitIndex> extends true
32
+ ? [
33
+ SplitFixedArrayByIndex<StaticPartOfArray<T>, SplitIndex>[0],
34
+ [
35
+ ...SplitFixedArrayByIndex<StaticPartOfArray<T>, SplitIndex>[1],
36
+ ...VariablePartOfArray<T>,
37
+ ],
38
+ ]
39
+ : [
40
+ [
41
+ ...StaticPartOfArray<T>,
42
+ ...(T2 extends UnknownArray ? T2 : []),
43
+ ],
44
+ VariablePartOfArray<T>,
45
+ ];
46
46
 
47
47
  /**
48
48
  Split the given array `T` by the given `SplitIndex`.
@@ -51,20 +51,20 @@ const availableTopSciFi = curry(searchBooks)('sci-fi')(4.5)(true);
51
51
 
52
52
  @category Array
53
53
  */
54
- export type ArrayTail<TArray extends UnknownArray> = IfNotAnyOrNever<TArray,
55
- TArray extends UnknownArray // For distributing `TArray`
54
+ export type ArrayTail<TArray extends UnknownArray> = IfNotAnyOrNever<TArray, {
55
+ ifNot: TArray extends UnknownArray // For distributing `TArray`
56
56
  ? _ArrayTail<TArray> extends infer Result
57
57
  ? If<IsArrayReadonly<TArray>, Readonly<Result>, Result>
58
58
  : never // Should never happen
59
- : never
60
- >;
59
+ : never;
60
+ }>;
61
61
 
62
62
  type _ArrayTail<TArray extends UnknownArray> = TArray extends readonly [unknown?, ...infer Tail]
63
- ? keyof TArray & `${number}` extends never
64
- ? TArray extends readonly []
63
+ ? '0' extends keyof TArray
64
+ ? Tail
65
+ : TArray extends readonly []
65
66
  ? []
66
67
  : TArray // Happens when `TArray` is a non-tuple array (e.g., `string[]`) or has a leading rest element (e.g., `[...string[], number]`)
67
- : Tail
68
68
  : [];
69
69
 
70
70
  export {};
@@ -1,5 +1,5 @@
1
1
  import type {ApplyDefaultOptions} from './internal/index.d.ts';
2
- import type {Words, WordsOptions} from './words.d.ts';
2
+ import type {_DefaultWordsOptions, Words, WordsOptions} from './words.d.ts';
3
3
 
4
4
  /**
5
5
  CamelCase options.
@@ -13,13 +13,39 @@ export type CamelCaseOptions = WordsOptions & {
13
13
  @default false
14
14
  */
15
15
  preserveConsecutiveUppercase?: boolean;
16
+
17
+ /**
18
+ Whether to preserve leading underscores.
19
+
20
+ This matches the behavior of the [`camelcase`](https://github.com/sindresorhus/camelcase) package v9+.
21
+
22
+ @default false
23
+ */
24
+ preserveLeadingUnderscores?: boolean;
16
25
  };
17
26
 
18
- export type _DefaultCamelCaseOptions = {
19
- splitOnNumbers: true;
27
+ export type _DefaultCamelCaseOptions = _DefaultWordsOptions & {
20
28
  preserveConsecutiveUppercase: false;
29
+ preserveLeadingUnderscores: false;
21
30
  };
22
31
 
32
+ /**
33
+ Extract leading underscores from a string.
34
+
35
+ @example
36
+ ```
37
+ type A = LeadingUnderscores<'__foo_bar'>;
38
+ //=> '__'
39
+
40
+ type B = LeadingUnderscores<'foo_bar'>;
41
+ //=> ''
42
+ ```
43
+ */
44
+ type LeadingUnderscores<Type extends string, Underscores extends string = ''> =
45
+ Type extends `_${infer Rest}`
46
+ ? LeadingUnderscores<Rest, `_${Underscores}`>
47
+ : Underscores;
48
+
23
49
  /**
24
50
  Convert an array of words to camel-case.
25
51
  */
@@ -43,6 +69,8 @@ This can be useful when, for example, converting some kebab-cased command-line f
43
69
 
44
70
  By default, consecutive uppercase letter are preserved. See {@link CamelCaseOptions.preserveConsecutiveUppercase preserveConsecutiveUppercase} option to change this behaviour.
45
71
 
72
+ Use the `preserveLeadingUnderscores` option to retain leading underscores, matching the runtime behavior of [`camelcase`](https://github.com/sindresorhus/camelcase) v9+.
73
+
46
74
  @example
47
75
  ```
48
76
  import type {CamelCase} from 'type-fest';
@@ -51,6 +79,8 @@ import type {CamelCase} from 'type-fest';
51
79
 
52
80
  const someVariable: CamelCase<'foo-bar'> = 'fooBar';
53
81
  const preserveConsecutiveUppercase: CamelCase<'foo-BAR-baz', {preserveConsecutiveUppercase: true}> = 'fooBARBaz';
82
+ const splitOnPunctuation: CamelCase<'foo-bar:BAZ', {splitOnPunctuation: true}> = 'fooBarBaz';
83
+ const preserveLeadingUnderscores: CamelCase<'_foo_bar', {preserveLeadingUnderscores: true}> = '_fooBar';
54
84
 
55
85
  // Advanced
56
86
 
@@ -83,10 +113,13 @@ const dbResult: CamelCasedProperties<RawOptions> = {
83
113
  export type CamelCase<Type, Options extends CamelCaseOptions = {}> = Type extends string
84
114
  ? string extends Type
85
115
  ? Type
86
- : Uncapitalize<CamelCaseFromArray<
116
+ : `${Options['preserveLeadingUnderscores'] extends true
117
+ ? LeadingUnderscores<Type>
118
+ : ''
119
+ }${Uncapitalize<CamelCaseFromArray<
87
120
  Words<Type extends Uppercase<Type> ? Lowercase<Type> : Type, Options>,
88
121
  ApplyDefaultOptions<CamelCaseOptions, _DefaultCamelCaseOptions, Options>
89
- >>
122
+ >>}`
90
123
  : Type;
91
124
 
92
125
  export {};
@@ -48,6 +48,13 @@ const preserveConsecutiveUppercase: CamelCasedPropertiesDeep<{fooBAR: {fooBARBiz
48
48
  }],
49
49
  },
50
50
  };
51
+
52
+ const splitOnPunctuation: CamelCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: true}> = {
53
+ userInfo: {
54
+ userId: 1,
55
+ userName: 'Tom',
56
+ },
57
+ };
51
58
  ```
52
59
 
53
60
  @category Change case
@@ -86,11 +93,11 @@ type CamelCasedPropertiesArrayDeep<
86
93
  ? [_CamelCasedPropertiesDeep<U, Options>, ..._CamelCasedPropertiesDeep<V, Options>]
87
94
  : Value extends readonly [infer U, ...infer V]
88
95
  ? readonly [_CamelCasedPropertiesDeep<U, Options>, ..._CamelCasedPropertiesDeep<V, Options>]
89
- : // Leading spread array
90
- Value extends readonly [...infer U, infer V]
96
+ // Leading spread array
97
+ : Value extends readonly [...infer U, infer V]
91
98
  ? [..._CamelCasedPropertiesDeep<U, Options>, _CamelCasedPropertiesDeep<V, Options>]
92
- : // Array
93
- Value extends Array<infer U>
99
+ // Array
100
+ : Value extends Array<infer U>
94
101
  ? Array<_CamelCasedPropertiesDeep<U, Options>>
95
102
  : Value extends ReadonlyArray<infer U>
96
103
  ? ReadonlyArray<_CamelCasedPropertiesDeep<U, Options>>
@@ -2,7 +2,7 @@ import type {CamelCase, CamelCaseOptions, _DefaultCamelCaseOptions} from './came
2
2
  import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
3
 
4
4
  /**
5
- Convert object properties to camel case but not recursively.
5
+ Convert top-level object properties to camel case.
6
6
 
7
7
  This can be useful when, for example, converting some API types from a different style.
8
8
 
@@ -26,6 +26,10 @@ const result: CamelCasedProperties<User> = {
26
26
  const preserveConsecutiveUppercase: CamelCasedProperties<{fooBAR: string}, {preserveConsecutiveUppercase: true}> = {
27
27
  fooBAR: 'string',
28
28
  };
29
+
30
+ const splitOnPunctuation: CamelCasedProperties<{'foo::bar': string}, {splitOnPunctuation: true}> = {
31
+ fooBar: 'string',
32
+ };
29
33
  ```
30
34
 
31
35
  @category Change case
@@ -50,7 +50,7 @@ type NumberValueIndices = ConditionalKeys<[string, number?, string?], number | u
50
50
  @category Object
51
51
  */
52
52
  export type ConditionalKeys<Base, Condition> = (Base extends UnknownArray ? TupleToObject<Base> : Base) extends infer _Base // Remove non-numeric keys from arrays
53
- ? IfNotAnyOrNever<_Base, _ConditionalKeys<_Base, Condition>, keyof _Base>
53
+ ? IfNotAnyOrNever<_Base, {ifNot: _ConditionalKeys<_Base, Condition>; ifAny: keyof _Base}>
54
54
  : never;
55
55
 
56
56
  type _ConditionalKeys<Base, Condition> = keyof {
@@ -1,7 +1,6 @@
1
1
  import type {ApplyDefaultOptions, AsciiPunctuation, StartsWith} from './internal/index.d.ts';
2
- import type {IsStringLiteral} from './is-literal.d.ts';
2
+ import type {IsStringLiteral} from './is-string-literal.d.ts';
3
3
  import type {Merge} from './merge.d.ts';
4
- import type {RemovePrefix} from './remove-prefix.d.ts';
5
4
  import type {_DefaultWordsOptions, Words, WordsOptions} from './words.d.ts';
6
5
 
7
6
  export type _DefaultDelimiterCaseOptions = Merge<_DefaultWordsOptions, {splitOnNumbers: false}>;
@@ -17,7 +16,7 @@ type DelimiterCaseFromArray<
17
16
  infer FirstWord extends string,
18
17
  ...infer RemainingWords extends string[],
19
18
  ]
20
- ? DelimiterCaseFromArray<RemainingWords, Delimiter, `${OutputString}${
19
+ ? DelimiterCaseFromArray<RemainingWords, Delimiter, OutputString extends '' ? FirstWord : `${OutputString}${
21
20
  StartsWith<FirstWord, AsciiPunctuation> extends true ? '' : Delimiter
22
21
  }${FirstWord}`>
23
22
  : OutputString;
@@ -38,6 +37,7 @@ import type {DelimiterCase} from 'type-fest';
38
37
 
39
38
  const someVariable: DelimiterCase<'fooBar', '#'> = 'foo#bar';
40
39
  const someVariableNoSplitOnNumbers: DelimiterCase<'p2pNetwork', '#', {splitOnNumbers: false}> = 'p2p#network';
40
+ const someVariableWithPunctuation: DelimiterCase<'div.card::after', '#', {splitOnPunctuation: true}> = 'div#card#after';
41
41
 
42
42
  // Advanced
43
43
 
@@ -66,12 +66,14 @@ export type DelimiterCase<
66
66
  Delimiter extends string,
67
67
  Options extends WordsOptions = {},
68
68
  > = Value extends string
69
- ? IsStringLiteral<Value> extends false
70
- ? Value
71
- : Lowercase<RemovePrefix<DelimiterCaseFromArray<
72
- Words<Value, ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>,
73
- Delimiter
74
- >, string, {strict: false}>>
69
+ ? Delimiter extends string // For distributing `Delimiter`
70
+ ? IsStringLiteral<Value> extends false
71
+ ? Value
72
+ : Lowercase<DelimiterCaseFromArray<
73
+ Words<Value, ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>,
74
+ Delimiter
75
+ >>
76
+ : never
75
77
  : Value;
76
78
 
77
79
  export {};
@@ -4,7 +4,7 @@ import type {UnknownArray} from './unknown-array.d.ts';
4
4
  import type {WordsOptions} from './words.d.ts';
5
5
 
6
6
  /**
7
- Convert object properties to delimiter case recursively.
7
+ Convert object properties to a custom string delimiter casing recursively.
8
8
 
9
9
  This can be useful when, for example, converting some API types from a different style.
10
10
 
@@ -51,6 +51,13 @@ const splitOnNumbers: DelimiterCasedPropertiesDeep<{line1: {line2: [{line3: stri
51
51
  ],
52
52
  },
53
53
  };
54
+
55
+ const splitOnPunctuation: DelimiterCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, '-', {splitOnPunctuation: true}> = {
56
+ 'user-info': {
57
+ 'user-id': 1,
58
+ 'user-name': 'Tom',
59
+ },
60
+ };
54
61
  ```
55
62
 
56
63
  @category Change case
@@ -3,7 +3,7 @@ import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
3
  import type {WordsOptions} from './words.d.ts';
4
4
 
5
5
  /**
6
- Convert object properties to delimiter case but not recursively.
6
+ Convert object properties to a custom string delimiter casing.
7
7
 
8
8
  This can be useful when, for example, converting some API types from a different style.
9
9
 
@@ -27,6 +27,10 @@ const result: DelimiterCasedProperties<User, '-'> = {
27
27
  const splitOnNumbers: DelimiterCasedProperties<{line1: string}, '-', {splitOnNumbers: true}> = {
28
28
  'line-1': 'string',
29
29
  };
30
+
31
+ const splitOnPunctuation: DelimiterCasedProperties<{'foo::bar': string}, '-', {splitOnPunctuation: true}> = {
32
+ 'foo-bar': 'string',
33
+ };
30
34
  ```
31
35
 
32
36
  @category Change case
@@ -32,7 +32,7 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
32
32
  export type EmptyObject = {[emptyObjectSymbol]?: never};
33
33
 
34
34
  /**
35
- Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
35
+ Returns a boolean for whether the type is strictly equal to an empty plain object, the `{}` value.
36
36
 
37
37
  @example
38
38
  ```
@@ -6,7 +6,7 @@ type ObjectEntries<BaseType> = Array<_ObjectEntry<BaseType>>;
6
6
  type SetEntries<BaseType extends Set<unknown>> = Array<_SetEntry<BaseType>>;
7
7
 
8
8
  /**
9
- Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entries` type will return the type of that collection's entries.
9
+ Create a type that describes the key-value pairs produced when calling a collection’s `entries` method.
10
10
 
11
11
  For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
12
12
 
package/source/entry.d.ts CHANGED
@@ -7,7 +7,7 @@ export type _ObjectEntry<BaseType> = [keyof BaseType, BaseType[keyof BaseType]];
7
7
  export type _SetEntry<BaseType> = BaseType extends Set<infer ItemType> ? [ItemType, ItemType] : never;
8
8
 
9
9
  /**
10
- Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entry` type will return the type of that collection's entry.
10
+ Create a type that describes a single key-value pair produced when calling a collection’s `entries` method.
11
11
 
12
12
  For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
13
13
 
@@ -33,25 +33,25 @@ type TestExcludeExactly3 = ExcludeExactly<{a: string} | {a: string; b: string},
33
33
  @category Improved Built-in
34
34
  */
35
35
  export type ExcludeExactly<Union, Delete> =
36
- IfNotAnyOrNever<
37
- Union,
38
- _ExcludeExactly<Union, Delete>,
36
+ IfNotAnyOrNever<Union, {
37
+ ifNot: _ExcludeExactly<Union, Delete>;
39
38
  // If `Union` is `any`, then if `Delete` is `any`, return `never`, else return `Union`.
40
- If<IsAny<Delete>, never, Union>,
39
+ ifAny: If<IsAny<Delete>, never, Union>;
41
40
  // If `Union` is `never`, then if `Delete` is `never`, return `never`, else return `Union`.
42
- If<IsNever<Delete>, never, Union>
43
- >;
41
+ ifNever: If<IsNever<Delete>, never, Union>;
42
+ }>;
44
43
 
45
44
  type _ExcludeExactly<Union, Delete> =
46
- IfNotAnyOrNever<Delete,
47
- Union extends unknown // For distributing `Union`
45
+ IfNotAnyOrNever<Delete, {
46
+ ifNot: Union extends unknown // For distributing `Union`
48
47
  ? [Delete extends unknown // For distributing `Delete`
49
48
  ? If<IsEqual<Union, Delete>, true, never>
50
49
  : never] extends [never] ? Union : never
51
- : never,
50
+ : never;
52
51
  // If `Delete` is `any` or `never`, then return `Union`,
53
52
  // because `Union` cannot be `any` or `never` here.
54
- Union, Union
55
- >;
53
+ ifAny: Union;
54
+ ifNever: Union;
55
+ }>;
56
56
 
57
57
  export {};
@@ -27,14 +27,14 @@ type T4 = ExcludeRestElement<[number, string]>;
27
27
  @see {@link SplitOnRestElement}
28
28
  @category Array
29
29
  */
30
- export type ExcludeRestElement<Array_ extends UnknownArray> = IfNotAnyOrNever<Array_,
31
- SplitOnRestElement<Array_> extends infer Result
30
+ export type ExcludeRestElement<Array_ extends UnknownArray> = IfNotAnyOrNever<Array_, {
31
+ ifNot: SplitOnRestElement<Array_> extends infer Result
32
32
  ? Result extends readonly UnknownArray[]
33
33
  ? IsArrayReadonly<Array_> extends true
34
34
  ? Readonly<[...Result[0], ...Result[2]]>
35
35
  : [...Result[0], ...Result[2]]
36
36
  : never
37
- : never
38
- >;
37
+ : never;
38
+ }>;
39
39
 
40
40
  export {};
@@ -125,13 +125,13 @@ type D = ExclusifyUnion<{a?: 1; readonly b: 2} | {d: 4}>;
125
125
  @category Object
126
126
  @category Union
127
127
  */
128
- export type ExclusifyUnion<Union> = IfNotAnyOrNever<Union,
129
- If<IsUnknown<Union>, Union,
128
+ export type ExclusifyUnion<Union> = IfNotAnyOrNever<Union, {
129
+ ifNot: If<IsUnknown<Union>, Union,
130
130
  Extract<Union, NonRecursiveType | MapsSetsOrArrays> extends infer SkippedMembers
131
131
  ? SkippedMembers | _ExclusifyUnion<Exclude<Union, SkippedMembers>>
132
132
  : never
133
- >
134
- >;
133
+ >;
134
+ }>;
135
135
 
136
136
  type _ExclusifyUnion<Union, UnionCopy = Union> = Union extends unknown // For distributing `Union`
137
137
  ? Simplify<