Skip to content

Commit

Permalink
refactor: enhance camelize and genStringKey and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Oct 28, 2024
1 parent bb1d154 commit 5f4fad5
Show file tree
Hide file tree
Showing 21 changed files with 357 additions and 49 deletions.
55 changes: 16 additions & 39 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineConfig } from 'vitepress'
import { generalItems, numberItems, stringItems } from './items'

function withI18n(items: { link: string; text: string }[], locale: 'zh') {
return items.map((item) => {
Expand All @@ -9,43 +10,6 @@ function withI18n(items: { link: string; text: string }[], locale: 'zh') {
})
}

const generalItems = [
{ text: 'isString', link: '/general/is-string' },
{ text: 'isNumber', link: '/general/is-number' },
{ text: 'isNumeric', link: '/general/is-numeric' },
{ text: 'isBoolean', link: '/general/is-boolean' },
{ text: 'isTruthy', link: '/general/is-truthy' },
{ text: 'isPlainObject', link: '/general/is-plain-object' },
{ text: 'isObject', link: '/general/is-object' },
{ text: 'isArray', link: '/general/is-array' },
{ text: 'isNullish', link: '/general/is-nullish' },
{ text: 'isPromise', link: '/general/is-promise' },
{ text: 'isFunction', link: '/general/is-function' },
{ text: 'isDate', link: '/general/is-date' },
{ text: 'isSet', link: '/general/is-set' },
{ text: 'isMap', link: '/general/is-map' },
{ text: 'isSymbol', link: '/general/is-symbol' },
{ text: 'isWindow', link: '/general/is-window' },
{ text: 'isRegExp', link: '/general/is-reg-exp' },
{ text: 'isEmpty', link: '/general/is-empty' },
{ text: 'isNonEmptyArray', link: '/general/is-non-empty-array' },
{ text: 'inBrowser', link: '/general/in-browser' },
{ text: 'inMobile', link: '/general/in-mobile' },
{ text: 'hasOwn', link: '/general/has-own' },
{ text: 'supportTouch', link: '/general/support-touch' },
{ text: 'toTypeString', link: '/general/to-type-string' },
{ text: 'toRawType', link: '/general/to-raw-type' },
{ text: 'getGlobalThis', link: '/general/get-global-this' },
]

const numberItems = [
{ text: 'toNumber', link: '/number/to-number' },
{ text: 'genNumberKey', link: '/number/gen-number-key' },
{ text: 'randomNumber', link: '/number/random-number' },
{ text: 'clamp', link: '/number/clamp' },
{ text: 'clampArrayRange', link: '/number/clamp-array-range' },
]

export default defineConfig({
title: 'Rattail',
description: 'A utilities library for front-end developers, lightweight and ts-friendly',
Expand All @@ -69,14 +33,23 @@ export default defineConfig({
},
{
text: '通用',
items: withI18n(numberItems, 'zh'),
items: withI18n(generalItems, 'zh'),
},
{
text: '数字',
items: withI18n(generalItems, 'zh'),
items: withI18n(numberItems, 'zh'),
},
{
text: '字符串',
items: withI18n(stringItems, 'zh'),
},
],

docFooter: {
prev: '上一篇',
next: '下一篇',
},

socialLinks: [{ icon: 'github', link: 'https://github.com/varletjs/rattail' }],
},
},
Expand Down Expand Up @@ -104,6 +77,10 @@ export default defineConfig({
text: 'Number',
items: numberItems,
},
{
text: 'String',
items: stringItems,
},
],

socialLinks: [{ icon: 'github', link: 'https://github.com/varletjs/rattail' }],
Expand Down
28 changes: 28 additions & 0 deletions docs/.vitepress/items/general.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const generalItems = [
{ text: 'isString', link: '/general/is-string' },
{ text: 'isNumber', link: '/general/is-number' },
{ text: 'isNumeric', link: '/general/is-numeric' },
{ text: 'isBoolean', link: '/general/is-boolean' },
{ text: 'isTruthy', link: '/general/is-truthy' },
{ text: 'isPlainObject', link: '/general/is-plain-object' },
{ text: 'isObject', link: '/general/is-object' },
{ text: 'isArray', link: '/general/is-array' },
{ text: 'isNullish', link: '/general/is-nullish' },
{ text: 'isPromise', link: '/general/is-promise' },
{ text: 'isFunction', link: '/general/is-function' },
{ text: 'isDate', link: '/general/is-date' },
{ text: 'isSet', link: '/general/is-set' },
{ text: 'isMap', link: '/general/is-map' },
{ text: 'isSymbol', link: '/general/is-symbol' },
{ text: 'isWindow', link: '/general/is-window' },
{ text: 'isRegExp', link: '/general/is-reg-exp' },
{ text: 'isEmpty', link: '/general/is-empty' },
{ text: 'isNonEmptyArray', link: '/general/is-non-empty-array' },
{ text: 'inBrowser', link: '/general/in-browser' },
{ text: 'inMobile', link: '/general/in-mobile' },
{ text: 'hasOwn', link: '/general/has-own' },
{ text: 'supportTouch', link: '/general/support-touch' },
{ text: 'toTypeString', link: '/general/to-type-string' },
{ text: 'toRawType', link: '/general/to-raw-type' },
{ text: 'getGlobalThis', link: '/general/get-global-this' },
]
3 changes: 3 additions & 0 deletions docs/.vitepress/items/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './general'
export * from './string'
export * from './number'
7 changes: 7 additions & 0 deletions docs/.vitepress/items/number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const numberItems = [
{ text: 'toNumber', link: '/number/to-number' },
{ text: 'genNumberKey', link: '/number/gen-number-key' },
{ text: 'randomNumber', link: '/number/random-number' },
{ text: 'clamp', link: '/number/clamp' },
{ text: 'clampArrayRange', link: '/number/clamp-array-range' },
]
8 changes: 8 additions & 0 deletions docs/.vitepress/items/string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const stringItems = [
{ text: 'genStringKey', link: '/string/gen-string-key' },
{ text: 'camelize', link: '/string/camelize' },
{ text: 'kebabCase', link: '/string/kebab-case' },
{ text: 'pascalCase', link: '/string/pascal-case' },
{ text: 'capitalizeFirstLetter', link: '/string/capitalize-first-letter' },
{ text: 'slash', link: '/string/slash' },
]
2 changes: 1 addition & 1 deletion docs/general/get-global-this.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Retrieve the global object based on the current environment
```ts
import { getGlobalThis } from 'rattail'

getGlobalThis()
// returns `window` in browser, `global` in Node.js,
// or `self` in web worker
const globalThis = getGlobalThis()
```

### Return
Expand Down
24 changes: 24 additions & 0 deletions docs/string/camelize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# camelize

Convert a string to `camelCase`

### Usage

```ts
import { camelize } from 'rattail'

camelize('hello-world') // return 'helloWorld'
camelize('FooBar') // return 'fooBar'
```

### Arguments

| Arg | Type | Defaults |
| --- | :----: | -------: |
| `value` | `string` | |

### Return

| Type |
| :------: |
| `string` |
24 changes: 24 additions & 0 deletions docs/string/capitalize-first-letter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# capitalizeFirstLetter

Capitalize the first letter of a string, leaving the rest of the string unchanged.

### Usage

```ts
import { capitalizeFirstLetter } from 'rattail'

capitalizeFirstLetter('hello world') // return 'Hello world'
capitalizeFirstLetter('rattail') // return 'Rattail'
```

### Arguments

| Arg | Type | Defaults |
| ------- | :------: | -------: |
| `value` | `string` | |

### Return

| Type |
| :------: |
| `string` |
19 changes: 19 additions & 0 deletions docs/string/gen-string-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# genStringKey

Generate a unique string key by incrementing a numeric value and converting it to a string

### Usage

```ts
import { genStringKey } from 'rattail'

genStringKey() // return 'generated-key-0'
genStringKey() // return 'generated-key-1'
genStringKey() // return 'generated-key-2'
```

### Return

| Type |
| :------: |
| `string` |
24 changes: 24 additions & 0 deletions docs/string/kebab-case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# kebabCase

Convert a string to `kebab-case`

### Usage

```ts
import { kebabCase } from 'rattail'

kebabCase('HelloWorld') // return 'hello-world'
kebabCase('fooBar') // return 'foo-bar'
```

### Arguments

| Arg | Type | Defaults |
| --- | :----: | -------: |
| `value` | `string` | |

### Return

| Type |
| :------: |
| `string` |
24 changes: 24 additions & 0 deletions docs/string/pascal-case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pascalCase

Convert a string to `PascalCase`

### Usage

```ts
import { pascalCase } from 'rattail'

pascalCase('hello-world') // return 'HelloWorld'
pascalCase('fooBar') // return 'FooBar'
```

### Arguments

| Arg | Type | Defaults |
| ------- | :------: | -------: |
| `value` | `string` | |

### Return

| Type |
| :------: |
| `string` |
27 changes: 27 additions & 0 deletions docs/string/slash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# slash

Convert all backslashes (`\`) in a path to forward slashes (`/`). If the path starts with `\\?\`, indicating an extended-length path, it is returned as-is without modification.

### Usage

```ts
import { slash } from 'rattail'

slash('C:\\path\\to\\file')
// return 'C:/path/to/file'

slash('\\\\?\\C:\\path\\to\\file')
// return '\\\\?\\C:\\path\\to\\file' (unmodified)
```

### Arguments

| Arg | Type | Defaults |
| ------ | :------: | -------: |
| `path` | `string` | |

### Return

| Type |
| :------: |
| `string` |
4 changes: 2 additions & 2 deletions docs/zh/general/get-global-this.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
```ts
import { getGlobalThis } from 'rattail'

getGlobalThis()
// 在浏览器中 return `window`,在 Node.js 中 return `global`,
// 在 web worker 返回 `self`
const globalThis = getGlobalThis()
// 在 web worker return `self`
```

### Return
Expand Down
24 changes: 24 additions & 0 deletions docs/zh/string/camelize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# camelize

将字符串转换为 camelCase 格式

### 使用

```ts
import { camelize } from 'rattail'

camelize('hello-world') // return 'helloWorld'
camelize('FooBar') // return 'fooBar'
```

### 参数列表

| 参数 | 类型 | 默认值 |
| ------- | :------: | -----: |
| `value` | `string` | |

### 返回值

| 类型 |
| :------: |
| `string` |
24 changes: 24 additions & 0 deletions docs/zh/string/capitalize-first-letter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# capitalizeFirstLetter

将字符串的首字母大写,其余部分保持不变

### 使用

```ts
import { capitalizeFirstLetter } from 'rattail'

capitalizeFirstLetter('hello world') // return 'Hello world'
capitalizeFirstLetter('rattail') // return 'Rattail'
```

### 参数列表

| 参数 | 类型 | 默认值 |
| ------- | :------: | -----: |
| `value` | `string` | |

### 返回值

| 类型 |
| :------: |
| `string` |
19 changes: 19 additions & 0 deletions docs/zh/string/gen-string-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# genStringKey

生成一个唯一的字符串键,通过递增数字值并将其转换为字符串

### 使用

```ts
import { genStringKey } from 'rattail'

genStringKey() // return 'generated-key-0'
genStringKey() // return 'generated-key-1'
genStringKey() // return 'generated-key-2'
```

### 返回值

| 类型 |
| :------: |
| `string` |
Loading

0 comments on commit 5f4fad5

Please sign in to comment.