MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / validate

Function validate

src/lib/user-query.ts:90–108  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

88 options: IntegerInputOptions<number | undefined> & { required: boolean },
89): Promise<number | undefined> => {
90 const validate = (input: string): true | string => {
91 if (options?.helpText && input === '?') {
92 return true
93 }
94
95 if (!options.required && input === '') {
96 return true
97 }
98
99 if (!input.match(/^-?\d+$/)) {
100 return `"${input}" is not a valid integer`
101 }
102
103 if (!options.validate) {
104 return true
105 }
106
107 return options.validate(Number(input))
108 }
109
110 // Using `inquirer`'s `number` function instead of `input` would be nice but it doesn't allow
111 // us to accept `?` for help text.

Callers 3

validateWithContextFnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected