Skip to content

Commit 3cf0f84

Browse files
committed
refactor: replace deprecated String.prototype.substr()
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated Signed-off-by: Tobias Speicher <[email protected]>
1 parent c1b21a9 commit 3cf0f84

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/lib/isDataURI.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export default function isDataURI(str) {
1414
}
1515
const attributes = data.shift().trim().split(';');
1616
const schemeAndMediaType = attributes.shift();
17-
if (schemeAndMediaType.substr(0, 5) !== 'data:') {
17+
if (schemeAndMediaType.slice(0, 5) !== 'data:') {
1818
return false;
1919
}
20-
const mediaType = schemeAndMediaType.substr(5);
20+
const mediaType = schemeAndMediaType.slice(5);
2121
if (mediaType !== '' && !validMediaType.test(mediaType)) {
2222
return false;
2323
}

src/lib/isEmail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function isEmail(str, options) {
7777
// eg. myname <[email protected]>
7878
// the display name is `myname` instead of `myname `, so need to trim the last space
7979
if (display_name.endsWith(' ')) {
80-
display_name = display_name.substr(0, display_name.length - 1);
80+
display_name = display_name.slice(0, -1);
8181
}
8282

8383
if (!validateDisplayName(display_name)) {
@@ -144,7 +144,7 @@ export default function isEmail(str, options) {
144144
return false;
145145
}
146146

147-
let noBracketdomain = domain.substr(1, domain.length - 2);
147+
let noBracketdomain = domain.slice(1, -1);
148148

149149
if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
150150
return false;

src/lib/isIdentityCard.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ const validators = {
130130
},
131131
IR: (str) => {
132132
if (!str.match(/^\d{10}$/)) return false;
133-
str = (`0000${str}`).substr(str.length - 6);
133+
str = (`0000${str}`).slice(str.length - 6);
134134

135-
if (parseInt(str.substr(3, 6), 10) === 0) return false;
135+
if (parseInt(str.slice(3, 9), 10) === 0) return false;
136136

137-
const lastNumber = parseInt(str.substr(9, 1), 10);
137+
const lastNumber = parseInt(str.slice(9, 10), 10);
138138
let sum = 0;
139139

140140
for (let i = 0; i < 9; i++) {
141-
sum += parseInt(str.substr(i, 1), 10) * (10 - i);
141+
sum += parseInt(str.slice(i, i + 1), 10) * (10 - i);
142142
}
143143

144144
sum %= 11;

src/lib/isTaxID.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ function enUsGetPrefixes() {
373373
* Verify that the TIN starts with a valid IRS campus prefix
374374
*/
375375
function enUsCheck(tin) {
376-
return enUsGetPrefixes().indexOf(tin.substr(0, 2)) !== -1;
376+
return enUsGetPrefixes().indexOf(tin.slice(0, 2)) !== -1;
377377
}
378378

379379
/*

src/lib/isURL.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ export default function isURL(url, options) {
8787
}
8888
} else if (options.require_protocol) {
8989
return false;
90-
} else if (url.substr(0, 2) === '//') {
90+
} else if (url.slice(0, 2) === '//') {
9191
if (!options.allow_protocol_relative_urls) {
9292
return false;
9393
}
94-
split[0] = url.substr(2);
94+
split[0] = url.slice(2);
9595
}
9696
url = split.join('://');
9797

0 commit comments

Comments
 (0)