Passed
Push — master ( f91fcb...083070 )
by Night
01:21
created

src/ub.strings.findAndInsert.js   A

Complexity

Total Complexity 8
Complexity/F 1.33

Size

Lines of Code 41
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
eloc 27
nc 1
dl 0
loc 41
rs 10
c 1
b 0
f 0
wmc 8
mnd 1
bc 8
fnc 6
bpm 1.3333
cpm 1.3333
noi 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A stringFuncs.insertBeforeLast 0 4 1
A stringFuncs.insertBeforeFirst 0 4 1
A stringFuncs.insertAfterLast 0 4 1
A stringFuncs.insertAfterNth 0 8 2
A stringFuncs.insertAfterFirst 0 4 1
A stringFuncs.insertBeforeNth 0 8 2
1
/** global: UB */
2
3
var stringFuncs = {
4
	
5
	insertAfterNth(find, insert, nth = 1, caseSensitive = true, wholeWords = false) {
6
		var text = this.toString();
7
		var index = text.indexOfNth(find, nth, wholeWords, caseSensitive);
8
		if (index > -1) {
9
			return text.insertAt(insert, index + find.Length);
10
		}
11
		return text;
12
	},
13
	insertAfterLast(find, insert, caseSensitive = true, wholeWords = false) {
14
		var text = this.toString();
15
		return text.insertAfterNth(find, insert, 1, true, caseSensitive, wholeWords);
16
	},
17
	insertAfterFirst(find, insert, caseSensitive = true, wholeWords = false) {
18
		var text = this.toString();
19
		return text.insertAfterNth(find, insert, 1, false, caseSensitive, wholeWords);
20
	},
21
22
	insertBeforeNth(find, insert, nth = 1, caseSensitive = true, wholeWords = false) {
23
		var text = this.toString();
24
		var index = text.indexOfNth(find, nth, wholeWords, caseSensitive);
25
		if (index > -1) {
26
			return text.insertAt(insert, index);
27
		}
28
		return text;
29
	},
30
	insertBeforeLast(find, insert, caseSensitive = true, wholeWords = false) {
31
		var text = this.toString();
32
		return text.insertBeforeNth(find, insert, 1, true, caseSensitive, wholeWords);
33
	},
34
	insertBeforeFirst(find, insert, caseSensitive = true, wholeWords = false) {
35
		var text = this.toString();
36
		return text.insertBeforeNth(find, insert, 1, false, caseSensitive, wholeWords);
37
	},
38
	
39
	none:null
40
};
41
42
// register funcs
43
UB.registerFuncs(String.prototype, stringFuncs);