1 | <h1 align="center">dedent</h1>
|
2 |
|
3 | <p align="center">A string tag that strips indentation from multi-line strings. β¬
οΈ</p>
|
4 |
|
5 | <p align="center">
|
6 | <a href="#contributors" target="_blank">
|
7 |
|
8 |
|
9 | <img alt="All Contributors: 18 πͺ" src="https://img.shields.io/badge/all_contributors-18_πͺ-21bb42.svg" />
|
10 |
|
11 |
|
12 | </a>
|
13 | <a href="https://codecov.io/gh/dmnd/dedent" target="_blank">
|
14 | <img alt="Codecov Test Coverage" src="https://codecov.io/gh/dmnd/dedent/branch/main/graph/badge.svg"/>
|
15 | </a>
|
16 | <a href="https://github.com/dmnd/dedent/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank">
|
17 | <img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" />
|
18 | </a>
|
19 | <a href="https://github.com/dmnd/dedent/blob/main/LICENSE.md" target="_blank">
|
20 | <img alt="License: MIT" src="https://img.shields.io/github/license/dmnd/dedent?color=21bb42">
|
21 | </a>
|
22 | <img alt="Style: Prettier" src="https://img.shields.io/badge/style-prettier-21bb42.svg" />
|
23 | <img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />
|
24 | <img alt="npm package version" src="https://img.shields.io/npm/v/dedent?color=21bb42" />
|
25 | <img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" />
|
26 | </p>
|
27 |
|
28 | ## Usage
|
29 |
|
30 | ```shell
|
31 | npm i dedent
|
32 | ```
|
33 |
|
34 | ```js
|
35 | import dedent from "dedent";
|
36 |
|
37 | function usageExample() {
|
38 | const first = dedent`A string that gets so long you need to break it over
|
39 | multiple lines. Luckily dedent is here to keep it
|
40 | readable without lots of spaces ending up in the string
|
41 | itself.`;
|
42 |
|
43 | const second = dedent`
|
44 | Leading and trailing lines will be trimmed, so you can write something like
|
45 | this and have it work as you expect:
|
46 |
|
47 | * how convenient it is
|
48 | * that I can use an indented list
|
49 | - and still have it do the right thing
|
50 |
|
51 | That's all.
|
52 | `;
|
53 |
|
54 | const third = dedent(`
|
55 | Wait! I lied. Dedent can also be used as a function.
|
56 | `);
|
57 |
|
58 | return first + "\n\n" + second + "\n\n" + third;
|
59 | }
|
60 |
|
61 | console.log(usageExample());
|
62 | ```
|
63 |
|
64 | ```plaintext
|
65 | A string that gets so long you need to break it over
|
66 | multiple lines. Luckily dedent is here to keep it
|
67 | readable without lots of spaces ending up in the string
|
68 | itself.
|
69 |
|
70 | Leading and trailing lines will be trimmed, so you can write something like
|
71 | this and have it work as you expect:
|
72 |
|
73 | * how convenient it is
|
74 | * that I can use an indented list
|
75 | - and still have it do the right thing
|
76 |
|
77 | That's all.
|
78 |
|
79 | Wait! I lied. Dedent can also be used as a function.
|
80 | ```
|
81 |
|
82 | ## Options
|
83 |
|
84 | You can customize the options `dedent` runs with by calling its `withOptions` method with an object:
|
85 |
|
86 |
|
87 | ```js
|
88 | import dedent from 'dedent';
|
89 |
|
90 | dedent.withOptions({ /* ... */ })`input`;
|
91 | dedent.withOptions({ /* ... */ })(`input`);
|
92 | ```
|
93 |
|
94 | `options` returns a new `dedent` function, so if you'd like to reuse the same options, you can create a dedicated `dedent` function:
|
95 |
|
96 |
|
97 | ```js
|
98 | import dedent from 'dedent';
|
99 |
|
100 | const dedenter = dedent.withOptions({ /* ... */ });
|
101 |
|
102 | dedenter`input`;
|
103 | dedenter(`input`);
|
104 | ```
|
105 |
|
106 | ### `escapeSpecialCharacters`
|
107 |
|
108 | JavaScript string tags by default add an extra `\` escape in front of some special characters such as `$` dollar signs.
|
109 | `dedent` will escape those special characters when called as a string tag.
|
110 |
|
111 | If you'd like to change the behavior, an `escapeSpecialCharacters` option is available.
|
112 | It defaults to:
|
113 |
|
114 | - `false`: when `dedent` is called as a function
|
115 | - `true`: when `dedent` is called as a string tag
|
116 |
|
117 | ```js
|
118 | import dedent from "dedent";
|
119 |
|
120 | // "$hello!"
|
121 | dedent`
|
122 | $hello!
|
123 | `;
|
124 |
|
125 | // "\$hello!"
|
126 | dedent.withOptions({ escapeSpecialCharacters: false })`
|
127 | $hello!
|
128 | `;
|
129 |
|
130 | // "$hello!"
|
131 | dedent.withOptions({ escapeSpecialCharacters: true })`
|
132 | $hello!
|
133 | `;
|
134 | ```
|
135 |
|
136 | For more context, see [π Feature: Add an option to disable special character escaping](https://github.com/dmnd/dedent/issues/63).
|
137 |
|
138 | ## License
|
139 |
|
140 | MIT
|
141 |
|
142 | ## Contributors
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | <table>
|
149 | <tbody>
|
150 | <tr>
|
151 | <td align="center" valign="top" width="14.28%"><a href="https://adrianjost.dev/"><img src="https://avatars.githubusercontent.com/u/22987140?v=4?s=100" width="100px;" alt="Adrian Jost"/><br /><sub><b>Adrian Jost</b></sub></a><br /><a href="https://github.com/dmnd/dedent/commits?author=adrianjost" title="Code">π»</a></td>
|
152 | <td align="center" valign="top" width="14.28%"><a href="https://m811.com/"><img src="https://avatars.githubusercontent.com/u/156837?v=4?s=100" width="100px;" alt="Andri MΓΆll"/><br /><sub><b>Andri MΓΆll</b></sub></a><br /><a href="https://github.com/dmnd/dedent/issues?q=author%3Amoll" title="Bug reports">π</a></td>
|
153 | <td align="center" valign="top" width="14.28%"><a href="https://bennypowers.dev/"><img src="https://avatars.githubusercontent.com/u/1466420?v=4?s=100" width="100px;" alt="Benny Powers - Χ’Χ ΧΧ©Χ¨ΧΧ ΧΧ!"/><br /><sub><b>Benny Powers - Χ’Χ ΧΧ©Χ¨ΧΧ ΧΧ!</b></sub></a><br /><a href="#tool-bennypowers" title="Tools">π§</a></td>
|
154 | <td align="center" valign="top" width="14.28%"><a href="https://github.com/phenomnomnominal"><img src="https://avatars.githubusercontent.com/u/1086286?v=4?s=100" width="100px;" alt="Craig Spence"/><br /><sub><b>Craig Spence</b></sub></a><br /><a href="https://github.com/dmnd/dedent/commits?author=phenomnomnominal" title="Code">π»</a></td>
|
155 | <td align="center" valign="top" width="14.28%"><a href="https://synthesis.com/"><img src="https://avatars.githubusercontent.com/u/4427?v=4?s=100" width="100px;" alt="Desmond Brand"/><br /><sub><b>Desmond Brand</b></sub></a><br /><a href="https://github.com/dmnd/dedent/issues?q=author%3Admnd" title="Bug reports">π</a> <a href="https://github.com/dmnd/dedent/commits?author=dmnd" title="Code">π»</a> <a href="https://github.com/dmnd/dedent/commits?author=dmnd" title="Documentation">π</a> <a href="#ideas-dmnd" title="Ideas, Planning, & Feedback">π€</a> <a href="#infra-dmnd" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#maintenance-dmnd" title="Maintenance">π§</a> <a href="#projectManagement-dmnd" title="Project Management">π</a> <a href="#tool-dmnd" title="Tools">π§</a></td>
|
156 | <td align="center" valign="top" width="14.28%"><a href="https://github.com/G-Rath"><img src="https://avatars.githubusercontent.com/u/3151613?v=4?s=100" width="100px;" alt="Gareth Jones"/><br /><sub><b>Gareth Jones</b></sub></a><br /><a href="https://github.com/dmnd/dedent/commits?author=G-Rath" title="Code">π»</a> <a href="https://github.com/dmnd/dedent/issues?q=author%3AG-Rath" title="Bug reports">π</a></td>
|
157 | <td align="center" valign="top" width="14.28%"><a href="https://github.com/otakustay"><img src="https://avatars.githubusercontent.com/u/639549?v=4?s=100" width="100px;" alt="Gray Zhang"/><br /><sub><b>Gray Zhang</b></sub></a><br /><a href="https://github.com/dmnd/dedent/issues?q=author%3Aotakustay" title="Bug reports">π</a></td>
|
158 | </tr>
|
159 | <tr>
|
160 | <td align="center" valign="top" width="14.28%"><a href="https://haroen.me/"><img src="https://avatars.githubusercontent.com/u/6270048?v=4?s=100" width="100px;" alt="Haroen Viaene"/><br /><sub><b>Haroen Viaene</b></sub></a><br /><a href="https://github.com/dmnd/dedent/commits?author=Haroenv" title="Code">π»</a> <a href="#maintenance-Haroenv" title="Maintenance">π§</a></td>
|
161 | <td align="center" valign="top" width="14.28%"><a href="https://blog.cometkim.kr/"><img src="https://avatars.githubusercontent.com/u/9696352?v=4?s=100" width="100px;" alt="Hyeseong Kim"/><br /><sub><b>Hyeseong Kim</b></sub></a><br /><a href="#tool-cometkim" title="Tools">π§</a> <a href="#infra-cometkim" title="Infrastructure (Hosting, Build-Tools, etc)">π</a></td>
|
162 | <td align="center" valign="top" width="14.28%"><a href="https://github.com/jlarmstrongiv"><img src="https://avatars.githubusercontent.com/u/20903247?v=4?s=100" width="100px;" alt="John L. Armstrong IV"/><br /><sub><b>John L. Armstrong IV</b></sub></a><br /><a href="https://github.com/dmnd/dedent/issues?q=author%3Ajlarmstrongiv" title="Bug reports">π</a></td>
|
163 | <td align="center" valign="top" width="14.28%"><a href="http://www.joshuakgoldberg.com/"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg β¨"/><br /><sub><b>Josh Goldberg β¨</b></sub></a><br /><a href="https://github.com/dmnd/dedent/issues?q=author%3AJoshuaKGoldberg" title="Bug reports">π</a> <a href="https://github.com/dmnd/dedent/commits?author=JoshuaKGoldberg" title="Code">π»</a> <a href="https://github.com/dmnd/dedent/commits?author=JoshuaKGoldberg" title="Documentation">π</a> <a href="#ideas-JoshuaKGoldberg" title="Ideas, Planning, & Feedback">π€</a> <a href="#infra-JoshuaKGoldberg" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#maintenance-JoshuaKGoldberg" title="Maintenance">π§</a> <a href="#projectManagement-JoshuaKGoldberg" title="Project Management">π</a> <a href="#tool-JoshuaKGoldberg" title="Tools">π§</a></td>
|
164 | <td align="center" valign="top" width="14.28%"><a href="https://pratapvardhan.com/"><img src="https://avatars.githubusercontent.com/u/3757165?v=4?s=100" width="100px;" alt="Pratap Vardhan"/><br /><sub><b>Pratap Vardhan</b></sub></a><br /><a href="https://github.com/dmnd/dedent/commits?author=pratapvardhan" title="Code">π»</a></td>
|
165 | <td align="center" valign="top" width="14.28%"><a href="https://github.com/lydell"><img src="https://avatars.githubusercontent.com/u/2142817?v=4?s=100" width="100px;" alt="Simon Lydell"/><br /><sub><b>Simon Lydell</b></sub></a><br /><a href="https://github.com/dmnd/dedent/issues?q=author%3Alydell" title="Bug reports">π</a></td>
|
166 | <td align="center" valign="top" width="14.28%"><a href="https://github.com/yinm"><img src="https://avatars.githubusercontent.com/u/13295106?v=4?s=100" width="100px;" alt="Yusuke Iinuma"/><br /><sub><b>Yusuke Iinuma</b></sub></a><br /><a href="https://github.com/dmnd/dedent/commits?author=yinm" title="Code">π»</a></td>
|
167 | </tr>
|
168 | <tr>
|
169 | <td align="center" valign="top" width="14.28%"><a href="https://github.com/yvele"><img src="https://avatars.githubusercontent.com/u/4225430?v=4?s=100" width="100px;" alt="Yves M."/><br /><sub><b>Yves M.</b></sub></a><br /><a href="#tool-yvele" title="Tools">π§</a></td>
|
170 | <td align="center" valign="top" width="14.28%"><a href="https://github.com/d07RiV"><img src="https://avatars.githubusercontent.com/u/3448203?v=4?s=100" width="100px;" alt="d07riv"/><br /><sub><b>d07riv</b></sub></a><br /><a href="https://github.com/dmnd/dedent/issues?q=author%3Ad07RiV" title="Bug reports">π</a></td>
|
171 | <td align="center" valign="top" width="14.28%"><a href="https://mizdra.net/"><img src="https://avatars.githubusercontent.com/u/9639995?v=4?s=100" width="100px;" alt="mizdra"/><br /><sub><b>mizdra</b></sub></a><br /><a href="https://github.com/dmnd/dedent/commits?author=mizdra" title="Code">π»</a></td>
|
172 | <td align="center" valign="top" width="14.28%"><a href="https://github.com/sirian"><img src="https://avatars.githubusercontent.com/u/897643?v=4?s=100" width="100px;" alt="sirian"/><br /><sub><b>sirian</b></sub></a><br /><a href="https://github.com/dmnd/dedent/issues?q=author%3Asirian" title="Bug reports">π</a></td>
|
173 | </tr>
|
174 | </tbody>
|
175 | </table>
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 | > π This package was templated with [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
|