@sinclair/typebox 0.24.33 → 0.24.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/value/cast.js +6 -3
package/package.json
CHANGED
package/value/cast.js
CHANGED
|
@@ -81,7 +81,7 @@ exports.ValueCastUnknownTypeError = ValueCastUnknownTypeError;
|
|
|
81
81
|
var ValueCast;
|
|
82
82
|
(function (ValueCast) {
|
|
83
83
|
// -----------------------------------------------------------
|
|
84
|
-
//
|
|
84
|
+
// Convert
|
|
85
85
|
// -----------------------------------------------------------
|
|
86
86
|
function IsString(value) {
|
|
87
87
|
return typeof value === 'string';
|
|
@@ -104,6 +104,9 @@ var ValueCast;
|
|
|
104
104
|
function IsValueTrue(value) {
|
|
105
105
|
return value === true || (IsNumber(value) && value === 1) || (IsBigInt(value) && value === 1n) || (IsString(value) && (value.toLowerCase() === 'true' || value === '1'));
|
|
106
106
|
}
|
|
107
|
+
function IsValueFalse(value) {
|
|
108
|
+
return value === false || (IsNumber(value) && value === 0) || (IsBigInt(value) && value === 0n) || (IsString(value) && (value.toLowerCase() === 'false' || value === '0'));
|
|
109
|
+
}
|
|
107
110
|
function TryConvertString(value) {
|
|
108
111
|
return IsValueToString(value) ? value.toString() : value;
|
|
109
112
|
}
|
|
@@ -114,10 +117,10 @@ var ValueCast;
|
|
|
114
117
|
return IsStringNumeric(value) ? parseInt(value) : IsValueTrue(value) ? 1 : value;
|
|
115
118
|
}
|
|
116
119
|
function TryConvertBoolean(value) {
|
|
117
|
-
return IsValueTrue(value) ? true : value;
|
|
120
|
+
return IsValueTrue(value) ? true : IsValueFalse(value) ? false : value;
|
|
118
121
|
}
|
|
119
122
|
// -----------------------------------------------------------
|
|
120
|
-
//
|
|
123
|
+
// Cast
|
|
121
124
|
// -----------------------------------------------------------
|
|
122
125
|
function Any(schema, references, value) {
|
|
123
126
|
return check_1.ValueCheck.Check(schema, references, value) ? value : create_1.ValueCreate.Create(schema, references);
|