
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@bztes/svelte-ds-validator
Advanced tools
Damn simple value checker for Svelte. Works well with forms
npm i -D @bztes/svelte-ds-validator
yarn add -D @bztes/svelte-ds-validator
<script>
import { and, createChecker, email, number, required } from '@bztes/svelte-ds-validator';
export let data;
// apply validation rules
const checker = createChecker({
fields: {
email: {
value: () => data.email,
rule: and(required(), email()),
},
age: {
value: () => data.age,
rule: and(required(), number({ min: 0, max: 130, int: true })),
},
message: {
value: () => data.message,
// Default rule can be skipped
// rule: required(),
},
},
});
// validate on data changed
$: data, checker.validate();
</script>
<form>
<p>
<label for="email">E-Mail</label>
<input type="email" name="email" bind:value={data.email} />
<span>{$checker.fields.email.error}</span>
</p>
<p>
<label for="age">Age</label>
<input type="number" name="age" bind:value={data.age} />
<span>{$checker.fields.age.error}</span>
</p>
<p>
<label for="message">Message</label>
<textarea name="message" bind:value={data.message} />
<span>{$checker.fields.message.error}</span>
</p>
<p>
<button type="submit" disabled={!$checker.valid}>Send</button>
</p>
</form>
const checker = createChecker({
defaultRule: ...
fields: {
[field_name]: {
value: () => ...
rule: ...
}
}
});
defaultRule (Optional)
A default rule that will be used by all checker fields where no specified rule is defined
fields.[].rule (Optional)
The rule to be checked. Use and()
or or()
to combine rules. If no rule is provided checker.defaultRule
, settings.defaultRule
or required()
is used (in this order).
fields.[].value()
The function that provides the input value to be checked
<script>
...
const checker = ...
// validate on data changed
$: data, checker.validate();
</script>
<form>
<p>
<label for="message">Message</label>
<textarea name="message" bind:value={data.message} />
<span>{$checker.fields.message.error}</span>
</p>
<p>
<button type="submit" disabled={!$checker.valid}>Send</button>
</p>
</form>
checker.validate()
Triggers the validation. You probably want to call this function after the input has changed
$checker.fields.[].error
Contains the error message for the individual fields if the input is invalid, null
otherwise
$checker.fields.[].valid
true
if the specific input value is valid, false
otherwise
$checker.valid
true
if all input values are valid, false
otherwise
const settings = {
fields: {
userMail: {
rule: email(),
},
},
};
const options = {
min: 18,
msg = {
numberToSmall: 'adults only',
},
};
rule = number(options);
number.Options.msg.numberToSmall = 'adults only';
Static
rule = {
validate(input): true | string
value(fieldValue)?: any
error?: string
}
validate
Validation function that takes an input value and returns true on validation success or an error message otherwise
value(input) (Optional)
Function that can be used to provide a rule specific input value for validate(). If undefined the field value will be used as an input
error (Optional)
Can be used to provide a rule specific error message. If undefined the return value from validate will be used as error message
const isTrue = {
validate: (input) => input === true || 'Input value must be true',
};
With parameters
const equals = (value) => ({
validate: (input) => value == input || 'Invalid value',
});
const checker = createChecker({
fields: {
legal: {
value: () => data.legal,
rule: { ...equals(true), error: 'Legal rules have to be accepted' },
},
},
});
let message = { response: 'Succeed', error: null };
const checker = createChecker({
fields: {
message: {
value: () => message,
rule: and({ ...required(), value: (v) => v.response }, { ...falsy(), value: (v) => v.error }),
},
},
});
FAQs
Damn simple value validation for Svelte
The npm package @bztes/svelte-ds-validator receives a total of 0 weekly downloads. As such, @bztes/svelte-ds-validator popularity was classified as not popular.
We found that @bztes/svelte-ds-validator 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.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.