
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
@builtwithjavascript/file-input-validator
Advanced tools
A generic file input validator that can be used in other frameworks like React, Vue, Svelte etc.
A generic file input validator
npm i -D @builtwithjavascript/file-input-validator
import type {
IFileInfo,
IFileValidatorItem,
IFileValidatorOptions,
} from '@builtwithjavascript/file-input-validator'
import { useFileInputValidator } from '@builtwithjavascript/file-input-validator'
// file validator:
const fileValidator = useFileInputValidator(validatorOptions)
// file info state
const [fileInfo, setFileInfo] = useState<IFileInfo>({
file: null,
lastModified: '',
fileSelected: false,
isValid: false,
name: '',
displayName: '',
message: ''
})
// validator items state
const [validatorItems, setValidatorItems] = useState<IFileValidatorItem[]>([])
const onFileInputChanged = (updatedModel: IFileInfo) => {
setFileInfo(updatedModel)
setValidatorItems(fileValidator.validateFile(fileInfo))
}
...
<script setup lang="ts">
import { ref } from 'vue'
import { FileUploadComponent } from '@builtwithjavascript/vue-file-upload'
import type {
IFileInfo,
IFileValidatorOptions
} from '@builtwithjavascript/vue-file-upload'
const fileValidatorOptions: IFileValidatorOptions = {
allowedTypes: ['csv', 'json', 'txt'],
maxSize: 3, // in MB
maxNameLength: 60, // max name length in chars
nameTruncateMaxLength: 35, // will truncate the display of the name
propertiesToValidate: ['name', 'type', 'size']
}
const onUploadClicked = async (fileInfo: IFileInfo) => {
// do what you need to do with fileInfo.file
// i.e. create form data and post it to an API endpoint
const file = new FormData()
file.append('file', fileInfo.file as Blob)
const response = await someApiClient.post({
file: file
})
...
}
// optional: to reset from your parent component:
const refFileUploadComp = ref<InstanceType<typeof FileUploadComponent> | null>()
const reset = () => {
refFileUploadComp.value?.reset()
}
</script>
<template>
<FileUploadComponent
id="file-input"
uploadLabel="Import File"
ref="refFileUploadComp"
:validatorOptions="fileValidatorOptions"
:roundedCorners="true"
:showOnlyErrors="true"
successClass="success bg-pink-500"
errorClass = "error bg-gray-500"
inputCssClass = "border border-slate-500"
@uploadClicked="onUploadClicked" />
<!-- optional: to reset from your parent component -->
<button @click="reset">Reset</button>
</template>
NOTE: if you pass showOnlyErrors true, then only the validator items that fail will be displayed.
@types/node jsdom prettier typescript vite vitest
FAQs
A generic file input validator that can be used in other frameworks like React, Vue, Svelte etc.
We found that @builtwithjavascript/file-input-validator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.