@visulima/package 3.0.11 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1693 @@
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
+ Returns a boolean for whether the two given types are equal.
89
+
90
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
91
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
92
+
93
+ Use-cases:
94
+ - If you want to make a conditional branch based on the result of a comparison of two types.
95
+
96
+ @example
97
+ ```
98
+ import type {IsEqual} from 'type-fest';
99
+
100
+ // This type returns a boolean for whether the given array includes the given item.
101
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
102
+ type Includes<Value extends readonly any[], Item> =
103
+ Value extends readonly [Value[0], ...infer rest]
104
+ ? IsEqual<Value[0], Item> extends true
105
+ ? true
106
+ : Includes<rest, Item>
107
+ : false;
108
+ ```
109
+
110
+ @category Type Guard
111
+ @category Utilities
112
+ */
113
+ type IsEqual<A, B> =
114
+ (<G>() => G extends A ? 1 : 2) extends
115
+ (<G>() => G extends B ? 1 : 2)
116
+ ? true
117
+ : false;
118
+
119
+ /**
120
+ Represents an array with `unknown` value.
121
+
122
+ Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
123
+
124
+ @example
125
+ ```
126
+ import type {UnknownArray} from 'type-fest';
127
+
128
+ type IsArray<T> = T extends UnknownArray ? true : false;
129
+
130
+ type A = IsArray<['foo']>;
131
+ //=> true
132
+
133
+ type B = IsArray<readonly number[]>;
134
+ //=> true
135
+
136
+ type C = IsArray<string>;
137
+ //=> false
138
+ ```
139
+
140
+ @category Type
141
+ @category Array
142
+ */
143
+ type UnknownArray = readonly unknown[];
144
+
145
+ /**
146
+ Returns the static, fixed-length portion of the given array, excluding variable-length parts.
147
+
148
+ @example
149
+ ```
150
+ type A = [string, number, boolean, ...string[]];
151
+ type B = StaticPartOfArray<A>;
152
+ //=> [string, number, boolean]
153
+ ```
154
+ */
155
+ type StaticPartOfArray<T extends UnknownArray, Result extends UnknownArray = []> =
156
+ T extends unknown
157
+ ? number extends T['length'] ?
158
+ T extends readonly [infer U, ...infer V]
159
+ ? StaticPartOfArray<V, [...Result, U]>
160
+ : Result
161
+ : T
162
+ : never; // Should never happen
163
+
164
+ /**
165
+ Returns the variable, non-fixed-length portion of the given array, excluding static-length parts.
166
+
167
+ @example
168
+ ```
169
+ type A = [string, number, boolean, ...string[]];
170
+ type B = VariablePartOfArray<A>;
171
+ //=> string[]
172
+ ```
173
+ */
174
+ type VariablePartOfArray<T extends UnknownArray> =
175
+ T extends unknown
176
+ ? T extends readonly [...StaticPartOfArray<T>, ...infer U]
177
+ ? U
178
+ : []
179
+ : never;
180
+
181
+ /**
182
+ Returns a boolean for whether the given type is `any`.
183
+
184
+ @link https://stackoverflow.com/a/49928360/1490091
185
+
186
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
187
+
188
+ @example
189
+ ```
190
+ import type {IsAny} from 'type-fest';
191
+
192
+ const typedObject = {a: 1, b: 2} as const;
193
+ const anyObject: any = {a: 1, b: 2};
194
+
195
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
196
+ return obj[key];
197
+ }
198
+
199
+ const typedA = get(typedObject, 'a');
200
+ //=> 1
201
+
202
+ const anyA = get(anyObject, 'a');
203
+ //=> any
204
+ ```
205
+
206
+ @category Type Guard
207
+ @category Utilities
208
+ */
209
+ type IsAny<T> = 0 extends 1 & T ? true : false;
210
+
211
+ type Numeric = number | bigint;
212
+
213
+ type Zero = 0 | 0n;
214
+
215
+ /**
216
+ Matches the hidden `Infinity` type.
217
+
218
+ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
219
+
220
+ @see NegativeInfinity
221
+
222
+ @category Numeric
223
+ */
224
+ // See https://github.com/microsoft/TypeScript/issues/31752
225
+ // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
226
+ type PositiveInfinity = 1e999;
227
+
228
+ /**
229
+ Matches the hidden `-Infinity` type.
230
+
231
+ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
232
+
233
+ @see PositiveInfinity
234
+
235
+ @category Numeric
236
+ */
237
+ // See https://github.com/microsoft/TypeScript/issues/31752
238
+ // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
239
+ type NegativeInfinity = -1e999;
240
+
241
+ /**
242
+ A negative `number`/`bigint` (`-∞ < x < 0`)
243
+
244
+ Use-case: Validating and documenting parameters.
245
+
246
+ @see NegativeInteger
247
+ @see NonNegative
248
+
249
+ @category Numeric
250
+ */
251
+ type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
252
+
253
+ /**
254
+ Returns a boolean for whether the given number is a negative number.
255
+
256
+ @see Negative
257
+
258
+ @example
259
+ ```
260
+ import type {IsNegative} from 'type-fest';
261
+
262
+ type ShouldBeFalse = IsNegative<1>;
263
+ type ShouldBeTrue = IsNegative<-1>;
264
+ ```
265
+
266
+ @category Numeric
267
+ */
268
+ type IsNegative<T extends Numeric> = T extends Negative<T> ? true : false;
269
+
270
+ /**
271
+ Returns a boolean for whether two given types are both true.
272
+
273
+ Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
274
+
275
+ @example
276
+ ```
277
+ import type {And} from 'type-fest';
278
+
279
+ And<true, true>;
280
+ //=> true
281
+
282
+ And<true, false>;
283
+ //=> false
284
+ ```
285
+
286
+ @see {@link Or}
287
+ */
288
+ type And<A extends boolean, B extends boolean> = [A, B][number] extends true
289
+ ? true
290
+ : true extends [IsEqual<A, false>, IsEqual<B, false>][number]
291
+ ? false
292
+ : never;
293
+
294
+ /**
295
+ Returns a boolean for whether either of two given types are true.
296
+
297
+ Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
298
+
299
+ @example
300
+ ```
301
+ import type {Or} from 'type-fest';
302
+
303
+ Or<true, false>;
304
+ //=> true
305
+
306
+ Or<false, false>;
307
+ //=> false
308
+ ```
309
+
310
+ @see {@link And}
311
+ */
312
+ type Or<A extends boolean, B extends boolean> = [A, B][number] extends false
313
+ ? false
314
+ : true extends [IsEqual<A, true>, IsEqual<B, true>][number]
315
+ ? true
316
+ : never;
317
+
318
+ /**
319
+ Returns a boolean for whether a given number is greater than another number.
320
+
321
+ @example
322
+ ```
323
+ import type {GreaterThan} from 'type-fest';
324
+
325
+ GreaterThan<1, -5>;
326
+ //=> true
327
+
328
+ GreaterThan<1, 1>;
329
+ //=> false
330
+
331
+ GreaterThan<1, 5>;
332
+ //=> false
333
+ ```
334
+ */
335
+ type GreaterThan<A extends number, B extends number> = number extends A | B
336
+ ? never
337
+ : [
338
+ IsEqual<A, PositiveInfinity>, IsEqual<A, NegativeInfinity>,
339
+ IsEqual<B, PositiveInfinity>, IsEqual<B, NegativeInfinity>,
340
+ ] extends infer R extends [boolean, boolean, boolean, boolean]
341
+ ? Or<
342
+ And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
343
+ And<IsEqual<R[3], true>, IsEqual<R[1], false>>
344
+ > extends true
345
+ ? true
346
+ : Or<
347
+ And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
348
+ And<IsEqual<R[2], true>, IsEqual<R[0], false>>
349
+ > extends true
350
+ ? false
351
+ : true extends R[number]
352
+ ? false
353
+ : [IsNegative<A>, IsNegative<B>] extends infer R extends [boolean, boolean]
354
+ ? [true, false] extends R
355
+ ? false
356
+ : [false, true] extends R
357
+ ? true
358
+ : [false, false] extends R
359
+ ? PositiveNumericStringGt<`${A}`, `${B}`>
360
+ : PositiveNumericStringGt<`${NumberAbsolute<B>}`, `${NumberAbsolute<A>}`>
361
+ : never
362
+ : never;
363
+
364
+ /**
365
+ Returns a boolean for whether a given number is greater than or equal to another number.
366
+
367
+ @example
368
+ ```
369
+ import type {GreaterThanOrEqual} from 'type-fest';
370
+
371
+ GreaterThanOrEqual<1, -5>;
372
+ //=> true
373
+
374
+ GreaterThanOrEqual<1, 1>;
375
+ //=> true
376
+
377
+ GreaterThanOrEqual<1, 5>;
378
+ //=> false
379
+ ```
380
+ */
381
+ type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B
382
+ ? never
383
+ : A extends B ? true : GreaterThan<A, B>;
384
+
385
+ /**
386
+ Returns a boolean for whether a given number is less than another number.
387
+
388
+ @example
389
+ ```
390
+ import type {LessThan} from 'type-fest';
391
+
392
+ LessThan<1, -5>;
393
+ //=> false
394
+
395
+ LessThan<1, 1>;
396
+ //=> false
397
+
398
+ LessThan<1, 5>;
399
+ //=> true
400
+ ```
401
+ */
402
+ type LessThan<A extends number, B extends number> = number extends A | B
403
+ ? never
404
+ : GreaterThanOrEqual<A, B> extends true ? false : true;
405
+
406
+ // Should never happen
407
+
408
+ /**
409
+ Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.
410
+
411
+ If `<Fill>` is not provided, it will default to `unknown`.
412
+
413
+ @link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
414
+ */
415
+ type BuildTuple<L extends number, Fill = unknown, T extends readonly unknown[] = []> = T['length'] extends L
416
+ ? T
417
+ : BuildTuple<L, Fill, [...T, Fill]>;
418
+
419
+ /**
420
+ Returns the maximum value from a tuple of integers.
421
+
422
+ Note:
423
+ - Float numbers are not supported.
424
+
425
+ @example
426
+ ```
427
+ ArrayMax<[1, 2, 5, 3]>;
428
+ //=> 5
429
+
430
+ ArrayMax<[1, 2, 5, 3, 99, -1]>;
431
+ //=> 99
432
+ ```
433
+ */
434
+ type TupleMax<A extends number[], Result extends number = NegativeInfinity> = number extends A[number]
435
+ ? never :
436
+ A extends [infer F extends number, ...infer R extends number[]]
437
+ ? GreaterThan<F, Result> extends true
438
+ ? TupleMax<R, F>
439
+ : TupleMax<R, Result>
440
+ : Result;
441
+
442
+ /**
443
+ Returns the minimum value from a tuple of integers.
444
+
445
+ Note:
446
+ - Float numbers are not supported.
447
+
448
+ @example
449
+ ```
450
+ ArrayMin<[1, 2, 5, 3]>;
451
+ //=> 1
452
+
453
+ ArrayMin<[1, 2, 5, 3, -5]>;
454
+ //=> -5
455
+ ```
456
+ */
457
+ type TupleMin<A extends number[], Result extends number = PositiveInfinity> = number extends A[number]
458
+ ? never
459
+ : A extends [infer F extends number, ...infer R extends number[]]
460
+ ? LessThan<F, Result> extends true
461
+ ? TupleMin<R, F>
462
+ : TupleMin<R, Result>
463
+ : Result;
464
+
465
+ /**
466
+ Return a string representation of the given string or number.
467
+
468
+ Note: This type is not the return type of the `.toString()` function.
469
+ */
470
+ type ToString<T> = T extends string | number ? `${T}` : never;
471
+
472
+ /**
473
+ Converts a numeric string to a number.
474
+
475
+ @example
476
+ ```
477
+ type PositiveInt = StringToNumber<'1234'>;
478
+ //=> 1234
479
+
480
+ type NegativeInt = StringToNumber<'-1234'>;
481
+ //=> -1234
482
+
483
+ type PositiveFloat = StringToNumber<'1234.56'>;
484
+ //=> 1234.56
485
+
486
+ type NegativeFloat = StringToNumber<'-1234.56'>;
487
+ //=> -1234.56
488
+
489
+ type PositiveInfinity = StringToNumber<'Infinity'>;
490
+ //=> Infinity
491
+
492
+ type NegativeInfinity = StringToNumber<'-Infinity'>;
493
+ //=> -Infinity
494
+ ```
495
+
496
+ @category String
497
+ @category Numeric
498
+ @category Template literal
499
+ */
500
+ type StringToNumber<S extends string> = S extends `${infer N extends number}`
501
+ ? N
502
+ : S extends 'Infinity'
503
+ ? PositiveInfinity
504
+ : S extends '-Infinity'
505
+ ? NegativeInfinity
506
+ : never;
507
+
508
+ /**
509
+ Returns an array of the characters of the string.
510
+
511
+ @example
512
+ ```
513
+ StringToArray<'abcde'>;
514
+ //=> ['a', 'b', 'c', 'd', 'e']
515
+
516
+ StringToArray<string>;
517
+ //=> never
518
+ ```
519
+
520
+ @category String
521
+ */
522
+ type StringToArray<S extends string, Result extends string[] = []> = string extends S
523
+ ? never
524
+ : S extends `${infer F}${infer R}`
525
+ ? StringToArray<R, [...Result, F]>
526
+ : Result;
527
+
528
+ /**
529
+ Returns the length of the given string.
530
+
531
+ @example
532
+ ```
533
+ StringLength<'abcde'>;
534
+ //=> 5
535
+
536
+ StringLength<string>;
537
+ //=> never
538
+ ```
539
+
540
+ @category String
541
+ @category Template literal
542
+ */
543
+ type StringLength<S extends string> = string extends S
544
+ ? never
545
+ : StringToArray<S>['length'];
546
+
547
+ /**
548
+ 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.
549
+
550
+ @example
551
+ ```
552
+ SameLengthPositiveNumericStringGt<'50', '10'>;
553
+ //=> true
554
+
555
+ SameLengthPositiveNumericStringGt<'10', '10'>;
556
+ //=> false
557
+ ```
558
+ */
559
+ type SameLengthPositiveNumericStringGt<A extends string, B extends string> = A extends `${infer FirstA}${infer RestA}`
560
+ ? B extends `${infer FirstB}${infer RestB}`
561
+ ? FirstA extends FirstB
562
+ ? SameLengthPositiveNumericStringGt<RestA, RestB>
563
+ : PositiveNumericCharacterGt<FirstA, FirstB>
564
+ : never
565
+ : false;
566
+
567
+ type NumericString = '0123456789';
568
+
569
+ /**
570
+ Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
571
+
572
+ @example
573
+ ```
574
+ PositiveNumericStringGt<'500', '1'>;
575
+ //=> true
576
+
577
+ PositiveNumericStringGt<'1', '1'>;
578
+ //=> false
579
+
580
+ PositiveNumericStringGt<'1', '500'>;
581
+ //=> false
582
+ ```
583
+ */
584
+ type PositiveNumericStringGt<A extends string, B extends string> = A extends B
585
+ ? false
586
+ : [BuildTuple<StringLength<A>, 0>, BuildTuple<StringLength<B>, 0>] extends infer R extends [readonly unknown[], readonly unknown[]]
587
+ ? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]]
588
+ ? 0 extends Remain['length']
589
+ ? SameLengthPositiveNumericStringGt<A, B>
590
+ : true
591
+ : false
592
+ : never;
593
+
594
+ /**
595
+ Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
596
+
597
+ @example
598
+ ```
599
+ PositiveNumericCharacterGt<'5', '1'>;
600
+ //=> true
601
+
602
+ PositiveNumericCharacterGt<'1', '1'>;
603
+ //=> false
604
+ ```
605
+ */
606
+ type PositiveNumericCharacterGt<A extends string, B extends string> = NumericString extends `${infer HeadA}${A}${infer TailA}`
607
+ ? NumericString extends `${infer HeadB}${B}${infer TailB}`
608
+ ? HeadA extends `${HeadB}${infer _}${infer __}`
609
+ ? true
610
+ : false
611
+ : never
612
+ : never;
613
+
614
+ /**
615
+ Returns the absolute value of a given value.
616
+
617
+ @example
618
+ ```
619
+ NumberAbsolute<-1>;
620
+ //=> 1
621
+
622
+ NumberAbsolute<1>;
623
+ //=> 1
624
+
625
+ NumberAbsolute<NegativeInfinity>
626
+ //=> PositiveInfinity
627
+ ```
628
+ */
629
+ type NumberAbsolute<N extends number> = `${N}` extends `-${infer StringPositiveN}` ? StringToNumber<StringPositiveN> : N;
630
+
631
+ /**
632
+ Check whether the given type is a number or a number string.
633
+
634
+ Supports floating-point as a string.
635
+
636
+ @example
637
+ ```
638
+ type A = IsNumberLike<'1'>;
639
+ //=> true
640
+
641
+ type B = IsNumberLike<'-1.1'>;
642
+ //=> true
643
+
644
+ type C = IsNumberLike<1>;
645
+ //=> true
646
+
647
+ type D = IsNumberLike<'a'>;
648
+ //=> false
649
+ */
650
+ type IsNumberLike<N> =
651
+ N extends number ? true
652
+ : N extends `${number}`
653
+ ? true
654
+ : N extends `${number}.${number}`
655
+ ? true
656
+ : false;
657
+
658
+ /**
659
+ Matches any primitive, `void`, `Date`, or `RegExp` value.
660
+ */
661
+ type BuiltIns = Primitive | void | Date | RegExp;
662
+
663
+ /**
664
+ Matches non-recursive types.
665
+ */
666
+ type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown);
667
+
668
+ /**
669
+ Returns the sum of two numbers.
670
+
671
+ Note:
672
+ - A or B can only support `-999` ~ `999`.
673
+ - A and B can only be small integers, less than 1000.
674
+ - If the result is negative, you can only get `number`.
675
+
676
+ @example
677
+ ```
678
+ import type {Sum} from 'type-fest';
679
+
680
+ Sum<111, 222>;
681
+ //=> 333
682
+
683
+ Sum<-111, 222>;
684
+ //=> 111
685
+
686
+ Sum<111, -222>;
687
+ //=> number
688
+
689
+ Sum<PositiveInfinity, -9999>;
690
+ //=> PositiveInfinity
691
+
692
+ Sum<PositiveInfinity, NegativeInfinity>;
693
+ //=> number
694
+ ```
695
+
696
+ @category Numeric
697
+ */
698
+ // TODO: Support big integer and negative number.
699
+ type Sum<A extends number, B extends number> = number extends A | B
700
+ ? number
701
+ : [
702
+ IsEqual<A, PositiveInfinity>, IsEqual<A, NegativeInfinity>,
703
+ IsEqual<B, PositiveInfinity>, IsEqual<B, NegativeInfinity>,
704
+ ] extends infer R extends [boolean, boolean, boolean, boolean]
705
+ ? Or<
706
+ And<IsEqual<R[0], true>, IsEqual<R[3], false>>,
707
+ And<IsEqual<R[2], true>, IsEqual<R[1], false>>
708
+ > extends true
709
+ ? PositiveInfinity
710
+ : Or<
711
+ And<IsEqual<R[1], true>, IsEqual<R[2], false>>,
712
+ And<IsEqual<R[3], true>, IsEqual<R[0], false>>
713
+ > extends true
714
+ ? NegativeInfinity
715
+ : true extends R[number]
716
+ ? number
717
+ : ([IsNegative<A>, IsNegative<B>] extends infer R
718
+ ? [false, false] extends R
719
+ ? [...BuildTuple<A>, ...BuildTuple<B>]['length']
720
+ : [true, true] extends R
721
+ ? number
722
+ : TupleMax<[NumberAbsolute<A>, NumberAbsolute<B>]> extends infer Max_
723
+ ? TupleMin<[NumberAbsolute<A>, NumberAbsolute<B>]> extends infer Min_ extends number
724
+ ? Max_ extends A | B
725
+ ? Subtract<Max_, Min_>
726
+ : number
727
+ : never
728
+ : never
729
+ : never) & number
730
+ : never;
731
+
732
+ /**
733
+ Returns the difference between two numbers.
734
+
735
+ Note:
736
+ - A or B can only support `-999` ~ `999`.
737
+ - If the result is negative, you can only get `number`.
738
+
739
+ @example
740
+ ```
741
+ import type {Subtract} from 'type-fest';
742
+
743
+ Subtract<333, 222>;
744
+ //=> 111
745
+
746
+ Subtract<111, -222>;
747
+ //=> 333
748
+
749
+ Subtract<-111, 222>;
750
+ //=> number
751
+
752
+ Subtract<PositiveInfinity, 9999>;
753
+ //=> PositiveInfinity
754
+
755
+ Subtract<PositiveInfinity, PositiveInfinity>;
756
+ //=> number
757
+ ```
758
+
759
+ @category Numeric
760
+ */
761
+ // TODO: Support big integer and negative number.
762
+ type Subtract<A extends number, B extends number> = number extends A | B
763
+ ? number
764
+ : [
765
+ IsEqual<A, PositiveInfinity>, IsEqual<A, NegativeInfinity>,
766
+ IsEqual<B, PositiveInfinity>, IsEqual<B, NegativeInfinity>,
767
+ ] extends infer R extends [boolean, boolean, boolean, boolean]
768
+ ? Or<
769
+ And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
770
+ And<IsEqual<R[3], true>, IsEqual<R[1], false>>
771
+ > extends true
772
+ ? PositiveInfinity
773
+ : Or<
774
+ And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
775
+ And<IsEqual<R[2], true>, IsEqual<R[0], false>>
776
+ > extends true
777
+ ? NegativeInfinity
778
+ : true extends R[number]
779
+ ? number
780
+ : [IsNegative<A>, IsNegative<B>] extends infer R
781
+ ? [false, false] extends R
782
+ ? BuildTuple<A> extends infer R
783
+ ? R extends [...BuildTuple<B>, ...infer R]
784
+ ? R['length']
785
+ : number
786
+ : never
787
+ : LessThan<A, B> extends true
788
+ ? number
789
+ : [false, true] extends R
790
+ ? Sum<A, NumberAbsolute<B>>
791
+ : Subtract<NumberAbsolute<B>, NumberAbsolute<A>>
792
+ : never
793
+ : never;
794
+
795
+ /**
796
+ Paths options.
797
+
798
+ @see {@link Paths}
799
+ */
800
+ type PathsOptions = {
801
+ /**
802
+ The maximum depth to recurse when searching for paths.
803
+
804
+ @default 10
805
+ */
806
+ maxRecursionDepth?: number;
807
+
808
+ /**
809
+ Use bracket notation for array indices and numeric object keys.
810
+
811
+ @default false
812
+
813
+ @example
814
+ ```
815
+ type ArrayExample = {
816
+ array: ['foo'];
817
+ };
818
+
819
+ type A = Paths<ArrayExample, {bracketNotation: false}>;
820
+ //=> 'array' | 'array.0'
821
+
822
+ type B = Paths<ArrayExample, {bracketNotation: true}>;
823
+ //=> 'array' | 'array[0]'
824
+ ```
825
+
826
+ @example
827
+ ```
828
+ type NumberKeyExample = {
829
+ 1: ['foo'];
830
+ };
831
+
832
+ type A = Paths<NumberKeyExample, {bracketNotation: false}>;
833
+ //=> 1 | '1' | '1.0'
834
+
835
+ type B = Paths<NumberKeyExample, {bracketNotation: true}>;
836
+ //=> '[1]' | '[1][0]'
837
+ ```
838
+ */
839
+ bracketNotation?: boolean;
840
+ };
841
+
842
+ type DefaultPathsOptions = {
843
+ maxRecursionDepth: 10;
844
+ bracketNotation: false;
845
+ };
846
+
847
+ /**
848
+ Generate a union of all possible paths to properties in the given object.
849
+
850
+ It also works with arrays.
851
+
852
+ Use-case: You want a type-safe way to access deeply nested properties in an object.
853
+
854
+ @example
855
+ ```
856
+ import type {Paths} from 'type-fest';
857
+
858
+ type Project = {
859
+ filename: string;
860
+ listA: string[];
861
+ listB: [{filename: string}];
862
+ folder: {
863
+ subfolder: {
864
+ filename: string;
865
+ };
866
+ };
867
+ };
868
+
869
+ type ProjectPaths = Paths<Project>;
870
+ //=> 'filename' | 'listA' | 'listB' | 'folder' | `listA.${number}` | 'listB.0' | 'listB.0.filename' | 'folder.subfolder' | 'folder.subfolder.filename'
871
+
872
+ declare function open<Path extends ProjectPaths>(path: Path): void;
873
+
874
+ open('filename'); // Pass
875
+ open('folder.subfolder'); // Pass
876
+ open('folder.subfolder.filename'); // Pass
877
+ open('foo'); // TypeError
878
+
879
+ // Also works with arrays
880
+ open('listA.1'); // Pass
881
+ open('listB.0'); // Pass
882
+ open('listB.1'); // TypeError. Because listB only has one element.
883
+ ```
884
+
885
+ @category Object
886
+ @category Array
887
+ */
888
+ type Paths<T, Options extends PathsOptions = {}> = _Paths<T, {
889
+ // Set default maxRecursionDepth to 10
890
+ maxRecursionDepth: Options['maxRecursionDepth'] extends number ? Options['maxRecursionDepth'] : DefaultPathsOptions['maxRecursionDepth'];
891
+ // Set default bracketNotation to false
892
+ bracketNotation: Options['bracketNotation'] extends boolean ? Options['bracketNotation'] : DefaultPathsOptions['bracketNotation'];
893
+ }>;
894
+
895
+ type _Paths<T, Options extends Required<PathsOptions>> =
896
+ T extends NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>
897
+ ? never
898
+ : IsAny<T> extends true
899
+ ? never
900
+ : T extends UnknownArray
901
+ ? number extends T['length']
902
+ // We need to handle the fixed and non-fixed index part of the array separately.
903
+ ? InternalPaths<StaticPartOfArray<T>, Options>
904
+ | InternalPaths<Array<VariablePartOfArray<T>[number]>, Options>
905
+ : InternalPaths<T, Options>
906
+ : T extends object
907
+ ? InternalPaths<T, Options>
908
+ : never;
909
+
910
+ type InternalPaths<T, Options extends Required<PathsOptions>> =
911
+ Options['maxRecursionDepth'] extends infer MaxDepth extends number
912
+ ? Required<T> extends infer T
913
+ ? T extends EmptyObject | readonly []
914
+ ? never
915
+ : {
916
+ [Key in keyof T]:
917
+ Key extends string | number // Limit `Key` to string or number.
918
+ ? (
919
+ Options['bracketNotation'] extends true
920
+ ? IsNumberLike<Key> extends true
921
+ ? `[${Key}]`
922
+ : (Key | ToString<Key>)
923
+ : never
924
+ |
925
+ Options['bracketNotation'] extends false
926
+ // If `Key` is a number, return `Key | `${Key}``, because both `array[0]` and `array['0']` work.
927
+ ? (Key | ToString<Key>)
928
+ : never
929
+ ) extends infer TranformedKey extends string | number ?
930
+ // 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
931
+ // 2. If style is 'a.0.b', transform 'Key' to `${Key}` | Key
932
+ | TranformedKey
933
+ | (
934
+ // Recursively generate paths for the current key
935
+ GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
936
+ ? _Paths<T[Key], {bracketNotation: Options['bracketNotation']; maxRecursionDepth: Subtract<MaxDepth, 1>}> extends infer SubPath
937
+ ? SubPath extends string | number
938
+ ? (
939
+ Options['bracketNotation'] extends true
940
+ ? SubPath extends `[${any}]` | `[${any}]${string}`
941
+ ? `${TranformedKey}${SubPath}` // If next node is number key like `[3]`, no need to add `.` before it.
942
+ : `${TranformedKey}.${SubPath}`
943
+ : never
944
+ ) | (
945
+ Options['bracketNotation'] extends false
946
+ ? `${TranformedKey}.${SubPath}`
947
+ : never
948
+ )
949
+ : never
950
+ : never
951
+ : never
952
+ )
953
+ : never
954
+ : never
955
+ }[keyof T & (T extends UnknownArray ? number : unknown)]
956
+ : never
957
+ : never;
958
+
959
+ /**
960
+ 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.
961
+
962
+ 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.
963
+
964
+ 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.
965
+
966
+ @example
967
+ ```
968
+ import type {LiteralUnion} from 'type-fest';
969
+
970
+ // Before
971
+
972
+ type Pet = 'dog' | 'cat' | string;
973
+
974
+ const pet: Pet = '';
975
+ // Start typing in your TypeScript-enabled IDE.
976
+ // You **will not** get auto-completion for `dog` and `cat` literals.
977
+
978
+ // After
979
+
980
+ type Pet2 = LiteralUnion<'dog' | 'cat', string>;
981
+
982
+ const pet: Pet2 = '';
983
+ // You **will** get auto-completion for `dog` and `cat` literals.
984
+ ```
985
+
986
+ @category Type
987
+ */
988
+ type LiteralUnion<
989
+ LiteralType,
990
+ BaseType extends Primitive,
991
+ > = LiteralType | (BaseType & Record<never, never>);
992
+
993
+ declare namespace PackageJson$1 {
994
+ /**
995
+ A person who has been involved in creating or maintaining the package.
996
+ */
997
+ export type Person =
998
+ | string
999
+ | {
1000
+ name: string;
1001
+ url?: string;
1002
+ email?: string;
1003
+ };
1004
+
1005
+ export type BugsLocation =
1006
+ | string
1007
+ | {
1008
+ /**
1009
+ The URL to the package's issue tracker.
1010
+ */
1011
+ url?: string;
1012
+
1013
+ /**
1014
+ The email address to which issues should be reported.
1015
+ */
1016
+ email?: string;
1017
+ };
1018
+
1019
+ export type DirectoryLocations = {
1020
+ [directoryType: string]: JsonValue | undefined;
1021
+
1022
+ /**
1023
+ Location for executable scripts. Sugar to generate entries in the `bin` property by walking the folder.
1024
+ */
1025
+ bin?: string;
1026
+
1027
+ /**
1028
+ Location for Markdown files.
1029
+ */
1030
+ doc?: string;
1031
+
1032
+ /**
1033
+ Location for example scripts.
1034
+ */
1035
+ example?: string;
1036
+
1037
+ /**
1038
+ Location for the bulk of the library.
1039
+ */
1040
+ lib?: string;
1041
+
1042
+ /**
1043
+ Location for man pages. Sugar to generate a `man` array by walking the folder.
1044
+ */
1045
+ man?: string;
1046
+
1047
+ /**
1048
+ Location for test files.
1049
+ */
1050
+ test?: string;
1051
+ };
1052
+
1053
+ export type Scripts = {
1054
+ /**
1055
+ Run **before** the package is published (Also run on local `npm install` without any arguments).
1056
+ */
1057
+ prepublish?: string;
1058
+
1059
+ /**
1060
+ 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`.
1061
+ */
1062
+ prepare?: string;
1063
+
1064
+ /**
1065
+ Run **before** the package is prepared and packed, **only** on `npm publish`.
1066
+ */
1067
+ prepublishOnly?: string;
1068
+
1069
+ /**
1070
+ Run **before** a tarball is packed (on `npm pack`, `npm publish`, and when installing git dependencies).
1071
+ */
1072
+ prepack?: string;
1073
+
1074
+ /**
1075
+ Run **after** the tarball has been generated and moved to its final destination.
1076
+ */
1077
+ postpack?: string;
1078
+
1079
+ /**
1080
+ Run **after** the package is published.
1081
+ */
1082
+ publish?: string;
1083
+
1084
+ /**
1085
+ Run **after** the package is published.
1086
+ */
1087
+ postpublish?: string;
1088
+
1089
+ /**
1090
+ Run **before** the package is installed.
1091
+ */
1092
+ preinstall?: string;
1093
+
1094
+ /**
1095
+ Run **after** the package is installed.
1096
+ */
1097
+ install?: string;
1098
+
1099
+ /**
1100
+ Run **after** the package is installed and after `install`.
1101
+ */
1102
+ postinstall?: string;
1103
+
1104
+ /**
1105
+ Run **before** the package is uninstalled and before `uninstall`.
1106
+ */
1107
+ preuninstall?: string;
1108
+
1109
+ /**
1110
+ Run **before** the package is uninstalled.
1111
+ */
1112
+ uninstall?: string;
1113
+
1114
+ /**
1115
+ Run **after** the package is uninstalled.
1116
+ */
1117
+ postuninstall?: string;
1118
+
1119
+ /**
1120
+ Run **before** bump the package version and before `version`.
1121
+ */
1122
+ preversion?: string;
1123
+
1124
+ /**
1125
+ Run **before** bump the package version.
1126
+ */
1127
+ version?: string;
1128
+
1129
+ /**
1130
+ Run **after** bump the package version.
1131
+ */
1132
+ postversion?: string;
1133
+
1134
+ /**
1135
+ Run with the `npm test` command, before `test`.
1136
+ */
1137
+ pretest?: string;
1138
+
1139
+ /**
1140
+ Run with the `npm test` command.
1141
+ */
1142
+ test?: string;
1143
+
1144
+ /**
1145
+ Run with the `npm test` command, after `test`.
1146
+ */
1147
+ posttest?: string;
1148
+
1149
+ /**
1150
+ Run with the `npm stop` command, before `stop`.
1151
+ */
1152
+ prestop?: string;
1153
+
1154
+ /**
1155
+ Run with the `npm stop` command.
1156
+ */
1157
+ stop?: string;
1158
+
1159
+ /**
1160
+ Run with the `npm stop` command, after `stop`.
1161
+ */
1162
+ poststop?: string;
1163
+
1164
+ /**
1165
+ Run with the `npm start` command, before `start`.
1166
+ */
1167
+ prestart?: string;
1168
+
1169
+ /**
1170
+ Run with the `npm start` command.
1171
+ */
1172
+ start?: string;
1173
+
1174
+ /**
1175
+ Run with the `npm start` command, after `start`.
1176
+ */
1177
+ poststart?: string;
1178
+
1179
+ /**
1180
+ Run with the `npm restart` command, before `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
1181
+ */
1182
+ prerestart?: string;
1183
+
1184
+ /**
1185
+ Run with the `npm restart` command. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
1186
+ */
1187
+ restart?: string;
1188
+
1189
+ /**
1190
+ Run with the `npm restart` command, after `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
1191
+ */
1192
+ postrestart?: string;
1193
+ } & Partial<Record<string, string>>;
1194
+
1195
+ /**
1196
+ 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.
1197
+ */
1198
+ export type Dependency = Partial<Record<string, string>>;
1199
+
1200
+ /**
1201
+ A mapping of conditions and the paths to which they resolve.
1202
+ */
1203
+ type ExportConditions = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
1204
+ [condition: string]: Exports;
1205
+ };
1206
+
1207
+ /**
1208
+ Entry points of a module, optionally with conditions and subpath exports.
1209
+ */
1210
+ export type Exports =
1211
+ | null
1212
+ | string
1213
+ | Array<string | ExportConditions>
1214
+ | ExportConditions;
1215
+
1216
+ /**
1217
+ Import map entries of a module, optionally with conditions and subpath imports.
1218
+ */
1219
+ export type Imports = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
1220
+ [key: `#${string}`]: Exports;
1221
+ };
1222
+
1223
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1224
+ export interface NonStandardEntryPoints {
1225
+ /**
1226
+ An ECMAScript module ID that is the primary entry point to the program.
1227
+ */
1228
+ module?: string;
1229
+
1230
+ /**
1231
+ A module ID with untranspiled code that is the primary entry point to the program.
1232
+ */
1233
+ esnext?:
1234
+ | string
1235
+ | {
1236
+ [moduleName: string]: string | undefined;
1237
+ main?: string;
1238
+ browser?: string;
1239
+ };
1240
+
1241
+ /**
1242
+ A hint to JavaScript bundlers or component tools when packaging modules for client side use.
1243
+ */
1244
+ browser?:
1245
+ | string
1246
+ | Partial<Record<string, string | false>>;
1247
+
1248
+ /**
1249
+ Denote which files in your project are "pure" and therefore safe for Webpack to prune if unused.
1250
+
1251
+ [Read more.](https://webpack.js.org/guides/tree-shaking/)
1252
+ */
1253
+ sideEffects?: boolean | string[];
1254
+ }
1255
+
1256
+ export type TypeScriptConfiguration = {
1257
+ /**
1258
+ Location of the bundled TypeScript declaration file.
1259
+ */
1260
+ types?: string;
1261
+
1262
+ /**
1263
+ Version selection map of TypeScript.
1264
+ */
1265
+ typesVersions?: Partial<Record<string, Partial<Record<string, string[]>>>>;
1266
+
1267
+ /**
1268
+ Location of the bundled TypeScript declaration file. Alias of `types`.
1269
+ */
1270
+ typings?: string;
1271
+ };
1272
+
1273
+ /**
1274
+ An alternative configuration for workspaces.
1275
+ */
1276
+ export type WorkspaceConfig = {
1277
+ /**
1278
+ An array of workspace pattern strings which contain the workspace packages.
1279
+ */
1280
+ packages?: WorkspacePattern[];
1281
+
1282
+ /**
1283
+ 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.
1284
+
1285
+ [Supported](https://classic.yarnpkg.com/blog/2018/02/15/nohoist/) by Yarn.
1286
+ [Not supported](https://github.com/npm/rfcs/issues/287) by npm.
1287
+ */
1288
+ nohoist?: WorkspacePattern[];
1289
+ };
1290
+
1291
+ /**
1292
+ A workspace pattern points to a directory or group of directories which contain packages that should be included in the workspace installation process.
1293
+
1294
+ The patterns are handled with [minimatch](https://github.com/isaacs/minimatch).
1295
+
1296
+ @example
1297
+ `docs` → Include the docs directory and install its dependencies.
1298
+ `packages/*` → Include all nested directories within the packages directory, like `packages/cli` and `packages/core`.
1299
+ */
1300
+ type WorkspacePattern = string;
1301
+
1302
+ export type YarnConfiguration = {
1303
+ /**
1304
+ 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`.
1305
+
1306
+ 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.
1307
+ */
1308
+ flat?: boolean;
1309
+
1310
+ /**
1311
+ Selective version resolutions. Allows the definition of custom package versions inside dependencies without manual edits in the `yarn.lock` file.
1312
+ */
1313
+ resolutions?: Dependency;
1314
+ };
1315
+
1316
+ export type JSPMConfiguration = {
1317
+ /**
1318
+ JSPM configuration.
1319
+ */
1320
+ jspm?: PackageJson$1;
1321
+ };
1322
+
1323
+ /**
1324
+ Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Containing standard npm properties.
1325
+ */
1326
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1327
+ export interface PackageJsonStandard {
1328
+ /**
1329
+ The name of the package.
1330
+ */
1331
+ name?: string;
1332
+
1333
+ /**
1334
+ Package version, parseable by [`node-semver`](https://github.com/npm/node-semver).
1335
+ */
1336
+ version?: string;
1337
+
1338
+ /**
1339
+ Package description, listed in `npm search`.
1340
+ */
1341
+ description?: string;
1342
+
1343
+ /**
1344
+ Keywords associated with package, listed in `npm search`.
1345
+ */
1346
+ keywords?: string[];
1347
+
1348
+ /**
1349
+ The URL to the package's homepage.
1350
+ */
1351
+ homepage?: LiteralUnion<'.', string>;
1352
+
1353
+ /**
1354
+ The URL to the package's issue tracker and/or the email address to which issues should be reported.
1355
+ */
1356
+ bugs?: BugsLocation;
1357
+
1358
+ /**
1359
+ The license for the package.
1360
+ */
1361
+ license?: string;
1362
+
1363
+ /**
1364
+ The licenses for the package.
1365
+ */
1366
+ licenses?: Array<{
1367
+ type?: string;
1368
+ url?: string;
1369
+ }>;
1370
+
1371
+ author?: Person;
1372
+
1373
+ /**
1374
+ A list of people who contributed to the package.
1375
+ */
1376
+ contributors?: Person[];
1377
+
1378
+ /**
1379
+ A list of people who maintain the package.
1380
+ */
1381
+ maintainers?: Person[];
1382
+
1383
+ /**
1384
+ The files included in the package.
1385
+ */
1386
+ files?: string[];
1387
+
1388
+ /**
1389
+ Resolution algorithm for importing ".js" files from the package's scope.
1390
+
1391
+ [Read more.](https://nodejs.org/api/esm.html#esm_package_json_type_field)
1392
+ */
1393
+ type?: 'module' | 'commonjs';
1394
+
1395
+ /**
1396
+ The module ID that is the primary entry point to the program.
1397
+ */
1398
+ main?: string;
1399
+
1400
+ /**
1401
+ Subpath exports to define entry points of the package.
1402
+
1403
+ [Read more.](https://nodejs.org/api/packages.html#subpath-exports)
1404
+ */
1405
+ exports?: Exports;
1406
+
1407
+ /**
1408
+ Subpath imports to define internal package import maps that only apply to import specifiers from within the package itself.
1409
+
1410
+ [Read more.](https://nodejs.org/api/packages.html#subpath-imports)
1411
+ */
1412
+ imports?: Imports;
1413
+
1414
+ /**
1415
+ The executable files that should be installed into the `PATH`.
1416
+ */
1417
+ bin?:
1418
+ | string
1419
+ | Partial<Record<string, string>>;
1420
+
1421
+ /**
1422
+ Filenames to put in place for the `man` program to find.
1423
+ */
1424
+ man?: string | string[];
1425
+
1426
+ /**
1427
+ Indicates the structure of the package.
1428
+ */
1429
+ directories?: DirectoryLocations;
1430
+
1431
+ /**
1432
+ Location for the code repository.
1433
+ */
1434
+ repository?:
1435
+ | string
1436
+ | {
1437
+ type: string;
1438
+ url: string;
1439
+
1440
+ /**
1441
+ Relative path to package.json if it is placed in non-root directory (for example if it is part of a monorepo).
1442
+
1443
+ [Read more.](https://github.com/npm/rfcs/blob/latest/implemented/0010-monorepo-subdirectory-declaration.md)
1444
+ */
1445
+ directory?: string;
1446
+ };
1447
+
1448
+ /**
1449
+ 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.
1450
+ */
1451
+ scripts?: Scripts;
1452
+
1453
+ /**
1454
+ Is used to set configuration parameters used in package scripts that persist across upgrades.
1455
+ */
1456
+ config?: JsonObject;
1457
+
1458
+ /**
1459
+ The dependencies of the package.
1460
+ */
1461
+ dependencies?: Dependency;
1462
+
1463
+ /**
1464
+ Additional tooling dependencies that are not required for the package to work. Usually test, build, or documentation tooling.
1465
+ */
1466
+ devDependencies?: Dependency;
1467
+
1468
+ /**
1469
+ Dependencies that are skipped if they fail to install.
1470
+ */
1471
+ optionalDependencies?: Dependency;
1472
+
1473
+ /**
1474
+ Dependencies that will usually be required by the package user directly or via another dependency.
1475
+ */
1476
+ peerDependencies?: Dependency;
1477
+
1478
+ /**
1479
+ Indicate peer dependencies that are optional.
1480
+ */
1481
+ peerDependenciesMeta?: Partial<Record<string, {optional: true}>>;
1482
+
1483
+ /**
1484
+ Package names that are bundled when the package is published.
1485
+ */
1486
+ bundledDependencies?: string[];
1487
+
1488
+ /**
1489
+ Alias of `bundledDependencies`.
1490
+ */
1491
+ bundleDependencies?: string[];
1492
+
1493
+ /**
1494
+ Engines that this package runs on.
1495
+ */
1496
+ engines?: {
1497
+ [EngineName in 'npm' | 'node' | string]?: string;
1498
+ };
1499
+
1500
+ /**
1501
+ @deprecated
1502
+ */
1503
+ engineStrict?: boolean;
1504
+
1505
+ /**
1506
+ Operating systems the module runs on.
1507
+ */
1508
+ os?: Array<LiteralUnion<
1509
+ | 'aix'
1510
+ | 'darwin'
1511
+ | 'freebsd'
1512
+ | 'linux'
1513
+ | 'openbsd'
1514
+ | 'sunos'
1515
+ | 'win32'
1516
+ | '!aix'
1517
+ | '!darwin'
1518
+ | '!freebsd'
1519
+ | '!linux'
1520
+ | '!openbsd'
1521
+ | '!sunos'
1522
+ | '!win32',
1523
+ string
1524
+ >>;
1525
+
1526
+ /**
1527
+ CPU architectures the module runs on.
1528
+ */
1529
+ cpu?: Array<LiteralUnion<
1530
+ | 'arm'
1531
+ | 'arm64'
1532
+ | 'ia32'
1533
+ | 'mips'
1534
+ | 'mipsel'
1535
+ | 'ppc'
1536
+ | 'ppc64'
1537
+ | 's390'
1538
+ | 's390x'
1539
+ | 'x32'
1540
+ | 'x64'
1541
+ | '!arm'
1542
+ | '!arm64'
1543
+ | '!ia32'
1544
+ | '!mips'
1545
+ | '!mipsel'
1546
+ | '!ppc'
1547
+ | '!ppc64'
1548
+ | '!s390'
1549
+ | '!s390x'
1550
+ | '!x32'
1551
+ | '!x64',
1552
+ string
1553
+ >>;
1554
+
1555
+ /**
1556
+ 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.
1557
+
1558
+ @deprecated
1559
+ */
1560
+ preferGlobal?: boolean;
1561
+
1562
+ /**
1563
+ If set to `true`, then npm will refuse to publish it.
1564
+ */
1565
+ private?: boolean;
1566
+
1567
+ /**
1568
+ 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.
1569
+ */
1570
+ publishConfig?: PublishConfig;
1571
+
1572
+ /**
1573
+ Describes and notifies consumers of a package's monetary support information.
1574
+
1575
+ [Read more.](https://github.com/npm/rfcs/blob/latest/accepted/0017-add-funding-support.md)
1576
+ */
1577
+ funding?: string | {
1578
+ /**
1579
+ The type of funding.
1580
+ */
1581
+ type?: LiteralUnion<
1582
+ | 'github'
1583
+ | 'opencollective'
1584
+ | 'patreon'
1585
+ | 'individual'
1586
+ | 'foundation'
1587
+ | 'corporation',
1588
+ string
1589
+ >;
1590
+
1591
+ /**
1592
+ The URL to the funding page.
1593
+ */
1594
+ url: string;
1595
+ };
1596
+
1597
+ /**
1598
+ Used to configure [npm workspaces](https://docs.npmjs.com/cli/using-npm/workspaces) / [Yarn workspaces](https://classic.yarnpkg.com/docs/workspaces/).
1599
+
1600
+ 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.
1601
+
1602
+ Please note that the top-level `private` property of `package.json` **must** be set to `true` in order to use workspaces.
1603
+ */
1604
+ workspaces?: WorkspacePattern[] | WorkspaceConfig;
1605
+ }
1606
+
1607
+ /**
1608
+ Type for [`package.json` file used by the Node.js runtime](https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions).
1609
+ */
1610
+ export type NodeJsStandard = {
1611
+ /**
1612
+ 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.
1613
+
1614
+ __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.__
1615
+
1616
+ @example
1617
+ ```json
1618
+ {
1619
+ "packageManager": "<package manager name>@<version>"
1620
+ }
1621
+ ```
1622
+ */
1623
+ packageManager?: string;
1624
+ };
1625
+
1626
+ export type PublishConfig = {
1627
+ /**
1628
+ Additional, less common properties from the [npm docs on `publishConfig`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#publishconfig).
1629
+ */
1630
+ [additionalProperties: string]: JsonValue | undefined;
1631
+
1632
+ /**
1633
+ 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.
1634
+ */
1635
+ access?: 'public' | 'restricted';
1636
+
1637
+ /**
1638
+ The base URL of the npm registry.
1639
+
1640
+ Default: `'https://registry.npmjs.org/'`
1641
+ */
1642
+ registry?: string;
1643
+
1644
+ /**
1645
+ The tag to publish the package under.
1646
+
1647
+ Default: `'latest'`
1648
+ */
1649
+ tag?: string;
1650
+ };
1651
+ }
1652
+
1653
+ /**
1654
+ 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.
1655
+
1656
+ @category File
1657
+ */
1658
+ type PackageJson$1 =
1659
+ JsonObject &
1660
+ PackageJson$1.NodeJsStandard &
1661
+ PackageJson$1.PackageJsonStandard &
1662
+ PackageJson$1.NonStandardEntryPoints &
1663
+ PackageJson$1.TypeScriptConfiguration &
1664
+ PackageJson$1.YarnConfiguration &
1665
+ PackageJson$1.JSPMConfiguration;
1666
+
1667
+ type NormalizedPackageJson = Package & PackageJson;
1668
+ type PackageJson = PackageJson$1;
1669
+ type Cache<T = any> = Map<string, T>;
1670
+
1671
+ type ReadOptions = {
1672
+ cache?: Cache<NormalizedReadResult> | boolean;
1673
+ };
1674
+ type NormalizedReadResult = {
1675
+ packageJson: NormalizedPackageJson;
1676
+ path: string;
1677
+ };
1678
+ declare const findPackageJson: (cwd?: URL | string, options?: ReadOptions) => Promise<NormalizedReadResult>;
1679
+ declare const findPackageJsonSync: (cwd?: URL | string, options?: ReadOptions) => NormalizedReadResult;
1680
+ declare const writePackageJson: <T = PackageJson$1>(data: T, options?: WriteJsonOptions & {
1681
+ cwd?: URL | string;
1682
+ }) => Promise<void>;
1683
+ declare const writePackageJsonSync: <T = PackageJson$1>(data: T, options?: WriteJsonOptions & {
1684
+ cwd?: URL | string;
1685
+ }) => void;
1686
+ declare const parsePackageJson: (packageFile: JsonObject | string) => NormalizedPackageJson;
1687
+ declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
1688
+ declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
1689
+ declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
1690
+ peerDeps?: boolean;
1691
+ }) => boolean;
1692
+
1693
+ export { type NormalizedReadResult as N, type PackageJson as P, findPackageJsonSync as a, writePackageJsonSync as b, hasPackageJsonAnyDependency as c, type NormalizedPackageJson as d, findPackageJson as f, getPackageJsonProperty as g, hasPackageJsonProperty as h, parsePackageJson as p, writePackageJson as w };