@@ -37,7 +37,7 @@ const set = (obj: NestedMapping, key: string, value: any, type?: string) => {
3737
3838const type = (
3939 key : string ,
40- opts : Record < "boolean" | "string" | "array" , string [ ] > ,
40+ opts : Record < "boolean" | "string" | "array" , string [ ] >
4141) : "boolean" | "string" | "array" | undefined => {
4242 if ( opts . array && opts . array . length > 0 && opts . array . includes ( key ) )
4343 return "array" ;
@@ -56,13 +56,12 @@ const defaultValue = (type?: "boolean" | "string" | "array") => {
5656
5757const coerce = ( value ?: string , type ?: "string" | "boolean" | "array" ) => {
5858 if ( type === "string" ) return value ;
59- if ( type === "boolean" ) return value === undefined ? true : value === " true" ;
59+ if ( type === "boolean" ) return value === undefined ? true : value === ' true' ;
6060
6161 if ( ! value ) return value ;
6262 if ( value . length > 3 && BOOL_RE . test ( value ) ) return value === "true" ;
6363 if ( value . length > 2 && QUOTED_RE . test ( value ) ) return value . slice ( 1 , - 1 ) ;
64- if ( ( value [ 0 ] === "." && / \d / . test ( value [ 1 ] ) ) || / \d / . test ( value [ 0 ] ) )
65- return Number ( value ) ;
64+ if ( value [ 0 ] === '.' && / \d / . test ( value [ 1 ] ) || / \d / . test ( value [ 0 ] ) ) return Number ( value ) ;
6665 return value ;
6766} ;
6867
@@ -81,14 +80,14 @@ export function parse<
8180 TDefaults extends Record < string , unknown > | undefined = undefined ,
8281 TAliases extends Aliases < TAliasArgNames , TAliasNames > | undefined = undefined ,
8382 TAliasArgNames extends string = string ,
84- TAliasNames extends string = string ,
83+ TAliasNames extends string = string
8584> (
8685 argv : string [ ] ,
8786 {
8887 default : defaults ,
8988 alias : aliases ,
9089 ...types
91- } : ParseOptions < TBooleans , TStrings , TCollectable , TDefaults , TAliases > = { } ,
90+ } : ParseOptions < TBooleans , TStrings , TCollectable , TDefaults , TAliases > = { }
9291) : Args < TArgs > {
9392 const obj = { ...defaults , _ : [ ] } as unknown as Args < TArgs > ;
9493 if ( argv . length === 0 ) return obj ;
@@ -97,60 +96,57 @@ export function parse<
9796 const curr = argv [ i ] ;
9897 const next = argv [ i + 1 ] ;
9998
100- let t : " string" | " boolean" | " array" | undefined ;
101- let key = "" ;
99+ let t : ' string' | ' boolean' | ' array' | undefined ;
100+ let key = '' ;
102101 let value : string | undefined ;
103102
104103 if ( curr . length > 1 && curr [ 0 ] === "-" ) {
105- if ( curr [ 1 ] !== "-" && curr . length > 2 && ! curr . includes ( "=" ) ) {
106- if ( curr . includes ( "." ) ) {
104+ if ( curr [ 1 ] !== "-" && curr . length > 2 && ! curr . includes ( '=' ) ) {
105+ if ( curr . includes ( '.' ) ) {
107106 key = curr . slice ( 1 , 2 ) ;
108107 value = curr . slice ( 2 ) ;
109108 } else {
110109 const keys = curr . slice ( 1 , - 1 ) ;
111110 for ( let key of keys ) {
112- if (
113- aliases &&
114- ( aliases as Record < string , any > ) [ key ] !== undefined
115- ) {
111+ if ( aliases && ( aliases as Record < string , any > ) [ key ] !== undefined ) {
116112 key = aliases [ key as keyof typeof aliases ] as string ;
117113 }
118- set ( obj , key , defaultValue ( t ) , t ) ;
114+ set ( obj , key , defaultValue ( t ) , t )
119115 }
120- key = curr . slice ( - 1 ) ;
121- if ( next && next [ 0 ] !== "-" ) {
116+ key = curr . slice ( - 1 )
117+ if ( next && next [ 0 ] !== '-' ) {
122118 value = next ;
123119 i ++ ;
124120 }
125121 }
126122 } else if ( ! curr . includes ( "=" ) && next && next [ 0 ] !== "-" ) {
127- key = curr . replace ( / ^ - { 1 , 2 } / , "" ) ;
123+ key = curr . replace ( / ^ - { 1 , 2 } / , '' ) ;
128124 t = type ( key , types as any ) ;
129125 // treat boolean as flag without parameter
130- if ( t === " boolean" ) {
131- value = " true" ;
126+ if ( t === ' boolean' ) {
127+ value = ' true' ;
132128 } else {
133129 value = next ;
134130 i ++ ;
135131 }
136132 } else {
137- const eq = curr . indexOf ( "=" ) ;
133+ const eq = curr . indexOf ( '=' ) ;
138134 if ( eq === - 1 ) {
139- key = curr . replace ( / ^ - { 1 , 2 } / , "" ) ;
135+ key = curr . replace ( / ^ - { 1 , 2 } / , '' ) ;
140136 } else {
141- key = curr . slice ( 0 , eq ) . replace ( / ^ - { 1 , 2 } / , "" ) ;
137+ key = curr . slice ( 0 , eq ) . replace ( / ^ - { 1 , 2 } / , '' ) ;
142138 value = curr . slice ( eq + 1 ) ;
143139 }
144140 t = type ( key , types as any ) ;
145141 }
146142
147- if ( ( ! t || t === "boolean" ) && key . length > 3 && key . startsWith ( " no-" ) ) {
148- set ( obj , key . slice ( 3 ) , false ) ;
143+ if ( ( ! t || t === "boolean" ) && key . length > 3 && key . startsWith ( ' no-' ) ) {
144+ set ( obj , key . slice ( 3 ) , false )
149145 } else {
150146 if ( aliases && ( aliases as Record < string , any > ) [ key ] !== undefined ) {
151147 key = aliases [ key as keyof typeof aliases ] as string ;
152148 }
153- set ( obj , key , coerce ( value , t ) ?? defaultValue ( t ) , t ) ;
149+ set ( obj , key , coerce ( value , t ) ?? defaultValue ( t ) , t )
154150 }
155151 } else if ( curr ) {
156152 ( obj as any ) . _ . push ( coerce ( curr ) ) ;
0 commit comments