pax_global_header00006660000000000000000000000064130745227200014514gustar00rootroot0000000000000052 comment=c87a2f9e4998ffdd987a92c1c5795a5dbe1c5aec node-qw-1.0.1/000077500000000000000000000000001307452272000130655ustar00rootroot00000000000000node-qw-1.0.1/.gitignore000066400000000000000000000000241307452272000150510ustar00rootroot00000000000000*~ .#* node_modules node-qw-1.0.1/.travis.yml000066400000000000000000000000771307452272000152020ustar00rootroot00000000000000language: node_js sudo: false node_js: - "7" - "6" - "4" node-qw-1.0.1/LICENSE000066400000000000000000000013601307452272000140720ustar00rootroot00000000000000Copyright (c) 2016, Rebecca Turner 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. node-qw-1.0.1/README.md000066400000000000000000000013021307452272000143400ustar00rootroot00000000000000# 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. node-qw-1.0.1/package.json000066400000000000000000000011541307452272000153540ustar00rootroot00000000000000{ "name": "qw", "version": "1.0.1", "description": "Quoted word literals!", "main": "qw.js", "scripts": { "test": "tap test" }, "keywords": [], "author": "Rebecca Turner (http://re-becca.org/)", "license": "ISC", "devDependencies": { "tap": "^8.0.0" }, "directories": { "test": "test" }, "dependencies": {}, "files": [ "qw.js" ], "repository": { "type": "git", "url": "git+https://github.com/iarna/node-qw.git" }, "bugs": { "url": "https://github.com/iarna/node-qw/issues" }, "homepage": "https://github.com/iarna/node-qw#readme" } node-qw-1.0.1/qw.js000066400000000000000000000020211307452272000140450ustar00rootroot00000000000000'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 } node-qw-1.0.1/test/000077500000000000000000000000001307452272000140445ustar00rootroot00000000000000node-qw-1.0.1/test/qw.js000066400000000000000000000062321307452272000150340ustar00rootroot00000000000000'use strict' const test = require('tap').test const qw = require('../qw.js') test('qw', function (t) { t.isDeeply(qw`foo`, ['foo'], 'single') t.isDeeply(qw`foo `, ['foo'], 'single trailing whitespace') t.isDeeply(qw` foo`, ['foo'], 'single leading whitespace') t.isDeeply(qw` foo `, ['foo'], 'single both whitespace') t.isDeeply(qw`foo bar`, ['foo', 'bar'], 'double') t.isDeeply(qw`foo bar`, ['foo', 'bar'], 'double middle whitespace') t.isDeeply(qw`foo bar `, ['foo', 'bar'], 'double trailing whitespace') t.isDeeply(qw` foo bar`, ['foo', 'bar'], 'double leading whitespace') t.isDeeply(qw` foo bar `, ['foo', 'bar'], 'double both whitespace') t.isDeeply(qw` foo bar `, ['foo', 'bar'], 'double all whitespace') t.isDeeply(qw`foo bar baz`, ['foo', 'bar', 'baz'], 'triple') t.isDeeply(qw`foo bar baz`, ['foo', 'bar', 'baz'], 'triple middle whitespace') t.isDeeply(qw`foo bar baz `, ['foo', 'bar', 'baz'], 'triple trailing whitespace') t.isDeeply(qw` foo bar baz`, ['foo', 'bar', 'baz'], 'triple leading whitespace') t.isDeeply(qw` foo bar baz `, ['foo', 'bar', 'baz'], 'triple both whitespace') t.isDeeply(qw` foo bar baz `, ['foo', 'bar', 'baz'], 'triple all whitespace') const foo = 'exam ple' t.isDeeply(qw`${foo} bar baz`, ['exam ple', 'bar', 'baz'], 'one var') t.isDeeply(qw`${foo} bar baz`, ['exam ple', 'bar', 'baz'], 'one var middle whitespace') t.isDeeply(qw`${foo} bar baz `, ['exam ple', 'bar', 'baz'], 'one var trailing whitespace') t.isDeeply(qw` ${foo} bar baz`, ['exam ple', 'bar', 'baz'], 'one var leading whitespace') t.isDeeply(qw` ${foo} bar baz `, ['exam ple', 'bar', 'baz'], 'one var both whitespace') t.isDeeply(qw` ${foo} bar baz `, ['exam ple', 'bar', 'baz'], 'one var all whitespace') const bar = 'zzzz' t.isDeeply(qw`${foo} ${bar} baz`, ['exam ple', 'zzzz', 'baz'], 'two var') t.isDeeply(qw`${foo} ${bar} baz`, ['exam ple', 'zzzz', 'baz'], 'two var middle whitespace') t.isDeeply(qw`${foo} ${bar} baz `, ['exam ple', 'zzzz', 'baz'], 'two var trailing whitespace') t.isDeeply(qw` ${foo} ${bar} baz`, ['exam ple', 'zzzz', 'baz'], 'two var leading whitespace') t.isDeeply(qw` ${foo} ${bar} baz `, ['exam ple', 'zzzz', 'baz'], 'two var both whitespace') t.isDeeply(qw` ${foo} ${bar} baz `, ['exam ple', 'zzzz', 'baz'], 'two var all whitespace') const baz = ['THINGY'] t.isDeeply(qw`${foo} ${bar} ${baz}`, ['exam ple', 'zzzz', ['THINGY']], 'three var') t.isDeeply(qw`${foo} ${bar} ${baz}`, ['exam ple', 'zzzz', ['THINGY']], 'three var middle whitespace') t.isDeeply(qw`${foo} ${bar} ${baz} `, ['exam ple', 'zzzz', ['THINGY']], 'three var trailing whitespace') t.isDeeply(qw` ${foo} ${bar} ${baz}`, ['exam ple', 'zzzz', ['THINGY']], 'three var leading whitespace') t.isDeeply(qw` ${foo} ${bar} ${baz} `, ['exam ple', 'zzzz', ['THINGY']], 'three var both whitespace') t.isDeeply(qw` ${foo} ${bar} ${baz} `, ['exam ple', 'zzzz', ['THINGY']], 'three var all whitespace') t.isDeeply(qw`abc${foo}`, ['abcexam ple'], 'append vars') t.isDeeply(qw`${foo}abc`, ['exam pleabc'], 'prepend vars') t.isDeeply(qw`${foo}${bar}`, ['exam plezzzz'], 'chain vars') t.done() })