Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace deprecated String.prototype.substr() #1942

Merged
merged 1 commit into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/isDataURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export default function isDataURI(str) {
}
const attributes = data.shift().trim().split(';');
const schemeAndMediaType = attributes.shift();
if (schemeAndMediaType.substr(0, 5) !== 'data:') {
if (schemeAndMediaType.slice(0, 5) !== 'data:') {
return false;
}
const mediaType = schemeAndMediaType.substr(5);
const mediaType = schemeAndMediaType.slice(5);
if (mediaType !== '' && !validMediaType.test(mediaType)) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function isEmail(str, options) {
// eg. myname <[email protected]>
// the display name is `myname` instead of `myname `, so need to trim the last space
if (display_name.endsWith(' ')) {
display_name = display_name.substr(0, display_name.length - 1);
display_name = display_name.slice(0, -1);
}

if (!validateDisplayName(display_name)) {
Expand Down Expand Up @@ -144,7 +144,7 @@ export default function isEmail(str, options) {
return false;
}

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

if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/isIdentityCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ const validators = {
},
IR: (str) => {
if (!str.match(/^\d{10}$/)) return false;
str = (`0000${str}`).substr(str.length - 6);
str = (`0000${str}`).slice(str.length - 6);

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

const lastNumber = parseInt(str.substr(9, 1), 10);
const lastNumber = parseInt(str.slice(9, 10), 10);
let sum = 0;

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

sum %= 11;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isTaxID.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ function enUsGetPrefixes() {
* Verify that the TIN starts with a valid IRS campus prefix
*/
function enUsCheck(tin) {
return enUsGetPrefixes().indexOf(tin.substr(0, 2)) !== -1;
return enUsGetPrefixes().indexOf(tin.slice(0, 2)) !== -1;
}

/*
Expand Down
4 changes: 2 additions & 2 deletions src/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ export default function isURL(url, options) {
}
} else if (options.require_protocol) {
return false;
} else if (url.substr(0, 2) === '//') {
} else if (url.slice(0, 2) === '//') {
if (!options.allow_protocol_relative_urls) {
return false;
}
split[0] = url.substr(2);
split[0] = url.slice(2);
}
url = split.join('://');

Expand Down