2.4.1 • Published 10 months ago

@iimm/shared v2.4.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@iimm/shared

NPM version NPM downloads

Install

npm install

导出内容

nanoid

const nanoid: (size?: number = 21) => string
const customNanoidAlphabet: (alpha: string, defaultSize?: number = 21) => ((size?: number = defaultSize) => string)

file

// ===== convert =====
const fileToBase64 = (file: File) => Promise<string>;
const fileToArrayBuffer = (file: File) => Promise<ArrayBuffer>;
const fileToBinaryString = (file: File) => Promise<string>;
const fileToText = (file: File, encoding = 'utf-8') => Promise<string>;

// ==== info =====
const getMimeTypeFromBase64 = (base64Str: string) => mimeType:string;

// ==== download ====
const generateFileDownload = (file: InputFile, fileName = '', extension = '', onDownloadSuccess?: (file: InputFile, fileName: string) => void, onDownloadFail?: (file: InputFile, fileName: string) => void) => void;

image

const isImageMimeType = (type: string) => type.indexOf('image/') === 0;

url

const getFileNameFromUrl = (url = '') => string;
const getFileExtensionFromUrl = (url = '') => string;

isX

const isEqual = (a?: any, b?: any) => [ 'number', 'string' ].includes(typeof (a ?? 0))
  ? a === b
  : JSON.stringify(a) === JSON.stringify(b);

const isInArray = (value: any, array: any[]) => {
  if (!array || !Array.isArray(array)) return false;
  return [ 'number', 'string' ].includes(typeof (value ?? 0))
    ? array.includes(value)
    : array.some(item => isEqual(value, item));
};

const isObject = (value: any) => value !== null && typeof value === 'object';
const isFunction = (value: any) => typeof value === 'function';
const isString = (value: any) => typeof value === 'string';
const isNumber = (value: any) => typeof value === 'number';
const isUndefined = (value: any) => typeof value === 'undefined';


const isBrowser = !!(typeof window !== 'undefined' && window.document && window.document.createElement);

/** 字符串是否是Base64,可以有data前缀,也可以无 */
const isBase64 = (str: string) => {
  if (!str) return false;
  const re = /^(data:([a-z0-9/+.-])+;base64,)?([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/;
  return re.test(str);
};

TODO

LICENSE

MIT

2.4.1

10 months ago

2.4.0

12 months ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

2.3.0

1 year ago

2.1.2

1 year ago

2.2.0

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago