Comparing version 3.2.4 to 3.2.5
@@ -8,3 +8,2 @@ /// <reference types="node" /> | ||
import { inspect, InspectOptions } from 'node:util'; | ||
export type ValidOptions<T extends ConfigType> = undefined | (T extends 'boolean' ? never : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[]); | ||
/** | ||
@@ -22,3 +21,3 @@ * Defines the type of value that is valid, given a config definition's | ||
*/ | ||
export type ConfigOptionMeta<T extends ConfigType, M extends boolean = boolean, O extends ValidOptions<T> = ValidOptions<T>> = { | ||
export type ConfigOptionMeta<T extends ConfigType, M extends boolean = boolean, O extends undefined | (T extends 'boolean' ? never : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[]) = undefined | (T extends 'boolean' ? never : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[])> = { | ||
default?: undefined | (ValidValue<T, M> & (O extends number[] | string[] ? M extends false ? O[number] : O[number][] : unknown)); | ||
@@ -50,3 +49,3 @@ validOptions?: O; | ||
export type ConfigSetFromMetaSet<T extends ConfigType, M extends boolean, S extends ConfigMetaSet<T, M>> = { | ||
[longOption in keyof S]: ConfigOptionBase<T, M, S[longOption]['validOptions']>; | ||
[longOption in keyof S]: ConfigOptionBase<T, M>; | ||
}; | ||
@@ -71,3 +70,3 @@ /** | ||
*/ | ||
export type ConfigOptionBase<T extends ConfigType, M extends boolean = boolean, O extends ValidOptions<T> = ValidOptions<T>> = { | ||
export type ConfigOptionBase<T extends ConfigType, M extends boolean = boolean> = { | ||
type: T; | ||
@@ -79,9 +78,6 @@ short?: string | undefined; | ||
validate?: (v: unknown) => v is ValidValue<T, M>; | ||
} & (O extends undefined ? { | ||
validOptions?: O; | ||
} : { | ||
validOptions: O; | ||
}) & MultiType<M>; | ||
validOptions?: T extends 'boolean' ? undefined : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[]; | ||
} & MultiType<M>; | ||
export declare const isConfigType: (t: string) => t is ConfigType; | ||
export declare const isConfigOption: <T extends ConfigType, M extends boolean>(o: any, type: T, multi: M) => o is ConfigOptionBase<T, M, any>; | ||
export declare const isConfigOption: <T extends ConfigType, M extends boolean>(o: any, type: T, multi: M) => o is ConfigOptionBase<T, M>; | ||
/** | ||
@@ -98,3 +94,3 @@ * A set of {@link ConfigOptionBase} objects, referenced by their longOption | ||
export type OptionsResults<T extends ConfigSet> = { | ||
[k in keyof T]?: T[k]['validOptions'] extends (readonly string[] | readonly number[]) ? T[k] extends (ConfigOptionBase<'string' | 'number', false, T[k]['validOptions']>) ? T[k]['validOptions'][number] : T[k] extends (ConfigOptionBase<'string' | 'number', true, T[k]['validOptions']>) ? T[k]['validOptions'][number][] : never : T[k] extends ConfigOptionBase<'string', false> ? string : T[k] extends ConfigOptionBase<'string', true> ? string[] : T[k] extends ConfigOptionBase<'number', false> ? number : T[k] extends ConfigOptionBase<'number', true> ? number[] : T[k] extends ConfigOptionBase<'boolean', false> ? boolean : T[k] extends ConfigOptionBase<'boolean', true> ? boolean[] : never; | ||
[k in keyof T]?: T[k]['validOptions'] extends (readonly string[] | readonly number[]) ? T[k] extends ConfigOptionBase<'string' | 'number', false> ? T[k]['validOptions'][number] : T[k] extends ConfigOptionBase<'string' | 'number', true> ? T[k]['validOptions'][number][] : never : T[k] extends ConfigOptionBase<'string', false> ? string : T[k] extends ConfigOptionBase<'string', true> ? string[] : T[k] extends ConfigOptionBase<'number', false> ? number : T[k] extends ConfigOptionBase<'number', true> ? number[] : T[k] extends ConfigOptionBase<'boolean', false> ? boolean : T[k] extends ConfigOptionBase<'boolean', true> ? boolean[] : never; | ||
}; | ||
@@ -101,0 +97,0 @@ /** |
@@ -968,3 +968,4 @@ "use strict"; | ||
return ('\n```\n' + | ||
split.map(s => `\u200b${s.substring(i)}`).join('\n') + | ||
split.map(s => `\u200b${s.substring(i)}`) | ||
.join('\n') + | ||
'\n```\n'); | ||
@@ -971,0 +972,0 @@ } |
@@ -8,3 +8,2 @@ /// <reference types="node" resolution-mode="require"/> | ||
import { inspect, InspectOptions } from 'node:util'; | ||
export type ValidOptions<T extends ConfigType> = undefined | (T extends 'boolean' ? never : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[]); | ||
/** | ||
@@ -22,3 +21,3 @@ * Defines the type of value that is valid, given a config definition's | ||
*/ | ||
export type ConfigOptionMeta<T extends ConfigType, M extends boolean = boolean, O extends ValidOptions<T> = ValidOptions<T>> = { | ||
export type ConfigOptionMeta<T extends ConfigType, M extends boolean = boolean, O extends undefined | (T extends 'boolean' ? never : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[]) = undefined | (T extends 'boolean' ? never : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[])> = { | ||
default?: undefined | (ValidValue<T, M> & (O extends number[] | string[] ? M extends false ? O[number] : O[number][] : unknown)); | ||
@@ -50,3 +49,3 @@ validOptions?: O; | ||
export type ConfigSetFromMetaSet<T extends ConfigType, M extends boolean, S extends ConfigMetaSet<T, M>> = { | ||
[longOption in keyof S]: ConfigOptionBase<T, M, S[longOption]['validOptions']>; | ||
[longOption in keyof S]: ConfigOptionBase<T, M>; | ||
}; | ||
@@ -71,3 +70,3 @@ /** | ||
*/ | ||
export type ConfigOptionBase<T extends ConfigType, M extends boolean = boolean, O extends ValidOptions<T> = ValidOptions<T>> = { | ||
export type ConfigOptionBase<T extends ConfigType, M extends boolean = boolean> = { | ||
type: T; | ||
@@ -79,9 +78,6 @@ short?: string | undefined; | ||
validate?: (v: unknown) => v is ValidValue<T, M>; | ||
} & (O extends undefined ? { | ||
validOptions?: O; | ||
} : { | ||
validOptions: O; | ||
}) & MultiType<M>; | ||
validOptions?: T extends 'boolean' ? undefined : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[]; | ||
} & MultiType<M>; | ||
export declare const isConfigType: (t: string) => t is ConfigType; | ||
export declare const isConfigOption: <T extends ConfigType, M extends boolean>(o: any, type: T, multi: M) => o is ConfigOptionBase<T, M, any>; | ||
export declare const isConfigOption: <T extends ConfigType, M extends boolean>(o: any, type: T, multi: M) => o is ConfigOptionBase<T, M>; | ||
/** | ||
@@ -98,3 +94,3 @@ * A set of {@link ConfigOptionBase} objects, referenced by their longOption | ||
export type OptionsResults<T extends ConfigSet> = { | ||
[k in keyof T]?: T[k]['validOptions'] extends (readonly string[] | readonly number[]) ? T[k] extends (ConfigOptionBase<'string' | 'number', false, T[k]['validOptions']>) ? T[k]['validOptions'][number] : T[k] extends (ConfigOptionBase<'string' | 'number', true, T[k]['validOptions']>) ? T[k]['validOptions'][number][] : never : T[k] extends ConfigOptionBase<'string', false> ? string : T[k] extends ConfigOptionBase<'string', true> ? string[] : T[k] extends ConfigOptionBase<'number', false> ? number : T[k] extends ConfigOptionBase<'number', true> ? number[] : T[k] extends ConfigOptionBase<'boolean', false> ? boolean : T[k] extends ConfigOptionBase<'boolean', true> ? boolean[] : never; | ||
[k in keyof T]?: T[k]['validOptions'] extends (readonly string[] | readonly number[]) ? T[k] extends ConfigOptionBase<'string' | 'number', false> ? T[k]['validOptions'][number] : T[k] extends ConfigOptionBase<'string' | 'number', true> ? T[k]['validOptions'][number][] : never : T[k] extends ConfigOptionBase<'string', false> ? string : T[k] extends ConfigOptionBase<'string', true> ? string[] : T[k] extends ConfigOptionBase<'number', false> ? number : T[k] extends ConfigOptionBase<'number', true> ? number[] : T[k] extends ConfigOptionBase<'boolean', false> ? boolean : T[k] extends ConfigOptionBase<'boolean', true> ? boolean[] : never; | ||
}; | ||
@@ -101,0 +97,0 @@ /** |
@@ -959,3 +959,4 @@ import { inspect } from 'node:util'; | ||
return ('\n```\n' + | ||
split.map(s => `\u200b${s.substring(i)}`).join('\n') + | ||
split.map(s => `\u200b${s.substring(i)}`) | ||
.join('\n') + | ||
'\n```\n'); | ||
@@ -962,0 +963,0 @@ } |
{ | ||
"name": "jackspeak", | ||
"version": "3.2.4", | ||
"version": "3.2.5", | ||
"description": "A very strict and proper argument parser.", | ||
@@ -5,0 +5,0 @@ "tshy": { |
@@ -38,5 +38,5 @@ # jackspeak | ||
.flag({ | ||
asdf: { description: 'sets the asfd flag', short: 'a', default: true } as const, | ||
'no-asdf': { description: 'unsets the asdf flag', short: 'A' } as const, | ||
foo: { description: 'another boolean', short: 'f' } as const, | ||
asdf: { description: 'sets the asfd flag', short: 'a', default: true }, | ||
'no-asdf': { description: 'unsets the asdf flag', short: 'A' }, | ||
foo: { description: 'another boolean', short: 'f' }, | ||
}) | ||
@@ -48,3 +48,3 @@ .optList({ | ||
default: ['127.0.0.1'], | ||
} as const, | ||
}, | ||
}) | ||
@@ -143,8 +143,2 @@ .parse([ | ||
It's best to define the option definitions `as const`, so that | ||
`validOptions` all type information be inferred fully through to | ||
the resulting parsed values. (It'll do its best with what it's | ||
given otherwise, but you won't get the `validOptions` showing up | ||
as the only possible values according to TS.) | ||
Options: | ||
@@ -173,3 +167,3 @@ | ||
### `Jack.flag({ [option: string]: definition as const, ... })` | ||
### `Jack.flag({ [option: string]: definition, ... })` | ||
@@ -186,7 +180,7 @@ Define one or more boolean fields. | ||
### `Jack.flagList({ [option: string]: definition as const, ... })` | ||
### `Jack.flagList({ [option: string]: definition, ... })` | ||
Define one or more boolean array fields. | ||
### `Jack.num({ [option: string]: definition as const, ... })` | ||
### `Jack.num({ [option: string]: definition, ... })` | ||
@@ -197,3 +191,3 @@ Define one or more number fields. These will be set in the | ||
### `Jack.numList({ [option: string]: definition as const, ... })` | ||
### `Jack.numList({ [option: string]: definition, ... })` | ||
@@ -204,11 +198,11 @@ Define one or more number list fields. These will be set in the | ||
### `Jack.opt({ [option: string]: definition as const, ... })` | ||
### `Jack.opt({ [option: string]: definition, ... })` | ||
Define one or more string option fields. | ||
### `Jack.optList({ [option: string]: definition as const, ... })` | ||
### `Jack.optList({ [option: string]: definition, ... })` | ||
Define one or more string list fields. | ||
### `Jack.addFields({ [option: string]: definition as const, ... })` | ||
### `Jack.addFields({ [option: string]: definition, ... })` | ||
@@ -215,0 +209,0 @@ Define one or more fields of any type. Note that `type` and |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
293406
2692
352