Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "vue-nl2br", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A vue component that turns new lines into line breaks.", | ||
@@ -8,3 +8,4 @@ "main": "./dist/vue-nl2br.js", | ||
"test": "echo \\\"Error: no test specified\\\" && exit 1", | ||
"build": "webpack" | ||
"build": "webpack", | ||
"version": "conventional-changelog --preset angular --infile CHANGELOG.md --same-file && git add CHANGELOG.md" | ||
}, | ||
@@ -32,4 +33,5 @@ "repository": { | ||
"babel-preset-es2015": "^6.24.1", | ||
"conventional-changelog-cli": "^2.0.11", | ||
"webpack": "^2.6.1" | ||
} | ||
} |
# vue-nl2br | ||
A vue component that turns new lines into line breaks. | ||
A vue component which turns new lines into line breaks. | ||
## Why not just use CSS? | ||
See [Why not just use CSS `white-space: pre;`? · Issue #7](https://github.com/inouetakuya/vue-nl2br/issues/7) | ||
## Requirement | ||
* [Vue.js](https://github.com/vuejs/vue) `^2.0.0` | ||
- [Vue.js](https://github.com/vuejs/vue) `^2.0.0` | ||
## Installation | ||
```sh | ||
```shell | ||
npm install --save vue-nl2br | ||
@@ -18,3 +22,3 @@ ``` | ||
```html | ||
<nl2br tag="p" :text="`myLine1\nmyLine2`" /> | ||
<nl2br tag="p" :text="`myLine1\nmyLine2`" class-name="foo bar" /> | ||
``` | ||
@@ -25,6 +29,6 @@ | ||
```html | ||
<p>myLine1<br>myLine2</p> | ||
<p class="foo bar">myLine1<br>myLine2</p> | ||
``` | ||
### (1) To register a global component | ||
### (1) Global registration | ||
@@ -55,3 +59,3 @@ https://vuejs.org/v2/guide/components.html#Registration | ||
export default { | ||
name: 'my-component', | ||
name: 'MyComponent', | ||
components: { | ||
@@ -67,8 +71,11 @@ Nl2br, | ||
* `tag`: HTML tag name which is passed to [createElement function](https://vuejs.org/v2/guide/render-function.html#createElement-Arguments) | ||
* Type: `String` | ||
* Required: true | ||
* `text`: Text in the tag. | ||
* Type: `String` | ||
* Required: true | ||
- `tag`: HTML tag name which is passed to [createElement function](https://vuejs.org/v2/guide/render-function.html#createElement-Arguments) | ||
- Type: `String` | ||
- Required: true | ||
- `text`: Text in the tag. | ||
- Type: `String` | ||
- Required: true | ||
- `className`: HTML class name(s) | ||
- Type: `String` | ||
- Required: false | ||
@@ -75,0 +82,0 @@ ## License |
@@ -12,12 +12,17 @@ export default { | ||
}, | ||
className: { | ||
type: String, | ||
required: false, | ||
}, | ||
}, | ||
render (createElement, context) { | ||
return createElement(context.props.tag, | ||
context.props.text.split('\n').reduce((accumulator, string) => { | ||
if (!Array.isArray(accumulator)) { | ||
return [accumulator, createElement('br'), string] | ||
} | ||
return accumulator.concat([createElement('br'), string]) | ||
})) | ||
render(createElement, context) { | ||
return createElement(context.props.tag, { | ||
'class': context.props.className | ||
}, context.props.text.split('\n').reduce((accumulator, string) => { | ||
if (!Array.isArray(accumulator)) { | ||
return [accumulator, createElement('br'), string] | ||
} | ||
return accumulator.concat([createElement('br'), string]) | ||
})) | ||
}, | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126826
17
167
81
5