Last Updated on : 2024-06-05 03:14:36download
This topic describes the utility methods related to core settings.
toFixed
Extract a substring with the required length that starts from the end of a specified string. If the string length is less than the required one, one or more leading zeros are added to the string to reach the required length.
Name | Data type | Description | Required |
---|---|---|---|
str | string | String | Yes |
num | number | The length of the returned substring. | Yes |
Name | Data type | Description |
---|---|---|
result | string | The returned substring of the required length. |
import { Utils } from "tuya-panel-kit";
const { toFixed } = Utils.CoreUtils;
toFixed(str, num);
// Example:
toFixed("111", 5);
toFixed("3456111", 5);
'00111'
'56111'
toFilled
If the length of a specified string is less than the required length, pad the string with one or more leading zeros to the required length. If the string length is more than the required one, return the string.
Name | Data type | Description | Required |
---|---|---|---|
str | string | String | Yes |
num | number | The length of the returned substring. | Yes |
Name | Data type | Description |
---|---|---|
result | string | The returned substring of the required length. |
import { Utils } from "tuya-panel-kit";
const { toFilled } = Utils.CoreUtils;
toFilled(str, num);
// Example:
toFilled("111", 5);
toFilled("3456111", 5);
'00111'
'3456111'
partition
Convert a string to an array in which each element is a substring of the specified string. The substring length is specified.
Name | Data type | Description | Required |
---|---|---|---|
str | string | String | Yes |
num | number | The length of the returned substring. | Yes |
Name | Data type | Description |
---|---|---|
result | str[] | The array in which each element is a substring of the specified string. The length of each substring is specified by num . If the actual length of a substring is less than num , the actual length is used. |
import { Utils } from "tuya-panel-kit";
const { partition } = Utils.CoreUtils;
partition(str, num);
// Example:
partition("1234567", 3);
['123', '456', '7']
Method name | Request parameter type | Return parameter type | Description |
---|---|---|---|
isObject |
any |
boolean |
Indicate whether the specified value is an object. |
isArray |
any |
boolean |
Indicate whether the specified value is an array. |
isDate |
any |
boolean |
Indicate whether the specified value is a date. |
isRegExp |
any |
boolean |
Indicate whether the specified value is a regular expression. |
isBoolean |
any |
boolean |
Indicate whether the specified value is a Boolean value. |
isNumerical |
any |
boolean |
Indicate whether the specified value is a number. |
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback