mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-27 14:57:44 +03:00
docs: Add docs for isLength
This commit is contained in:
parent
caedf69aed
commit
1e20a97134
@ -147,6 +147,7 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
text: '谓词',
|
||||
items: [
|
||||
{ text: 'isEqual', link: '/zh_hans/reference/predicate/isEqual' },
|
||||
{ text: 'isLength', link: '/zh_hans/reference/predicate/isLength' },
|
||||
{ text: 'isPlainObject', link: '/zh_hans/reference/predicate/isPlainObject' },
|
||||
{ text: 'isNil', link: '/zh_hans/reference/predicate/isNil' },
|
||||
{ text: 'isNotNil', link: '/zh_hans/reference/predicate/isNotNil' },
|
||||
@ -173,7 +174,7 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{ text: 'startsWith (兼容性)', link: '/zh_hans/reference/string/startsWith' },
|
||||
{ text: 'endsWith (兼容性)', link: '/zh_hans/reference/string/endsWith' },
|
||||
],
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
Checks if a given value is a valid length.
|
||||
|
||||
This function tests whether the provided value is of type `number`, is a non-negative integer, and is less than or equal to JavaScript's maximum safe integer (`Number.MAX_SAFE_INTEGER`). It returns `true` if the value is a valid length, and `false` otherwise.
|
||||
A valid length is of type `number`, is a non-negative integer, and is less than or equal to JavaScript's maximum safe integer (`Number.MAX_SAFE_INTEGER`). It returns `true` if the value is a valid length, and `false` otherwise.
|
||||
|
||||
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to a valid length (`number`).
|
||||
|
||||
|
41
docs/zh_hans/reference/predicate/isLength.md
Normal file
41
docs/zh_hans/reference/predicate/isLength.md
Normal file
@ -0,0 +1,41 @@
|
||||
# isLength
|
||||
|
||||
检查给定的值是否是一个有效的长度。
|
||||
|
||||
该函数测试提供的值是否为 `number` 类型,是非负整数,并且小于或等于 JavaScript 的最大安全整数 (`Number.MAX_SAFE_INTEGER`)。如果该值是一个有效的长度,则返回 `true`,否则返回 `false`。
|
||||
|
||||
此函数还可以作为 TypeScript 中的类型预测器,将参数的类型缩小为有效的长度 (`number`)。
|
||||
|
||||
## 签名
|
||||
|
||||
```typescript
|
||||
function isLength(value: unknown): value is number;
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
||||
- `value` (`unknown`): 要检查是否为有效长度的值。
|
||||
|
||||
### 返回值
|
||||
|
||||
(`value is number`): 如果值是有效长度,则返回 `true`,否则返回 `false`。
|
||||
|
||||
## 示例
|
||||
|
||||
```typescript
|
||||
import { isLength } from 'es-toolkit/predicate';
|
||||
|
||||
const value1 = 0;
|
||||
const value2 = 42;
|
||||
const value3 = -1;
|
||||
const value4 = 1.5;
|
||||
const value5 = Number.MAX_SAFE_INTEGER;
|
||||
const value6 = Number.MAX_SAFE_INTEGER + 1;
|
||||
|
||||
console.log(isLength(value1)); // true
|
||||
console.log(isLength(value2)); // true
|
||||
console.log(isLength(value3)); // false
|
||||
console.log(isLength(value4)); // false
|
||||
console.log(isLength(value5)); // true
|
||||
console.log(isLength(value6)); // false
|
||||
```
|
Loading…
Reference in New Issue
Block a user