Skip to content

Commit

Permalink
fix(core): fix type Number in slideToLoop (#5732)
Browse files Browse the repository at this point in the history
  • Loading branch information
vchereshnevyi authored May 31, 2022
1 parent 90610bf commit 1e1336b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/core/slide/slideToLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ export default function slideToLoop(
runCallbacks = true,
internal,
) {
if (typeof index === 'string') {
/**
* The `index` argument converted from `string` to `number`.
* @type {number}
*/
const indexAsNumber = parseInt(index, 10);

/**
* Determines whether the `index` argument is a valid `number`
* after being converted from the `string` type.
* @type {boolean}
*/
const isValidNumber = isFinite(indexAsNumber);

if (!isValidNumber) {
throw new Error(
`The passed-in 'index' (string) couldn't be converted to 'number'. [${index}] given.`,
);
}

// Knowing that the converted `index` is a valid number,
// we can update the original argument's value.
index = indexAsNumber;
}

const swiper = this;
let newIndex = index;
if (swiper.params.loop) {
Expand Down

0 comments on commit 1e1336b

Please sign in to comment.