type-fest 4.24.0 → 4.25.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 CHANGED
@@ -36,6 +36,7 @@ export type {UndefinedOnPartialDeep} from './source/undefined-on-partial-deep';
36
36
  export type {ReadonlyDeep} from './source/readonly-deep';
37
37
  export type {LiteralUnion} from './source/literal-union';
38
38
  export type {Promisable} from './source/promisable';
39
+ export type {Arrayable} from './source/arrayable';
39
40
  export type {Opaque, UnwrapOpaque, Tagged, GetTagMetadata, UnwrapTagged} from './source/opaque';
40
41
  export type {InvariantOf} from './source/invariant-of';
41
42
  export type {SetOptional} from './source/set-optional';
@@ -154,6 +155,7 @@ export type {Join} from './source/join';
154
155
  export type {Split} from './source/split';
155
156
  export type {Trim} from './source/trim';
156
157
  export type {Replace} from './source/replace';
158
+ export type {StringRepeat} from './source/string-repeat';
157
159
  export type {Includes} from './source/includes';
158
160
  export type {Get} from './source/get';
159
161
  export type {LastArrayElement} from './source/last-array-element';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "4.24.0",
3
+ "version": "4.25.0",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
package/readme.md CHANGED
@@ -269,9 +269,11 @@ type ShouldBeNever = IfAny<'not any', 'not never', 'never'>;
269
269
  - [`Split`](source/split.d.ts) - Represents an array of strings split using a given character or character set.
270
270
  - [`Replace`](source/replace.d.ts) - Represents a string with some or all matches replaced by a replacement.
271
271
  - [`StringSlice`](source/string-slice.d.ts) - Returns a string slice of a given range, just like `String#slice()`.
272
+ - [`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()`.
272
273
 
273
274
  ### Array
274
275
 
276
+ - [`Arrayable`](source/arrayable.d.ts) - Create a type that represents either the value or an array of the value.
275
277
  - [`Includes`](source/includes.d.ts) - Returns a boolean for whether the given array includes the given item.
276
278
  - [`Join`](source/join.d.ts) - Join an array of strings and/or numbers using the given string as a delimiter.
277
279
  - [`ArraySlice`](source/array-slice.d.ts) - Returns an array slice of a given range, just like `Array#slice()`.
@@ -0,0 +1,26 @@
1
+ /**
2
+ Create a type that represents either the value or an array of the value.
3
+
4
+ @see Promisable
5
+
6
+ @example
7
+ ```
8
+ import type {Arrayable} from 'type-fest';
9
+
10
+ function bundle(input: string, output: Arrayable<string>) {
11
+ const outputList = Array.isArray(output) ? output : [output];
12
+
13
+ // …
14
+
15
+ for (const output of outputList) {
16
+ console.log(`write to: ${output}`);
17
+ }
18
+ }
19
+
20
+ bundle('src/index.js', 'dist/index.js');
21
+ bundle('src/index.js', ['dist/index.cjs', 'dist/index.mjs']);
22
+ ```
23
+
24
+ @category Array
25
+ */
26
+ export type Arrayable<T> = T | readonly T[];
@@ -37,6 +37,25 @@ type UsefulInfo = OmitDeep<Info, 'userInfo.uselessInfo'>;
37
37
  // userInfo: {
38
38
  // name: string;
39
39
  // };
40
+ // };
41
+
42
+ // Supports removing multiple paths
43
+ type Info1 = {
44
+ userInfo: {
45
+ name: string;
46
+ uselessField: string;
47
+ uselessInfo: {
48
+ foo: string;
49
+ };
50
+ };
51
+ };
52
+
53
+ type UsefulInfo1 = OmitDeep<Info1, 'userInfo.uselessInfo' | 'userInfo.uselessField'>;
54
+ // type UsefulInfo1 = {
55
+ // userInfo: {
56
+ // name: string;
57
+ // };
58
+ // };
40
59
 
41
60
  // Supports array
42
61
  type A = OmitDeep<[1, 'foo', 2], 1>;
@@ -0,0 +1,43 @@
1
+ import type {IsNegative} from './numeric';
2
+ import type {Subtract} from './subtract';
3
+
4
+ /**
5
+ Returns a new string which contains the specified number of copies of a given string, just like `String#repeat()`.
6
+
7
+ @example
8
+ ```
9
+ import {StringRepeat} from 'type-fest';
10
+
11
+ declare function stringRepeat<
12
+ Input extends string,
13
+ Count extends number
14
+ >(input: Input, count: Count): StringRepeat<Input, Count>;
15
+
16
+ // The return type is the exact string literal, not just `string`.
17
+
18
+ stringRepeat('foo', 2);
19
+ //=> 'foofoo'
20
+
21
+ stringRepeat('=', 3);
22
+ //=> '==='
23
+ ```
24
+
25
+ @category String
26
+ @category Template literal
27
+ */
28
+ export type StringRepeat<
29
+ Input extends string,
30
+ Count extends number,
31
+ > = number extends Count
32
+ ? Input extends ''
33
+ ? ''
34
+ : string
35
+ : IsNegative<Count> extends true
36
+ ? never
37
+ : Count extends 0
38
+ ? ''
39
+ : string extends Input
40
+ ? string
41
+ : StringRepeat<Input, Subtract<Count, 1>> extends infer R extends string
42
+ ? `${Input}${R}`
43
+ : never;