mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 12:25:12 +00:00

PR-URL: https://github.com/nodejs/node/pull/30533 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
36 lines
706 B
Markdown
36 lines
706 B
Markdown
# qw
|
|
|
|
Quoted word literals!
|
|
|
|
```js
|
|
const qw = require('qw')
|
|
|
|
const myword = qw` this is
|
|
a long list
|
|
of words`
|
|
// equiv of:
|
|
const myword = [ 'this', 'is', 'a', 'long', 'list', 'of', 'words' ]
|
|
```
|
|
|
|
You can embed vars in the usual way:
|
|
|
|
```js
|
|
const mywords = qw`product ${23 * 5} also ${'escaping a string'}`
|
|
// equiv of:
|
|
const mywords = [ 'product', 23 * 5, 'also', 'escaping a string' ]
|
|
```
|
|
|
|
You can also embed vars inside strings:
|
|
|
|
```js
|
|
const mywords = qw`product=${23 * 5} also "${'escaping a string'}"`
|
|
// equiv of:
|
|
const mywords = [ 'product=' + (23 * 5), 'also', '"escaping a string"' ]
|
|
```
|
|
|
|
## DESCRIPTION
|
|
|
|
This uses template strings to bring over this little common convenience from
|
|
Perl-land.
|
|
|