44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Markdown
		
	
	
	
		
		
			
		
	
	
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Markdown
		
	
	
	
| 
								 | 
							
								# expand-template
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								> Expand placeholders in a template string.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								[](https://www.npmjs.com/package/expand-template)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								[](https://travis-ci.org/ralphtheninja/expand-template)
							 | 
						||
| 
								 | 
							
								[](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).
							 |