@devp0nt/route0 1.0.0-next.62 → 1.0.0-next.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -239,7 +239,7 @@ export class Route0<TDefinition extends string> {
239
239
  TDefinition,
240
240
  {
241
241
  search?: _LooseSearchInput<TDefinition>
242
- abs?: boolean
242
+ abs?: boolean | string
243
243
  hash?: string | number
244
244
  }
245
245
  >
@@ -287,7 +287,7 @@ export class Route0<TDefinition extends string> {
287
287
  TDefinition,
288
288
  {
289
289
  search?: _LooseSearchInput<TDefinition>
290
- abs?: boolean
290
+ abs?: boolean | string
291
291
  hash?: string | number
292
292
  }
293
293
  >,
@@ -295,10 +295,11 @@ export class Route0<TDefinition extends string> {
295
295
 
296
296
  // implementation
297
297
  get(...args: unknown[]): string {
298
- const { searchInput, paramsInput, absInput, hashInput } = ((): {
298
+ const { searchInput, paramsInput, absInput, absBaseurlInput, hashInput } = ((): {
299
299
  searchInput: Record<string, string | number>
300
300
  paramsInput: Record<string, string | number>
301
301
  absInput: boolean
302
+ absBaseurlInput: string | undefined
302
303
  hashInput: string | undefined
303
304
  } => {
304
305
  if (args.length === 0) {
@@ -306,6 +307,7 @@ export class Route0<TDefinition extends string> {
306
307
  searchInput: {},
307
308
  paramsInput: {},
308
309
  absInput: false,
310
+ absBaseurlInput: undefined,
309
311
  hashInput: undefined,
310
312
  }
311
313
  }
@@ -316,21 +318,23 @@ export class Route0<TDefinition extends string> {
316
318
  searchInput: {},
317
319
  paramsInput: {},
318
320
  absInput: false,
321
+ absBaseurlInput: undefined,
319
322
  hashInput: undefined,
320
323
  }
321
324
  }
322
325
  const { search, abs, hash, ...params } = input as Record<string, string | number> & {
323
326
  search: Record<string, string | number>
324
- abs: boolean
327
+ abs: boolean | string
325
328
  hash: string | undefined
326
329
  [key: string]: unknown
327
330
  }
331
+ const absBaseurlInput = typeof abs === 'string' && abs.length > 0 ? abs : undefined
328
332
  return {
329
333
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
330
334
  searchInput: search || {},
331
335
  paramsInput: params,
332
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
333
- absInput: abs ?? false,
336
+ absInput: absBaseurlInput !== undefined || abs === true,
337
+ absBaseurlInput,
334
338
  hashInput: hash,
335
339
  }
336
340
  })()
@@ -356,7 +360,7 @@ export class Route0<TDefinition extends string> {
356
360
  // dedupe slashes
357
361
  url = url.replace(/\/{2,}/g, '/')
358
362
  // absolute
359
- url = absInput ? Route0._getAbsPath(this.baseurl, url) : url
363
+ url = absInput ? Route0._getAbsPath(absBaseurlInput || this.baseurl, url) : url
360
364
  // hash
361
365
  if (hashInput !== undefined) {
362
366
  url = `${url}#${hashInput}`
@@ -413,7 +417,7 @@ export class Route0<TDefinition extends string> {
413
417
  TDefinition,
414
418
  WithParamsInput<TDefinition, FlatInput<TDefinition, TLoose> & { hash?: string | number }>
415
419
  >,
416
- abs?: boolean,
420
+ abs?: boolean | string,
417
421
  loose?: TLoose,
418
422
  ): OnlyIfHasParams<TDefinition, string>
419
423
 
@@ -449,7 +453,7 @@ export class Route0<TDefinition extends string> {
449
453
  flat(...args: OnlyIfNoParams<TDefinition, [], [never]>): string
450
454
  flat<TLoose extends boolean = HasLooseSearch<TDefinition>>(
451
455
  input: OnlyIfNoParams<TDefinition, FlatInput<TDefinition, TLoose> & { hash?: string | number }>,
452
- abs?: boolean,
456
+ abs?: boolean | string,
453
457
  loose?: TLoose,
454
458
  ): OnlyIfNoParams<TDefinition, string>
455
459
 
@@ -458,7 +462,7 @@ export class Route0<TDefinition extends string> {
458
462
  const { searchInput, paramsInput, absInput, hashInput } = ((): {
459
463
  searchInput: Record<string, string | number>
460
464
  paramsInput: Record<string, string | number>
461
- absInput: boolean
465
+ absInput: boolean | string
462
466
  hashInput: string | undefined
463
467
  } => {
464
468
  if (args.length === 0) {
@@ -476,7 +480,7 @@ export class Route0<TDefinition extends string> {
476
480
  return {
477
481
  searchInput: {},
478
482
  paramsInput: {},
479
- absInput: (args[1] as boolean | undefined) ?? false,
483
+ absInput: (args[1] as boolean | string | undefined) ?? false,
480
484
  hashInput: undefined,
481
485
  }
482
486
  }
@@ -511,7 +515,7 @@ export class Route0<TDefinition extends string> {
511
515
  return {
512
516
  searchInput,
513
517
  paramsInput,
514
- absInput: (args[1] as boolean | undefined) ?? false,
518
+ absInput: (args[1] as boolean | string | undefined) ?? false,
515
519
  hashInput: hashInput as string | undefined,
516
520
  }
517
521
  })()
@@ -530,12 +534,12 @@ export class Route0<TDefinition extends string> {
530
534
  TDefinition,
531
535
  WithParamsInput<TDefinition, LooseFlatInput<TDefinition> & { hash?: string | number }>
532
536
  >,
533
- abs?: boolean,
537
+ abs?: boolean | string,
534
538
  ): OnlyIfHasParams<TDefinition, string>
535
539
  flatLoose(...args: OnlyIfNoParams<TDefinition, [], [never]>): string
536
540
  flatLoose(
537
541
  input: OnlyIfNoParams<TDefinition, LooseFlatInput<TDefinition> & { hash?: string | number }>,
538
- abs?: boolean,
542
+ abs?: boolean | string,
539
543
  ): OnlyIfNoParams<TDefinition, string>
540
544
  flatLoose(...args: unknown[]): string {
541
545
  return this.flat(args[0] as never, args[1] as never, true)
@@ -547,12 +551,12 @@ export class Route0<TDefinition extends string> {
547
551
  TDefinition,
548
552
  WithParamsInput<TDefinition, StrictFlatInput<TDefinition> & { hash?: string | number }>
549
553
  >,
550
- abs?: boolean,
554
+ abs?: boolean | string,
551
555
  ): OnlyIfHasParams<TDefinition, string>
552
556
  flatStrict(...args: OnlyIfNoParams<TDefinition, [], [never]>): string
553
557
  flatStrict(
554
558
  input: OnlyIfNoParams<TDefinition, StrictFlatInput<TDefinition> & { hash?: string | number }>,
555
- abs?: boolean,
559
+ abs?: boolean | string,
556
560
  ): OnlyIfNoParams<TDefinition, string>
557
561
  flatStrict(...args: unknown[]): string {
558
562
  return this.flat(args[0] as never, args[1] as never, false)
@@ -764,7 +768,6 @@ export class Route0<TDefinition extends string> {
764
768
  ? this.pathDefinition.slice(0, -1)
765
769
  : this.pathDefinition
766
770
  def.replace(/:([A-Za-z0-9_]+)/g, (_m: string, name: string) => {
767
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion
768
771
  paramNames.push(String(name))
769
772
  return ''
770
773
  })
@@ -1659,7 +1662,6 @@ export type SearchTailDefinitionWithoutFirstAndLastAmp<S extends string> = S ext
1659
1662
  : ''
1660
1663
  export type SearchTailDefinitionWithFirstAmp<S extends string> = S extends `${string}&${infer T}` ? `&${T}` : ''
1661
1664
  export type AmpSplit<S extends string> = S extends `${infer A}&${infer B}` ? A | AmpSplit<B> : S
1662
- // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
1663
1665
  export type NonEmpty<T> = [T] extends ['' | never] ? never : T
1664
1666
  export type ExtractPathParams<S extends string> = S extends `${string}:${infer After}`
1665
1667
  ? After extends `${infer Name}/${infer Rest}`
@@ -1719,7 +1721,7 @@ export type WithParamsInput<
1719
1721
  T extends
1720
1722
  | {
1721
1723
  search?: _LooseSearchInput<any>
1722
- abs?: boolean
1724
+ abs?: boolean | string
1723
1725
  hash?: string | number
1724
1726
  }
1725
1727
  | undefined = undefined,