aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/expand-template
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--node_modules/expand-template/.travis.yml6
-rw-r--r--node_modules/expand-template/LICENSE21
-rw-r--r--node_modules/expand-template/README.md43
-rw-r--r--node_modules/expand-template/index.js26
-rw-r--r--node_modules/expand-template/package.json29
-rw-r--r--node_modules/expand-template/test.js67
6 files changed, 192 insertions, 0 deletions
diff --git a/node_modules/expand-template/.travis.yml b/node_modules/expand-template/.travis.yml
new file mode 100644
index 0000000..1335a77
--- /dev/null
+++ b/node_modules/expand-template/.travis.yml
@@ -0,0 +1,6 @@
+language: node_js
+
+node_js:
+ - 6
+ - 8
+ - 10
diff --git a/node_modules/expand-template/LICENSE b/node_modules/expand-template/LICENSE
new file mode 100644
index 0000000..814aef4
--- /dev/null
+++ b/node_modules/expand-template/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2018 Lars-Magnus Skog
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE. \ No newline at end of file
diff --git a/node_modules/expand-template/README.md b/node_modules/expand-template/README.md
new file mode 100644
index 0000000..b98aa48
--- /dev/null
+++ b/node_modules/expand-template/README.md
@@ -0,0 +1,43 @@
+# expand-template
+
+> Expand placeholders in a template string.
+
+[![npm](https://img.shields.io/npm/v/expand-template.svg)](https://www.npmjs.com/package/expand-template)
+![Node version](https://img.shields.io/node/v/expand-template.svg)
+[![Build Status](https://travis-ci.org/ralphtheninja/expand-template.svg?branch=master)](https://travis-ci.org/ralphtheninja/expand-template)
+[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
+
+## Install
+
+```
+$ npm i expand-template -S
+```
+
+## Usage
+
+Default functionality expands templates using `{}` as separators for string placeholders.
+
+```js
+var expand = require('expand-template')()
+var template = '{foo}/{foo}/{bar}/{bar}'
+console.log(expand(template, {
+ foo: 'BAR',
+ bar: 'FOO'
+}))
+// -> BAR/BAR/FOO/FOO
+```
+
+Custom separators:
+
+```js
+var expand = require('expand-template')({ sep: '[]' })
+var template = '[foo]/[foo]/[bar]/[bar]'
+console.log(expand(template, {
+ foo: 'BAR',
+ bar: 'FOO'
+}))
+// -> BAR/BAR/FOO/FOO
+```
+
+## License
+All code, unless stated otherwise, is dual-licensed under [`WTFPL`](http://www.wtfpl.net/txt/copying/) and [`MIT`](https://opensource.org/licenses/MIT).
diff --git a/node_modules/expand-template/index.js b/node_modules/expand-template/index.js
new file mode 100644
index 0000000..e182837
--- /dev/null
+++ b/node_modules/expand-template/index.js
@@ -0,0 +1,26 @@
+module.exports = function (opts) {
+ var sep = opts ? opts.sep : '{}'
+ var len = sep.length
+
+ var whitespace = '\\s*'
+ var left = escape(sep.substring(0, len / 2)) + whitespace
+ var right = whitespace + escape(sep.substring(len / 2, len))
+
+ return function (template, values) {
+ Object.keys(values).forEach(function (key) {
+ var value = String(values[key]).replace(/\$/g, '$$$$')
+ template = template.replace(regExp(key), value)
+ })
+ return template
+ }
+
+ function escape (s) {
+ return [].map.call(s, function (char) {
+ return '\\' + char
+ }).join('')
+ }
+
+ function regExp (key) {
+ return new RegExp(left + key + right, 'g')
+ }
+}
diff --git a/node_modules/expand-template/package.json b/node_modules/expand-template/package.json
new file mode 100644
index 0000000..9a09656
--- /dev/null
+++ b/node_modules/expand-template/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "expand-template",
+ "version": "2.0.3",
+ "description": "Expand placeholders in a template string",
+ "main": "index.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/ralphtheninja/expand-template.git"
+ },
+ "homepage": "https://github.com/ralphtheninja/expand-template",
+ "scripts": {
+ "test": "tape test.js && standard"
+ },
+ "keywords": [
+ "template",
+ "expand",
+ "replace"
+ ],
+ "author": "LM <ralphtheninja@riseup.net>",
+ "license": "(MIT OR WTFPL)",
+ "dependencies": {},
+ "devDependencies": {
+ "standard": "^12.0.0",
+ "tape": "^4.2.2"
+ },
+ "engines": {
+ "node": ">=6"
+ }
+}
diff --git a/node_modules/expand-template/test.js b/node_modules/expand-template/test.js
new file mode 100644
index 0000000..ba6ed87
--- /dev/null
+++ b/node_modules/expand-template/test.js
@@ -0,0 +1,67 @@
+var test = require('tape')
+var Expand = require('./')
+
+test('default expands {} placeholders', function (t) {
+ var expand = Expand()
+ t.equal(typeof expand, 'function', 'is a function')
+ t.equal(expand('{foo}/{bar}', {
+ foo: 'BAR', bar: 'FOO'
+ }), 'BAR/FOO')
+ t.equal(expand('{foo}{foo}{foo}', {
+ foo: 'FOO'
+ }), 'FOOFOOFOO', 'expands one placeholder many times')
+ t.end()
+})
+
+test('support for custom separators', function (t) {
+ var expand = Expand({ sep: '[]' })
+ t.equal(expand('[foo]/[bar]', {
+ foo: 'BAR', bar: 'FOO'
+ }), 'BAR/FOO')
+ t.equal(expand('[foo][foo][foo]', {
+ foo: 'FOO'
+ }), 'FOOFOOFOO', 'expands one placeholder many times')
+ t.end()
+})
+
+test('support for longer custom separators', function (t) {
+ var expand = Expand({ sep: '[[]]' })
+ t.equal(expand('[[foo]]/[[bar]]', {
+ foo: 'BAR', bar: 'FOO'
+ }), 'BAR/FOO')
+ t.equal(expand('[[foo]][[foo]][[foo]]', {
+ foo: 'FOO'
+ }), 'FOOFOOFOO', 'expands one placeholder many times')
+ t.end()
+})
+
+test('whitespace-insensitive', function (t) {
+ var expand = Expand({ sep: '[]' })
+ t.equal(expand('[ foo ]/[ bar ]', {
+ foo: 'BAR', bar: 'FOO'
+ }), 'BAR/FOO')
+ t.equal(expand('[ foo ][ foo ][ foo]', {
+ foo: 'FOO'
+ }), 'FOOFOOFOO', 'expands one placeholder many times')
+ t.end()
+})
+
+test('dollar escape', function (t) {
+ var expand = Expand()
+ t.equal(expand('before {foo} after', {
+ foo: '$'
+ }), 'before $ after')
+ t.equal(expand('before {foo} after', {
+ foo: '$&'
+ }), 'before $& after')
+ t.equal(expand('before {foo} after', {
+ foo: '$`'
+ }), 'before $` after')
+ t.equal(expand('before {foo} after', {
+ foo: '$\''
+ }), 'before $\' after')
+ t.equal(expand('before {foo} after', {
+ foo: '$0'
+ }), 'before $0 after')
+ t.end()
+})