Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22393808
enum.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
enum.ts
View Options
import
{
is
,
predicates
}
from
"@sealcode/ts-predicates"
;
import
{
Context
}
from
"koa"
;
import
{
FormDataValue
}
from
"../form"
;
import
{
FieldParseResult
,
FormField
}
from
"./field"
;
export
class
EnumField
extends
FormField
<
string
>
{
constructor
(
required
=
false
,
public
options
:
string
[],
public
error_message
:
(
options
:
string
[])
=>
string
=
(
options
)
=>
options
.
join
(
", "
)
)
{
super
(
required
);
}
public
async
isValueValid
(
_
:
Context
,
value
:
unknown
)
:
Promise
<
{
valid
:
boolean
;
message
:
string
}
>
{
if
(
!
is
(
value
,
predicates
.
string
))
{
return
{
valid
:
false
,
message
:
"expected a string"
};
}
if
(
this
.
options
.
includes
(
value
))
{
return
{
valid
:
true
,
message
:
""
};
}
return
{
valid
:
false
,
message
:
this
.
error_message
(
this
.
options
)
};
}
async
parse
(
_
:
Context
,
value
:
FormDataValue
)
:
Promise
<
FieldParseResult
<
string
>>
{
if
(
is
(
value
,
predicates
.
string
))
{
return
{
parsable
:
true
,
parsed_value
:
value
,
error
:
null
,
};
}
else
{
return
{
parsable
:
false
,
parsed_value
:
null
,
error
:
"Please enter a string"
,
};
}
}
public
getEmptyValue
()
:
string
{
return
""
;
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 16:10 (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1229056
Default Alt Text
enum.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline