type-fest 5.5.0 → 5.6.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/index.d.ts +3 -0
- package/package.json +6 -4
- package/readme.md +70 -55
- package/source/absolute.d.ts +52 -0
- package/source/all-union-fields.d.ts +18 -18
- package/source/and.d.ts +1 -1
- package/source/array-splice.d.ts +24 -24
- package/source/camel-case.d.ts +38 -5
- package/source/camel-cased-properties-deep.d.ts +11 -4
- package/source/camel-cased-properties.d.ts +5 -1
- package/source/delimiter-case.d.ts +1 -0
- package/source/delimiter-cased-properties-deep.d.ts +8 -1
- package/source/delimiter-cased-properties.d.ts +5 -1
- package/source/empty-object.d.ts +1 -1
- package/source/entries.d.ts +1 -1
- package/source/entry.d.ts +1 -1
- package/source/get.d.ts +1 -1
- package/source/greater-than.d.ts +3 -2
- package/source/has-optional-keys.d.ts +1 -1
- package/source/has-readonly-keys.d.ts +1 -1
- package/source/has-required-keys.d.ts +1 -1
- package/source/has-writable-keys.d.ts +1 -1
- package/source/int-closed-range.d.ts +1 -3
- package/source/int-range.d.ts +3 -5
- package/source/internal/array.d.ts +7 -7
- package/source/internal/keys.d.ts +9 -9
- package/source/internal/numeric.d.ts +13 -23
- package/source/internal/tuple.d.ts +2 -2
- package/source/is-integer.d.ts +8 -8
- package/source/is-literal.d.ts +5 -5
- package/source/is-union.d.ts +12 -12
- package/source/iterable-element.d.ts +5 -5
- package/source/jsonify.d.ts +4 -4
- package/source/kebab-case.d.ts +1 -0
- package/source/kebab-cased-properties-deep.d.ts +7 -0
- package/source/kebab-cased-properties.d.ts +5 -1
- package/source/keys-of-union.d.ts +2 -2
- package/source/less-than-or-equal.d.ts +1 -1
- package/source/literal-to-primitive.d.ts +1 -1
- package/source/literal-union.d.ts +1 -1
- package/source/merge-exclusive.d.ts +3 -3
- package/source/multidimensional-array.d.ts +1 -1
- package/source/multidimensional-readonly-array.d.ts +1 -1
- package/source/non-nullable-deep.d.ts +102 -0
- package/source/numeric.d.ts +3 -3
- package/source/omit-deep.d.ts +22 -22
- package/source/or.d.ts +1 -1
- package/source/package-json.d.ts +7 -7
- package/source/partial-deep.d.ts +3 -1
- package/source/pascal-case.d.ts +1 -0
- package/source/pascal-cased-properties-deep.d.ts +7 -0
- package/source/pascal-cased-properties.d.ts +5 -1
- package/source/pick-deep.d.ts +2 -0
- package/source/readonly-deep.d.ts +5 -3
- package/source/remove-prefix.d.ts +15 -15
- package/source/replace.d.ts +2 -2
- package/source/require-all-or-none.d.ts +1 -1
- package/source/require-at-least-one.d.ts +5 -7
- package/source/require-exactly-one.d.ts +3 -3
- package/source/require-one-or-none.d.ts +1 -1
- package/source/required-deep.d.ts +3 -1
- package/source/screaming-snake-case.d.ts +1 -0
- package/source/set-non-nullable-deep.d.ts +6 -3
- package/source/set-non-nullable.d.ts +1 -1
- package/source/set-optional.d.ts +5 -5
- package/source/set-readonly.d.ts +3 -3
- package/source/set-required-deep.d.ts +1 -1
- package/source/set-required.d.ts +3 -3
- package/source/shared-union-fields.d.ts +9 -9
- package/source/snake-case.d.ts +1 -0
- package/source/snake-cased-properties-deep.d.ts +7 -0
- package/source/snake-cased-properties.d.ts +5 -1
- package/source/subtract.d.ts +4 -3
- package/source/sum.d.ts +5 -4
- package/source/tagged.d.ts +3 -5
- package/source/tsconfig-json.d.ts +39 -7
- package/source/union-length.d.ts +27 -0
- package/source/union-to-intersection.d.ts +1 -1
- package/source/union-to-tuple.d.ts +8 -4
- package/source/words.d.ts +30 -4
- package/source/writable.d.ts +14 -14
- package/source/xor.d.ts +1 -1
package/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export type {SetRequired} from './source/set-required.d.ts';
|
|
|
52
52
|
export type {SetRequiredDeep} from './source/set-required-deep.d.ts';
|
|
53
53
|
export type {SetNonNullable} from './source/set-non-nullable.d.ts';
|
|
54
54
|
export type {SetNonNullableDeep} from './source/set-non-nullable-deep.d.ts';
|
|
55
|
+
export type {NonNullableDeep} from './source/non-nullable-deep.d.ts';
|
|
55
56
|
export type {ValueOf} from './source/value-of.d.ts';
|
|
56
57
|
export type {AsyncReturnType} from './source/async-return-type.d.ts';
|
|
57
58
|
export type {ConditionalExcept} from './source/conditional-except.d.ts';
|
|
@@ -173,6 +174,8 @@ export type {TupleOf} from './source/tuple-of.d.ts';
|
|
|
173
174
|
export type {ExclusifyUnion} from './source/exclusify-union.d.ts';
|
|
174
175
|
export type {ArrayReverse} from './source/array-reverse.d.ts';
|
|
175
176
|
export type {UnionMember} from './source/union-member.d.ts';
|
|
177
|
+
export type {Absolute} from './source/absolute.d.ts';
|
|
178
|
+
export type {UnionLength} from './source/union-length.d.ts';
|
|
176
179
|
|
|
177
180
|
// Template literal types
|
|
178
181
|
export type {CamelCase, CamelCaseOptions} from './source/camel-case.d.ts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-fest",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "A collection of essential TypeScript types",
|
|
5
5
|
"license": "(MIT OR CC0-1.0)",
|
|
6
6
|
"repository": "sindresorhus/type-fest",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test:tsc": "node --max-old-space-size=6144 ./node_modules/.bin/tsc",
|
|
29
29
|
"test:tsd": "node --max-old-space-size=6144 ./node_modules/.bin/tsd",
|
|
30
|
-
"test:xo": "node --max-old-space-size=6144 ./node_modules/.bin/xo --ignores=lint-processors/fixtures/**/*.d.ts",
|
|
30
|
+
"test:xo": "node --max-old-space-size=6144 ./node_modules/.bin/xo --ignores=lint-processors/fixtures/**/*.d.ts '**/*.{js,ts,md}'",
|
|
31
31
|
"test:linter": "node --test",
|
|
32
32
|
"test": "run-p test:*"
|
|
33
33
|
},
|
|
@@ -53,17 +53,19 @@
|
|
|
53
53
|
"tagged-tag": "^1.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
+
"@eslint/markdown": "^8.0.1",
|
|
56
57
|
"@sindresorhus/tsconfig": "^8.0.1",
|
|
58
|
+
"@types/node": "^25.5.0",
|
|
57
59
|
"@typescript-eslint/parser": "^8.44.0",
|
|
58
|
-
"eslint": "^9.35.0",
|
|
59
60
|
"@typescript/vfs": "^1.6.1",
|
|
60
61
|
"dedent": "^1.7.0",
|
|
62
|
+
"eslint": "^10.1.0",
|
|
61
63
|
"expect-type": "^1.2.2",
|
|
62
64
|
"npm-run-all2": "^8.0.4",
|
|
63
65
|
"tsd": "^0.33.0",
|
|
64
66
|
"typescript": "^5.9.2",
|
|
65
67
|
"typescript-eslint": "^8.47.0",
|
|
66
|
-
"xo": "^
|
|
68
|
+
"xo": "^2.0.2"
|
|
67
69
|
},
|
|
68
70
|
"tsd": {
|
|
69
71
|
"compilerOptions": {
|
package/readme.md
CHANGED
|
@@ -29,6 +29,17 @@
|
|
|
29
29
|
<sup>An open-source framework that supports any programming language, cloud provider, or deployment automation tool.</sup>
|
|
30
30
|
</div>
|
|
31
31
|
</a>
|
|
32
|
+
<br>
|
|
33
|
+
<br>
|
|
34
|
+
<a href="https://circleback.ai?utm_source=sindresorhus&utm_medium=sponsorship&utm_campaign=awesome-list&utm_id=type-fest">
|
|
35
|
+
<div>
|
|
36
|
+
<img width="300" src="https://sindresorhus.com/assets/thanks/circleback-logo.png?x" alt="Circleback logo">
|
|
37
|
+
</div>
|
|
38
|
+
<b>Get the most out of every conversation.</b>
|
|
39
|
+
<div>
|
|
40
|
+
<sup>AI-powered meeting notes, automations, and search. Give AI agents the context they need to get things done.</sup>
|
|
41
|
+
</div>
|
|
42
|
+
</a>
|
|
32
43
|
</p>
|
|
33
44
|
</div>
|
|
34
45
|
<br>
|
|
@@ -102,51 +113,52 @@ Click the type names for complete docs.
|
|
|
102
113
|
- [`UnknownArray`](source/unknown-array.d.ts) - Represents an array with `unknown` value.
|
|
103
114
|
- [`UnknownMap`](source/unknown-map.d.ts) - Represents a map with `unknown` key and value.
|
|
104
115
|
- [`UnknownSet`](source/unknown-set.d.ts) - Represents a set with `unknown` value.
|
|
105
|
-
- [`Except`](source/except.d.ts) - Create a type from an object type without certain keys.
|
|
116
|
+
- [`Except`](source/except.d.ts) - Create a type from an object type without certain keys.
|
|
106
117
|
- [`Writable`](source/writable.d.ts) - Create a type that strips `readonly` from the given type. Inverse of `Readonly<T>`.
|
|
107
118
|
- [`WritableDeep`](source/writable-deep.d.ts) - Create a deeply mutable version of an `object`/`ReadonlyMap`/`ReadonlySet`/`ReadonlyArray` type. The inverse of `ReadonlyDeep<T>`. Use `Writable<T>` if you only need one level deep.
|
|
108
119
|
- [`Merge`](source/merge.d.ts) - Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
109
120
|
- [`ObjectMerge`](source/object-merge.d.ts) - Merge two object types into a new object type, where keys from the second override keys from the first.
|
|
110
121
|
- [`MergeDeep`](source/merge-deep.d.ts) - Merge two objects or two arrays/tuples recursively into a new type.
|
|
111
122
|
- [`MergeExclusive`](source/merge-exclusive.d.ts) - Create a type that has mutually exclusive keys.
|
|
112
|
-
- [`OverrideProperties`](source/override-properties.d.ts) - Override
|
|
113
|
-
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given keys.
|
|
114
|
-
- [`RequireExactlyOne`](source/require-exactly-one.d.ts) - Create a type that requires exactly
|
|
115
|
-
- [`RequireAllOrNone`](source/require-all-or-none.d.ts) - Create a type that requires all of the given keys or none of the given keys.
|
|
116
|
-
- [`RequireOneOrNone`](source/require-one-or-none.d.ts) - Create a type that requires exactly
|
|
123
|
+
- [`OverrideProperties`](source/override-properties.d.ts) - Override existing properties of the given type. Similar to `Merge`, but enforces that the original type has the properties you want to override.
|
|
124
|
+
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given keys, while keeping the remaining keys as is.
|
|
125
|
+
- [`RequireExactlyOne`](source/require-exactly-one.d.ts) - Create a type that requires exactly one of the given keys and disallows more, while keeping the remaining keys as is.
|
|
126
|
+
- [`RequireAllOrNone`](source/require-all-or-none.d.ts) - Create a type that requires all of the given keys or none of the given keys, while keeping the remaining keys as is.
|
|
127
|
+
- [`RequireOneOrNone`](source/require-one-or-none.d.ts) - Create a type that requires exactly one of the given keys or none of the given keys, while keeping the remaining keys as is.
|
|
117
128
|
- [`SingleKeyObject`](source/single-key-object.d.ts) - Create a type that only accepts an object with a single key.
|
|
118
|
-
- [`RequiredDeep`](source/required-deep.d.ts) - Create a deeply required version of another type.
|
|
119
|
-
- [`PickDeep`](source/pick-deep.d.ts) - Pick properties from a deeply-nested object.
|
|
120
|
-
- [`OmitDeep`](source/omit-deep.d.ts) - Omit properties from a deeply-nested object.
|
|
129
|
+
- [`RequiredDeep`](source/required-deep.d.ts) - Create a deeply required version of another type.
|
|
130
|
+
- [`PickDeep`](source/pick-deep.d.ts) - Pick properties from a deeply-nested object.
|
|
131
|
+
- [`OmitDeep`](source/omit-deep.d.ts) - Omit properties from a deeply-nested object.
|
|
121
132
|
- [`OmitIndexSignature`](source/omit-index-signature.d.ts) - Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
122
133
|
- [`PickIndexSignature`](source/pick-index-signature.d.ts) - Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
123
|
-
- [`PartialDeep`](source/partial-deep.d.ts) - Create a deeply optional version of another type.
|
|
134
|
+
- [`PartialDeep`](source/partial-deep.d.ts) - Create a deeply optional version of another type.
|
|
124
135
|
- [`PartialOnUndefinedDeep`](source/partial-on-undefined-deep.d.ts) - Create a deep version of another type where all keys accepting `undefined` type are set to optional.
|
|
125
136
|
- [`UndefinedOnPartialDeep`](source/undefined-on-partial-deep.d.ts) - Create a deep version of another type where all optional keys are set to also accept `undefined`.
|
|
126
137
|
- [`UnwrapPartial`](source/unwrap-partial.d.ts) - Revert the `Partial` modifier on an object type.
|
|
127
|
-
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of
|
|
128
|
-
- [`LiteralUnion`](source/literal-union.d.ts) - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
129
|
-
- [`Tagged`](source/tagged.d.ts) - Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d) that can support [multiple tags](https://github.com/sindresorhus/type-fest/issues/665) and [per-tag metadata](https://medium.com/@ethanresnick/advanced-typescript-tagged-types-improved-with-type-level-metadata-5072fc125fcf).
|
|
130
|
-
- [`UnwrapTagged`](source/tagged.d.ts) - Get the untagged portion of a tagged type created with `Tagged`.
|
|
138
|
+
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of another type.
|
|
139
|
+
- [`LiteralUnion`](source/literal-union.d.ts) - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
140
|
+
- [`Tagged`](source/tagged.d.ts) - Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d) that can support [multiple tags](https://github.com/sindresorhus/type-fest/issues/665) and [per-tag metadata](https://medium.com/@ethanresnick/advanced-typescript-tagged-types-improved-with-type-level-metadata-5072fc125fcf).
|
|
141
|
+
- [`UnwrapTagged`](source/tagged.d.ts) - Get the untagged portion of a tagged type created with `Tagged`.
|
|
131
142
|
- [`InvariantOf`](source/invariant-of.d.ts) - Create an [invariant type](https://basarat.gitbook.io/typescript/type-system/type-compatibility#footnote-invariance), which is a type that does not accept supertypes and subtypes.
|
|
132
|
-
- [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional.
|
|
133
|
-
- [`SetReadonly`](source/set-readonly.d.ts) - Create a type that makes the given keys readonly.
|
|
134
|
-
- [`SetRequired`](source/set-required.d.ts) - Create a type that makes the given keys required.
|
|
135
|
-
- [`SetRequiredDeep`](source/set-required-deep.d.ts) -
|
|
136
|
-
- [`SetNonNullable`](source/set-non-nullable.d.ts) - Create a type that makes the given keys non-nullable.
|
|
143
|
+
- [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional, while keeping the remaining keys as is.
|
|
144
|
+
- [`SetReadonly`](source/set-readonly.d.ts) - Create a type that makes the given keys readonly, while keeping the remaining keys as is.
|
|
145
|
+
- [`SetRequired`](source/set-required.d.ts) - Create a type that makes the given keys required, while keeping the remaining keys as is.
|
|
146
|
+
- [`SetRequiredDeep`](source/set-required-deep.d.ts) - Create a type that makes the given keys required, with support for deeply nested key paths, while keeping the remaining keys as is.
|
|
147
|
+
- [`SetNonNullable`](source/set-non-nullable.d.ts) - Create a type that makes the given keys non-nullable, while keeping the remaining keys as is.
|
|
137
148
|
- [`SetNonNullableDeep`](source/set-non-nullable-deep.d.ts) - Create a type that makes the specified keys non-nullable (removes `null` and `undefined`), supports deeply nested key paths, and leaves all other keys unchanged.
|
|
149
|
+
- [`NonNullableDeep`](source/non-nullable-deep.d.ts) - Recursively removes `null` and `undefined` from the specified type.
|
|
138
150
|
- [`ValueOf`](source/value-of.d.ts) - Create a union of the given object's values, and optionally specify which keys to get the values from.
|
|
139
|
-
- [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract keys from a
|
|
140
|
-
- [`ConditionalPick`](source/conditional-pick.d.ts) -
|
|
141
|
-
- [`ConditionalPickDeep`](source/conditional-pick-deep.d.ts) -
|
|
142
|
-
- [`ConditionalExcept`](source/conditional-except.d.ts) -
|
|
151
|
+
- [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract the keys from a type where the value type of the key extends the given `Condition`.
|
|
152
|
+
- [`ConditionalPick`](source/conditional-pick.d.ts) - Pick keys from the shape that matches the given `Condition`.
|
|
153
|
+
- [`ConditionalPickDeep`](source/conditional-pick-deep.d.ts) - Pick keys recursively from the shape that matches the given condition.
|
|
154
|
+
- [`ConditionalExcept`](source/conditional-except.d.ts) - Exclude keys from a shape that matches the given `Condition`.
|
|
143
155
|
- [`UnionToIntersection`](source/union-to-intersection.d.ts) - Convert a union type to an intersection type.
|
|
144
|
-
- [`LiteralToPrimitive`](source/literal-to-primitive.d.ts) -
|
|
156
|
+
- [`LiteralToPrimitive`](source/literal-to-primitive.d.ts) - Given a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) return the [primitive type](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) it belongs to, or `never` if it's not a primitive.
|
|
145
157
|
- [`LiteralToPrimitiveDeep`](source/literal-to-primitive-deep.d.ts) - Like `LiteralToPrimitive` except it converts literal types inside an object or array deeply.
|
|
146
158
|
- [`Stringified`](source/stringified.d.ts) - Create a type with the keys of the given type changed to `string` type.
|
|
147
159
|
- [`IterableElement`](source/iterable-element.d.ts) - Get the element type of an `Iterable`/`AsyncIterable`. For example, `Array`, `Set`, `Map`, generator, stream, etc.
|
|
148
|
-
- [`Entry`](source/entry.d.ts) - Create a type that
|
|
149
|
-
- [`Entries`](source/entries.d.ts) - Create a type that
|
|
160
|
+
- [`Entry`](source/entry.d.ts) - Create a type that describes a single key-value pair produced when calling a collection’s `entries` method.
|
|
161
|
+
- [`Entries`](source/entries.d.ts) - Create a type that describes the key-value pairs produced when calling a collection’s `entries` method.
|
|
150
162
|
- [`SetReturnType`](source/set-return-type.d.ts) - Create a function type with a return type of your choice and the same parameters as the given function type.
|
|
151
163
|
- [`SetParameterType`](source/set-parameter-type.d.ts) - Create a function that replaces some parameters with the given parameters.
|
|
152
164
|
- [`Simplify`](source/simplify.d.ts) - Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
@@ -154,21 +166,21 @@ Click the type names for complete docs.
|
|
|
154
166
|
- [`Get`](source/get.d.ts) - Get a deeply-nested property from an object using a key path, like [Lodash's `.get()`](https://lodash.com/docs/latest#get) function.
|
|
155
167
|
- [`KeyAsString`](source/key-as-string.d.ts) - Get keys of the given type as strings.
|
|
156
168
|
- [`Schema`](source/schema.d.ts) - Create a deep version of another object type where property values are recursively replaced into a given value type.
|
|
157
|
-
- [`Exact`](source/exact.d.ts) - Create a type that does not allow extra properties.
|
|
169
|
+
- [`Exact`](source/exact.d.ts) - Create a type that does not allow extra properties, meaning it only allows properties that are explicitly declared.
|
|
158
170
|
- [`KeysOfUnion`](source/keys-of-union.d.ts) - Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
159
171
|
- [`OptionalKeysOf`](source/optional-keys-of.d.ts) - Extract all optional keys from the given type.
|
|
160
|
-
- [`HasOptionalKeys`](source/has-optional-keys.d.ts) -
|
|
172
|
+
- [`HasOptionalKeys`](source/has-optional-keys.d.ts) - Returns a boolean for whether the given type has any optional fields.
|
|
161
173
|
- [`RequiredKeysOf`](source/required-keys-of.d.ts) - Extract all required keys from the given type.
|
|
162
|
-
- [`HasRequiredKeys`](source/has-required-keys.d.ts) -
|
|
174
|
+
- [`HasRequiredKeys`](source/has-required-keys.d.ts) - Returns a boolean for whether the given type has any required fields.
|
|
163
175
|
- [`ReadonlyKeysOf`](source/readonly-keys-of.d.ts) - Extract all readonly keys from the given type.
|
|
164
|
-
- [`HasReadonlyKeys`](source/has-readonly-keys.d.ts) -
|
|
165
|
-
- [`WritableKeysOf`](source/writable-keys-of.d.ts) - Extract all writable
|
|
166
|
-
- [`HasWritableKeys`](source/has-writable-keys.d.ts) -
|
|
176
|
+
- [`HasReadonlyKeys`](source/has-readonly-keys.d.ts) - Returns a boolean for whether the given type has any readonly fields.
|
|
177
|
+
- [`WritableKeysOf`](source/writable-keys-of.d.ts) - Extract all writable keys from the given type.
|
|
178
|
+
- [`HasWritableKeys`](source/has-writable-keys.d.ts) - Returns a boolean for whether the given type has any writable fields.
|
|
167
179
|
- [`Spread`](source/spread.d.ts) - Mimic the type inferred by TypeScript when merging two objects or two arrays/tuples using the spread syntax.
|
|
168
180
|
- [`IsEqual`](source/is-equal.d.ts) - Returns a boolean for whether the two given types are equal.
|
|
169
181
|
- [`TaggedUnion`](source/tagged-union.d.ts) - Create a union of types that share a common discriminant property.
|
|
170
|
-
- [`IntRange`](source/int-range.d.ts) - Generate a union of numbers
|
|
171
|
-
- [`IntClosedRange`](source/int-closed-range.d.ts) - Generate a union of numbers
|
|
182
|
+
- [`IntRange`](source/int-range.d.ts) - Generate a union of numbers between a specified start (inclusive) and end (exclusive), with an optional step.
|
|
183
|
+
- [`IntClosedRange`](source/int-closed-range.d.ts) - Generate a union of numbers between a specified start and end (both inclusive), with an optional step.
|
|
172
184
|
- [`ArrayIndices`](source/array-indices.d.ts) - Provides valid indices for a constant array or tuple.
|
|
173
185
|
- [`ArrayValues`](source/array-values.d.ts) - Provides all values for a constant array or tuple.
|
|
174
186
|
- [`ArraySplice`](source/array-splice.d.ts) - Create a new array type by adding or removing elements at a specified index range in the original array.
|
|
@@ -179,7 +191,7 @@ Click the type names for complete docs.
|
|
|
179
191
|
- [`SharedUnionFieldsDeep`](source/shared-union-fields-deep.d.ts) - Create a type with shared fields from a union of object types, deeply traversing nested structures.
|
|
180
192
|
- [`AllUnionFields`](source/all-union-fields.d.ts) - Create a type with all fields from a union of object types.
|
|
181
193
|
- [`DistributedOmit`](source/distributed-omit.d.ts) - Omits keys from a type, distributing the operation over a union.
|
|
182
|
-
- [`DistributedPick`](source/distributed-pick.d.ts) -
|
|
194
|
+
- [`DistributedPick`](source/distributed-pick.d.ts) - Pick keys from a type, distributing the operation over a union.
|
|
183
195
|
- [`And`](source/and.d.ts) - Returns a boolean for whether two given types are both `true`.
|
|
184
196
|
- [`Or`](source/or.d.ts) - Returns a boolean for whether either of two given types is `true`.
|
|
185
197
|
- [`Xor`](source/xor.d.ts) - Returns a boolean for whether only one of two given types is `true`.
|
|
@@ -196,6 +208,7 @@ Click the type names for complete docs.
|
|
|
196
208
|
- [`ExclusifyUnion`](source/exclusify-union.d.ts) - Ensure mutual exclusivity in object unions by adding other members’ keys as `?: never`.
|
|
197
209
|
- [`Optional`](source/optional.d.ts) - Create a type that represents either the value or `undefined`, while stripping `null` from the type.
|
|
198
210
|
- [`UnionMember`](source/union-member.d.ts) - Returns an arbitrary member of a union type.
|
|
211
|
+
- [`UnionLength`](source/union-length.d.ts) - Returns the length of a union type.
|
|
199
212
|
|
|
200
213
|
### Type Guard
|
|
201
214
|
|
|
@@ -226,7 +239,7 @@ Click the type names for complete docs.
|
|
|
226
239
|
|
|
227
240
|
- [`Jsonify`](source/jsonify.d.ts) - Transform a type to one that is assignable to the `JsonValue` type.
|
|
228
241
|
- [`Jsonifiable`](source/jsonifiable.d.ts) - Matches a value that can be losslessly converted to JSON.
|
|
229
|
-
- [`JsonPrimitive`](source/json-value.d.ts) - Matches
|
|
242
|
+
- [`JsonPrimitive`](source/json-value.d.ts) - Matches any valid JSON primitive value.
|
|
230
243
|
- [`JsonObject`](source/json-value.d.ts) - Matches a JSON object.
|
|
231
244
|
- [`JsonArray`](source/json-value.d.ts) - Matches a JSON array.
|
|
232
245
|
- [`JsonValue`](source/json-value.d.ts) - Matches any valid JSON value.
|
|
@@ -239,13 +252,13 @@ Click the type names for complete docs.
|
|
|
239
252
|
|
|
240
253
|
- [`Promisable`](source/promisable.d.ts) - Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
|
241
254
|
- [`AsyncReturnType`](source/async-return-type.d.ts) - Unwrap the return type of a function that returns a `Promise`.
|
|
242
|
-
- [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
|
|
255
|
+
- [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type, by boxing the return type in `Promise` while keeping the same parameter types.
|
|
243
256
|
|
|
244
257
|
### String
|
|
245
258
|
|
|
246
259
|
- [`Trim`](source/trim.d.ts) - Remove leading and trailing spaces from a string.
|
|
247
260
|
- [`Split`](source/split.d.ts) - Represents an array of strings split using a given character or character set.
|
|
248
|
-
- [`Words`](source/words.d.ts) -
|
|
261
|
+
- [`Words`](source/words.d.ts) - Split a string similar to Lodash's `_.words()` function.
|
|
249
262
|
- [`Replace`](source/replace.d.ts) - Represents a string with some or all matches replaced by a replacement.
|
|
250
263
|
- [`StringSlice`](source/string-slice.d.ts) - Returns a string slice of a given range, just like `String#slice()`.
|
|
251
264
|
- [`StringRepeat`](source/string-repeat.d.ts) - Returns a new string which contains the specified number of copies of a given string, just like `String#repeat()`.
|
|
@@ -260,8 +273,8 @@ Click the type names for complete docs.
|
|
|
260
273
|
- [`ArrayElement`](source/array-element.d.ts) - Extracts the element type of an array or tuple.
|
|
261
274
|
- [`LastArrayElement`](source/last-array-element.d.ts) - Extract the type of the last element of an array.
|
|
262
275
|
- [`FixedLengthArray`](source/fixed-length-array.d.ts) - Create a type that represents an array of the given type and length. The `Array` prototype methods that manipulate its length are excluded from the resulting type.
|
|
263
|
-
- [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and
|
|
264
|
-
- [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and
|
|
276
|
+
- [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and dimension.
|
|
277
|
+
- [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and dimension.
|
|
265
278
|
- [`ReadonlyTuple`](source/readonly-tuple.d.ts) - Create a type that represents a read-only tuple of the given type and length.
|
|
266
279
|
- [`TupleToUnion`](source/tuple-to-union.d.ts) - Convert a tuple/array into a union type of its elements.
|
|
267
280
|
- [`UnionToTuple`](source/union-to-tuple.d.ts) - Convert a union type into an unordered tuple type of its elements.
|
|
@@ -287,29 +300,30 @@ Click the type names for complete docs.
|
|
|
287
300
|
- [`NonNegativeInteger`](source/numeric.d.ts) - A non-negative (`0 <= x < ∞`) `number` that is an integer.
|
|
288
301
|
- [`IsNegative`](source/numeric.d.ts) - Returns a boolean for whether the given number is a negative number.
|
|
289
302
|
- [`IsFloat`](source/is-float.d.ts) - Returns a boolean for whether the given number is a float, like `1.5` or `-1.5`.
|
|
290
|
-
- [`IsInteger`](source/is-integer.d.ts) - Returns a boolean for whether the given number is an integer, like `-5`, `1.0
|
|
303
|
+
- [`IsInteger`](source/is-integer.d.ts) - Returns a boolean for whether the given number is an integer, like `-5`, `1.0`, or `100`.
|
|
291
304
|
- [`GreaterThan`](source/greater-than.d.ts) - Returns a boolean for whether a given number is greater than another number.
|
|
292
305
|
- [`GreaterThanOrEqual`](source/greater-than-or-equal.d.ts) - Returns a boolean for whether a given number is greater than or equal to another number.
|
|
293
306
|
- [`LessThan`](source/less-than.d.ts) - Returns a boolean for whether a given number is less than another number.
|
|
294
307
|
- [`LessThanOrEqual`](source/less-than-or-equal.d.ts) - Returns a boolean for whether a given number is less than or equal to another number.
|
|
295
308
|
- [`Sum`](source/sum.d.ts) - Returns the sum of two numbers.
|
|
296
309
|
- [`Subtract`](source/subtract.d.ts) - Returns the difference between two numbers.
|
|
310
|
+
- [`Absolute`](source/absolute.d.ts) - Returns the absolute value of the specified number or bigint.
|
|
297
311
|
|
|
298
312
|
### Change case
|
|
299
313
|
|
|
300
|
-
- [`CamelCase`](source/camel-case.d.ts) - Convert a string literal to camel-case
|
|
301
|
-
- [`CamelCasedProperties`](source/camel-cased-properties.d.ts) - Convert object properties to camel
|
|
302
|
-
- [`CamelCasedPropertiesDeep`](source/camel-cased-properties-deep.d.ts) - Convert object properties to camel
|
|
303
|
-
- [`KebabCase`](source/kebab-case.d.ts) - Convert a string literal to kebab-case
|
|
304
|
-
- [`KebabCasedProperties`](source/kebab-cased-properties.d.ts) - Convert object properties to kebab
|
|
305
|
-
- [`KebabCasedPropertiesDeep`](source/kebab-cased-properties-deep.d.ts) - Convert object properties to kebab
|
|
306
|
-
- [`PascalCase`](source/pascal-case.d.ts) - Convert a string literal to pascal-case
|
|
307
|
-
- [`PascalCasedProperties`](source/pascal-cased-properties.d.ts) - Convert object properties to pascal
|
|
308
|
-
- [`PascalCasedPropertiesDeep`](source/pascal-cased-properties-deep.d.ts) - Convert object properties to pascal
|
|
309
|
-
- [`SnakeCase`](source/snake-case.d.ts) - Convert a string literal to snake-case
|
|
310
|
-
- [`SnakeCasedProperties`](source/snake-cased-properties.d.ts) - Convert object properties to snake
|
|
311
|
-
- [`SnakeCasedPropertiesDeep`](source/snake-cased-properties-deep.d.ts) - Convert object properties to snake
|
|
312
|
-
- [`ScreamingSnakeCase`](source/screaming-snake-case.d.ts) - Convert a string literal to screaming-snake-case
|
|
314
|
+
- [`CamelCase`](source/camel-case.d.ts) - Convert a string literal to camel-case.
|
|
315
|
+
- [`CamelCasedProperties`](source/camel-cased-properties.d.ts) - Convert top-level object properties to camel case.
|
|
316
|
+
- [`CamelCasedPropertiesDeep`](source/camel-cased-properties-deep.d.ts) - Convert object properties to camel case recursively.
|
|
317
|
+
- [`KebabCase`](source/kebab-case.d.ts) - Convert a string literal to kebab-case.
|
|
318
|
+
- [`KebabCasedProperties`](source/kebab-cased-properties.d.ts) - Convert top-level object properties to kebab case.
|
|
319
|
+
- [`KebabCasedPropertiesDeep`](source/kebab-cased-properties-deep.d.ts) - Convert object properties to kebab case recursively.
|
|
320
|
+
- [`PascalCase`](source/pascal-case.d.ts) - Convert a string literal to pascal-case.
|
|
321
|
+
- [`PascalCasedProperties`](source/pascal-cased-properties.d.ts) - Convert top-level object properties to pascal case.
|
|
322
|
+
- [`PascalCasedPropertiesDeep`](source/pascal-cased-properties-deep.d.ts) - Convert object properties to pascal case recursively.
|
|
323
|
+
- [`SnakeCase`](source/snake-case.d.ts) - Convert a string literal to snake-case.
|
|
324
|
+
- [`SnakeCasedProperties`](source/snake-cased-properties.d.ts) - Convert top-level object properties to snake case.
|
|
325
|
+
- [`SnakeCasedPropertiesDeep`](source/snake-cased-properties-deep.d.ts) - Convert object properties to snake case recursively.
|
|
326
|
+
- [`ScreamingSnakeCase`](source/screaming-snake-case.d.ts) - Convert a string literal to screaming-snake-case.
|
|
313
327
|
- [`DelimiterCase`](source/delimiter-case.d.ts) - Convert a string literal to a custom string delimiter casing.
|
|
314
328
|
- [`DelimiterCasedProperties`](source/delimiter-cased-properties.d.ts) - Convert object properties to a custom string delimiter casing.
|
|
315
329
|
- [`DelimiterCasedPropertiesDeep`](source/delimiter-cased-properties-deep.d.ts) - Convert object properties to a custom string delimiter casing recursively.
|
|
@@ -317,7 +331,7 @@ Click the type names for complete docs.
|
|
|
317
331
|
### Miscellaneous
|
|
318
332
|
|
|
319
333
|
- [`GlobalThis`](source/global-this.d.ts) - Declare locally scoped properties on `globalThis`.
|
|
320
|
-
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file).
|
|
334
|
+
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Also includes types for fields used by other popular projects, like TypeScript and Yarn.
|
|
321
335
|
- [`TsConfigJson`](source/tsconfig-json.d.ts) - Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
|
|
322
336
|
|
|
323
337
|
### Improved built-in
|
|
@@ -370,6 +384,7 @@ Click the type names for complete docs.
|
|
|
370
384
|
|
|
371
385
|
### Extending existing types
|
|
372
386
|
|
|
387
|
+
<!-- eslint-disable-next-line type-fest/readme-jsdoc-sync -->
|
|
373
388
|
- [`PackageJson`](source/package-json.d.ts) - There are a lot of tools that place extra configurations inside the `package.json` file. You can extend `PackageJson` to support these additional configurations.
|
|
374
389
|
<details>
|
|
375
390
|
<summary>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type {StringToNumber} from './internal/string.d.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Returns the absolute value of the specified number or bigint.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {Absolute} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type A = Absolute<-1>;
|
|
11
|
+
//=> 1
|
|
12
|
+
|
|
13
|
+
type B = Absolute<1>;
|
|
14
|
+
//=> 1
|
|
15
|
+
|
|
16
|
+
type C = Absolute<0>;
|
|
17
|
+
//=> 0
|
|
18
|
+
|
|
19
|
+
type D = Absolute<-1.025>;
|
|
20
|
+
//=> 1.025
|
|
21
|
+
|
|
22
|
+
type E = Absolute<-9999n>;
|
|
23
|
+
//=> 9999n
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Returns back the same type if the input is not a literal type.
|
|
27
|
+
|
|
28
|
+
@example
|
|
29
|
+
```
|
|
30
|
+
import type {Absolute} from 'type-fest';
|
|
31
|
+
|
|
32
|
+
type A = Absolute<number>;
|
|
33
|
+
//=> number
|
|
34
|
+
|
|
35
|
+
type B = Absolute<bigint>;
|
|
36
|
+
//=> bigint
|
|
37
|
+
|
|
38
|
+
type C = Absolute<number | bigint>;
|
|
39
|
+
//=> number | bigint
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
@category Numeric
|
|
43
|
+
*/
|
|
44
|
+
export type Absolute<N extends number | bigint> = N extends bigint // Also, distributes `N`
|
|
45
|
+
? `${N}` extends `-${infer Magnitude extends bigint}`
|
|
46
|
+
? Magnitude
|
|
47
|
+
: N
|
|
48
|
+
: `${N}` extends `-${infer Magnitude}` // This doesn't use the `extends number` constraint approach because that fails with the `-Infinity` case
|
|
49
|
+
? StringToNumber<Magnitude>
|
|
50
|
+
: N;
|
|
51
|
+
|
|
52
|
+
export {};
|
|
@@ -69,23 +69,23 @@ function displayPetInfoWithAllUnionFields(petInfo: AllUnionFields<Cat | Dog>) {
|
|
|
69
69
|
@category Union
|
|
70
70
|
*/
|
|
71
71
|
export type AllUnionFields<Union> =
|
|
72
|
-
Extract<Union, NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | UnknownArray> extends infer SkippedMembers
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
72
|
+
Extract<Union, NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | UnknownArray> extends infer SkippedMembers
|
|
73
|
+
? Exclude<Union, SkippedMembers> extends infer RelevantMembers
|
|
74
|
+
? // eslint-disable-line @stylistic/operator-linebreak
|
|
75
|
+
| SkippedMembers
|
|
76
|
+
| Simplify<
|
|
77
|
+
// Include fields that are common in all union members
|
|
78
|
+
SharedUnionFields<RelevantMembers>
|
|
79
|
+
// Include readonly fields present in any union member
|
|
80
|
+
& {
|
|
81
|
+
readonly [P in ReadonlyKeysOfUnion<RelevantMembers>]?: ValueOfUnion<RelevantMembers, P & KeysOfUnion<RelevantMembers>>
|
|
82
|
+
}
|
|
83
|
+
// Include remaining fields that are neither common nor readonly
|
|
84
|
+
& {
|
|
85
|
+
[P in Exclude<KeysOfUnion<RelevantMembers>, ReadonlyKeysOfUnion<RelevantMembers> | keyof RelevantMembers>]?: ValueOfUnion<RelevantMembers, P>
|
|
86
|
+
}
|
|
87
|
+
>
|
|
88
|
+
: never
|
|
89
|
+
: never;
|
|
90
90
|
|
|
91
91
|
export {};
|
package/source/and.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {AndAll} from './and-all.d.ts';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
Returns a boolean for whether two given types are both true
|
|
4
|
+
Returns a boolean for whether two given types are both `true`.
|
|
5
5
|
|
|
6
6
|
Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
|
|
7
7
|
|
package/source/array-splice.d.ts
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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`.
|
package/source/camel-case.d.ts
CHANGED
|
@@ -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
|
-
:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
@@ -38,6 +38,7 @@ import type {DelimiterCase} from 'type-fest';
|
|
|
38
38
|
|
|
39
39
|
const someVariable: DelimiterCase<'fooBar', '#'> = 'foo#bar';
|
|
40
40
|
const someVariableNoSplitOnNumbers: DelimiterCase<'p2pNetwork', '#', {splitOnNumbers: false}> = 'p2p#network';
|
|
41
|
+
const someVariableWithPunctuation: DelimiterCase<'div.card::after', '#', {splitOnPunctuation: true}> = 'div#card#after';
|
|
41
42
|
|
|
42
43
|
// Advanced
|
|
43
44
|
|