Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22424430
boolean.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
boolean.ts
View Options
import
{
Field
,
Context
}
from
"../../../main"
;
type
InputType
=
boolean
|
"false"
|
"true"
|
"1"
|
"0"
|
1
|
0
;
export
default
class
Boolean
extends
Field
<
{},
InputType
>
{
getTypeName
=
()
=>
"boolean"
;
async
isProperValue
(
_
:
Context
,
value
:
InputType
)
{
if
(
typeof
value
===
"boolean"
)
{
return
Field
.
valid
();
}
if
(
(
typeof
value
===
"string"
||
typeof
value
===
"number"
)
&&
(
value
.
toString
()
===
"1"
||
value
.
toString
()
===
"0"
)
)
{
return
Field
.
valid
();
}
if
(
typeof
value
===
"string"
&&
(
value
.
toLowerCase
()
===
"true"
||
value
.
toLowerCase
()
===
"false"
)
)
{
return
Field
.
valid
();
}
return
Field
.
invalid
(
`Value '
${
value
}
' is not boolean format.`
);
}
async
encode
(
_
:
Context
,
value
:
InputType
)
{
if
(
typeof
value
===
"boolean"
)
{
return
value
;
}
else
if
(
value
.
toString
()
===
"1"
)
{
return
true
;
}
else
if
(
value
.
toString
()
===
"0"
)
{
return
false
;
}
else
if
(
typeof
value
===
"string"
)
{
if
(
value
.
toLowerCase
()
===
"true"
)
{
return
true
;
}
else
if
(
value
.
toLowerCase
()
===
"false"
)
{
return
false
;
}
}
throw
new
Error
(
"invalid value"
);
}
async
filterToQuery
(
context
:
Context
,
filter
:
""
|
null
|
InputType
)
{
if
(
filter
===
""
)
{
return
{
$exists
:
false
};
}
else
if
(
filter
===
null
)
{
return
{
$in
:
[
true
,
false
]
};
}
else
{
return
this
.
encode
(
context
,
filter
);
}
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Sat, Nov 28, 04:01 (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1229610
Default Alt Text
boolean.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline