Skip to content

Commit 1ba5a39

Browse files
committed
chore: better documentation
1 parent 3b0cf57 commit 1ba5a39

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

README.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- Sanity checks that correct variables were passed in
1313
- Returns the correct type based on passed in variable substitutions
1414
- Options to customize return, pattern matching and sanity checking
15-
- Both ES Module `.mjs` and CommonJS `.cjs` distributions available. Use anywhere!
15+
- Both ES Module and CommonJS distributions available. Use anywhere!
1616
- Tiny footprint:
1717
- ES Module: `0.46kB` (`0.77kB` unpacked)
1818
- CommonJS: `0.83kB` (`1.75kB` unpacked)
@@ -25,7 +25,7 @@ This utility aims to provide a high quality string interpolation "primitive" to
2525

2626
## Getting started
2727

28-
Easiest way to get started is to play around with a [React example sandbox](https://codesandbox.io/p/sandbox/typed-string-interpolation-react-example-slpjgp).
28+
Easiest way to get started is to play around with a [React example sandbox](https://codesandbox.io/p/sandbox/typed-string-interpolation-react-example-slpjgp?file=%2Fsrc%2Fmain.tsx).
2929

3030
### Install
3131

@@ -45,36 +45,35 @@ const { stringInterpolation } = require("typed-string-interpolation")
4545
Returns a `string` when the result can be joined into a string.
4646

4747
```ts
48-
stringInterpolation("hello {{world}}", {
49-
world: "world",
50-
}) // "hello world"
48+
stringInterpolation("You have {{n}} messages", {
49+
n: 3,
50+
}) // "You have 3 messages"
5151
```
5252

5353
Returns an array when the result can't be joined into a `string`. This makes it really easy to use the utility with libraries like `react` or anything else.
5454

5555
```tsx
56-
stringInterpolation("hello {{world}} with {{anything}}", {
57-
world: "world",
58-
anything: <strong>anything</strong>,
59-
}) // ["hello ", "world", " with ", <strong>anything</strong>]
56+
stringInterpolation("You have {{n}} messages", {
57+
n: <strong>3</strong>,
58+
}) // ["You have ", <strong>3</strong>, " messages"]
6059
```
6160

6261
## TypeScript support
6362

6463
If the string can be joined you'll get back a `string` type. Otherwise a `union` type within an array is returned based on the passed in variables.
6564

6665
```ts
67-
stringInterpolation("hello {{world}} with number {{number}}", {
68-
world: "world",
69-
number: 1,
66+
stringInterpolation("You have {{n}} messages from {{person}}", {
67+
n: 3,
68+
person: "John",
7069
}) // : string
7170
```
7271

7372
```tsx
74-
stringInterpolation("hello {{world}} with number {{number}}", {
75-
world: <strong>world</strong>,
76-
number: 1,
77-
}) // : (string | JSX.Element | number)[]
73+
stringInterpolation("You have {{n}} messages from {{person}}", {
74+
n: <strong>3</strong>,
75+
person: "John",
76+
}) // : (JSX.Element | string)[]
7877
```
7978

8079
## Options
@@ -99,13 +98,13 @@ Return the raw interpolation results without joining to string when you want ful
9998
10099
```tsx
101100
stringInterpolation(
102-
"hello {{world}} with number {{number}}",
101+
"You have {{n}} messages from {{person}}",
103102
{
104-
world: "world",
105-
number: 1,
103+
n: 3,
104+
person: "John",
106105
},
107106
{ raw: true }
108-
) // : (string | number)[]
107+
) // : (number | string)[]
109108
```
110109
111110
`pattern`

docs/cover.png

-111 KB
Loading

0 commit comments

Comments
 (0)