Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F12657202
enum.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1015 B
Referenced Files
None
Subscribers
None
enum.ts
View Options
import
{
is
,
predicates
}
from
"@sealcode/ts-predicates"
;
import
{
JDDContext
}
from
"../jdd-context.js"
;
import
{
StringBasedArgument
}
from
"./string-based-argument.js"
;
export
class
Enum
<
T
extends
string
>
extends
StringBasedArgument
<
T
>
{
public
readonly
values
:
Readonly
<
T
[]
>
;
constructor
(
values
:
Readonly
<
T
[]
>
)
{
super
();
this
.
values
=
values
;
}
getTypeName
()
{
return
"enum"
;
}
getEmptyValue
()
{
return
this
.
values
[
0
];
}
getExampleValue
()
{
const
pick_from
=
this
.
example_values
.
length
?
this
.
example_values
:
this
.
values
;
return
pick_from
[
Math
.
floor
(
Math
.
random
()
*
pick_from
.
length
)];
}
countWords
()
:
number
{
return
0
;
}
// TODO: this should be maybe removed or change into receivedToParsed?
parseFormInput
(
_
:
JDDContext
,
input
:
Record
<
string
,
unknown
>
)
{
if
(
is
(
input
,
predicates
.
string
)
&&
(
is
(
input
,
predicates
.
enum
(
this
.
values
))
||
is
(
input
.
trim
(),
predicates
.
enum
(
this
.
values
)))
)
{
return
input
.
trim
()
as
T
;
}
else
{
return
null
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-Algol68
Expires
Fri, Nov 28, 15:17 (8 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1053561
Default Alt Text
enum.ts (1015 B)
Attached To
Mode
rJDD jdd
Attached
Detach File
Event Timeline
Log In to Comment