Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
sveltekit-yup
Advanced tools
Svelte component library using Yup for form validation.
An update has been made for the svelte-yup project sveltekit.
$ npm i sveltekit-yup --save-dev
$ npm i yup
<script>
import * as yup from 'yup';
import {YupForm, YupMessage} from 'sveltekit-yup';
let schema = yup.object().shape({
name: yup.string().required().max(30).label("Name"),
email: yup.string().required().email().label("Email address"),
});
let fields = {email: "", name: ""};
let submitted = false;
let isValid;
function formSubmit(){
submitted = true;
isValid = schema.isValidSync(fields);
if(isValid){
alert('Everything is validated!');
}
}
</script>
<YupForm class="form" {schema} {fields} submitHandler={formSubmit} {submitted}>
<input type="text" bind:value={fields.name} placeholder="Name">
<YupMessage name="name" />
<input type="text" bind:value={fields.email} placeholder="Email address">
<YupMessage name="email" />
<button type="submit">Submit</button>
</YupForm>
Example:
<script>
...
import {YupMessage, isInvalid} from 'sveltekit-yup';
...
$: invalid = (name)=>{
if(submitted){
return isInvalid(schema, name, fields);
}
return false;
}
...
</script>
<input type="text" class:invalid={invalid("name")} bind:value={fields.name} placeholder="Name">
<style>
.invalid {
border-color: red !important;
}
</style>
Example below to put all messages in one place by YupAllMessages
component.
import {YupAllMessages} from 'sveltekit-yup';
<YupAllMessages />
<YupForm ... color="#b00020">
name | props | description |
---|---|---|
YupForm | schema , fields , submitHandler , submitted and color | |
YupMessage | name | Error message of a field name by name prop. name should be the schema field name (no label name) |
YupAllMessages | Puts all field messages in one place |
isInvalid(schema:Object, name:String, fields:Object)
...
let btnDisabled = false;
$: if(submitted){
btnDisabled = true;
isValid = schema.isValidSync(fields);
if(isValid){
btnDisabled = false;
}
}
...
<button type="submit" disabled={btnDisabled}>Submit</button>
Emrullah TUNCAY
MIT
FAQs
Svelte component library using Yup for form validation.
We found that sveltekit-yup demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.