typof 1.1.0 → 1.1.1
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/README.md +24 -0
- package/dist/main.cjs +4 -0
- package/dist/main.d.cts +2 -1
- package/dist/main.d.mts +2 -1
- package/dist/main.mjs +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,6 +74,7 @@ typof
|
|
|
74
74
|
├── string(value)
|
|
75
75
|
├── number(value)
|
|
76
76
|
├── integer(value)
|
|
77
|
+
├── float(value)
|
|
77
78
|
├── boolean(value)
|
|
78
79
|
├── date(value)
|
|
79
80
|
├── object(value)
|
|
@@ -207,6 +208,29 @@ Convert to integer.
|
|
|
207
208
|
|
|
208
209
|
<br/>
|
|
209
210
|
|
|
211
|
+
`float(value, fraction_digits)`
|
|
212
|
+
|
|
213
|
+
Convert to float.
|
|
214
|
+
|
|
215
|
+
> | Parameter | Type | Default | Description |
|
|
216
|
+
> | ----------------- | ------- | ------- | ----------------- |
|
|
217
|
+
> | `value` | Unknown | | Value to convert. |
|
|
218
|
+
> | `fraction_digits` | Number | | Fraction digits. |
|
|
219
|
+
>
|
|
220
|
+
> returns String | Value
|
|
221
|
+
>
|
|
222
|
+
> Example:
|
|
223
|
+
>
|
|
224
|
+
> ```typescript
|
|
225
|
+
> float('0', 2); // '0.00'
|
|
226
|
+
> float(0, 2); // '0.00'
|
|
227
|
+
> float(0.5555, 2); // '0.55'
|
|
228
|
+
> float(0.5555, 4); // '0.5555'
|
|
229
|
+
> float('test', 2); // 'test'
|
|
230
|
+
> ```
|
|
231
|
+
|
|
232
|
+
<br/>
|
|
233
|
+
|
|
210
234
|
`boolean(value)`
|
|
211
235
|
|
|
212
236
|
Convert to boolean.
|
package/dist/main.cjs
CHANGED
|
@@ -61,6 +61,9 @@ const number = (value) => {
|
|
|
61
61
|
const integer = (value) => {
|
|
62
62
|
return typof(value).includes("number") ? Math.trunc(Number(value)) : NaN;
|
|
63
63
|
};
|
|
64
|
+
const float = (value, fraction_digits) => {
|
|
65
|
+
return typof(value).includes("number") ? Number(value).toFixed(fraction_digits) : value;
|
|
66
|
+
};
|
|
64
67
|
const boolean = (value) => {
|
|
65
68
|
const types = typof(value);
|
|
66
69
|
if (types.includes("boolean") && types.includes("string")) if (value.trim() === "true") return true;
|
|
@@ -91,6 +94,7 @@ exports._undefined = _undefined;
|
|
|
91
94
|
exports.array = array;
|
|
92
95
|
exports.boolean = boolean;
|
|
93
96
|
exports.date = date;
|
|
97
|
+
exports.float = float;
|
|
94
98
|
exports.integer = integer;
|
|
95
99
|
exports.number = number;
|
|
96
100
|
exports.object = object;
|
package/dist/main.d.cts
CHANGED
|
@@ -9,6 +9,7 @@ declare const typof: (value: unknown) => Types[];
|
|
|
9
9
|
declare const string: (value: unknown) => string;
|
|
10
10
|
declare const number: (value: unknown) => number;
|
|
11
11
|
declare const integer: (value: unknown) => number;
|
|
12
|
+
declare const float: <Value>(value: Value, fraction_digits: number) => string | Value;
|
|
12
13
|
declare const boolean: <Value>(value: Value) => boolean | Value;
|
|
13
14
|
declare const date: <Value>(value: Value) => Date | Value;
|
|
14
15
|
declare const object: <Value>(value: Value) => UnknownObject | Value;
|
|
@@ -16,4 +17,4 @@ declare const array: <Value>(value: Value) => unknown[] | Value;
|
|
|
16
17
|
declare const _null: <Value>(value: Value) => null | Value;
|
|
17
18
|
declare const _undefined: <Value>(value: Value) => undefined | Value;
|
|
18
19
|
//#endregion
|
|
19
|
-
export { type Types, type UnknownObject, _null, _undefined, array, boolean, date, integer, number, object, string, typof };
|
|
20
|
+
export { type Types, type UnknownObject, _null, _undefined, array, boolean, date, float, integer, number, object, string, typof };
|
package/dist/main.d.mts
CHANGED
|
@@ -9,6 +9,7 @@ declare const typof: (value: unknown) => Types[];
|
|
|
9
9
|
declare const string: (value: unknown) => string;
|
|
10
10
|
declare const number: (value: unknown) => number;
|
|
11
11
|
declare const integer: (value: unknown) => number;
|
|
12
|
+
declare const float: <Value>(value: Value, fraction_digits: number) => string | Value;
|
|
12
13
|
declare const boolean: <Value>(value: Value) => boolean | Value;
|
|
13
14
|
declare const date: <Value>(value: Value) => Date | Value;
|
|
14
15
|
declare const object: <Value>(value: Value) => UnknownObject | Value;
|
|
@@ -16,4 +17,4 @@ declare const array: <Value>(value: Value) => unknown[] | Value;
|
|
|
16
17
|
declare const _null: <Value>(value: Value) => null | Value;
|
|
17
18
|
declare const _undefined: <Value>(value: Value) => undefined | Value;
|
|
18
19
|
//#endregion
|
|
19
|
-
export { type Types, type UnknownObject, _null, _undefined, array, boolean, date, integer, number, object, string, typof };
|
|
20
|
+
export { type Types, type UnknownObject, _null, _undefined, array, boolean, date, float, integer, number, object, string, typof };
|
package/dist/main.mjs
CHANGED
|
@@ -60,6 +60,9 @@ const number = (value) => {
|
|
|
60
60
|
const integer = (value) => {
|
|
61
61
|
return typof(value).includes("number") ? Math.trunc(Number(value)) : NaN;
|
|
62
62
|
};
|
|
63
|
+
const float = (value, fraction_digits) => {
|
|
64
|
+
return typof(value).includes("number") ? Number(value).toFixed(fraction_digits) : value;
|
|
65
|
+
};
|
|
63
66
|
const boolean = (value) => {
|
|
64
67
|
const types = typof(value);
|
|
65
68
|
if (types.includes("boolean") && types.includes("string")) if (value.trim() === "true") return true;
|
|
@@ -85,4 +88,4 @@ const _undefined = (value) => {
|
|
|
85
88
|
return typof(value).includes("undefined") ? void 0 : value;
|
|
86
89
|
};
|
|
87
90
|
//#endregion
|
|
88
|
-
export { _null, _undefined, array, boolean, date, integer, number, object, string, typof };
|
|
91
|
+
export { _null, _undefined, array, boolean, date, float, integer, number, object, string, typof };
|