Skip to content

Commit 30ba284

Browse files
committed
refactor(lastElement): created a function that returns the last element of a charact
1 parent 1e03d07 commit 30ba284

15 files changed

Lines changed: 128 additions & 108 deletions

File tree

.eslintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"BASICIMAGE": true,
6161
"INSTAGRAM": true,
6262
"OPENGRAPH": true,
63-
"ejs": true,
6463
"GITHUB": true,
6564
"SLIDESHARE": true
6665
}

dist/embed.min.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.

src/embed.es2015.js

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

src/embed.es2015.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.

src/embed.js

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

src/embed.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.

src/js/modules/audio/spotify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Base from '../base'
22
import regex from '../regex'
3+
import { lastElement } from '../utils'
34

45
export default class Spotify extends Base{
56
constructor(input,output, options, embeds) {
@@ -9,8 +10,7 @@ export default class Spotify extends Base{
910
}
1011

1112
template(match){
12-
let a = match.split('/');
13-
let id = a[a.length-1];
13+
let id = lastElement(match.split('/'));
1414
return this.options.template.spotify(id, this.options);
1515
}
1616
}

src/js/modules/code/jsfiddle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Base from '../base'
22
import regex from '../regex'
3+
import {lastElement} from '../utils'
34

45
export default class JsFiddle extends Base {
56
constructor(input, output, options, embeds) {
@@ -9,7 +10,7 @@ export default class JsFiddle extends Base {
910
}
1011

1112
template(id) {
12-
id = id[id.length - 1] == '/' ? id.slice(0, - 1) : id;
13+
id = lastElement(id) == '/' ? id.slice(0, - 1) : id;
1314
id = (id.indexOf('//') !== -1) ? id : `//${id}`;
1415
return this.options.template.jsFiddle(id, this.options)
1516
}

src/js/modules/code/plunker.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import Base from '../base'
22
import regex from '../regex'
3+
import {lastElement} from '../utils'
34

45
export default class Plunker extends Base {
5-
constructor(input, output, options, embeds) {
6-
super(input, output, options, embeds);
7-
this.regex = regex.plunker;
8-
this.service = 'plunker'
9-
}
6+
constructor(input, output, options, embeds) {
7+
super(input, output, options, embeds);
8+
this.regex = regex.plunker;
9+
this.service = 'plunker'
10+
}
1011

11-
template(match) {
12-
let a = match.split('?')[0].split('/');
13-
const id = a[a.length - 1];
14-
return this.options.template.plunker(id, this.options)
15-
}
12+
template(match) {
13+
const a = match.split('?')[0].split('/'); //TODO : make sure ? is excluded in regex.
14+
const id = lastElement(a);
15+
return this.options.template.plunker(id, this.options)
16+
}
1617
}
1718

src/js/modules/url.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { urlRegex } from './utils'
1+
import { urlRegex, lastElement } from './utils'
22

33
export default class Url {
44
constructor(input, options) {
@@ -10,8 +10,8 @@ export default class Url {
1010
process() {
1111
var config = this.options.linkOptions;
1212
return this.input.replace(this.urlRegex, (match)=> {
13-
let extension = match.split('.')[match.split('.').length - 1];
14-
if ((match[match.length - 1] == '/'))
13+
let extension = lastElement(match.split('.'));
14+
if ((lastElement(match) === '/'))
1515
match = match.slice(0, -1);
1616
if (config.exclude.indexOf(extension) === -1)
1717
return this.options.template.url(match, this.options);

0 commit comments

Comments
 (0)