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

Commit 73fcdcf

Browse files
author
Irfan Maulana
committed
v.1.1.0 #1 add slug filter
1 parent e754190 commit 73fcdcf

File tree

8 files changed

+28
-10
lines changed

8 files changed

+28
-10
lines changed

App.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99

1010

1111
<div>
12-
<b>Before filter</b> : {{ textInput }}
12+
<b>Before filter</b>: {{ textInput }}
1313
</div>
1414
<div>
15-
<b>Uppercase</b> : <b class="result__uppercase">{{ textInput | uppercase }}</b>
15+
<b>Uppercase</b>: <span class="result__uppercase">{{ textInput | uppercase }}</span>
1616
<br>
17-
<b>Lowercase</b> : <b class="result__lowercase">{{ textInput | lowercase }}</b>
17+
<b>Lowercase</b>: <span class="result__lowercase">{{ textInput | lowercase }}</span>
1818
<br>
19-
<b>Capitalize</b> : <b class="result__capitalize">{{ textInput | capitalize }}</b>
19+
<b>Capitalize</b>: <span class="result__capitalize">{{ textInput | capitalize }}</span>
2020
<br>
21-
<b>Titlecase</b> : <b class="result__titlecase">{{ textInput | titlecase }}</b>
21+
<b>Titlecase</b>: <span class="result__titlecase">{{ textInput | titlecase }}</span>
22+
<br>
23+
<b>Slug</b>: <span class="result__slug">{{ textInput | slug }}</span>
2224
<br>
2325
</div>
2426

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
+ `lowercase`
2424
+ `capitalize`
2525
+ `titlecase`
26+
+ `slug`
2627

2728
## Download
2829

@@ -53,6 +54,7 @@ Vue.use(VueStringFilter)
5354
<span>{{ stringWillFormatted | lowercase }}</span>
5455
<span>{{ stringWillFormatted | capitalize }}</span>
5556
<span>{{ stringWillFormatted | titlecase }}</span>
57+
<span>{{ stringWillFormatted | slug }}</span>
5658
```
5759

5860

VueStringFilter.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ const VueStringFilter = {
2222
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
2323
})
2424
})
25+
26+
Vue.filter('slug', function (value) {
27+
28+
// credit for gist : https://gist.github.com/mathewbyrne/1280286
29+
let result = value.toString()
30+
.toLowerCase()
31+
.trim()
32+
.replace(/&/g, '-and-') //
33+
.replace(/[\s\W-]+/g, '-')
34+
.replace(/--+/g, '-')
35+
.replace(/^-+|-+$/g, '')
36+
37+
return result
38+
})
2539

2640
}
2741
}

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

49 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.0.0",
4+
"version": "1.1.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)