Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

Commit 49c97d4

Browse files
author
Irfan Maulana
committed
v.1.2.0 add truncate and cut
1 parent 73fcdcf commit 49c97d4

8 files changed

+32
-6
lines changed

App.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
<div>
1212
<b>Before filter</b>: {{ textInput }}
13+
<br>
14+
<br>
1315
</div>
1416
<div>
1517
<b>Uppercase</b>: <span class="result__uppercase">{{ textInput | uppercase }}</span>
@@ -22,6 +24,10 @@
2224
<br>
2325
<b>Slug</b>: <span class="result__slug">{{ textInput | slug }}</span>
2426
<br>
27+
<b>Truncate</b>: <span class="result__truncate">{{ textInput | truncate(10) }}</span>
28+
<br>
29+
<b>Cut</b>: <span class="result__cut">{{ textInput | cut(10) }}</span>
30+
<br>
2531
</div>
2632

2733

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
+ `capitalize`
2525
+ `titlecase`
2626
+ `slug`
27+
+ `truncate`
28+
+ `cut`
2729

2830
## Download
2931

@@ -55,6 +57,8 @@ Vue.use(VueStringFilter)
5557
<span>{{ stringWillFormatted | capitalize }}</span>
5658
<span>{{ stringWillFormatted | titlecase }}</span>
5759
<span>{{ stringWillFormatted | slug }}</span>
60+
<span>{{ stringWillFormatted | truncate(10) }}</span>
61+
<span>{{ stringWillFormatted | cut(10) }}</span>
5862
```
5963

6064

VueStringFilter.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const VueStringFilter = {
2-
install(Vue, options) {
2+
install(Vue) {
33

44
Vue.filter('lowercase', function (value) {
55

@@ -37,6 +37,22 @@ const VueStringFilter = {
3737
return result
3838
})
3939

40+
Vue.filter('truncate', function (value, count) {
41+
if (typeof value === 'string') {
42+
return value.length < count ? value : value.slice(0, count) + '...'
43+
} else {
44+
return value
45+
}
46+
})
47+
48+
Vue.filter('cut', function (value, count) {
49+
if (typeof value === 'string') {
50+
return value.length < count ? value : value.slice(0, count)
51+
} else {
52+
return value
53+
}
54+
})
55+
4056
}
4157
}
4258

dist/VueStringFilter.bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueStringFilter.bundle.js.gz

45 Bytes
Binary file not shown.

dist/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-string-filter",
33
"description": "Lightweight Vue 2 String Manipulation Filter",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"license": "MIT",
66
"author": "Irfan Maulana (https://github.com/mazipan/)",
77
"homepage": "https://mazipan.github.io/vue-string-filter/",

0 commit comments

Comments
 (0)