amplify-prompts
Advanced tools
Comparing version 1.5.1 to 1.5.2-apiext5.0
@@ -6,2 +6,10 @@ # Change Log | ||
## [1.5.2-apiext5.0](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@1.5.1...amplify-prompts@1.5.2-apiext5.0) (2021-11-22) | ||
**Note:** Version bump only for package amplify-prompts | ||
## [1.5.1](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@1.3.0...amplify-prompts@1.5.1) (2021-11-15) | ||
@@ -8,0 +16,0 @@ |
@@ -31,7 +31,7 @@ "use strict"; | ||
transform: input => Number.parseInt(input, 10), | ||
validate: validators_1.integer(), | ||
validate: (0, validators_1.integer)(), | ||
})); | ||
printer_1.printer.info('Validators can also be combined using boolean utility functions'); | ||
printResult(await prompter_1.prompter.input('This input must be alphanumeric and at least 3 characters', { | ||
validate: validators_1.and([validators_1.alphanumeric(), validators_1.minLength(3)]), | ||
validate: (0, validators_1.and)([(0, validators_1.alphanumeric)(), (0, validators_1.minLength)(3)]), | ||
})); | ||
@@ -85,3 +85,3 @@ printer_1.printer.info('An initial value can be specified to a prompt'); | ||
printer_1.printer.info('Choices can also be selected by value using the provided helper function "byValue" (or "byValues" for multi-select)'); | ||
printResult(await prompter_1.prompter.pick('Pick your favorite color', choices2, { initial: prompter_1.byValue(4) })); | ||
printResult(await prompter_1.prompter.pick('Pick your favorite color', choices2, { initial: (0, prompter_1.byValue)(4) })); | ||
printer_1.printer.info('Individual choices can be disabled or have hint text next to them'); | ||
@@ -91,4 +91,7 @@ choices2[1].hint = 'definitely the best'; | ||
printResult(await prompter_1.prompter.pick('Pick your favorite Skittle color', choices2, { returnSize: 'many' })); | ||
printer_1.printer.info('A minimum and / or maximum number of choices can be specified'); | ||
choices2[2].disabled = false; | ||
printResult(await prompter_1.prompter.pick('Pick 2 to 4 colors', choices2, { returnSize: 'many', pickAtLeast: 2, pickAtMost: 4 })); | ||
}; | ||
demo().catch(console.error); | ||
//# sourceMappingURL=demo.js.map |
@@ -23,2 +23,8 @@ import { Validator } from './validators'; | ||
}; | ||
declare type MultiSelectMinimun<RS extends ReturnSize> = RS extends 'one' ? {} : { | ||
pickAtLeast?: number; | ||
}; | ||
declare type MultiSelectMaximum<RS extends ReturnSize> = RS extends 'one' ? {} : { | ||
pickAtMost?: number; | ||
}; | ||
declare type ValidateValueOption = { | ||
@@ -47,5 +53,5 @@ validate?: Validator; | ||
declare type PromptReturn<RS extends ReturnSize, T> = RS extends 'many' ? T[] : T; | ||
declare type PickOptions<RS extends ReturnSize, T> = ReturnSizeOption<RS> & InitialSelectionOption<RS, T>; | ||
declare type PickOptions<RS extends ReturnSize, T> = ReturnSizeOption<RS> & InitialSelectionOption<RS, T> & MultiSelectMaximum<RS> & MultiSelectMinimun<RS>; | ||
declare type InputOptions<RS extends ReturnSize, T> = ReturnSizeOption<RS> & ValidateValueOption & InitialValueOption<T> & MaybeOptionalTransformOption<T> & MaybeAvailableHiddenInputOption<RS>; | ||
export {}; | ||
//# sourceMappingURL=prompter.d.ts.map |
@@ -135,2 +135,14 @@ "use strict"; | ||
}, | ||
validate() { | ||
var _a, _b; | ||
if (opts && ('pickAtLeast' in opts || 'pickAtMost' in opts)) { | ||
if (this.selected.length < ((_a = opts.pickAtLeast) !== null && _a !== void 0 ? _a : 0)) { | ||
return `Select at least ${opts.pickAtLeast} items`; | ||
} | ||
if (this.selected.length > ((_b = opts.pickAtMost) !== null && _b !== void 0 ? _b : Number.POSITIVE_INFINITY)) { | ||
return `Select at most ${opts.pickAtMost} items`; | ||
} | ||
} | ||
return true; | ||
}, | ||
})); | ||
@@ -137,0 +149,0 @@ process.removeListener('SIGTSTP', sigTstpListener); |
{ | ||
"name": "amplify-prompts", | ||
"version": "1.5.1", | ||
"version": "1.5.2-apiext5.0", | ||
"description": "Utility functions for Amplify CLI terminal I/O", | ||
@@ -51,3 +51,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "644886fa3d1a047e8b37995e3ad5ba4c3bee28b1" | ||
"gitHead": "5cb3a127872e34ba86995cd23e44b2264817526f" | ||
} |
@@ -127,4 +127,8 @@ import { printer } from '../printer'; | ||
printResult(await prompter.pick<'many', number>('Pick your favorite Skittle color', choices2, { returnSize: 'many' })); | ||
printer.info('A minimum and / or maximum number of choices can be specified'); | ||
(choices2[2] as any).disabled = false; | ||
printResult(await prompter.pick<'many', number>('Pick 2 to 4 colors', choices2, { returnSize: 'many', pickAtLeast: 2, pickAtMost: 4 })); | ||
}; | ||
demo().catch(console.error); |
@@ -106,3 +106,3 @@ import { prompt } from 'enquirer'; | ||
* @param choices The selection set to choose from | ||
* @param options Control prompt settings. options.multiSelect = true is required if PickType = 'many' | ||
* @param options Control prompt settings | ||
* @returns The item(s) selected. If PickType = 'one' this is a single value. If PickType = 'many', this is an array | ||
@@ -187,2 +187,18 @@ * | ||
}, | ||
validate() { | ||
if (opts && ('pickAtLeast' in opts || 'pickAtMost' in opts)) { | ||
// this.selected is bound to a property of enquirer's prompt object, it does not reference a property of AmplifyPrompter | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
if (this.selected.length < (opts.pickAtLeast ?? 0)) { | ||
return `Select at least ${opts.pickAtLeast} items`; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
if (this.selected.length > (opts.pickAtMost ?? Number.POSITIVE_INFINITY)) { | ||
return `Select at most ${opts.pickAtMost} items`; | ||
} | ||
} | ||
return true; | ||
}, | ||
})); | ||
@@ -293,2 +309,14 @@ // remove the TSTP listener | ||
type MultiSelectMinimun<RS extends ReturnSize> = RS extends 'one' | ||
? {} | ||
: { | ||
pickAtLeast?: number; | ||
}; | ||
type MultiSelectMaximum<RS extends ReturnSize> = RS extends 'one' | ||
? {} | ||
: { | ||
pickAtMost?: number; | ||
}; | ||
type ValidateValueOption = { | ||
@@ -336,3 +364,6 @@ validate?: Validator; | ||
// the following types are the method input types | ||
type PickOptions<RS extends ReturnSize, T> = ReturnSizeOption<RS> & InitialSelectionOption<RS, T>; | ||
type PickOptions<RS extends ReturnSize, T> = ReturnSizeOption<RS> & | ||
InitialSelectionOption<RS, T> & | ||
MultiSelectMaximum<RS> & | ||
MultiSelectMinimun<RS>; | ||
@@ -339,0 +370,0 @@ type InputOptions<RS extends ReturnSize, T> = ReturnSizeOption<RS> & |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
164165
1396
1