@visulima/package 3.6.0 → 4.0.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 (45) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/LICENSE.md +0 -116
  3. package/README.md +153 -51
  4. package/dist/error.js +1 -0
  5. package/dist/index.d.ts +3 -1
  6. package/dist/index.js +1 -0
  7. package/dist/monorepo.js +1 -0
  8. package/dist/package-json.d.ts +3 -1
  9. package/dist/package-json.js +3 -0
  10. package/dist/package-manager.js +13 -0
  11. package/dist/package.js +1 -0
  12. package/dist/packem_shared/PackageNotFoundError-BictYTIA.js +1 -0
  13. package/dist/packem_shared/json-value.d-DU4PzU4Z.d.ts +33 -0
  14. package/dist/packem_shared/{package-json-KA2fTML0.d.cts → package-json-k3TJ_oy7.d.ts} +1056 -710
  15. package/dist/pnpm.d.ts +15 -0
  16. package/dist/pnpm.js +1 -0
  17. package/package.json +27 -78
  18. package/dist/error.cjs +0 -1
  19. package/dist/error.d.cts +0 -9
  20. package/dist/error.d.mts +0 -9
  21. package/dist/error.mjs +0 -1
  22. package/dist/index.cjs +0 -1
  23. package/dist/index.d.cts +0 -7
  24. package/dist/index.d.mts +0 -7
  25. package/dist/index.mjs +0 -1
  26. package/dist/monorepo.cjs +0 -1
  27. package/dist/monorepo.d.cts +0 -9
  28. package/dist/monorepo.d.mts +0 -9
  29. package/dist/monorepo.mjs +0 -1
  30. package/dist/package-json.cjs +0 -3
  31. package/dist/package-json.d.cts +0 -3
  32. package/dist/package-json.d.mts +0 -3
  33. package/dist/package-json.mjs +0 -3
  34. package/dist/package-manager.cjs +0 -13
  35. package/dist/package-manager.d.cts +0 -21
  36. package/dist/package-manager.d.mts +0 -21
  37. package/dist/package-manager.mjs +0 -13
  38. package/dist/package.cjs +0 -1
  39. package/dist/package.d.cts +0 -4
  40. package/dist/package.d.mts +0 -4
  41. package/dist/package.mjs +0 -1
  42. package/dist/packem_shared/PackageNotFoundError-CEETCi0X.mjs +0 -1
  43. package/dist/packem_shared/PackageNotFoundError-CY57YCot.cjs +0 -1
  44. package/dist/packem_shared/package-json-KA2fTML0.d.mts +0 -2405
  45. package/dist/packem_shared/package-json-KA2fTML0.d.ts +0 -2405
@@ -1,2405 +0,0 @@
1
- import { WriteJsonOptions } from '@visulima/fs';
2
- import { Package } from 'normalize-package-data';
3
-
4
- /**
5
- Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
6
-
7
- @category Type
8
- */
9
- type Primitive =
10
- | null
11
- | undefined
12
- | string
13
- | number
14
- | boolean
15
- | symbol
16
- | bigint;
17
-
18
- /**
19
- Matches a JSON object.
20
-
21
- This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
22
-
23
- @category JSON
24
- */
25
- type JsonObject = {[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined};
26
-
27
- /**
28
- Matches a JSON array.
29
-
30
- @category JSON
31
- */
32
- type JsonArray = JsonValue[] | readonly JsonValue[];
33
-
34
- /**
35
- Matches any valid JSON primitive value.
36
-
37
- @category JSON
38
- */
39
- type JsonPrimitive = string | number | boolean | null;
40
-
41
- /**
42
- Matches any valid JSON value.
43
-
44
- @see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
45
-
46
- @category JSON
47
- */
48
- type JsonValue = JsonPrimitive | JsonObject | JsonArray;
49
-
50
- declare global {
51
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
52
- interface SymbolConstructor {
53
- readonly observable: symbol;
54
- }
55
- }
56
-
57
- declare const emptyObjectSymbol: unique symbol;
58
-
59
- /**
60
- Represents a strictly empty plain object, the `{}` value.
61
-
62
- When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
63
-
64
- @example
65
- ```
66
- import type {EmptyObject} from 'type-fest';
67
-
68
- // The following illustrates the problem with `{}`.
69
- const foo1: {} = {}; // Pass
70
- const foo2: {} = []; // Pass
71
- const foo3: {} = 42; // Pass
72
- const foo4: {} = {a: 1}; // Pass
73
-
74
- // With `EmptyObject` only the first case is valid.
75
- const bar1: EmptyObject = {}; // Pass
76
- const bar2: EmptyObject = 42; // Fail
77
- const bar3: EmptyObject = []; // Fail
78
- const bar4: EmptyObject = {a: 1}; // Fail
79
- ```
80
-
81
- Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
82
-
83
- @category Object
84
- */
85
- type EmptyObject = {[emptyObjectSymbol]?: never};
86
-
87
- /**
88
- Extract all optional keys from the given type.
89
-
90
- This is useful when you want to create a new type that contains different type values for the optional keys only.
91
-
92
- @example
93
- ```
94
- import type {OptionalKeysOf, Except} from 'type-fest';
95
-
96
- interface User {
97
- name: string;
98
- surname: string;
99
-
100
- luckyNumber?: number;
101
- }
102
-
103
- const REMOVE_FIELD = Symbol('remove field symbol');
104
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
105
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
106
- };
107
-
108
- const update1: UpdateOperation<User> = {
109
- name: 'Alice'
110
- };
111
-
112
- const update2: UpdateOperation<User> = {
113
- name: 'Bob',
114
- luckyNumber: REMOVE_FIELD
115
- };
116
- ```
117
-
118
- @category Utilities
119
- */
120
- type OptionalKeysOf<BaseType extends object> =
121
- BaseType extends unknown // For distributing `BaseType`
122
- ? (keyof {
123
- [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
124
- }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
125
- : never; // Should never happen
126
-
127
- /**
128
- Extract all required keys from the given type.
129
-
130
- This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
131
-
132
- @example
133
- ```
134
- import type {RequiredKeysOf} from 'type-fest';
135
-
136
- declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
137
-
138
- interface User {
139
- name: string;
140
- surname: string;
141
-
142
- luckyNumber?: number;
143
- }
144
-
145
- const validator1 = createValidation<User>('name', value => value.length < 25);
146
- const validator2 = createValidation<User>('surname', value => value.length < 25);
147
- ```
148
-
149
- @category Utilities
150
- */
151
- type RequiredKeysOf<BaseType extends object> =
152
- BaseType extends unknown // For distributing `BaseType`
153
- ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
154
- : never; // Should never happen
155
-
156
- /**
157
- Returns a boolean for whether the given type is `never`.
158
-
159
- @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
160
- @link https://stackoverflow.com/a/53984913/10292952
161
- @link https://www.zhenghao.io/posts/ts-never
162
-
163
- Useful in type utilities, such as checking if something does not occur.
164
-
165
- @example
166
- ```
167
- import type {IsNever, And} from 'type-fest';
168
-
169
- // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
170
- type AreStringsEqual<A extends string, B extends string> =
171
- And<
172
- IsNever<Exclude<A, B>> extends true ? true : false,
173
- IsNever<Exclude<B, A>> extends true ? true : false
174
- >;
175
-
176
- type EndIfEqual<I extends string, O extends string> =
177
- AreStringsEqual<I, O> extends true
178
- ? never
179
- : void;
180
-
181
- function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
182
- if (input === output) {
183
- process.exit(0);
184
- }
185
- }
186
-
187
- endIfEqual('abc', 'abc');
188
- //=> never
189
-
190
- endIfEqual('abc', '123');
191
- //=> void
192
- ```
193
-
194
- @category Type Guard
195
- @category Utilities
196
- */
197
- type IsNever<T> = [T] extends [never] ? true : false;
198
-
199
- /**
200
- An if-else-like type that resolves depending on whether the given type is `never`.
201
-
202
- @see {@link IsNever}
203
-
204
- @example
205
- ```
206
- import type {IfNever} from 'type-fest';
207
-
208
- type ShouldBeTrue = IfNever<never>;
209
- //=> true
210
-
211
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
212
- //=> 'bar'
213
- ```
214
-
215
- @category Type Guard
216
- @category Utilities
217
- */
218
- type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
219
- IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
220
- );
221
-
222
- /**
223
- Represents an array with `unknown` value.
224
-
225
- Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
226
-
227
- @example
228
- ```
229
- import type {UnknownArray} from 'type-fest';
230
-
231
- type IsArray<T> = T extends UnknownArray ? true : false;
232
-
233
- type A = IsArray<['foo']>;
234
- //=> true
235
-
236
- type B = IsArray<readonly number[]>;
237
- //=> true
238
-
239
- type C = IsArray<string>;
240
- //=> false
241
- ```
242
-
243
- @category Type
244
- @category Array
245
- */
246
- type UnknownArray = readonly unknown[];
247
-
248
- /**
249
- Returns the static, fixed-length portion of the given array, excluding variable-length parts.
250
-
251
- @example
252
- ```
253
- type A = [string, number, boolean, ...string[]];
254
- type B = StaticPartOfArray<A>;
255
- //=> [string, number, boolean]
256
- ```
257
- */
258
- type StaticPartOfArray<T extends UnknownArray, Result extends UnknownArray = []> =
259
- T extends unknown
260
- ? number extends T['length'] ?
261
- T extends readonly [infer U, ...infer V]
262
- ? StaticPartOfArray<V, [...Result, U]>
263
- : Result
264
- : T
265
- : never; // Should never happen
266
-
267
- /**
268
- Returns the variable, non-fixed-length portion of the given array, excluding static-length parts.
269
-
270
- @example
271
- ```
272
- type A = [string, number, boolean, ...string[]];
273
- type B = VariablePartOfArray<A>;
274
- //=> string[]
275
- ```
276
- */
277
- type VariablePartOfArray<T extends UnknownArray> =
278
- T extends unknown
279
- ? T extends readonly [...StaticPartOfArray<T>, ...infer U]
280
- ? U
281
- : []
282
- : never;
283
-
284
- // Can eventually be replaced with the built-in once this library supports
285
- // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
286
- type NoInfer<T> = T extends infer U ? U : never;
287
-
288
- /**
289
- Returns a boolean for whether the given type is `any`.
290
-
291
- @link https://stackoverflow.com/a/49928360/1490091
292
-
293
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
294
-
295
- @example
296
- ```
297
- import type {IsAny} from 'type-fest';
298
-
299
- const typedObject = {a: 1, b: 2} as const;
300
- const anyObject: any = {a: 1, b: 2};
301
-
302
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
303
- return obj[key];
304
- }
305
-
306
- const typedA = get(typedObject, 'a');
307
- //=> 1
308
-
309
- const anyA = get(anyObject, 'a');
310
- //=> any
311
- ```
312
-
313
- @category Type Guard
314
- @category Utilities
315
- */
316
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
317
-
318
- type Numeric = number | bigint;
319
-
320
- type Zero = 0 | 0n;
321
-
322
- /**
323
- Matches the hidden `Infinity` type.
324
-
325
- Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
326
-
327
- @see NegativeInfinity
328
-
329
- @category Numeric
330
- */
331
- // See https://github.com/microsoft/TypeScript/issues/31752
332
- // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
333
- type PositiveInfinity = 1e999;
334
-
335
- /**
336
- Matches the hidden `-Infinity` type.
337
-
338
- Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
339
-
340
- @see PositiveInfinity
341
-
342
- @category Numeric
343
- */
344
- // See https://github.com/microsoft/TypeScript/issues/31752
345
- // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
346
- type NegativeInfinity = -1e999;
347
-
348
- /**
349
- A negative `number`/`bigint` (`-∞ < x < 0`)
350
-
351
- Use-case: Validating and documenting parameters.
352
-
353
- @see NegativeInteger
354
- @see NonNegative
355
-
356
- @category Numeric
357
- */
358
- type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
359
-
360
- /**
361
- Returns a boolean for whether the given number is a negative number.
362
-
363
- @see Negative
364
-
365
- @example
366
- ```
367
- import type {IsNegative} from 'type-fest';
368
-
369
- type ShouldBeFalse = IsNegative<1>;
370
- type ShouldBeTrue = IsNegative<-1>;
371
- ```
372
-
373
- @category Numeric
374
- */
375
- type IsNegative<T extends Numeric> = T extends Negative<T> ? true : false;
376
-
377
- /**
378
- Returns a boolean for whether the two given types are equal.
379
-
380
- @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
381
- @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
382
-
383
- Use-cases:
384
- - If you want to make a conditional branch based on the result of a comparison of two types.
385
-
386
- @example
387
- ```
388
- import type {IsEqual} from 'type-fest';
389
-
390
- // This type returns a boolean for whether the given array includes the given item.
391
- // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
392
- type Includes<Value extends readonly any[], Item> =
393
- Value extends readonly [Value[0], ...infer rest]
394
- ? IsEqual<Value[0], Item> extends true
395
- ? true
396
- : Includes<rest, Item>
397
- : false;
398
- ```
399
-
400
- @category Type Guard
401
- @category Utilities
402
- */
403
- type IsEqual<A, B> =
404
- (<G>() => G extends A & G | G ? 1 : 2) extends
405
- (<G>() => G extends B & G | G ? 1 : 2)
406
- ? true
407
- : false;
408
-
409
- /**
410
- Returns a boolean for whether two given types are both true.
411
-
412
- Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
413
-
414
- @example
415
- ```
416
- import type {And} from 'type-fest';
417
-
418
- And<true, true>;
419
- //=> true
420
-
421
- And<true, false>;
422
- //=> false
423
- ```
424
-
425
- @see {@link Or}
426
- */
427
- type And<A extends boolean, B extends boolean> = [A, B][number] extends true
428
- ? true
429
- : true extends [IsEqual<A, false>, IsEqual<B, false>][number]
430
- ? false
431
- : never;
432
-
433
- /**
434
- Returns a boolean for whether either of two given types are true.
435
-
436
- Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
437
-
438
- @example
439
- ```
440
- import type {Or} from 'type-fest';
441
-
442
- Or<true, false>;
443
- //=> true
444
-
445
- Or<false, false>;
446
- //=> false
447
- ```
448
-
449
- @see {@link And}
450
- */
451
- type Or<A extends boolean, B extends boolean> = [A, B][number] extends false
452
- ? false
453
- : true extends [IsEqual<A, true>, IsEqual<B, true>][number]
454
- ? true
455
- : never;
456
-
457
- /**
458
- Returns a boolean for whether a given number is greater than another number.
459
-
460
- @example
461
- ```
462
- import type {GreaterThan} from 'type-fest';
463
-
464
- GreaterThan<1, -5>;
465
- //=> true
466
-
467
- GreaterThan<1, 1>;
468
- //=> false
469
-
470
- GreaterThan<1, 5>;
471
- //=> false
472
- ```
473
- */
474
- type GreaterThan<A extends number, B extends number> =
475
- A extends number // For distributing `A`
476
- ? B extends number // For distributing `B`
477
- ? number extends A | B
478
- ? never
479
- : [
480
- IsEqual<A, PositiveInfinity>, IsEqual<A, NegativeInfinity>,
481
- IsEqual<B, PositiveInfinity>, IsEqual<B, NegativeInfinity>,
482
- ] extends infer R extends [boolean, boolean, boolean, boolean]
483
- ? Or<
484
- And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
485
- And<IsEqual<R[3], true>, IsEqual<R[1], false>>
486
- > extends true
487
- ? true
488
- : Or<
489
- And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
490
- And<IsEqual<R[2], true>, IsEqual<R[0], false>>
491
- > extends true
492
- ? false
493
- : true extends R[number]
494
- ? false
495
- : [IsNegative<A>, IsNegative<B>] extends infer R extends [boolean, boolean]
496
- ? [true, false] extends R
497
- ? false
498
- : [false, true] extends R
499
- ? true
500
- : [false, false] extends R
501
- ? PositiveNumericStringGt<`${A}`, `${B}`>
502
- : PositiveNumericStringGt<`${NumberAbsolute<B>}`, `${NumberAbsolute<A>}`>
503
- : never
504
- : never
505
- : never // Should never happen
506
- : never; // Should never happen
507
-
508
- /**
509
- Returns a boolean for whether a given number is greater than or equal to another number.
510
-
511
- @example
512
- ```
513
- import type {GreaterThanOrEqual} from 'type-fest';
514
-
515
- GreaterThanOrEqual<1, -5>;
516
- //=> true
517
-
518
- GreaterThanOrEqual<1, 1>;
519
- //=> true
520
-
521
- GreaterThanOrEqual<1, 5>;
522
- //=> false
523
- ```
524
- */
525
- type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B
526
- ? never
527
- : A extends B ? true : GreaterThan<A, B>;
528
-
529
- /**
530
- Returns a boolean for whether a given number is less than another number.
531
-
532
- @example
533
- ```
534
- import type {LessThan} from 'type-fest';
535
-
536
- LessThan<1, -5>;
537
- //=> false
538
-
539
- LessThan<1, 1>;
540
- //=> false
541
-
542
- LessThan<1, 5>;
543
- //=> true
544
- ```
545
- */
546
- type LessThan<A extends number, B extends number> = number extends A | B
547
- ? never
548
- : GreaterThanOrEqual<A, B> extends infer Result
549
- ? Result extends true
550
- ? false
551
- : true
552
- : never; // Should never happen
553
-
554
- // Should never happen
555
-
556
- /**
557
- Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.
558
-
559
- If `<Fill>` is not provided, it will default to `unknown`.
560
-
561
- @link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
562
- */
563
- type BuildTuple<L extends number, Fill = unknown, T extends readonly unknown[] = []> = number extends L
564
- ? Fill[]
565
- : L extends T['length']
566
- ? T
567
- : BuildTuple<L, Fill, [...T, Fill]>;
568
-
569
- /**
570
- Return a string representation of the given string or number.
571
-
572
- Note: This type is not the return type of the `.toString()` function.
573
- */
574
- type ToString<T> = T extends string | number ? `${T}` : never;
575
-
576
- /**
577
- Converts a numeric string to a number.
578
-
579
- @example
580
- ```
581
- type PositiveInt = StringToNumber<'1234'>;
582
- //=> 1234
583
-
584
- type NegativeInt = StringToNumber<'-1234'>;
585
- //=> -1234
586
-
587
- type PositiveFloat = StringToNumber<'1234.56'>;
588
- //=> 1234.56
589
-
590
- type NegativeFloat = StringToNumber<'-1234.56'>;
591
- //=> -1234.56
592
-
593
- type PositiveInfinity = StringToNumber<'Infinity'>;
594
- //=> Infinity
595
-
596
- type NegativeInfinity = StringToNumber<'-Infinity'>;
597
- //=> -Infinity
598
- ```
599
-
600
- @category String
601
- @category Numeric
602
- @category Template literal
603
- */
604
- type StringToNumber<S extends string> = S extends `${infer N extends number}`
605
- ? N
606
- : S extends 'Infinity'
607
- ? PositiveInfinity
608
- : S extends '-Infinity'
609
- ? NegativeInfinity
610
- : never;
611
-
612
- /**
613
- Returns an array of the characters of the string.
614
-
615
- @example
616
- ```
617
- StringToArray<'abcde'>;
618
- //=> ['a', 'b', 'c', 'd', 'e']
619
-
620
- StringToArray<string>;
621
- //=> never
622
- ```
623
-
624
- @category String
625
- */
626
- type StringToArray<S extends string, Result extends string[] = []> = string extends S
627
- ? never
628
- : S extends `${infer F}${infer R}`
629
- ? StringToArray<R, [...Result, F]>
630
- : Result;
631
-
632
- /**
633
- Returns the length of the given string.
634
-
635
- @example
636
- ```
637
- StringLength<'abcde'>;
638
- //=> 5
639
-
640
- StringLength<string>;
641
- //=> never
642
- ```
643
-
644
- @category String
645
- @category Template literal
646
- */
647
- type StringLength<S extends string> = string extends S
648
- ? never
649
- : StringToArray<S>['length'];
650
-
651
- /**
652
- Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both numeric strings and have the same length.
653
-
654
- @example
655
- ```
656
- SameLengthPositiveNumericStringGt<'50', '10'>;
657
- //=> true
658
-
659
- SameLengthPositiveNumericStringGt<'10', '10'>;
660
- //=> false
661
- ```
662
- */
663
- type SameLengthPositiveNumericStringGt<A extends string, B extends string> = A extends `${infer FirstA}${infer RestA}`
664
- ? B extends `${infer FirstB}${infer RestB}`
665
- ? FirstA extends FirstB
666
- ? SameLengthPositiveNumericStringGt<RestA, RestB>
667
- : PositiveNumericCharacterGt<FirstA, FirstB>
668
- : never
669
- : false;
670
-
671
- type NumericString = '0123456789';
672
-
673
- /**
674
- Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
675
-
676
- @example
677
- ```
678
- PositiveNumericStringGt<'500', '1'>;
679
- //=> true
680
-
681
- PositiveNumericStringGt<'1', '1'>;
682
- //=> false
683
-
684
- PositiveNumericStringGt<'1', '500'>;
685
- //=> false
686
- ```
687
- */
688
- type PositiveNumericStringGt<A extends string, B extends string> = A extends B
689
- ? false
690
- : [BuildTuple<StringLength<A>, 0>, BuildTuple<StringLength<B>, 0>] extends infer R extends [readonly unknown[], readonly unknown[]]
691
- ? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]]
692
- ? 0 extends Remain['length']
693
- ? SameLengthPositiveNumericStringGt<A, B>
694
- : true
695
- : false
696
- : never;
697
-
698
- /**
699
- Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
700
-
701
- @example
702
- ```
703
- PositiveNumericCharacterGt<'5', '1'>;
704
- //=> true
705
-
706
- PositiveNumericCharacterGt<'1', '1'>;
707
- //=> false
708
- ```
709
- */
710
- type PositiveNumericCharacterGt<A extends string, B extends string> = NumericString extends `${infer HeadA}${A}${infer TailA}`
711
- ? NumericString extends `${infer HeadB}${B}${infer TailB}`
712
- ? HeadA extends `${HeadB}${infer _}${infer __}`
713
- ? true
714
- : false
715
- : never
716
- : never;
717
-
718
- /**
719
- Returns the absolute value of a given value.
720
-
721
- @example
722
- ```
723
- NumberAbsolute<-1>;
724
- //=> 1
725
-
726
- NumberAbsolute<1>;
727
- //=> 1
728
-
729
- NumberAbsolute<NegativeInfinity>
730
- //=> PositiveInfinity
731
- ```
732
- */
733
- type NumberAbsolute<N extends number> = `${N}` extends `-${infer StringPositiveN}` ? StringToNumber<StringPositiveN> : N;
734
-
735
- /**
736
- Check whether the given type is a number or a number string.
737
-
738
- Supports floating-point as a string.
739
-
740
- @example
741
- ```
742
- type A = IsNumberLike<'1'>;
743
- //=> true
744
-
745
- type B = IsNumberLike<'-1.1'>;
746
- //=> true
747
-
748
- type C = IsNumberLike<1>;
749
- //=> true
750
-
751
- type D = IsNumberLike<'a'>;
752
- //=> false
753
- */
754
- type IsNumberLike<N> =
755
- N extends number ? true
756
- : N extends `${number}`
757
- ? true
758
- : N extends `${number}.${number}`
759
- ? true
760
- : false;
761
-
762
- /**
763
- Returns the number with reversed sign.
764
-
765
- @example
766
- ```
767
- ReverseSign<-1>;
768
- //=> 1
769
-
770
- ReverseSign<1>;
771
- //=> -1
772
-
773
- ReverseSign<NegativeInfinity>
774
- //=> PositiveInfinity
775
-
776
- ReverseSign<PositiveInfinity>
777
- //=> NegativeInfinity
778
- ```
779
- */
780
- type ReverseSign<N extends number> =
781
- // Handle edge cases
782
- N extends 0 ? 0 : N extends PositiveInfinity ? NegativeInfinity : N extends NegativeInfinity ? PositiveInfinity :
783
- // Handle negative numbers
784
- `${N}` extends `-${infer P extends number}` ? P
785
- // Handle positive numbers
786
- : `-${N}` extends `${infer R extends number}` ? R : never;
787
-
788
- /**
789
- 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.
790
-
791
- @example
792
- ```
793
- import type {Simplify} from 'type-fest';
794
-
795
- type PositionProps = {
796
- top: number;
797
- left: number;
798
- };
799
-
800
- type SizeProps = {
801
- width: number;
802
- height: number;
803
- };
804
-
805
- // In your editor, hovering over `Props` will show a flattened object with all the properties.
806
- type Props = Simplify<PositionProps & SizeProps>;
807
- ```
808
-
809
- Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
810
-
811
- If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
812
-
813
- @example
814
- ```
815
- import type {Simplify} from 'type-fest';
816
-
817
- interface SomeInterface {
818
- foo: number;
819
- bar?: string;
820
- baz: number | undefined;
821
- }
822
-
823
- type SomeType = {
824
- foo: number;
825
- bar?: string;
826
- baz: number | undefined;
827
- };
828
-
829
- const literal = {foo: 123, bar: 'hello', baz: 456};
830
- const someType: SomeType = literal;
831
- const someInterface: SomeInterface = literal;
832
-
833
- function fn(object: Record<string, unknown>): void {}
834
-
835
- fn(literal); // Good: literal object type is sealed
836
- fn(someType); // Good: type is sealed
837
- fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
838
- fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
839
- ```
840
-
841
- @link https://github.com/microsoft/TypeScript/issues/15300
842
- @see SimplifyDeep
843
- @category Object
844
- */
845
- type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
846
-
847
- /**
848
- Omit any index signatures from the given object type, leaving only explicitly defined properties.
849
-
850
- This is the counterpart of `PickIndexSignature`.
851
-
852
- Use-cases:
853
- - Remove overly permissive signatures from third-party types.
854
-
855
- This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
856
-
857
- It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
858
-
859
- (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
860
-
861
- ```
862
- const indexed: Record<string, unknown> = {}; // Allowed
863
-
864
- const keyed: Record<'foo', unknown> = {}; // Error
865
- // => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
866
- ```
867
-
868
- Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
869
-
870
- ```
871
- type Indexed = {} extends Record<string, unknown>
872
- ? '✅ `{}` is assignable to `Record<string, unknown>`'
873
- : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
874
- // => '✅ `{}` is assignable to `Record<string, unknown>`'
875
-
876
- type Keyed = {} extends Record<'foo' | 'bar', unknown>
877
- ? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
878
- : "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
879
- // => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
880
- ```
881
-
882
- Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
883
-
884
- ```
885
- import type {OmitIndexSignature} from 'type-fest';
886
-
887
- type OmitIndexSignature<ObjectType> = {
888
- [KeyType in keyof ObjectType // Map each key of `ObjectType`...
889
- ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
890
- };
891
- ```
892
-
893
- ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
894
-
895
- ```
896
- import type {OmitIndexSignature} from 'type-fest';
897
-
898
- type OmitIndexSignature<ObjectType> = {
899
- [KeyType in keyof ObjectType
900
- // Is `{}` assignable to `Record<KeyType, unknown>`?
901
- as {} extends Record<KeyType, unknown>
902
- ? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
903
- : ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
904
- ]: ObjectType[KeyType];
905
- };
906
- ```
907
-
908
- If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
909
-
910
- @example
911
- ```
912
- import type {OmitIndexSignature} from 'type-fest';
913
-
914
- interface Example {
915
- // These index signatures will be removed.
916
- [x: string]: any
917
- [x: number]: any
918
- [x: symbol]: any
919
- [x: `head-${string}`]: string
920
- [x: `${string}-tail`]: string
921
- [x: `head-${string}-tail`]: string
922
- [x: `${bigint}`]: string
923
- [x: `embedded-${number}`]: string
924
-
925
- // These explicitly defined keys will remain.
926
- foo: 'bar';
927
- qux?: 'baz';
928
- }
929
-
930
- type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
931
- // => { foo: 'bar'; qux?: 'baz' | undefined; }
932
- ```
933
-
934
- @see PickIndexSignature
935
- @category Object
936
- */
937
- type OmitIndexSignature<ObjectType> = {
938
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
939
- ? never
940
- : KeyType]: ObjectType[KeyType];
941
- };
942
-
943
- /**
944
- Pick only index signatures from the given object type, leaving out all explicitly defined properties.
945
-
946
- This is the counterpart of `OmitIndexSignature`.
947
-
948
- @example
949
- ```
950
- import type {PickIndexSignature} from 'type-fest';
951
-
952
- declare const symbolKey: unique symbol;
953
-
954
- type Example = {
955
- // These index signatures will remain.
956
- [x: string]: unknown;
957
- [x: number]: unknown;
958
- [x: symbol]: unknown;
959
- [x: `head-${string}`]: string;
960
- [x: `${string}-tail`]: string;
961
- [x: `head-${string}-tail`]: string;
962
- [x: `${bigint}`]: string;
963
- [x: `embedded-${number}`]: string;
964
-
965
- // These explicitly defined keys will be removed.
966
- ['kebab-case-key']: string;
967
- [symbolKey]: string;
968
- foo: 'bar';
969
- qux?: 'baz';
970
- };
971
-
972
- type ExampleIndexSignature = PickIndexSignature<Example>;
973
- // {
974
- // [x: string]: unknown;
975
- // [x: number]: unknown;
976
- // [x: symbol]: unknown;
977
- // [x: `head-${string}`]: string;
978
- // [x: `${string}-tail`]: string;
979
- // [x: `head-${string}-tail`]: string;
980
- // [x: `${bigint}`]: string;
981
- // [x: `embedded-${number}`]: string;
982
- // }
983
- ```
984
-
985
- @see OmitIndexSignature
986
- @category Object
987
- */
988
- type PickIndexSignature<ObjectType> = {
989
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
990
- ? KeyType
991
- : never]: ObjectType[KeyType];
992
- };
993
-
994
- // Merges two objects without worrying about index signatures.
995
- type SimpleMerge<Destination, Source> = {
996
- [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
997
- } & Source;
998
-
999
- /**
1000
- Merge two types into a new type. Keys of the second type overrides keys of the first type.
1001
-
1002
- @example
1003
- ```
1004
- import type {Merge} from 'type-fest';
1005
-
1006
- interface Foo {
1007
- [x: string]: unknown;
1008
- [x: number]: unknown;
1009
- foo: string;
1010
- bar: symbol;
1011
- }
1012
-
1013
- type Bar = {
1014
- [x: number]: number;
1015
- [x: symbol]: unknown;
1016
- bar: Date;
1017
- baz: boolean;
1018
- };
1019
-
1020
- export type FooBar = Merge<Foo, Bar>;
1021
- // => {
1022
- // [x: string]: unknown;
1023
- // [x: number]: number;
1024
- // [x: symbol]: unknown;
1025
- // foo: string;
1026
- // bar: Date;
1027
- // baz: boolean;
1028
- // }
1029
- ```
1030
-
1031
- @category Object
1032
- */
1033
- type Merge<Destination, Source> =
1034
- Simplify<
1035
- SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
1036
- & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
1037
- >;
1038
-
1039
- /**
1040
- An if-else-like type that resolves depending on whether the given type is `any`.
1041
-
1042
- @see {@link IsAny}
1043
-
1044
- @example
1045
- ```
1046
- import type {IfAny} from 'type-fest';
1047
-
1048
- type ShouldBeTrue = IfAny<any>;
1049
- //=> true
1050
-
1051
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
1052
- //=> 'bar'
1053
- ```
1054
-
1055
- @category Type Guard
1056
- @category Utilities
1057
- */
1058
- type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
1059
- IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
1060
- );
1061
-
1062
- /**
1063
- Matches any primitive, `void`, `Date`, or `RegExp` value.
1064
- */
1065
- type BuiltIns = Primitive | void | Date | RegExp;
1066
-
1067
- /**
1068
- Matches non-recursive types.
1069
- */
1070
- type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown);
1071
-
1072
- /**
1073
- Merges user specified options with default options.
1074
-
1075
- @example
1076
- ```
1077
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
1078
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
1079
- type SpecifiedOptions = {leavesOnly: true};
1080
-
1081
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
1082
- //=> {maxRecursionDepth: 10; leavesOnly: true}
1083
- ```
1084
-
1085
- @example
1086
- ```
1087
- // Complains if default values are not provided for optional options
1088
-
1089
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
1090
- type DefaultPathsOptions = {maxRecursionDepth: 10};
1091
- type SpecifiedOptions = {};
1092
-
1093
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
1094
- // ~~~~~~~~~~~~~~~~~~~
1095
- // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
1096
- ```
1097
-
1098
- @example
1099
- ```
1100
- // Complains if an option's default type does not conform to the expected type
1101
-
1102
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
1103
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
1104
- type SpecifiedOptions = {};
1105
-
1106
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
1107
- // ~~~~~~~~~~~~~~~~~~~
1108
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
1109
- ```
1110
-
1111
- @example
1112
- ```
1113
- // Complains if an option's specified type does not conform to the expected type
1114
-
1115
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
1116
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
1117
- type SpecifiedOptions = {leavesOnly: 'yes'};
1118
-
1119
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
1120
- // ~~~~~~~~~~~~~~~~
1121
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
1122
- ```
1123
- */
1124
- type ApplyDefaultOptions<
1125
- Options extends object,
1126
- Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
1127
- SpecifiedOptions extends Options,
1128
- > =
1129
- IfAny<SpecifiedOptions, Defaults,
1130
- IfNever<SpecifiedOptions, Defaults,
1131
- Simplify<Merge<Defaults, {
1132
- [Key in keyof SpecifiedOptions
1133
- as Key extends OptionalKeysOf<Options>
1134
- ? Extract<SpecifiedOptions[Key], undefined> extends never
1135
- ? Key
1136
- : never
1137
- : Key
1138
- ]: SpecifiedOptions[Key]
1139
- }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
1140
- >>;
1141
-
1142
- /**
1143
- Returns the difference between two numbers.
1144
-
1145
- Note:
1146
- - A or B can only support `-999` ~ `999`.
1147
-
1148
- @example
1149
- ```
1150
- import type {Subtract} from 'type-fest';
1151
-
1152
- Subtract<333, 222>;
1153
- //=> 111
1154
-
1155
- Subtract<111, -222>;
1156
- //=> 333
1157
-
1158
- Subtract<-111, 222>;
1159
- //=> -333
1160
-
1161
- Subtract<18, 96>;
1162
- //=> -78
1163
-
1164
- Subtract<PositiveInfinity, 9999>;
1165
- //=> PositiveInfinity
1166
-
1167
- Subtract<PositiveInfinity, PositiveInfinity>;
1168
- //=> number
1169
- ```
1170
-
1171
- @category Numeric
1172
- */
1173
- // TODO: Support big integer.
1174
- type Subtract<A extends number, B extends number> =
1175
- // Handle cases when A or B is the actual "number" type
1176
- number extends A | B ? number
1177
- // Handle cases when A and B are both +/- infinity
1178
- : A extends B & (PositiveInfinity | NegativeInfinity) ? number
1179
- // Handle cases when A is - infinity or B is + infinity
1180
- : A extends NegativeInfinity ? NegativeInfinity : B extends PositiveInfinity ? NegativeInfinity
1181
- // Handle cases when A is + infinity or B is - infinity
1182
- : A extends PositiveInfinity ? PositiveInfinity : B extends NegativeInfinity ? PositiveInfinity
1183
- // Handle case when numbers are equal to each other
1184
- : A extends B ? 0
1185
- // Handle cases when A or B is 0
1186
- : A extends 0 ? ReverseSign<B> : B extends 0 ? A
1187
- // Handle remaining regular cases
1188
- : SubtractPostChecks<A, B>;
1189
-
1190
- /**
1191
- Subtracts two numbers A and B, such that they are not equal and neither of them are 0, +/- infinity or the `number` type
1192
- */
1193
- type SubtractPostChecks<A extends number, B extends number, AreNegative = [IsNegative<A>, IsNegative<B>]> =
1194
- AreNegative extends [false, false]
1195
- ? SubtractPositives<A, B>
1196
- : AreNegative extends [true, true]
1197
- // When both numbers are negative we subtract the absolute values and then reverse the sign
1198
- ? ReverseSign<SubtractPositives<NumberAbsolute<A>, NumberAbsolute<B>>>
1199
- // When the signs are different we can add the absolute values and then reverse the sign if A < B
1200
- : [...BuildTuple<NumberAbsolute<A>>, ...BuildTuple<NumberAbsolute<B>>] extends infer R extends unknown[]
1201
- ? LessThan<A, B> extends true ? ReverseSign<R['length']> : R['length']
1202
- : never;
1203
-
1204
- /**
1205
- Subtracts two positive numbers.
1206
- */
1207
- type SubtractPositives<A extends number, B extends number> =
1208
- LessThan<A, B> extends true
1209
- // When A < B we can reverse the result of B - A
1210
- ? ReverseSign<SubtractIfAGreaterThanB<B, A>>
1211
- : SubtractIfAGreaterThanB<A, B>;
1212
-
1213
- /**
1214
- Subtracts two positive numbers A and B such that A > B.
1215
- */
1216
- type SubtractIfAGreaterThanB<A extends number, B extends number> =
1217
- // This is where we always want to end up and do the actual subtraction
1218
- BuildTuple<A> extends [...BuildTuple<B>, ...infer R]
1219
- ? R['length']
1220
- : never;
1221
-
1222
- /**
1223
- Paths options.
1224
-
1225
- @see {@link Paths}
1226
- */
1227
- type PathsOptions = {
1228
- /**
1229
- The maximum depth to recurse when searching for paths.
1230
-
1231
- @default 10
1232
- */
1233
- maxRecursionDepth?: number;
1234
-
1235
- /**
1236
- Use bracket notation for array indices and numeric object keys.
1237
-
1238
- @default false
1239
-
1240
- @example
1241
- ```
1242
- type ArrayExample = {
1243
- array: ['foo'];
1244
- };
1245
-
1246
- type A = Paths<ArrayExample, {bracketNotation: false}>;
1247
- //=> 'array' | 'array.0'
1248
-
1249
- type B = Paths<ArrayExample, {bracketNotation: true}>;
1250
- //=> 'array' | 'array[0]'
1251
- ```
1252
-
1253
- @example
1254
- ```
1255
- type NumberKeyExample = {
1256
- 1: ['foo'];
1257
- };
1258
-
1259
- type A = Paths<NumberKeyExample, {bracketNotation: false}>;
1260
- //=> 1 | '1' | '1.0'
1261
-
1262
- type B = Paths<NumberKeyExample, {bracketNotation: true}>;
1263
- //=> '[1]' | '[1][0]'
1264
- ```
1265
- */
1266
- bracketNotation?: boolean;
1267
-
1268
- /**
1269
- Only include leaf paths in the output.
1270
-
1271
- @default false
1272
-
1273
- @example
1274
- ```
1275
- type Post = {
1276
- id: number;
1277
- author: {
1278
- id: number;
1279
- name: {
1280
- first: string;
1281
- last: string;
1282
- };
1283
- };
1284
- };
1285
-
1286
- type AllPaths = Paths<Post, {leavesOnly: false}>;
1287
- //=> 'id' | 'author' | 'author.id' | 'author.name' | 'author.name.first' | 'author.name.last'
1288
-
1289
- type LeafPaths = Paths<Post, {leavesOnly: true}>;
1290
- //=> 'id' | 'author.id' | 'author.name.first' | 'author.name.last'
1291
- ```
1292
-
1293
- @example
1294
- ```
1295
- type ArrayExample = {
1296
- array: Array<{foo: string}>;
1297
- tuple: [string, {bar: string}];
1298
- };
1299
-
1300
- type AllPaths = Paths<ArrayExample, {leavesOnly: false}>;
1301
- //=> 'array' | `array.${number}` | `array.${number}.foo` | 'tuple' | 'tuple.0' | 'tuple.1' | 'tuple.1.bar'
1302
-
1303
- type LeafPaths = Paths<ArrayExample, {leavesOnly: true}>;
1304
- //=> `array.${number}.foo` | 'tuple.0' | 'tuple.1.bar'
1305
- ```
1306
- */
1307
- leavesOnly?: boolean;
1308
-
1309
- /**
1310
- Only include paths at the specified depth. By default all paths up to {@link PathsOptions.maxRecursionDepth | `maxRecursionDepth`} are included.
1311
-
1312
- Note: Depth starts at `0` for root properties.
1313
-
1314
- @default number
1315
-
1316
- @example
1317
- ```
1318
- type Post = {
1319
- id: number;
1320
- author: {
1321
- id: number;
1322
- name: {
1323
- first: string;
1324
- last: string;
1325
- };
1326
- };
1327
- };
1328
-
1329
- type DepthZero = Paths<Post, {depth: 0}>;
1330
- //=> 'id' | 'author'
1331
-
1332
- type DepthOne = Paths<Post, {depth: 1}>;
1333
- //=> 'author.id' | 'author.name'
1334
-
1335
- type DepthTwo = Paths<Post, {depth: 2}>;
1336
- //=> 'author.name.first' | 'author.name.last'
1337
-
1338
- type LeavesAtDepthOne = Paths<Post, {leavesOnly: true; depth: 1}>;
1339
- //=> 'author.id'
1340
- ```
1341
- */
1342
- depth?: number;
1343
- };
1344
-
1345
- type DefaultPathsOptions = {
1346
- maxRecursionDepth: 10;
1347
- bracketNotation: false;
1348
- leavesOnly: false;
1349
- depth: number;
1350
- };
1351
-
1352
- /**
1353
- Generate a union of all possible paths to properties in the given object.
1354
-
1355
- It also works with arrays.
1356
-
1357
- Use-case: You want a type-safe way to access deeply nested properties in an object.
1358
-
1359
- @example
1360
- ```
1361
- import type {Paths} from 'type-fest';
1362
-
1363
- type Project = {
1364
- filename: string;
1365
- listA: string[];
1366
- listB: [{filename: string}];
1367
- folder: {
1368
- subfolder: {
1369
- filename: string;
1370
- };
1371
- };
1372
- };
1373
-
1374
- type ProjectPaths = Paths<Project>;
1375
- //=> 'filename' | 'listA' | 'listB' | 'folder' | `listA.${number}` | 'listB.0' | 'listB.0.filename' | 'folder.subfolder' | 'folder.subfolder.filename'
1376
-
1377
- declare function open<Path extends ProjectPaths>(path: Path): void;
1378
-
1379
- open('filename'); // Pass
1380
- open('folder.subfolder'); // Pass
1381
- open('folder.subfolder.filename'); // Pass
1382
- open('foo'); // TypeError
1383
-
1384
- // Also works with arrays
1385
- open('listA.1'); // Pass
1386
- open('listB.0'); // Pass
1387
- open('listB.1'); // TypeError. Because listB only has one element.
1388
- ```
1389
-
1390
- @category Object
1391
- @category Array
1392
- */
1393
- type Paths<T, Options extends PathsOptions = {}> = _Paths<T, ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, Options>>;
1394
-
1395
- type _Paths<T, Options extends Required<PathsOptions>> =
1396
- T extends NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>
1397
- ? never
1398
- : IsAny<T> extends true
1399
- ? never
1400
- : T extends UnknownArray
1401
- ? number extends T['length']
1402
- // We need to handle the fixed and non-fixed index part of the array separately.
1403
- ? InternalPaths<StaticPartOfArray<T>, Options>
1404
- | InternalPaths<Array<VariablePartOfArray<T>[number]>, Options>
1405
- : InternalPaths<T, Options>
1406
- : T extends object
1407
- ? InternalPaths<T, Options>
1408
- : never;
1409
-
1410
- type InternalPaths<T, Options extends Required<PathsOptions>> =
1411
- Options['maxRecursionDepth'] extends infer MaxDepth extends number
1412
- ? Required<T> extends infer T
1413
- ? T extends EmptyObject | readonly []
1414
- ? never
1415
- : {
1416
- [Key in keyof T]:
1417
- Key extends string | number // Limit `Key` to string or number.
1418
- ? (
1419
- Options['bracketNotation'] extends true
1420
- ? IsNumberLike<Key> extends true
1421
- ? `[${Key}]`
1422
- : (Key | ToString<Key>)
1423
- : never
1424
- |
1425
- Options['bracketNotation'] extends false
1426
- // If `Key` is a number, return `Key | `${Key}``, because both `array[0]` and `array['0']` work.
1427
- ? (Key | ToString<Key>)
1428
- : never
1429
- ) extends infer TranformedKey extends string | number ?
1430
- // 1. If style is 'a[0].b' and 'Key' is a numberlike value like 3 or '3', transform 'Key' to `[${Key}]`, else to `${Key}` | Key
1431
- // 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
1432
- | ((Options['leavesOnly'] extends true
1433
- ? MaxDepth extends 0
1434
- ? TranformedKey
1435
- : T[Key] extends EmptyObject | readonly [] | NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>
1436
- ? TranformedKey
1437
- : never
1438
- : TranformedKey
1439
- ) extends infer _TransformedKey
1440
- // If `depth` is provided, the condition becomes truthy only when it reaches `0`.
1441
- // Otherwise, since `depth` defaults to `number`, the condition is always truthy, returning paths at all depths.
1442
- ? 0 extends Options['depth']
1443
- ? _TransformedKey
1444
- : never
1445
- : never)
1446
- | (
1447
- // Recursively generate paths for the current key
1448
- GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
1449
- ? _Paths<T[Key],
1450
- {
1451
- bracketNotation: Options['bracketNotation'];
1452
- maxRecursionDepth: Subtract<MaxDepth, 1>;
1453
- leavesOnly: Options['leavesOnly'];
1454
- depth: Subtract<Options['depth'], 1>;
1455
- }> extends infer SubPath
1456
- ? SubPath extends string | number
1457
- ? (
1458
- Options['bracketNotation'] extends true
1459
- ? SubPath extends `[${any}]` | `[${any}]${string}`
1460
- ? `${TranformedKey}${SubPath}` // If next node is number key like `[3]`, no need to add `.` before it.
1461
- : `${TranformedKey}.${SubPath}`
1462
- : never
1463
- ) | (
1464
- Options['bracketNotation'] extends false
1465
- ? `${TranformedKey}.${SubPath}`
1466
- : never
1467
- )
1468
- : never
1469
- : never
1470
- : never
1471
- )
1472
- : never
1473
- : never
1474
- }[keyof T & (T extends UnknownArray ? number : unknown)]
1475
- : never
1476
- : never;
1477
-
1478
- /**
1479
- Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
1480
-
1481
- Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
1482
-
1483
- This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
1484
-
1485
- @example
1486
- ```
1487
- import type {LiteralUnion} from 'type-fest';
1488
-
1489
- // Before
1490
-
1491
- type Pet = 'dog' | 'cat' | string;
1492
-
1493
- const pet: Pet = '';
1494
- // Start typing in your TypeScript-enabled IDE.
1495
- // You **will not** get auto-completion for `dog` and `cat` literals.
1496
-
1497
- // After
1498
-
1499
- type Pet2 = LiteralUnion<'dog' | 'cat', string>;
1500
-
1501
- const pet: Pet2 = '';
1502
- // You **will** get auto-completion for `dog` and `cat` literals.
1503
- ```
1504
-
1505
- @category Type
1506
- */
1507
- type LiteralUnion<
1508
- LiteralType,
1509
- BaseType extends Primitive,
1510
- > = LiteralType | (BaseType & Record<never, never>);
1511
-
1512
- declare namespace PackageJson$1 {
1513
- /**
1514
- A person who has been involved in creating or maintaining the package.
1515
- */
1516
- export type Person =
1517
- | string
1518
- | {
1519
- name: string;
1520
- url?: string;
1521
- email?: string;
1522
- };
1523
-
1524
- export type BugsLocation =
1525
- | string
1526
- | {
1527
- /**
1528
- The URL to the package's issue tracker.
1529
- */
1530
- url?: string;
1531
-
1532
- /**
1533
- The email address to which issues should be reported.
1534
- */
1535
- email?: string;
1536
- };
1537
-
1538
- export type DirectoryLocations = {
1539
- [directoryType: string]: JsonValue | undefined;
1540
-
1541
- /**
1542
- Location for executable scripts. Sugar to generate entries in the `bin` property by walking the folder.
1543
- */
1544
- bin?: string;
1545
-
1546
- /**
1547
- Location for Markdown files.
1548
- */
1549
- doc?: string;
1550
-
1551
- /**
1552
- Location for example scripts.
1553
- */
1554
- example?: string;
1555
-
1556
- /**
1557
- Location for the bulk of the library.
1558
- */
1559
- lib?: string;
1560
-
1561
- /**
1562
- Location for man pages. Sugar to generate a `man` array by walking the folder.
1563
- */
1564
- man?: string;
1565
-
1566
- /**
1567
- Location for test files.
1568
- */
1569
- test?: string;
1570
- };
1571
-
1572
- export type Scripts = {
1573
- /**
1574
- Run **before** the package is published (Also run on local `npm install` without any arguments).
1575
- */
1576
- prepublish?: string;
1577
-
1578
- /**
1579
- Run both **before** the package is packed and published, and on local `npm install` without any arguments. This is run **after** `prepublish`, but **before** `prepublishOnly`.
1580
- */
1581
- prepare?: string;
1582
-
1583
- /**
1584
- Run **before** the package is prepared and packed, **only** on `npm publish`.
1585
- */
1586
- prepublishOnly?: string;
1587
-
1588
- /**
1589
- Run **before** a tarball is packed (on `npm pack`, `npm publish`, and when installing git dependencies).
1590
- */
1591
- prepack?: string;
1592
-
1593
- /**
1594
- Run **after** the tarball has been generated and moved to its final destination.
1595
- */
1596
- postpack?: string;
1597
-
1598
- /**
1599
- Run **after** the package is published.
1600
- */
1601
- publish?: string;
1602
-
1603
- /**
1604
- Run **after** the package is published.
1605
- */
1606
- postpublish?: string;
1607
-
1608
- /**
1609
- Run **before** the package is installed.
1610
- */
1611
- preinstall?: string;
1612
-
1613
- /**
1614
- Run **after** the package is installed.
1615
- */
1616
- install?: string;
1617
-
1618
- /**
1619
- Run **after** the package is installed and after `install`.
1620
- */
1621
- postinstall?: string;
1622
-
1623
- /**
1624
- Run **before** the package is uninstalled and before `uninstall`.
1625
- */
1626
- preuninstall?: string;
1627
-
1628
- /**
1629
- Run **before** the package is uninstalled.
1630
- */
1631
- uninstall?: string;
1632
-
1633
- /**
1634
- Run **after** the package is uninstalled.
1635
- */
1636
- postuninstall?: string;
1637
-
1638
- /**
1639
- Run **before** bump the package version and before `version`.
1640
- */
1641
- preversion?: string;
1642
-
1643
- /**
1644
- Run **before** bump the package version.
1645
- */
1646
- version?: string;
1647
-
1648
- /**
1649
- Run **after** bump the package version.
1650
- */
1651
- postversion?: string;
1652
-
1653
- /**
1654
- Run with the `npm test` command, before `test`.
1655
- */
1656
- pretest?: string;
1657
-
1658
- /**
1659
- Run with the `npm test` command.
1660
- */
1661
- test?: string;
1662
-
1663
- /**
1664
- Run with the `npm test` command, after `test`.
1665
- */
1666
- posttest?: string;
1667
-
1668
- /**
1669
- Run with the `npm stop` command, before `stop`.
1670
- */
1671
- prestop?: string;
1672
-
1673
- /**
1674
- Run with the `npm stop` command.
1675
- */
1676
- stop?: string;
1677
-
1678
- /**
1679
- Run with the `npm stop` command, after `stop`.
1680
- */
1681
- poststop?: string;
1682
-
1683
- /**
1684
- Run with the `npm start` command, before `start`.
1685
- */
1686
- prestart?: string;
1687
-
1688
- /**
1689
- Run with the `npm start` command.
1690
- */
1691
- start?: string;
1692
-
1693
- /**
1694
- Run with the `npm start` command, after `start`.
1695
- */
1696
- poststart?: string;
1697
-
1698
- /**
1699
- Run with the `npm restart` command, before `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
1700
- */
1701
- prerestart?: string;
1702
-
1703
- /**
1704
- Run with the `npm restart` command. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
1705
- */
1706
- restart?: string;
1707
-
1708
- /**
1709
- Run with the `npm restart` command, after `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
1710
- */
1711
- postrestart?: string;
1712
- } & Partial<Record<string, string>>;
1713
-
1714
- /**
1715
- Dependencies of the package. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or Git URL.
1716
- */
1717
- export type Dependency = Partial<Record<string, string>>;
1718
-
1719
- /**
1720
- A mapping of conditions and the paths to which they resolve.
1721
- */
1722
- type ExportConditions = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
1723
- [condition: string]: Exports;
1724
- };
1725
-
1726
- /**
1727
- Entry points of a module, optionally with conditions and subpath exports.
1728
- */
1729
- export type Exports =
1730
- | null
1731
- | string
1732
- | Array<string | ExportConditions>
1733
- | ExportConditions;
1734
-
1735
- /**
1736
- Import map entries of a module, optionally with conditions and subpath imports.
1737
- */
1738
- export type Imports = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
1739
- [key: `#${string}`]: Exports;
1740
- };
1741
-
1742
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1743
- export interface NonStandardEntryPoints {
1744
- /**
1745
- An ECMAScript module ID that is the primary entry point to the program.
1746
- */
1747
- module?: string;
1748
-
1749
- /**
1750
- A module ID with untranspiled code that is the primary entry point to the program.
1751
- */
1752
- esnext?:
1753
- | string
1754
- | {
1755
- [moduleName: string]: string | undefined;
1756
- main?: string;
1757
- browser?: string;
1758
- };
1759
-
1760
- /**
1761
- A hint to JavaScript bundlers or component tools when packaging modules for client side use.
1762
- */
1763
- browser?:
1764
- | string
1765
- | Partial<Record<string, string | false>>;
1766
-
1767
- /**
1768
- Denote which files in your project are "pure" and therefore safe for Webpack to prune if unused.
1769
-
1770
- [Read more.](https://webpack.js.org/guides/tree-shaking/)
1771
- */
1772
- sideEffects?: boolean | string[];
1773
- }
1774
-
1775
- export type TypeScriptConfiguration = {
1776
- /**
1777
- Location of the bundled TypeScript declaration file.
1778
- */
1779
- types?: string;
1780
-
1781
- /**
1782
- Version selection map of TypeScript.
1783
- */
1784
- typesVersions?: Partial<Record<string, Partial<Record<string, string[]>>>>;
1785
-
1786
- /**
1787
- Location of the bundled TypeScript declaration file. Alias of `types`.
1788
- */
1789
- typings?: string;
1790
- };
1791
-
1792
- /**
1793
- An alternative configuration for workspaces.
1794
- */
1795
- export type WorkspaceConfig = {
1796
- /**
1797
- An array of workspace pattern strings which contain the workspace packages.
1798
- */
1799
- packages?: WorkspacePattern[];
1800
-
1801
- /**
1802
- Designed to solve the problem of packages which break when their `node_modules` are moved to the root workspace directory - a process known as hoisting. For these packages, both within your workspace, and also some that have been installed via `node_modules`, it is important to have a mechanism for preventing the default Yarn workspace behavior. By adding workspace pattern strings here, Yarn will resume non-workspace behavior for any package which matches the defined patterns.
1803
-
1804
- [Supported](https://classic.yarnpkg.com/blog/2018/02/15/nohoist/) by Yarn.
1805
- [Not supported](https://github.com/npm/rfcs/issues/287) by npm.
1806
- */
1807
- nohoist?: WorkspacePattern[];
1808
- };
1809
-
1810
- /**
1811
- A workspace pattern points to a directory or group of directories which contain packages that should be included in the workspace installation process.
1812
-
1813
- The patterns are handled with [minimatch](https://github.com/isaacs/minimatch).
1814
-
1815
- @example
1816
- `docs` → Include the docs directory and install its dependencies.
1817
- `packages/*` → Include all nested directories within the packages directory, like `packages/cli` and `packages/core`.
1818
- */
1819
- type WorkspacePattern = string;
1820
-
1821
- export type YarnConfiguration = {
1822
- /**
1823
- If your package only allows one version of a given dependency, and you’d like to enforce the same behavior as `yarn install --flat` on the command-line, set this to `true`.
1824
-
1825
- Note that if your `package.json` contains `"flat": true` and other packages depend on yours (e.g. you are building a library rather than an app), those other packages will also need `"flat": true` in their `package.json` or be installed with `yarn install --flat` on the command-line.
1826
- */
1827
- flat?: boolean;
1828
-
1829
- /**
1830
- Selective version resolutions. Allows the definition of custom package versions inside dependencies without manual edits in the `yarn.lock` file.
1831
- */
1832
- resolutions?: Dependency;
1833
- };
1834
-
1835
- export type JSPMConfiguration = {
1836
- /**
1837
- JSPM configuration.
1838
- */
1839
- jspm?: PackageJson$1;
1840
- };
1841
-
1842
- /**
1843
- Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Containing standard npm properties.
1844
- */
1845
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1846
- export interface PackageJsonStandard {
1847
- /**
1848
- The name of the package.
1849
- */
1850
- name?: string;
1851
-
1852
- /**
1853
- Package version, parseable by [`node-semver`](https://github.com/npm/node-semver).
1854
- */
1855
- version?: string;
1856
-
1857
- /**
1858
- Package description, listed in `npm search`.
1859
- */
1860
- description?: string;
1861
-
1862
- /**
1863
- Keywords associated with package, listed in `npm search`.
1864
- */
1865
- keywords?: string[];
1866
-
1867
- /**
1868
- The URL to the package's homepage.
1869
- */
1870
- homepage?: LiteralUnion<'.', string>;
1871
-
1872
- /**
1873
- The URL to the package's issue tracker and/or the email address to which issues should be reported.
1874
- */
1875
- bugs?: BugsLocation;
1876
-
1877
- /**
1878
- The license for the package.
1879
- */
1880
- license?: string;
1881
-
1882
- /**
1883
- The licenses for the package.
1884
- */
1885
- licenses?: Array<{
1886
- type?: string;
1887
- url?: string;
1888
- }>;
1889
-
1890
- author?: Person;
1891
-
1892
- /**
1893
- A list of people who contributed to the package.
1894
- */
1895
- contributors?: Person[];
1896
-
1897
- /**
1898
- A list of people who maintain the package.
1899
- */
1900
- maintainers?: Person[];
1901
-
1902
- /**
1903
- The files included in the package.
1904
- */
1905
- files?: string[];
1906
-
1907
- /**
1908
- Resolution algorithm for importing ".js" files from the package's scope.
1909
-
1910
- [Read more.](https://nodejs.org/api/esm.html#esm_package_json_type_field)
1911
- */
1912
- type?: 'module' | 'commonjs';
1913
-
1914
- /**
1915
- The module ID that is the primary entry point to the program.
1916
- */
1917
- main?: string;
1918
-
1919
- /**
1920
- Subpath exports to define entry points of the package.
1921
-
1922
- [Read more.](https://nodejs.org/api/packages.html#subpath-exports)
1923
- */
1924
- exports?: Exports;
1925
-
1926
- /**
1927
- Subpath imports to define internal package import maps that only apply to import specifiers from within the package itself.
1928
-
1929
- [Read more.](https://nodejs.org/api/packages.html#subpath-imports)
1930
- */
1931
- imports?: Imports;
1932
-
1933
- /**
1934
- The executable files that should be installed into the `PATH`.
1935
- */
1936
- bin?:
1937
- | string
1938
- | Partial<Record<string, string>>;
1939
-
1940
- /**
1941
- Filenames to put in place for the `man` program to find.
1942
- */
1943
- man?: string | string[];
1944
-
1945
- /**
1946
- Indicates the structure of the package.
1947
- */
1948
- directories?: DirectoryLocations;
1949
-
1950
- /**
1951
- Location for the code repository.
1952
- */
1953
- repository?:
1954
- | string
1955
- | {
1956
- type: string;
1957
- url: string;
1958
-
1959
- /**
1960
- Relative path to package.json if it is placed in non-root directory (for example if it is part of a monorepo).
1961
-
1962
- [Read more.](https://github.com/npm/rfcs/blob/latest/implemented/0010-monorepo-subdirectory-declaration.md)
1963
- */
1964
- directory?: string;
1965
- };
1966
-
1967
- /**
1968
- Script commands that are run at various times in the lifecycle of the package. The key is the lifecycle event, and the value is the command to run at that point.
1969
- */
1970
- scripts?: Scripts;
1971
-
1972
- /**
1973
- Is used to set configuration parameters used in package scripts that persist across upgrades.
1974
- */
1975
- config?: JsonObject;
1976
-
1977
- /**
1978
- The dependencies of the package.
1979
- */
1980
- dependencies?: Dependency;
1981
-
1982
- /**
1983
- Additional tooling dependencies that are not required for the package to work. Usually test, build, or documentation tooling.
1984
- */
1985
- devDependencies?: Dependency;
1986
-
1987
- /**
1988
- Dependencies that are skipped if they fail to install.
1989
- */
1990
- optionalDependencies?: Dependency;
1991
-
1992
- /**
1993
- Dependencies that will usually be required by the package user directly or via another dependency.
1994
- */
1995
- peerDependencies?: Dependency;
1996
-
1997
- /**
1998
- Indicate peer dependencies that are optional.
1999
- */
2000
- peerDependenciesMeta?: Partial<Record<string, {optional: true}>>;
2001
-
2002
- /**
2003
- Package names that are bundled when the package is published.
2004
- */
2005
- bundledDependencies?: string[];
2006
-
2007
- /**
2008
- Alias of `bundledDependencies`.
2009
- */
2010
- bundleDependencies?: string[];
2011
-
2012
- /**
2013
- Engines that this package runs on.
2014
- */
2015
- engines?: {
2016
- [EngineName in 'npm' | 'node' | string]?: string;
2017
- };
2018
-
2019
- /**
2020
- @deprecated
2021
- */
2022
- engineStrict?: boolean;
2023
-
2024
- /**
2025
- Operating systems the module runs on.
2026
- */
2027
- os?: Array<LiteralUnion<
2028
- | 'aix'
2029
- | 'darwin'
2030
- | 'freebsd'
2031
- | 'linux'
2032
- | 'openbsd'
2033
- | 'sunos'
2034
- | 'win32'
2035
- | '!aix'
2036
- | '!darwin'
2037
- | '!freebsd'
2038
- | '!linux'
2039
- | '!openbsd'
2040
- | '!sunos'
2041
- | '!win32',
2042
- string
2043
- >>;
2044
-
2045
- /**
2046
- CPU architectures the module runs on.
2047
- */
2048
- cpu?: Array<LiteralUnion<
2049
- | 'arm'
2050
- | 'arm64'
2051
- | 'ia32'
2052
- | 'mips'
2053
- | 'mipsel'
2054
- | 'ppc'
2055
- | 'ppc64'
2056
- | 's390'
2057
- | 's390x'
2058
- | 'x32'
2059
- | 'x64'
2060
- | '!arm'
2061
- | '!arm64'
2062
- | '!ia32'
2063
- | '!mips'
2064
- | '!mipsel'
2065
- | '!ppc'
2066
- | '!ppc64'
2067
- | '!s390'
2068
- | '!s390x'
2069
- | '!x32'
2070
- | '!x64',
2071
- string
2072
- >>;
2073
-
2074
- /**
2075
- If set to `true`, a warning will be shown if package is installed locally. Useful if the package is primarily a command-line application that should be installed globally.
2076
-
2077
- @deprecated
2078
- */
2079
- preferGlobal?: boolean;
2080
-
2081
- /**
2082
- If set to `true`, then npm will refuse to publish it.
2083
- */
2084
- private?: boolean;
2085
-
2086
- /**
2087
- A set of config values that will be used at publish-time. It's especially handy to set the tag, registry or access, to ensure that a given package is not tagged with 'latest', published to the global public registry or that a scoped module is private by default.
2088
- */
2089
- publishConfig?: PublishConfig;
2090
-
2091
- /**
2092
- Describes and notifies consumers of a package's monetary support information.
2093
-
2094
- [Read more.](https://github.com/npm/rfcs/blob/latest/accepted/0017-add-funding-support.md)
2095
- */
2096
- funding?: string | {
2097
- /**
2098
- The type of funding.
2099
- */
2100
- type?: LiteralUnion<
2101
- | 'github'
2102
- | 'opencollective'
2103
- | 'patreon'
2104
- | 'individual'
2105
- | 'foundation'
2106
- | 'corporation',
2107
- string
2108
- >;
2109
-
2110
- /**
2111
- The URL to the funding page.
2112
- */
2113
- url: string;
2114
- };
2115
-
2116
- /**
2117
- Used to configure [npm workspaces](https://docs.npmjs.com/cli/using-npm/workspaces) / [Yarn workspaces](https://classic.yarnpkg.com/docs/workspaces/).
2118
-
2119
- Workspaces allow you to manage multiple packages within the same repository in such a way that you only need to run your install command once in order to install all of them in a single pass.
2120
-
2121
- Please note that the top-level `private` property of `package.json` **must** be set to `true` in order to use workspaces.
2122
- */
2123
- workspaces?: WorkspacePattern[] | WorkspaceConfig;
2124
- }
2125
-
2126
- /**
2127
- Type for [`package.json` file used by the Node.js runtime](https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions).
2128
- */
2129
- export type NodeJsStandard = {
2130
- /**
2131
- Defines which package manager is expected to be used when working on the current project. It can set to any of the [supported package managers](https://nodejs.org/api/corepack.html#supported-package-managers), and will ensure that your teams use the exact same package manager versions without having to install anything else than Node.js.
2132
-
2133
- __This field is currently experimental and needs to be opted-in; check the [Corepack](https://nodejs.org/api/corepack.html) page for details about the procedure.__
2134
-
2135
- @example
2136
- ```json
2137
- {
2138
- "packageManager": "<package manager name>@<version>"
2139
- }
2140
- ```
2141
- */
2142
- packageManager?: string;
2143
- };
2144
-
2145
- export type PublishConfig = {
2146
- /**
2147
- Additional, less common properties from the [npm docs on `publishConfig`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#publishconfig).
2148
- */
2149
- [additionalProperties: string]: JsonValue | undefined;
2150
-
2151
- /**
2152
- When publishing scoped packages, the access level defaults to restricted. If you want your scoped package to be publicly viewable (and installable) set `--access=public`. The only valid values for access are public and restricted. Unscoped packages always have an access level of public.
2153
- */
2154
- access?: 'public' | 'restricted';
2155
-
2156
- /**
2157
- The base URL of the npm registry.
2158
-
2159
- Default: `'https://registry.npmjs.org/'`
2160
- */
2161
- registry?: string;
2162
-
2163
- /**
2164
- The tag to publish the package under.
2165
-
2166
- Default: `'latest'`
2167
- */
2168
- tag?: string;
2169
- };
2170
- }
2171
-
2172
- /**
2173
- 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.
2174
-
2175
- @category File
2176
- */
2177
- type PackageJson$1 =
2178
- JsonObject &
2179
- PackageJson$1.NodeJsStandard &
2180
- PackageJson$1.PackageJsonStandard &
2181
- PackageJson$1.NonStandardEntryPoints &
2182
- PackageJson$1.TypeScriptConfiguration &
2183
- PackageJson$1.YarnConfiguration &
2184
- PackageJson$1.JSPMConfiguration;
2185
-
2186
- interface InstallPackageOptions {
2187
- cwd?: string;
2188
- dev?: boolean;
2189
- silent?: boolean;
2190
- packageManager?: string;
2191
- preferOffline?: boolean;
2192
- additionalArgs?: string[] | ((agent: string, detectedAgent: string) => string[] | undefined);
2193
- }
2194
-
2195
- type Prettify<T> = {
2196
- [K in keyof T]: T[K];
2197
- } & {};
2198
- type PartialDeep<T> = T extends object ? {
2199
- [P in keyof T]?: PartialDeep<T[P]>;
2200
- } : T;
2201
-
2202
- /**
2203
- * Union type representing the possible statuses of a prompt.
2204
- *
2205
- * - `'loading'`: The prompt is currently loading.
2206
- * - `'idle'`: The prompt is loaded and currently waiting for the user to
2207
- * submit an answer.
2208
- * - `'done'`: The user has submitted an answer and the prompt is finished.
2209
- * - `string`: Any other string: The prompt is in a custom state.
2210
- */
2211
- type Status = 'loading' | 'idle' | 'done' | (string & {});
2212
- type DefaultTheme = {
2213
- /**
2214
- * Prefix to prepend to the message. If a function is provided, it will be
2215
- * called with the current status of the prompt, and the return value will be
2216
- * used as the prefix.
2217
- *
2218
- * @remarks
2219
- * If `status === 'loading'`, this property is ignored and the spinner (styled
2220
- * by the `spinner` property) will be displayed instead.
2221
- *
2222
- * @defaultValue
2223
- * ```ts
2224
- * // import colors from 'yoctocolors-cjs';
2225
- * (status) => status === 'done' ? colors.green('✔') : colors.blue('?')
2226
- * ```
2227
- */
2228
- prefix: string | Prettify<Omit<Record<Status, string>, 'loading'>>;
2229
- /**
2230
- * Configuration for the spinner that is displayed when the prompt is in the
2231
- * `'loading'` state.
2232
- *
2233
- * We recommend the use of {@link https://github.com/sindresorhus/cli-spinners|cli-spinners} for a list of available spinners.
2234
- */
2235
- spinner: {
2236
- /**
2237
- * The time interval between frames, in milliseconds.
2238
- *
2239
- * @defaultValue
2240
- * ```ts
2241
- * 80
2242
- * ```
2243
- */
2244
- interval: number;
2245
- /**
2246
- * A list of frames to show for the spinner.
2247
- *
2248
- * @defaultValue
2249
- * ```ts
2250
- * ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
2251
- * ```
2252
- */
2253
- frames: string[];
2254
- };
2255
- /**
2256
- * Object containing functions to style different parts of the prompt.
2257
- */
2258
- style: {
2259
- /**
2260
- * Style to apply to the user's answer once it has been submitted.
2261
- *
2262
- * @param text - The user's answer.
2263
- * @returns The styled answer.
2264
- *
2265
- * @defaultValue
2266
- * ```ts
2267
- * // import colors from 'yoctocolors-cjs';
2268
- * (text) => colors.cyan(text)
2269
- * ```
2270
- */
2271
- answer: (text: string) => string;
2272
- /**
2273
- * Style to apply to the message displayed to the user.
2274
- *
2275
- * @param text - The message to style.
2276
- * @param status - The current status of the prompt.
2277
- * @returns The styled message.
2278
- *
2279
- * @defaultValue
2280
- * ```ts
2281
- * // import colors from 'yoctocolors-cjs';
2282
- * (text, status) => colors.bold(text)
2283
- * ```
2284
- */
2285
- message: (text: string, status: Status) => string;
2286
- /**
2287
- * Style to apply to error messages.
2288
- *
2289
- * @param text - The error message.
2290
- * @returns The styled error message.
2291
- *
2292
- * @defaultValue
2293
- * ```ts
2294
- * // import colors from 'yoctocolors-cjs';
2295
- * (text) => colors.red(`> ${text}`)
2296
- * ```
2297
- */
2298
- error: (text: string) => string;
2299
- /**
2300
- * Style to apply to the default answer when one is provided.
2301
- *
2302
- * @param text - The default answer.
2303
- * @returns The styled default answer.
2304
- *
2305
- * @defaultValue
2306
- * ```ts
2307
- * // import colors from 'yoctocolors-cjs';
2308
- * (text) => colors.dim(`(${text})`)
2309
- * ```
2310
- */
2311
- defaultAnswer: (text: string) => string;
2312
- /**
2313
- * Style to apply to help text.
2314
- *
2315
- * @param text - The help text.
2316
- * @returns The styled help text.
2317
- *
2318
- * @defaultValue
2319
- * ```ts
2320
- * // import colors from 'yoctocolors-cjs';
2321
- * (text) => colors.dim(text)
2322
- * ```
2323
- */
2324
- help: (text: string) => string;
2325
- /**
2326
- * Style to apply to highlighted text.
2327
- *
2328
- * @param text - The text to highlight.
2329
- * @returns The highlighted text.
2330
- *
2331
- * @defaultValue
2332
- * ```ts
2333
- * // import colors from 'yoctocolors-cjs';
2334
- * (text) => colors.cyan(text)
2335
- * ```
2336
- */
2337
- highlight: (text: string) => string;
2338
- /**
2339
- * Style to apply to keyboard keys referred to in help texts.
2340
- *
2341
- * @param text - The key to style.
2342
- * @returns The styled key.
2343
- *
2344
- * @defaultValue
2345
- * ```ts
2346
- * // import colors from 'yoctocolors-cjs';
2347
- * (text) => colors.cyan(colors.bold(`<${text}>`))
2348
- * ```
2349
- */
2350
- key: (text: string) => string;
2351
- };
2352
- };
2353
- type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;
2354
-
2355
- type NormalizedPackageJson = Package & PackageJson;
2356
- type PackageJson = PackageJson$1;
2357
- type Cache<T = any> = Map<string, T>;
2358
- type EnsurePackagesOptions = {
2359
- confirm?: {
2360
- default?: boolean;
2361
- message: string | ((packages: string[]) => string);
2362
- theme?: PartialDeep<Theme>;
2363
- transformer?: (value: boolean) => string;
2364
- };
2365
- cwd?: URL | string;
2366
- deps?: boolean;
2367
- devDeps?: boolean;
2368
- installPackage?: Omit<InstallPackageOptions, "cwd" | "dev">;
2369
- peerDeps?: boolean;
2370
- logger?: {
2371
- warn: (message: string) => void;
2372
- };
2373
- throwOnWarn?: boolean;
2374
- };
2375
-
2376
- type ReadOptions = {
2377
- cache?: FindPackageJsonCache | boolean;
2378
- ignoreWarnings?: (RegExp | string)[];
2379
- strict?: boolean;
2380
- };
2381
- type FindPackageJsonCache = Cache<NormalizedReadResult>;
2382
- type NormalizedReadResult = {
2383
- packageJson: NormalizedPackageJson;
2384
- path: string;
2385
- };
2386
- declare const findPackageJson: (cwd?: URL | string, options?: ReadOptions) => Promise<NormalizedReadResult>;
2387
- declare const findPackageJsonSync: (cwd?: URL | string, options?: ReadOptions) => NormalizedReadResult;
2388
- declare const writePackageJson: <T = PackageJson>(data: T, options?: WriteJsonOptions & {
2389
- cwd?: URL | string;
2390
- }) => Promise<void>;
2391
- declare const writePackageJsonSync: <T = PackageJson>(data: T, options?: WriteJsonOptions & {
2392
- cwd?: URL | string;
2393
- }) => void;
2394
- declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
2395
- ignoreWarnings?: (RegExp | string)[];
2396
- strict?: boolean;
2397
- }) => NormalizedPackageJson;
2398
- declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
2399
- declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
2400
- declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
2401
- peerDeps?: boolean;
2402
- }) => boolean;
2403
- declare const ensurePackages: (packageJson: NormalizedPackageJson, packages: string[], installKey?: "dependencies" | "devDependencies", options?: EnsurePackagesOptions) => Promise<void>;
2404
-
2405
- export { type EnsurePackagesOptions as E, type FindPackageJsonCache as F, type NormalizedReadResult as N, type PackageJson as P, findPackageJsonSync as a, hasPackageJsonProperty as b, writePackageJsonSync as c, type NormalizedPackageJson as d, ensurePackages as e, findPackageJson as f, getPackageJsonProperty as g, hasPackageJsonAnyDependency as h, parsePackageJson as p, writePackageJson as w };