Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: isaacs/jackspeak
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.1.1
Choose a base ref
...
head repository: isaacs/jackspeak
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.1.2
Choose a head ref
  • 3 commits
  • 5 files changed
  • 1 contributor

Commits on May 21, 2024

  1. mention validate() signature change in changelog

    isaacs committed May 21, 2024
    Copy the full SHA
    b243cc1 View commit details
  2. Copy the full SHA
    c3a6fbd View commit details
  3. 3.1.2

    isaacs committed May 21, 2024
    Copy the full SHA
    63572a0 View commit details
Showing with 27 additions and 15 deletions.
  1. +3 −0 changelog.md
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
  4. +13 −8 src/index.ts
  5. +8 −4 test/basic.ts
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@

- Add `validOptions` config option, to specify a discrete set of
acceptable values.
- `validate` methods now take an `unknown` argument, which is
more appropriate than `any` as it encourages more deliberate
type assertions.

# 3.0

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jackspeak",
"version": "3.1.1",
"version": "3.1.2",
"description": "A very strict and proper argument parser.",
"tshy": {
"main": true,
21 changes: 13 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -95,14 +95,14 @@ export type ConfigOptionMeta<
O extends
| undefined
| (T extends 'boolean' ? never
: T extends 'string' ? string[]
: T extends 'number' ? number[]
: number[] | string[]) =
: T extends 'string' ? readonly string[]
: T extends 'number' ? readonly number[]
: readonly number[] | readonly string[]) =
| undefined
| (T extends 'boolean' ? never
: T extends 'string' ? string[]
: T extends 'number' ? number[]
: number[] | string[]),
: T extends 'string' ? readonly string[]
: T extends 'number' ? readonly number[]
: readonly number[] | readonly string[]),
> = {
default?:
| undefined
@@ -129,7 +129,10 @@ export type ConfigOptionMeta<
* A set of {@link ConfigOptionMeta} fields, referenced by their longOption
* string values.
*/
export type ConfigMetaSet<T extends ConfigType, M extends boolean = boolean> = {
export type ConfigMetaSet<
T extends ConfigType,
M extends boolean = boolean,
> = {
[longOption: string]: ConfigOptionMeta<T, M>
}

@@ -263,7 +266,9 @@ export type ConfigSet = {
* The 'values' field returned by {@link Jack#parse}
*/
export type OptionsResults<T extends ConfigSet> = {
[k in keyof T]?: T[k]['validOptions'] extends string[] | number[] ?
[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> ?
12 changes: 8 additions & 4 deletions test/basic.ts
Original file line number Diff line number Diff line change
@@ -381,21 +381,21 @@ t.test('validate against options', t => {
}).addFields({
'vo-opt': {
type: 'string',
validOptions: ['x', 'y'],
validOptions: ['x', 'y'] as const,
},
'vo-optlist': {
type: 'string',
multiple: true,
validOptions: ['x', 'y'],
validOptions: ['x', 'y'] as const,
},
'vo-num': {
type: 'number',
validOptions: [1, 2],
validOptions: [1, 2] as const,
},
'vo-numlist': {
type: 'number',
multiple: true,
validOptions: [1, 2],
validOptions: [1, 2] as const,
},
})
t.throws(() => j.validate({ 'vo-opt': 'a' }))
@@ -466,6 +466,10 @@ t.test('validate against options', t => {
},
})

const v = j.parse([]).values
//@ts-expect-error
v['vo-opt'] = 'a'

t.matchSnapshot(j.usage())
t.end()
})