@varlet/ui
Version:
A Vue3 component library based on Material Design 2 and 3, supporting mobile and desktop.
59 lines (58 loc) • 1.45 kB
JavaScript
import { isString, removeItem } from "@varlet/shared";
const isHTMLSupportImage = (val) => {
if (!isString(val)) {
return false;
}
return val.startsWith("data:image") || /\.(png|jpg|gif|jpeg|svg|webp|ico)$/i.test(val);
};
const isHTMLSupportVideo = (val) => {
if (!isString(val)) {
return false;
}
return val.startsWith("data:video") || /\.(mp4|webm|ogg)$/.test(val);
};
const createCache = (max) => {
const cache = [];
return {
cache,
has(key) {
return this.cache.includes(key);
},
add(key) {
if (this.has(key)) {
return;
}
this.cache.length === max && cache.shift();
this.cache.push(key);
},
remove(key) {
this.has(key) && removeItem(this.cache, key);
},
clear() {
this.cache.length = 0;
}
};
};
const linear = (value) => value;
const cubic = (value) => value ** 3;
const easeInOutCubic = (value) => value < 0.5 ? cubic(value * 2) / 2 : 1 - cubic((1 - value) * 2) / 2;
const padStart = (str, maxLength, fillString = "") => {
if (str === void 0) {
str = "";
}
if (str.length >= maxLength) {
return str;
}
const len = maxLength - str.length;
const repeatCount = Math.floor(len / fillString.length);
return fillString.repeat(repeatCount) + fillString.slice(0, len % fillString.length) + str;
};
export {
createCache,
cubic,
easeInOutCubic,
isHTMLSupportImage,
isHTMLSupportVideo,
linear,
padStart
};