Content-Length: 317155 | pFad | https://github.com/bootstrap-vue/bootstrap-vue/commit/66c66c8bfd7dee04a8160fc279c4b9451d3496b1

77 feat(utils): add file deep cloning · bootstrap-vue/bootstrap-vue@66c66c8 · GitHub
Skip to content

Commit 66c66c8

Browse files
committed
feat(utils): add file deep cloning
1 parent 19a1727 commit 66c66c8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/utils/clone-deep.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray, isPlainObject } from './inspect'
1+
import { isArray, isFile, isPlainObject } from './inspect'
22
import { keys } from './object'
33

44
export const cloneDeep = (obj, defaultValue = obj) => {
@@ -11,5 +11,11 @@ export const cloneDeep = (obj, defaultValue = obj) => {
1111
{}
1212
)
1313
}
14+
if (isFile(obj)) {
15+
return new File([obj], obj.name, {
16+
lastModified: obj.lastModified,
17+
type: obj.type
18+
})
19+
}
1420
return defaultValue
1521
}

src/utils/clone-deep.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,12 @@ describe('cloneDeep()', () => {
6767
expect(cloneDeep(a).c).toEqual(a.c)
6868
expect(cloneDeep(a).c).not.toBe(a.c)
6969
})
70+
71+
it('should clone files', () => {
72+
const a = new File([1, 2, 3], 'test.txt', { type: 'text/plain' })
73+
expect(cloneDeep(a)).toEqual(a)
74+
expect(cloneDeep(a)).not.toBe(a)
75+
expect(cloneDeep(a.name)).toEqual(a.name)
76+
expect(cloneDeep(a.type)).toEqual(a.type)
77+
})
7078
})

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/bootstrap-vue/bootstrap-vue/commit/66c66c8bfd7dee04a8160fc279c4b9451d3496b1

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy