ForgeTotal.js 5
pl

Total.js 5

Sprawdź granice schematu numerycznego zamiast przyjmować całą przymusu

Total.js 5 · total5@0.0.19 validationschemanumbersboundaries Uruchomiono z Total.js 5

W total5@0.0.19 wszystkie typy numeryczne wprowadzają kodowy numer. Int nie gwarantuje integralnego: 7.9 jest zachowany. Number2 również zachowuje tę frakcję; nie interpretuje nazwy jako okrągłe do dwóch dziesiątkowych miejsc.

TinyInt akceptuje wartości od 0 do 255. SmallInt akceptuje od -32767 do 32767; w szczególności -32768 jest w tej wersji odrzucane. Te kontrole podtypów wymuszają granice, ale nie wymagają wartości całkowitych: TinyInt akceptuje 1.5. Dla identyfikatorów, liczników lub ilości, które muszą być całkowite, zastosuj jawną kontrolę Number.isInteger(). Te obserwacje opisują tę wersję i testowane wartości, a nie semantykę kolumn SQL.

controllers/numbers.js
var schema = NEWSCHEMA('NumericBoundaries', '*integer:Int,*small:SmallInt,*tiny:TinyInt,*decimal:Number2');

exports.install = function() {
	ROUTE('POST /numbers/ @json', numbers);
};

function numbers($) {
	var result = schema.transform($.body);
	if (result.error) {
		$.response.status = 400;
		$.json({ error: 'invalid numeric input' });
		return;
	}
	$.json(result.response);
}