-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: unify zh docs subtitle * docs: add json docs
- Loading branch information
Showing
25 changed files
with
146 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# prettyJSONObject | ||
|
||
Formats a `JSON` object with indentation for easy readability. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { prettyJSONObject } from 'rattail' | ||
|
||
const jsonObject = { key: 'value', nested: { key: 'nestedValue' } } | ||
const pretty = prettyJSONObject(jsonObject) | ||
console.log(pretty) | ||
/* | ||
{ | ||
"key": "value", | ||
"nested": { | ||
"key": "nestedValue" | ||
} | ||
} | ||
*/ | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| ------------ | -------- | -------- | | ||
| `jsonObject` | `object` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| -------- | | ||
| `string` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# tryParseJSON | ||
|
||
Attempts to parse a `JSON` string. If parsing fails, returns `undefined`. | ||
|
||
### Usage | ||
|
||
```ts | ||
import { tryParseJSON } from 'rattail' | ||
|
||
const jsonString = '{"key": "value"}' | ||
const parsed = tryParseJSON(jsonString) | ||
console.log(parsed) // { key: "value" } | ||
|
||
const invalidJsonString = '{"key": value}' | ||
const invalidParsed = tryParseJSON(invalidJsonString) | ||
console.log(invalidParsed) // undefined | ||
``` | ||
|
||
### Arguments | ||
|
||
| Arg | Type | Defaults | | ||
| ------ | -------- | -------- | | ||
| `json` | `string` | | | ||
|
||
### Return | ||
|
||
| Type | | ||
| --------------------- | | ||
| `object \| undefined` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
递归合并两个对象,可通过回调函数自定义合并逻辑。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { mergeWith } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
递归合并两个对象。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { merge } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
将 `File` 对象转换为 `ArrayBuffer`。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { toArrayBuffer } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
将 `File` 对象转换为 Data URL 字符串。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { toDataURL } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
将 `File` 对象转换为文本字符串。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { toText } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
根据给定条件生成类名列表,或直接返回类名。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { classes } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
创建一个命名空间函数,用于生成 BEM 样式的组件和类名。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { createNamespaceFn } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
获取元素的所有可滚动父级元素,包含 `window` 作为最后一项。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { getAllParentScroller } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
获取元素或窗口的尺寸和位置,返回一个 `DOMRect` 对象。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { getRect } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
获取元素或窗口的水平滚动位置。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { getScrollLeft } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
获取元素或窗口的垂直滚动位置。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { getScrollTop } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
获取给定 DOM 元素的计算 CSS 样式。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { getStyle } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
判断元素是否在视口内可见。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { inViewport } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# prettyJSONObject | ||
|
||
格式化 `JSON` 对象,增加缩进以便于阅读。 | ||
|
||
### 使用 | ||
|
||
```ts | ||
import { prettyJSONObject } from 'rattail' | ||
|
||
const jsonObject = { key: 'value', nested: { key: 'nestedValue' } } | ||
const pretty = prettyJSONObject(jsonObject) | ||
console.log(pretty) | ||
/* | ||
{ | ||
"key": "value", | ||
"nested": { | ||
"key": "nestedValue" | ||
} | ||
} | ||
*/ | ||
``` | ||
|
||
### 参数 | ||
|
||
| 参数 | 类型 | 默认值 | | ||
| ------------ | -------- | ------ | | ||
| `jsonObject` | `object` | | | ||
|
||
### 返回值 | ||
|
||
| 类型 | | ||
| -------- | | ||
| `string` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
阻止事件的默认行为(如果该事件可取消)。 | ||
|
||
### 用法 | ||
### 使用 | ||
|
||
```ts | ||
import { preventDefault } from 'rattail' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# tryParseJSON | ||
|
||
尝试解析 `JSON` 字符串。如果解析失败,返回 `undefined`。 | ||
|
||
### 使用 | ||
|
||
```ts | ||
import { tryParseJSON } from 'rattail' | ||
|
||
const jsonString = '{"key": "value"}' | ||
const parsed = tryParseJSON(jsonString) | ||
console.log(parsed) // { key: "value" } | ||
|
||
const invalidJsonString = '{"key": value}' | ||
const invalidParsed = tryParseJSON(invalidJsonString) | ||
console.log(invalidParsed) // undefined | ||
``` | ||
|
||
### 参数 | ||
|
||
| 参数 | 类型 | 默认值 | | ||
| ------ | -------- | ------ | | ||
| `json` | `string` | | | ||
|
||
### 返回值 | ||
|
||
| 类型 | | ||
| --------------------- | | ||
| `object \| undefined` | |