@sinclair/typebox 0.24.32 → 0.24.33
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.d.ts +0 -3
- package/value/cast.js +6 -6
package/package.json
CHANGED
package/value/cast.d.ts
CHANGED
|
@@ -3,9 +3,6 @@ export declare class ValueCastUnknownTypeError extends Error {
|
|
|
3
3
|
readonly schema: Types.TSchema;
|
|
4
4
|
constructor(schema: Types.TSchema);
|
|
5
5
|
}
|
|
6
|
-
export interface ValueCastOptions {
|
|
7
|
-
convert: boolean;
|
|
8
|
-
}
|
|
9
6
|
export declare namespace ValueCast {
|
|
10
7
|
function Visit(schema: Types.TSchema, references: Types.TSchema[], value: any): any;
|
|
11
8
|
function Cast<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: any): Types.Static<T>;
|
package/value/cast.js
CHANGED
|
@@ -89,12 +89,12 @@ var ValueCast;
|
|
|
89
89
|
function IsBoolean(value) {
|
|
90
90
|
return typeof value === 'boolean';
|
|
91
91
|
}
|
|
92
|
-
function IsNumber(value) {
|
|
93
|
-
return typeof value === 'number';
|
|
94
|
-
}
|
|
95
92
|
function IsBigInt(value) {
|
|
96
93
|
return typeof value === 'bigint';
|
|
97
94
|
}
|
|
95
|
+
function IsNumber(value) {
|
|
96
|
+
return typeof value === 'number';
|
|
97
|
+
}
|
|
98
98
|
function IsStringNumeric(value) {
|
|
99
99
|
return IsString(value) && !isNaN(value) && !isNaN(parseFloat(value));
|
|
100
100
|
}
|
|
@@ -102,16 +102,16 @@ var ValueCast;
|
|
|
102
102
|
return IsBigInt(value) || IsBoolean(value) || IsNumber(value);
|
|
103
103
|
}
|
|
104
104
|
function IsValueTrue(value) {
|
|
105
|
-
return (IsNumber(value) && value === 1) || (IsString(value) &&
|
|
105
|
+
return value === true || (IsNumber(value) && value === 1) || (IsBigInt(value) && value === 1n) || (IsString(value) && (value.toLowerCase() === 'true' || value === '1'));
|
|
106
106
|
}
|
|
107
107
|
function TryConvertString(value) {
|
|
108
108
|
return IsValueToString(value) ? value.toString() : value;
|
|
109
109
|
}
|
|
110
110
|
function TryConvertNumber(value) {
|
|
111
|
-
return IsStringNumeric(value) ? parseFloat(value) : value;
|
|
111
|
+
return IsStringNumeric(value) ? parseFloat(value) : IsValueTrue(value) ? 1 : value;
|
|
112
112
|
}
|
|
113
113
|
function TryConvertInteger(value) {
|
|
114
|
-
return IsStringNumeric(value) ? parseInt(value) : value;
|
|
114
|
+
return IsStringNumeric(value) ? parseInt(value) : IsValueTrue(value) ? 1 : value;
|
|
115
115
|
}
|
|
116
116
|
function TryConvertBoolean(value) {
|
|
117
117
|
return IsValueTrue(value) ? true : value;
|