@rainte/js 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainte/js",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "main": "dist/index.umd.cjs",
6
6
  "module": "dist/index.js",
package/src/fast/index.ts CHANGED
@@ -1,8 +1,8 @@
1
- export const find = (list: any[], value: any, text = '') => {
1
+ export const find = (list: any[], value: any, label = '') => {
2
2
  return (
3
3
  list.find((item: any) => {
4
4
  return item.value == (Array.isArray(value) ? value[0] : value)
5
- })?.label ?? text
5
+ })?.label ?? label
6
6
  )
7
7
  }
8
8
 
package/src/file/index.ts CHANGED
@@ -8,11 +8,18 @@ export const toBase64 = (blob: Blob) => {
8
8
  }
9
9
 
10
10
  export const toBlob = (base64: string) => {
11
- if (!base64.includes(',')) return
12
- const character = atob(base64.split(',')[1])
13
- const bytes = []
11
+ const character = atob(base64.split(',')[1] || base64)
12
+ const bytes = new Uint8Array(character.length)
14
13
  for (let i = 0; i < character.length; i++) {
15
- bytes.push(character.charCodeAt(i))
14
+ bytes[i] = character.charCodeAt(i)
16
15
  }
17
- return new Blob([new Uint8Array(bytes)])
16
+ return new Blob([bytes])
17
+ }
18
+
19
+ export const download = (filename: string, obj: Blob | MediaSource) => {
20
+ const link = document.createElement('a')
21
+ link.href = URL.createObjectURL(obj)
22
+ link.download = filename
23
+ link.click()
24
+ URL.revokeObjectURL(link.href)
18
25
  }
package/src/http/index.ts CHANGED
@@ -11,6 +11,11 @@ export const post = (url: string, data?: Record<string, any>) => {
11
11
  return request({ url, method: 'POST', data })
12
12
  }
13
13
 
14
+ export const download = (config: AxiosRequestConfig) => {
15
+ config.responseType = config.responseType || 'blob'
16
+ return request(config)
17
+ }
18
+
14
19
  export const request = (config: AxiosRequestConfig) => {
15
20
  return axios.request(config)
16
21
  }