You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-20Lines changed: 19 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@
12
12
- Sanity checks that correct variables were passed in
13
13
- Returns the correct type based on passed in variable substitutions
14
14
- 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!
16
16
- Tiny footprint:
17
17
- ES Module: `0.46kB` (`0.77kB` unpacked)
18
18
- CommonJS: `0.83kB` (`1.75kB` unpacked)
@@ -25,7 +25,7 @@ This utility aims to provide a high quality string interpolation "primitive" to
25
25
26
26
## Getting started
27
27
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).
Returns a `string` when the result can be joined into a string.
46
46
47
47
```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"
51
51
```
52
52
53
53
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.
54
54
55
55
```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"]
60
59
```
61
60
62
61
## TypeScript support
63
62
64
63
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.
65
64
66
65
```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",
70
69
}) // : string
71
70
```
72
71
73
72
```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)[]
78
77
```
79
78
80
79
## Options
@@ -99,13 +98,13 @@ Return the raw interpolation results without joining to string when you want ful
0 commit comments