Skip to content
New issue

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

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

Already on GitHub? # to your account

Replace usages of substr with substring #343

Merged
merged 1 commit into from
Sep 3, 2023
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
2 changes: 1 addition & 1 deletion docs/demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@
load.data = function (dataArg) {
const data = dataArg || {};
dom.text(document.getElementById('description'), data.description || '');
if (data.url && trim(data.url).substr(0, 10) !== 'javascript') {
if (data.url && trim(data.url).substring(0, 10) !== 'javascript') {
document.getElementById('external-link').setAttribute('href', data.url);
document.getElementById('external-link').style.display = '';
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/filters/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export const reverseFilter = function arraysReverseFilter(context) {
context
.setResult([
context.delta[0],
parseInt(context.childName.substr(1), 10),
parseInt(context.childName.substring(1), 10),
ARRAY_MOVE,
])
.exit();
Expand All @@ -418,7 +418,7 @@ reverseFilter.filterName = 'arrays';

const reverseArrayDeltaIndex = (delta, index, itemDelta) => {
if (typeof index === 'string' && index[0] === '_') {
return parseInt(index.substr(1), 10);
return parseInt(index.substring(1), 10);
} else if (isArray(itemDelta) && itemDelta[2] === 0) {
return `_${index}`;
}
Expand All @@ -428,7 +428,7 @@ const reverseArrayDeltaIndex = (delta, index, itemDelta) => {
const deltaItem = delta[deltaIndex];
if (isArray(deltaItem)) {
if (deltaItem[2] === ARRAY_MOVE) {
const moveFromIndex = parseInt(deltaIndex.substr(1), 10);
const moveFromIndex = parseInt(deltaIndex.substring(1), 10);
const moveToIndex = deltaItem[1];
if (moveToIndex === +index) {
return moveFromIndex;
Expand All @@ -442,7 +442,7 @@ const reverseArrayDeltaIndex = (delta, index, itemDelta) => {
reverseIndex--;
}
} else if (deltaItem[2] === 0) {
const deleteIndex = parseInt(deltaIndex.substr(1), 10);
const deleteIndex = parseInt(deltaIndex.substring(1), 10);
if (deleteIndex <= reverseIndex) {
reverseIndex++;
}
Expand Down
10 changes: 5 additions & 5 deletions src/formatters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getObjectKeys =
};

const trimUnderscore = (str) => {
if (str.substr(0, 1) === '_') {
if (str.substring(0, 1) === '_') {
return str.slice(1);
}
return str;
Expand All @@ -27,7 +27,7 @@ const arrayKeyToSortNumber = (key) => {
if (key === '_t') {
return -1;
} else {
if (key.substr(0, 1) === '_') {
if (key.substring(0, 1) === '_') {
return parseInt(key.slice(1), 10);
} else {
return parseInt(key, 10) + 0.1;
Expand Down Expand Up @@ -159,7 +159,7 @@ class BaseFormatter {
if (isArray(value) && value[2] === 3) {
moveDestinations[value[1].toString()] = {
key: name,
value: left && left[parseInt(name.substr(1))],
value: left && left[parseInt(name.substring(1))],
};
if (this.includeMoveDestinations !== false) {
if (
Expand Down Expand Up @@ -247,9 +247,9 @@ class BaseFormatter {
const pieceOutput = {
type: 'context',
};
if (piece.substr(0, 1) === '+') {
if (piece.substring(0, 1) === '+') {
pieceOutput.type = 'added';
} else if (piece.substr(0, 1) === '-') {
} else if (piece.substring(0, 1) === '-') {
pieceOutput.type = 'deleted';
}
pieceOutput.text = piece.slice(1);
Expand Down
8 changes: 4 additions & 4 deletions test/examples/diffpatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ examples.text = [
minLength: 10,
},
},
left: largeText.substr(0, 10),
right: largeText.substr(0, 11).replace(/Madre/g, 'Padre'),
left: largeText.substring(0, 10),
right: largeText.substring(0, 11).replace(/Madre/g, 'Padre'),
delta: ['@@ -1,10 +1,11 @@\n -\n-M\n+P\n adre,%0Acu\n+a\n', 0, 2],
reverse: ['@@ -1,11 +1,10 @@\n -\n-P\n+M\n adre,%0Acu\n-a\n', 0, 2],
exactReverse: false,
Expand All @@ -609,8 +609,8 @@ examples.text = [
minLength: 10,
},
},
left: largeText.substr(0, 9),
right: largeText.substr(0, 11).replace(/Madre/g, 'Padre'),
left: largeText.substring(0, 9),
right: largeText.substring(0, 11).replace(/Madre/g, 'Padre'),
delta: ['-Madre,\nc', '-Padre,\ncua'],
reverse: ['-Padre,\ncua', '-Madre,\nc'],
exactReverse: false,
Expand Down