swiper-next
Version:
Vue3 的 Swiper 组件
31 lines (30 loc) • 647 B
JavaScript
import { isString } from "@vue/shared";
import { upx2px } from "../../shared/index.mjs";
function hasRpx(str) {
str = str + "";
return str.indexOf("rpx") !== -1 || str.indexOf("upx") !== -1;
}
function rpx2px(str, replace = false) {
if (replace) {
return rpx2pxWithReplace(str);
}
if (isString(str)) {
const res = parseInt(str) || 0;
if (hasRpx(str)) {
return upx2px(res);
}
return res;
}
return str;
}
function rpx2pxWithReplace(str) {
if (!hasRpx(str)) {
return str;
}
return str.replace(/(\d+(\.\d+)?)[ru]px/g, (_a, b) => {
return upx2px(parseFloat(b)) + "px";
});
}
export {
rpx2px
};