Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22398070
regexp.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
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
application/javascript
Expires
Fri, Nov 27, 17:19 (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1200878
Default Alt Text
regexp.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline