Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(utils): add file deep cloning#6668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
cabarnes wants to merge1 commit intobootstrap-vue:dev
base:dev
Choose a base branch
Loading
fromsmartfile:file-clone-deep
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletionsrc/utils/clone-deep.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { isArray, isPlainObject } from './inspect'
import { isArray,isFile,isPlainObject } from './inspect'
import { keys } from './object'

export const cloneDeep = (obj, defaultValue = obj) => {
Expand All@@ -11,5 +11,11 @@ export const cloneDeep = (obj, defaultValue = obj) => {
{}
)
}
if (isFile(obj)) {
return new File([obj], obj.name, {
lastModified: obj.lastModified,
type: obj.type
})
}
return defaultValue
}
8 changes: 8 additions & 0 deletionssrc/utils/clone-deep.spec.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,4 +67,12 @@ describe('cloneDeep()', () => {
expect(cloneDeep(a).c).toEqual(a.c)
expect(cloneDeep(a).c).not.toBe(a.c)
})

it('should clone files', () => {
const a = new File([1, 2, 3], 'test.txt', { type: 'text/plain' })
expect(cloneDeep(a)).toEqual(a)
expect(cloneDeep(a)).not.toBe(a)
expect(cloneDeep(a.name)).toEqual(a.name)
expect(cloneDeep(a.type)).toEqual(a.type)
})
})

[8]ページ先頭

©2009-2025 Movatter.jp