
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
🔌 S’intègre naturellement à vos projets, qu’ils soient front-end ou back-end, et permet de définir des schémas de manière intuitive tout en favorisant leur réutilisation.
💡 Pensée pour allier simplicité et puissance, elle propose des fonctionnalités avancées comme l’inférence de types, ainsi que des validateurs standards tels que isEmail, isUuid ou isIp.
> npm install valia
import { Schema } from 'valia';
const userSchema = new Schema({
type: "object",
shape: {
name: { type: "string" },
role: {
type: "string",
literal: ["WORKER", "CUSTOMER"]
}
}
});
let data = {
name: "Alice",
role: "WORKER"
};
if (userSchema.validate(data)) {
console.log(data.name, data.role);
}
import type { SchemaInfer } from 'valia';
type User = SchemaInfer<typeof userSchema>;
Number • String • Boolean • Object • Array • Function • Symbol • Union • Null • Undefined
Les formats représentent les noeuds de critères qui pourront être utilisés dans les schémas.
L'ordre des propriétés décrites pour chaque formats respecte l'ordre de validation.
Validé n'importe quel nombre
const schema = new Schema({
type: "number"
});
âś… schema.validate(0);
âś… schema.validate(10);
âś… schema.validate(-10);
Valide des nombres qui appartiennent à une plage spécifique
const schema = new Schema({
type: "number",
min: 0,
max: 10
});
âś… schema.validate(0);
âś… schema.validate(10);
❌ schema.validate(-1);
❌ schema.validate(-10);
Validé un nombre spécifique
const schema = new Schema({
type: "number",
literal: 141
});
âś… schema.validate(141);
❌ schema.validate(-1);
❌ schema.validate(-10);
Validé des nombres spécifique avec un tableau
const schema = new Schema({
type: "number",
literal: [141, 282]
});
âś… schema.validate(141);
âś… schema.validate(282);
❌ schema.validate(0);
❌ schema.validate(100);
❌ schema.validate(200);
Validé n'importe quel chaîne de caractères
const schema = new Schema({
type: "string"
});
âś… schema.validate("");
âś… schema.validate("abc");
Validé des chaînes de caractères ayant une longueur spécifique
const schema = new Schema({
type: "string",
min: 3,
max: 3
});
âś… schema.validate("abc");
❌ schema.validate("");
❌ schema.validate("a");
❌ schema.validate("abcd");
Validé des chaînes de caractères avec une expression régulière
const schema = new Schema({
type: "string",
regex: /^#[a-fA-F0-9]{6}$/
});
âś… schema.validate("#000000");
âś… schema.validate("#FFFFFF");
❌ schema.validate("");
❌ schema.validate("#000");
❌ schema.validate("#FFF");
Validé une chaîne de caractères spécifique
const schema = new Schema({
type: "string",
literal: "ABC"
});
âś… schema.validate("ABC");
❌ schema.validate("");
❌ schema.validate("a");
❌ schema.validate("abc");
Validé des chaînes de caractères spécifique avec un tableau
const schema = new Schema({
type: "string",
literal: ["ABC", "XYZ"]
});
âś… schema.validate("ABC");
âś… schema.validate("XYZ");
❌ schema.validate("");
❌ schema.validate("a");
❌ schema.validate("abc");
Validé des chaînes de caractères avec un testeur de chaîne
const schema = new Schema({
type: "string",
constraint: {
idIp: { cidr: true }
}
});
âś… schema.validate("127.0.0.1/24");
❌ schema.validate("");
❌ schema.validate("127.0.0.1");
Validé des chaînes de caractères avec plusieurs testeurs de chaîne
const schema = new Schema({
type: "string",
constraint: {
isEmail: true,
idIp: { cidr: true }
}
});
âś… schema.validate("foo@bar");
âś… schema.validate("127.0.0.1/24");
❌ schema.validate("");
❌ schema.validate("foo@");
❌ schema.validate("127.0.0.1");
Validé n'importe quel booléen
const schema = new Schema({
type: "boolean"
});
âś… schema.validate(true);
âś… schema.validate(false);
❌ schema.validate("");
❌ schema.validate({});
Validé un booléen avec un état spécifique
const schema = new Schema({
type: "boolean",
literal: true
});
âś… schema.validate(true);
❌ schema.validate("");
❌ schema.validate({});
❌ schema.validate(false);
Validé n'importe quel objet
const schema = new Schema({
type: "object"
});
âś… schema.validate({});
âś… schema.validate([]);
âś… schema.validate(new Date());
âś… schema.validate(Object.create(null));
❌ schema.validate("");
Validé un objet de nature simple
const schema = new Schema({
type: "object",
nature: "PLAIN"
});
âś… schema.validate({});
âś… schema.validate(Object.create(null));
❌ schema.validate("");
❌ schema.validate([]);
❌ schema.validate(new Date());
Validé un objet avec des propriétés fixes
const schema = new Schema({
type: "object",
shape: {
foo: { type: "string" },
bar: { type: "string" }
}
});
âś… schema.validate({ foo: "x", bar: "x" });
❌ schema.validate({});
❌ schema.validate({ foo: "x" });
❌ schema.validate({ bar: "x" });
❌ schema.validate({ foo: "x", bar: "x", a: "" });
Validé un objet et un sous-objet de propriétés fixes
const schema = new Schema({
type: "object",
shape: {
foo: { type: "string" },
bar: { type: "string" },
baz: {
foo: { type: "number" },
bar: { type: "number" }
}
}
});
âś… schema.validate({ foo: "x", bar: "x", baz: { foo: 0, bar: 0 } });
❌ schema.validate({});
❌ schema.validate({ foo: "x" });
❌ schema.validate({ foo: "x", bar: "x" });
❌ schema.validate({ foo: "x", bar: "x", baz: {} });
❌ schema.validate({ foo: "x", bar: "x", baz: { foo: 0 } });
Validé un objet avec des propriétés facultatives
const schema = new Schema({
type: "object",
shape: {
foo: { type: "string" },
bar: { type: "string" }
},
optional: true
});
âś… schema.validate({});
âś… schema.validate({ foo: "x" });
âś… schema.validate({ bar: "x" });
âś… schema.validate({ foo: "x", bar: "x" });
❌ schema.validate({ foo: "x", bar: "x", a: "x" });
Validé un objet avec une propriété fixe et une propriété facultative
const schema = new Schema({
type: "object",
shape: {
foo: { type: "string" },
bar: { type: "string" }
},
optional: ["bar"]
});
âś… schema.validate({ foo: "x" });
âś… schema.validate({ foo: "x", bar: "x" });
❌ schema.validate({});
❌ schema.validate({ bar: "x" });
❌ schema.validate({ foo: "x", bar: "x", a: "x" });
Validé un objet avec des propriétés fixes et des propriétés dynamiques libres
const schema = new Schema({
type: "object",
shape: {
foo: { type: "string" },
bar: { type: "string" }
},
values: { type: "unknown" }
});
âś… schema.validate({ foo: "x", bar: "x" });
âś… schema.validate({ foo: "x", bar: "x", a: "x", b: 0 });
❌ schema.validate({});
❌ schema.validate({ bar: "x" });
❌ schema.validate({ foo: "x" });
Validé un objet avec des propriétés fixes et des propriétés dynamiques contraintes
const schema = new Schema({
type: "object",
shape: {
foo: { type: "string" },
bar: { type: "string" }
},
keys: { type: "string" },
values: { type: "number" }
});
âś… schema.validate({ foo: "x", bar: "x" });
âś… schema.validate({ foo: "x", bar: "x", a: 0 });
âś… schema.validate({ foo: "x", bar: "x", a: 0, b: 0 });
❌ schema.validate({});
❌ schema.validate({ foo: "x" });
❌ schema.validate({ bar: "x" });
❌ schema.validate({ foo: "x", bar: "x", a: "x", b: 0 });
Validé un objet avec des propriétés dynamiques contraintes
const schema = new Schema({
type: "object",
keys: { type: "string" },
values: { type: "string" }
});
âś… schema.validate({});
âś… schema.validate({ a: "x" });
âś… schema.validate({ a: "x", b: "x" });
❌ schema.validate({ a: 0 });
❌ schema.validate({ a: "x", b: 0 });
Validé n'importe quel tableau
const schema = new Schema({
type: "array"
});
âś… schema.validate([]);
âś… schema.validate(["x"]);
❌ schema.validate({});
❌ schema.validate("x");
Validé un tableau d'éléments fixes
const schema = new Schema({
type: "array",
tuple: [
{ type: "string" },
{ type: "string" }
]
});
âś… schema.validate(["x", "x"]);
❌ schema.validate([]);
❌ schema.validate(["x"]);
❌ schema.validate(["x", "x", "x"]);
Validé un tableau et un sous-tableau d'éléments fixes
const schema = new Schema({
type: "array",
tuple: [
{ type: "string" },
{ type: "string" },
[
{ type: "number" },
{ type: "number" }
]
]
});
âś… schema.validate(["x", "x", [0, 0]]);
❌ schema.validate([]);
❌ schema.validate(["x"]);
❌ schema.validate(["x", "x", []]);
❌ schema.validate(["x", "x", [0]]);
Validé un tableau d'éléments fixes et des éléments dynamiques libres
const schema = new Schema({
type: "array",
tuple: [
{ type: "string" },
{ type: "string" }
],
items: { type: "unknown" }
});
âś… schema.validate(["x", "x"]);
âś… schema.validate(["x", "x", 0]);
âś… schema.validate(["x", "x", ""]);
âś… schema.validate(["x", "x", {}]);
❌ schema.validate([]);
❌ schema.validate(["x"]);
❌ schema.validate([0, "x"]);
Validé un tableau d'éléments fixes et des éléments dynamiques contraints
const schema = new Schema({
type: "array",
tuple: [
{ type: "string" },
{ type: "string" }
],
items: { type: "number" }
});
âś… schema.validate(["x"]);
âś… schema.validate(["x", "x"]);
âś… schema.validate(["x", "x", 0]);
âś… schema.validate(["x", "x", 0, 0]);
❌ schema.validate([]);
❌ schema.validate(["x"]);
❌ schema.validate(["x", "x", "x"]);
❌ schema.validate(["x", "x", "x", "x"]);
Validé un tableau avec éléments dynamiques contraints
const schema = new Schema({
type: "array",
items: { type: "string" }
});
âś… schema.validate([]);
âś… schema.validate(["x"]);
âś… schema.validate(["x", "x"]);
❌ schema.validate([0]);
❌ schema.validate(["x", 0]);
❌ schema.validate(["x", "x", 0]);
Validé n'importe quel symbole
const xSymbol = Symbol("x");
const ySymbol = Symbol("y");
const schema = new Schema({
type: "symbol"
});
âś… schema.validate(xSymbol);
âś… schema.validate(ySymbol);
Validé un symbole spécifique
const xSymbol = Symbol("x");
const ySymbol = Symbol("y");
const schema = new Schema({
type: "symbol",
literal: xSymbol
});
âś… schema.validate(xSymbol);
❌ schema.validate(ySymbol);
Validé des symboles spécifiques avec un tableau
const xSymbol = Symbol("x");
const ySymbol = Symbol("y");
const zSymbol = Symbol("z");
const schema = new Schema({
type: "symbol",
literal: [xSymbol, ySymbol]
});
âś… schema.validate(xSymbol);
âś… schema.validate(ySymbol);
❌ schema.validate(zSymbol);
Validé des symboles spécifiques avec un enum
enum mySymbol {
X = Symbol("x"),
Y = Symbol("y")
};
enum otherSymbol {
Z = Symbol("z")
};
const schema = new Schema({
type: "symbol",
literal: mySymbol
});
âś… schema.validate(mySymbol.X);
âś… schema.validate(mySymbol.Y);
❌ schema.validate(otherSymbol.Z);
const schema = new Schema({
type: "union",
union: [
{ type: "string" },
{ type: "number" }
]
});
âś… schema.validate(0);
âś… schema.validate("");
❌ schema.validate({});
const schema = new Schema({
type: "null"
});
âś… schema.validate(null);
❌ schema.validate(0);
❌ schema.validate("");
❌ schema.validate({});
const schema = new Schema({
type: "undefined"
});
âś… schema.validate(undefined);
❌ schema.validate(0);
❌ schema.validate("");
❌ schema.validate({});
const user = new Schema({
type: "object",
shape: {
name: {
type: "string",
min: 3,
max: 32
},
role: {
type: "string",
literal: ["WORKER", "CUSTOMER"]
}
}
});
âś… user.validate({
name: "Alice",
role: "WORKER"
});
❌ user.validate({
name: "Alice",
role: "MANAGER"
});
const name = new Schema({
type: "string",
min: 3,
max: 32
});
const role = new Schema({
type: "string",
literal: ["WORKER", "CUSTOMER"]
});
const user = new Schema({
type: "object",
shape: {
name: name.criteria,
role: role.criteria
}
});
âś… user.validate({
name: "Bob",
role: "CUSTOMER"
});
❌ user.validate({
name: "Bob",
role: "MANAGER"
});
const name = new Schema({
type: "string",
min: 3,
max: 32
});
const setting = new Schema({
type: "object",
shape: {
theme: {
type: "string",
literal: ["DARK", "LIGHT"]
},
notification: { type: "boolean" }
}
});
const user = new Schema({
type: "object",
object: {
name: name.criteria,
theme: setting.criteria.shape.theme
}
});
âś… user.validate({
name: "Alice",
theme: "DARK"
});
❌ user.validate({
name: "Alice",
theme: "DEFAULT"
});
isObject(value): booleanVérifie si la valeur fournie est de type object.
isPlainObject(value): booleanVérifie si la valeur fournie est de type object et dont le prototype est soit Object.prototype, soit null.
Par exemple les valeurs créées via le littérale {} ou via Object.create(null) font partie des valeurs acceptées.
isArray(value): booleanVérifie si la valeur fournie est de type array.
isTypedArray(value): booleanVérifie si la valeur fournie est de type array et si elle est une vue sur un ArrayBuffer, à l’exception des DataView.
isFunction(value): booleanVérifie si la valeur fournie est de type function.
isBasicFunction(value): booleanVérifie si la valeur fournie est de type function et qu'elle n'est pas de nature async, generator ou async generator.
isAsyncFunction(value): booleanVérifie si la valeur fournie est de type function et qu'elle n'est pas de nature basic, generator ou async generator.
isGeneratorFunction(value): booleanVérifie si la valeur fournie est de type function et qu'elle n'est pas de nature basic, async ou async generator.
isAsyncGeneratorFunction(value): booleanVérifie si la valeur fournie est de type function et qu'elle n'est pas de nature basic, async ou generator.
isAscii(str): booleanVérifie si la chaîne fournie n'est composée que de caractères ASCII. 
isIpV4(str [, options]): booleanVérifie si la chaîne fournie correspond à une IPV4.
isIpV6(str [, options]): booleanVérifie si la chaîne fournie correspond à une IPV6.
isIp(str [, options]): booleanVérifie si la chaîne fournie correspond à une IPV4 ou une IPV6.
Options:
isEmail(str [, options]): booleanVérifie si la chaîne fournie correspond à une adresse email.
Options:
Standards: RFC 5321
isDomain(str): booleanVérifie si la chaîne fournie correspond un nom de domain.
Standards: RFC 1035
isDataURL(str [, options]): booleanVérifie si la chaîne fournie correspond à une DataURL.
Options:
Standards: RFC 2397
isUuid(str [, options]): booleanVérifie si la chaîne fournie correspond à un UUID valide.
Options:
Standards: RFC 9562
isBase16(str): booleanVérifie si la chaîne fournie correspond à un encodage base16 valide.
Standards: RFC 4648
isBase32(str): booleanVérifie si la chaîne fournie correspond à un encodage base32 valide.
Standards: RFC 4648
isBase32Hex(str): booleanVérifie si la chaîne fournie correspond à un encodage base32Hex valide.
Standards: RFC 4648
isBase64(str): booleanVérifie si la chaîne fournie correspond à un encodage base64 valide.
Standards: RFC 4648
isBase64Url(str): booleanVérifie si la chaîne fournie correspond à un encodage base64Url valide.
Standards: RFC 4648
getInternalTag(target): stringRetourne le tag interne de la cible. Par exemple pour une cible async () => {} le tag retourné est "AsyncFunction".
base16ToBase32(str [, to, padding]): stringConvertie une chaîne en base16 en une chaîne en base32 ou base32Hex.
Arguments:
Standards: RFC 4648
base16ToBase64(str [, to, padding]): stringConvertie une chaîne en base16 en une chaîne en base64 ou base64Url.
Arguments:
Standards: RFC 4648
base32ToBase16(str [, from]): stringConvertie une chaîne en base32 ou base32Hex en une chaîne en base16.
Arguments:
Standards: RFC 4648
base64ToBase16(str [, from]): stringConvertie une chaîne en base64 ou base64Url en une chaîne en base16.
Arguments:
FAQs
Validation library for TypeScript and JavaScript.
The npm package valia receives a total of 3 weekly downloads. As such, valia popularity was classified as not popular.
We found that valia 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.