Bas950
Bas950
Aarktype
Created by Bas950 on 9/6/2024 in #questions
string input, number output
type('null').pipe(() => undefined) That should work right?
8 replies
Aarktype
Created by Bas950 on 9/6/2024 in #questions
string input, number output
Is there something like this for turning null into undefined? and the other way around?
8 replies
Aarktype
Created by Bas950 on 9/6/2024 in #questions
string input, number output
ty!
8 replies
Aarktype
Created by Bas950 on 8/15/2023 in #questions
Validate string is URL
oh yea thanks, forgot, you just have to check if the protocol is http: or https:
27 replies
Aarktype
Created by Bas950 on 8/15/2023 in #questions
Validate string is URL
For now I will use:
const urlMorph = (options?: {
minLength: number;
maxLength: number;
}) => morph("string", (value, problems) => {
if (options) {
if (value.length < options.minLength) {
problems.mustBe(`of length ${options.minLength} or more characters`);
return false;
}
if (value.length > options.maxLength) {
problems.mustBe(`of length ${options.maxLength} or less characters`);
return false;
}
}

try {
new URL(value);
return true;
} catch {
problems.mustBe("a valid URL");
return false;
}
});
const urlMorph = (options?: {
minLength: number;
maxLength: number;
}) => morph("string", (value, problems) => {
if (options) {
if (value.length < options.minLength) {
problems.mustBe(`of length ${options.minLength} or more characters`);
return false;
}
if (value.length > options.maxLength) {
problems.mustBe(`of length ${options.maxLength} or less characters`);
return false;
}
}

try {
new URL(value);
return true;
} catch {
problems.mustBe("a valid URL");
return false;
}
});
27 replies
Aarktype
Created by Bas950 on 8/15/2023 in #questions
Validate string is URL
hmmm, okay thanks. Never used those morphs before, but that should work I guess, thanks. Might be nice if @ssalbdivad can add url as a thing itself just like dates etc.
27 replies
Aarktype
Created by Bas950 on 8/15/2023 in #questions
Validate string is URL
yea but how can I do that inside of the type({...}) ? Or is that not possible
27 replies
Aarktype
Created by Bas950 on 8/15/2023 in #questions
Validate string is URL
I mean seeing if it would parse in new URL()
27 replies
Aarktype
Created by Bas950 on 6/27/2023 in #questions
Key not specified in type, but no problems
Is that keys stuff not documented in the docs website tho? Or am I just looking over it?
9 replies
Aarktype
Created by Bas950 on 6/27/2023 in #questions
Key not specified in type, but no problems
Ah thanks!
9 replies
Aarktype
Created by Bas950 on 6/27/2023 in #questions
Key not specified in type, but no problems
I was expecting a problem like unrecoginized key 'foo'
9 replies
Aarktype
Created by Bas950 on 6/27/2023 in #questions
Array/Object keys to type?
Thanks both! Will use:
arrayOf(
type(
Object.keys(supportedLanguages).map(lang => `'${lang}'`)
.join("|") as Infer<SupportedISOs>
)
)
arrayOf(
type(
Object.keys(supportedLanguages).map(lang => `'${lang}'`)
.join("|") as Infer<SupportedISOs>
)
)
5 replies