|
| 1 | +# Getting Started |
| 2 | + |
| 3 | +`@cc-heart/utils` is a library of JavaScript common tools — the environment-agnostic core of the utils family. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +```shell |
| 8 | +npm install @cc-heart/utils |
| 9 | +# or |
| 10 | +pnpm add @cc-heart/utils |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +```js |
| 16 | +import { capitalize } from '@cc-heart/utils' |
| 17 | + |
| 18 | +capitalize('string') // String |
| 19 | +``` |
| 20 | + |
| 21 | +## What's inside |
| 22 | + |
| 23 | +- **string** — `capitalize`, `unCapitalize`, ... |
| 24 | +- **date** — date formatting helpers |
| 25 | +- **random** — random number / string generators |
| 26 | +- **validate** — type & value validators |
| 27 | +- **promise** — async helpers (`retry`, `withTimeout`, ...) |
| 28 | +- **request** — fetch-based HTTP client, see the [Request guide](/guide/request) |
| 29 | +- **sse** — Server-Sent Events, see the [SSE guide](/guide/sse) |
| 30 | + |
| 31 | +## Try it online |
| 32 | + |
| 33 | +Edit the code below and see results instantly — the demo runs against the published `@cc-heart/utils` package: |
| 34 | + |
| 35 | +```tsx playground |
| 36 | +import { useState } from 'react' |
| 37 | +import { capitalize, unCapitalize, underlineToHump, random } from '@cc-heart/utils' |
| 38 | + |
| 39 | +export default function App() { |
| 40 | + const [text, setText] = useState('hello_world') |
| 41 | + const [num, setNum] = useState(() => random(1, 100)) |
| 42 | + |
| 43 | + return ( |
| 44 | + <div style={{ fontFamily: 'monospace', lineHeight: 2 }}> |
| 45 | + <input value={text} onChange={(e) => setText(e.target.value)} /> |
| 46 | + <div>capitalize: <b>{capitalize(text)}</b></div> |
| 47 | + <div>unCapitalize: <b>{unCapitalize(text)}</b></div> |
| 48 | + <div>underlineToHump: <b>{underlineToHump(text)}</b></div> |
| 49 | + <div> |
| 50 | + random(1, 100): <b>{num}</b>{' '} |
| 51 | + <button onClick={() => setNum(random(1, 100))}>re-roll</button> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + ) |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +## API Reference |
| 59 | + |
| 60 | +See the auto-generated [API documentation](/api/). |
0 commit comments