Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010813
regexp.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
regexp.ts
View Options
import
{
is
,
predicates
}
from
"@sealcode/ts-predicates"
;
import
{
Context
}
from
"koa"
;
import
{
FormDataValue
}
from
"../form-types.js"
;
import
{
FieldParseResult
,
FormField
}
from
"./field.js"
;
export
class
RegExpField
<
Required
extends
boolean
>
extends
FormField
<
Required
>
{
constructor
(
required
:
Required
,
public
regexp
:
RegExp
,
public
error_message
:
string
,
public
default_value
:
string
=
""
)
{
super
(
required
);
}
predicate
=
predicates
.
string
;
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
.
regexp
.
exec
(
value
))
{
return
{
valid
:
true
,
message
:
""
};
}
return
{
valid
:
false
,
message
:
this
.
error_message
};
}
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
this
.
default_value
||
""
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:48 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
625318
Default Alt Text
regexp.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment