yanzhen-design-vue
Version:
38 lines (37 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const typeValidator = (data) => {
const dataType = Object.prototype.toString.call(data);
return dataType;
};
const jsonParse = (origin = "", targetType) => {
let targetValue;
const dataType = typeValidator(targetType);
const originDataType = typeValidator(origin);
try {
targetValue = JSON.parse(origin);
} catch {
if (dataType === originDataType) {
targetValue = origin;
} else {
switch (dataType) {
case "[object Array]":
targetValue = origin ? [origin] : [];
break;
case "[object Object]":
targetValue = {};
break;
default:
targetValue = origin;
break;
}
}
}
return targetValue;
};
const getFileName = (filePath) => {
const lastSlashIndex = filePath.lastIndexOf("/");
return decodeURIComponent(filePath.slice(lastSlashIndex + 1));
};
exports.getFileName = getFileName;
exports.jsonParse = jsonParse;