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

Commit 1afba6f

Browse files
committed
Fixed code to work in Node 4.
1 parent 60aad2d commit 1afba6f

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"func-names": 0,
88
"no-extend-native": 0,
99
"no-invalid-this": 0,
10-
"prefer-reflect": 0
10+
"prefer-reflect": 0,
11+
"prefer-rest-params": 0
1112
}
1213
}

iknowishouldnt.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,38 @@
1515
* @public
1616
*/
1717

18-
const format = function (...replacements) {
18+
Object.defineProperty(String.prototype, 'format', {
19+
'enumerable': false,
20+
value () {
1921

20-
let value = this;
22+
'use strict';
2123

22-
(value.match(/(%[sidf])/g) || []).forEach((match, key) => {
24+
let value = this;
25+
const replacements = Array.prototype.slice.call(arguments);
2326

24-
if (typeof replacements[key] !== 'undefined') {
27+
(value.match(/(%[sidf])/g) || []).forEach((match, key) => {
2528

26-
if (match === '%i' || match === '%d') {
29+
if (typeof replacements[key] !== 'undefined') {
2730

28-
replacements[key] = parseInt(replacements[key], 10);
31+
if (match === '%i' || match === '%d') {
2932

30-
} else if (match === '%f') {
33+
replacements[key] = parseInt(replacements[key], 10);
3134

32-
replacements[key] = parseFloat(replacements[key]);
35+
} else if (match === '%f') {
3336

34-
}
37+
replacements[key] = parseFloat(replacements[key]);
3538

36-
value = value.replace(match, replacements[key]);
39+
}
3740

38-
}
41+
value = value.replace(match, replacements[key]);
3942

40-
});
43+
}
4144

42-
return value;
45+
});
4346

44-
};
47+
return value;
4548

46-
Object.defineProperty(String.prototype, 'format', {
47-
'enumerable': false,
48-
'value': format
49+
}
4950
});
5051

5152
/**
@@ -57,21 +58,21 @@ Object.defineProperty(String.prototype, 'format', {
5758
* @public
5859
*/
5960

60-
const chunk = function (num) {
61+
Object.defineProperty(Array.prototype, 'chunk', {
62+
'enumerable': false,
63+
value (num) {
6164

62-
const array = [];
65+
'use strict';
6366

64-
while (this.length) {
67+
const array = [];
6568

66-
array.push(this.splice(0, num));
69+
while (this.length) {
6770

68-
}
71+
array.push(this.splice(0, num));
6972

70-
return array;
73+
}
7174

72-
};
75+
return array;
7376

74-
Object.defineProperty(Array.prototype, 'chunk', {
75-
'enumerable': false,
76-
'value': chunk
77+
}
7778
});

0 commit comments

Comments
 (0)