@hzab/formily-result-utils
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "@hzab/formily-result-utils", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "formily 处理展示结果的工具库", | ||
@@ -5,0 +5,0 @@ "main": "src", |
@@ -5,3 +5,3 @@ import dayjs from "dayjs"; | ||
import { checkEmpty, handleEmptyVal } from "./empty-val"; | ||
import { checkEmpty, handleEmptyVal, IHandleEmptyValOpt } from "./empty-val"; | ||
@@ -21,3 +21,3 @@ dayjs.extend(advancedFormat); | ||
export interface IGetDateStrOpt { | ||
export interface IGetDateStrOpt extends IHandleEmptyValOpt { | ||
formatEnum?: Object; | ||
@@ -86,3 +86,3 @@ } | ||
if (checkEmpty(val)) { | ||
return handleEmptyVal(val); | ||
return handleEmptyVal(val, opt); | ||
} | ||
@@ -89,0 +89,0 @@ |
@@ -1,142 +0,6 @@ | ||
import { nanoid } from "nanoid"; | ||
/** | ||
* 建立一个可以存取该 file 的 url | ||
* @param {Object} file 文件 | ||
* @returns {string} url | ||
* blob:http://localhost:8000/c9950644-5118-4231-9be7-8183bde1fdc7 | ||
*/ | ||
export function getFileURL(file) { | ||
let url = file.url || null; | ||
try { | ||
// 下面函数执行的效果是一样的,只是需要针对不同的浏览器执行不同的 js 函数而已 | ||
if (window.createObjectURL != undefined) { | ||
// basic | ||
url = window.createObjectURL(file); | ||
} else if (window.URL != undefined) { | ||
// mozilla(firefox) | ||
url = window.URL.createObjectURL(file); | ||
} else if (window.webkitURL != undefined) { | ||
// webkit or chrome | ||
url = window.webkitURL.createObjectURL(file); | ||
} | ||
} catch (error) { | ||
console.warn("getFileURL Error: ", error); | ||
} | ||
return url; | ||
} | ||
/** | ||
* 判断 url 是否带有指定图片后缀 | ||
* @param {string} url | ||
* @returns | ||
*/ | ||
export function checkImageUrl(url) { | ||
const imgTypes = [ | ||
"apng", | ||
"avif", | ||
"bmp", | ||
"gif", | ||
"ico", | ||
"cur", | ||
"jpg", | ||
"jpeg", | ||
"jfif", | ||
"pjpeg", | ||
"pjp", | ||
"png", | ||
"svg", | ||
"tif", | ||
"tiff", | ||
"webp", | ||
]; | ||
return checkUrlSuffix(url, imgTypes); | ||
} | ||
/** | ||
* 判断 url 是否带有指定视频后缀 | ||
* @param {string} url | ||
* @returns | ||
*/ | ||
export function checkVideoUrl(url) { | ||
const imgTypes = ["3gp", "mpg", "mpeg", "mp4", "m4v", "m4p", "ogv", "ogg", "mov", "webm"]; | ||
return checkUrlSuffix(url, imgTypes); | ||
} | ||
/** | ||
* 判断 url 是否带有指定音频后缀 | ||
* @param {string} url | ||
* @returns | ||
*/ | ||
export function checkAudioUrl(url) { | ||
const imgTypes = ["3gp", "adts", "mpeg", "mp3", "mp4", "ogg", "mov", "webm", "rtp", "amr", "wav"]; | ||
return checkUrlSuffix(url, imgTypes); | ||
} | ||
/** | ||
* 检查 url 是否带有指定后缀 | ||
* @param {string} url url 地址 | ||
* @param {Array} types 后缀数组 | ||
* @returns | ||
*/ | ||
export function checkUrlSuffix(url, types = [], caseSensitive) { | ||
if (!url) { | ||
return false; | ||
} | ||
let _url = url?.replace(/\?.+/, ""); | ||
const reg = new RegExp(`\.(${types.join("|")})$`, caseSensitive ? undefined : "i"); | ||
if (reg.test(_url)) { | ||
return true; | ||
} | ||
} | ||
function getArr(value) { | ||
return Array.isArray(value) ? value : (value && [value]) || []; | ||
} | ||
export function handleMaxCount(fileList, maxCount) { | ||
let list = getArr(fileList); | ||
if (maxCount > 0 && list.length > maxCount) { | ||
list = list.slice(maxCount); | ||
} | ||
return list; | ||
} | ||
/** | ||
* 处理传入的数据,数据格式统一转成 Array<fileObject> | ||
* @param {Array} fileList Array<fileObject|string> | ||
* @param {number} maxCount | ||
* @returns Array<fileObject> | ||
*/ | ||
export function handleInputFileList(_fileList, maxCount = 1) { | ||
const fileList = handleMaxCount(getArr(_fileList), maxCount); | ||
if (fileList.length === 0) { | ||
return fileList; | ||
} | ||
let resList = fileList; | ||
if (!Array.isArray(resList)) { | ||
resList = [resList]; | ||
} | ||
resList = fileList.map((file, i) => { | ||
if (typeof file === "string") { | ||
const uid = nanoid(); | ||
return { | ||
name: uid, | ||
uid: uid, | ||
ossUrl: file, | ||
url: file, | ||
// size: Infinity, | ||
}; | ||
} | ||
if (file && !file.uid) { | ||
file.uid = nanoid(); | ||
} | ||
if (file && !file.name) { | ||
file.name = file.uid; | ||
} | ||
return file; | ||
}); | ||
return resList; | ||
} | ||
export const mergeGlobalProps = (props) => { | ||
return { | ||
...props.globalProps, | ||
...props, | ||
}; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24977
23
763