diff options
author | Rebecca Turner <me@re-becca.org> | 2017-09-23 02:50:25 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2017-10-04 10:02:38 +0300 |
commit | d13ea47c862c9e8040efaaffe0766b2b81b3b25d (patch) | |
tree | 20f1b379f65c75ff60f1bff1d5039fb0cc44ebad /node_modules/qw | |
parent | a60a79625fa7dc21bca2a0ac491b2f2fa3120c6a (diff) |
qw@1.0.1
Diffstat (limited to 'node_modules/qw')
-rw-r--r-- | node_modules/qw/LICENSE | 14 | ||||
-rw-r--r-- | node_modules/qw/README.md | 35 | ||||
-rw-r--r-- | node_modules/qw/package.json | 60 | ||||
-rw-r--r-- | node_modules/qw/qw.js | 43 |
4 files changed, 152 insertions, 0 deletions
diff --git a/node_modules/qw/LICENSE b/node_modules/qw/LICENSE new file mode 100644 index 000000000..51bcf57ee --- /dev/null +++ b/node_modules/qw/LICENSE @@ -0,0 +1,14 @@ +Copyright (c) 2016, Rebecca Turner <me@re-becca.org> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + diff --git a/node_modules/qw/README.md b/node_modules/qw/README.md new file mode 100644 index 000000000..e42fc66d5 --- /dev/null +++ b/node_modules/qw/README.md @@ -0,0 +1,35 @@ +# 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. + diff --git a/node_modules/qw/package.json b/node_modules/qw/package.json new file mode 100644 index 000000000..fb4c272f3 --- /dev/null +++ b/node_modules/qw/package.json @@ -0,0 +1,60 @@ +{ + "_from": "qw", + "_id": "qw@1.0.1", + "_inBundle": false, + "_integrity": "sha1-77/cdA+a0FQwRCassYNBLMi5ltQ=", + "_location": "/qw", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "qw", + "name": "qw", + "escapedName": "qw", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/qw/-/qw-1.0.1.tgz", + "_shasum": "efbfdc740f9ad054304426acb183412cc8b996d4", + "_spec": "qw", + "_where": "/Users/rebecca/code/npm", + "author": { + "name": "Rebecca Turner", + "email": "me@re-becca.org", + "url": "http://re-becca.org/" + }, + "bugs": { + "url": "https://github.com/iarna/node-qw/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "Quoted word literals!", + "devDependencies": { + "tap": "^8.0.0" + }, + "directories": { + "test": "test" + }, + "files": [ + "qw.js" + ], + "homepage": "https://github.com/iarna/node-qw#readme", + "keywords": [], + "license": "ISC", + "main": "qw.js", + "name": "qw", + "repository": { + "type": "git", + "url": "git+https://github.com/iarna/node-qw.git" + }, + "scripts": { + "test": "tap test" + }, + "version": "1.0.1" +} diff --git a/node_modules/qw/qw.js b/node_modules/qw/qw.js new file mode 100644 index 000000000..239e5a565 --- /dev/null +++ b/node_modules/qw/qw.js @@ -0,0 +1,43 @@ +'use strict' +module.exports = qw + +function appendLast (arr, str) { + var last = arr.length - 1 + if (last < 0) { + arr.push(str) + } else { + var lastValue = String(arr[last]) + return arr[last] = lastValue + String(str) + } +} + +function qw () { + const args = Object.assign([], arguments[0]) + const values = [].slice.call(arguments, 1) + const words = [] + let lastWordWasValue = false + while (args.length) { + const arg = args.shift() + const concatValue = arg.length === 0 || arg.slice(-1) !== ' ' + if (arg.trim() !== '') { + const theseWords = arg.replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ').split(/ /) + if (lastWordWasValue && arg[0] !== ' ') { + appendLast(words, theseWords.shift()) + } + words.push.apply(words, theseWords) + } + + if (values.length) { + const val = values.shift() + if (concatValue) { + appendLast(words, val) + } else { + words.push(val) + } + lastWordWasValue = true + } else { + lastWordWasValue = false + } + } + return words +} |