Skip to content

extract 封装的一些提取信息的函数

从 DataUrl 中提取 base64

查看代码
typescript
/**
 * 从Data URL中提取Base64编码的数据
 *
 * @param dataUrl 包含Base64编码数据的Data URL
 * @returns 返回Base64编码的数据字符串
 */
export const extractBase64FromDataUrl = (dataUrl: string) => dataUrl.split(',')[1]
输入
输出
iVBORw0KGgoAAAANSUhEUgAAAAUA

从文件全名中提取文件名和文件后缀

查看代码
typescript
/**
 * 提取文件名信息
 *
 * @param fileName 文件名
 * @returns 包含文件名(不含后缀)和文件后缀的元组,如果文件名没有后缀,则后缀为undefined
 */
export function extractFileNameInfo(fileName: string): [string, string | undefined] {
  const index = fileName.lastIndexOf('.')
  if (index === -1) {
    return [fileName, undefined]
  }
  return [fileName.substring(0, index), fileName.substring(index + 1)]
}
输入
输出
["1","png"]