You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: update build process to enable tree shaking (#568)
BREAKING CHANGE:
Validation functions was removed from `Validator` class to enable tree shaking.
BEFORE:
import {Validator} from "class-validator";
const validator = new Validator();
validator.isNotIn(value, possibleValues);
validator.isBoolean(value);
AFTER:
import {isNotIn, isBoolean} from "class-validator";
isNotIn(value, possibleValues);
isBoolean(value);
Closes#258, #248, #247, #212
validator.isDefined(value); // Checks if value is defined ("!==undefined").
800
-
validator.equals(value, comparison); // Checks if value matches ("===") the comparison.
801
-
validator.notEquals(value, comparison); // Checks if value does not match ("!==") the comparison.
802
-
validator.isEmpty(value); // Checks if given value is empty (=== '', === null, === undefined).
803
-
validator.isNotEmpty(value); // Checks if given value is not empty (!== '', !== null, !== undefined).
804
-
validator.isIn(value, possibleValues); // Checks if given value is in a array of allowed values.
805
-
validator.isNotIn(value, possibleValues); // Checks if given value not in a array of allowed values.
806
-
807
-
// type validation methods
808
-
validator.isBoolean(value); // Checks if a given value is a real boolean.
809
-
validator.isDate(value); // Checks if a given value is a real date.
810
-
validator.isString(value); // Checks if a given value is a real string.
811
-
validator.isArray(value); // Checks if a given value is an array.
812
-
validator.isNumber(value, options); // Checks if a given value is a real number.
813
-
validator.isInt(value); // Checks if value is an integer.
814
-
validator.isEnum(value, entity); // Checks if value is valid for a certain enum entity.
815
-
816
-
// number validation methods
817
-
validator.isDivisibleBy(value, num); // Checks if value is a number that's divisible by another.
818
-
validator.isPositive(value); // Checks if the value is a positive number.
819
-
validator.isNegative(value); // Checks if the value is a negative number.
820
-
validator.min(num, min); // Checks if the first number is greater than or equal to the second.
821
-
validator.max(num, max); // Checks if the first number is less than or equal to the second.
822
-
823
-
// date validation methods
824
-
validator.minDate(date, minDate); // Checks if the value is a date that's after the specified date.
825
-
validator.maxDate(date, maxDate); // Checks if the value is a date that's before the specified date.
826
-
827
-
// string-type validation methods
828
-
validator.isBooleanString(str); // Checks if a string is a boolean.
829
-
validator.isNumberString(str); // Checks if the string is numeric.
830
-
831
-
// string validation methods
832
-
validator.contains(str, seed); // Checks if the string contains the seed.
833
-
validator.notContains(str, seed); // Checks if the string does not contain the seed.
834
-
validator.isAlpha(str); // Checks if the string contains only letters (a-zA-Z).
835
-
validator.isAlphanumeric(str); // Checks if the string contains only letters and numbers.
836
-
validator.isDecimal(str, options); // Checks if the string is a valid decimal value.
837
-
validator.isAscii(str); // Checks if the string contains ASCII chars only.
838
-
validator.isBase64(str); // Checks if a string is base64 encoded.
839
-
validator.isByteLength(str, min, max); // Checks if the string's length (in bytes) falls in a range.
840
-
validator.isCreditCard(str); // Checks if the string is a credit card.
841
-
validator.isCurrency(str, options); // Checks if the string is a valid currency amount.
842
-
validator.isEmail(str, options); // Checks if the string is an email.
843
-
validator.isFQDN(str, options); // Checks if the string is a fully qualified domain name (e.g. domain.com).
844
-
validator.isFullWidth(str); // Checks if the string contains any full-width chars.
845
-
validator.isHalfWidth(str); // Checks if the string contains any half-width chars.
846
-
validator.isVariableWidth(str); // Checks if the string contains variable-width chars.
847
-
validator.isHexColor(str); // Checks if the string is a hexadecimal color.
848
-
validator.isHexadecimal(str); // Checks if the string is a hexadecimal number.
849
-
validator.isMACAddress(str); // Checks if the string is a MAC Address.
850
-
validator.isIP(str, version); // Checks if the string is an IP (version 4 or 6).
851
-
validator.isPort(str); // Check if the string is a valid port number.
852
-
validator.isISBN(str, version); // Checks if the string is an ISBN (version 10 or 13).
853
-
validator.isISIN(str); // Checks if the string is an ISIN (stock/security identifier).
854
-
validator.isISO8601(str, options); // Checks if the string is a valid ISO 8601 date. Use the option strict = true for additional checks for a valid date, e.g. invalidates dates like 2019-02-29.
855
-
validator.isJSON(str); // Checks if the string is valid JSON (note: uses JSON.parse).
856
-
validator.isJWT(str) // Checks if the string is valid JWT.
857
-
validator.isObject(object); // Checks if the object is valid Object (null, functions, arrays will return false)
858
-
validator.isNotEmptyObject(object); // Checks if the object is not empty
859
-
validator.isLowercase(str); // Checks if the string is lowercase.
860
-
validator.isLatLong(str); // Checks if the string is a valid latitude-longitude coordinate in the format lat,long
861
-
validator.isLatitude(str); // Checks if the string or number is a valid latitude coordinate
862
-
validator.isLongtitude(str); // Checks if the string or number is a valid longitude coordinate
863
-
validator.isMobilePhone(str, locale); // Checks if the string is a mobile phone number.
864
-
validator.isISO31661Alpha2(str); // Check if the string is a valid ISO 3166-1 alpha-2
865
-
validator.isISO31661Alpha3(str); // Check if the string is a valid ISO 3166-1 alpha-3
866
-
validator.isPhoneNumber(str, region); // Checks if the string is a valid phone number.
867
-
validator.isMongoId(str); // Checks if the string is a valid hex-encoded representation of a MongoDB ObjectId.
868
-
validator.isMultibyte(str); // Checks if the string contains one or more multibyte chars.
869
-
validator.isSurrogatePair(str); // Checks if the string contains any surrogate pairs chars.
870
-
validator.isURL(str, options); // Checks if the string is an url.
871
-
validator.isUUID(str, version); // Checks if the string is a UUID (version 3, 4, 5 or all).
872
-
validator.IsFirebasePushId(str); // Checks if the string is a Firebase Push Id
873
-
validator.isUppercase(str); // Checks if the string is uppercase.
874
-
validator.length(str, min, max); // Checks if the string's length falls in a range.
875
-
validator.minLength(str, min); // Checks if the string's length is not less than given number.
876
-
validator.maxLength(str, max); // Checks if the string's length is not more than given number.
877
-
validator.matches(str, pattern, modifiers); // Checks if string matches the pattern. Either matches('foo', /foo/i) or matches('foo', 'foo', 'i').
878
-
validator.isMilitaryTime(str); // Checks if the string is a valid representation of military time in the format HH:MM.
879
-
validator.isHash(str, algorithm); // Checks if the string is a hash of type algorithm.
880
-
validator.isISSN(str, options); // Checks if the string is a ISSN.
881
-
882
-
// array validation methods
883
-
validator.arrayContains(array, values); // Checks if array contains all values from the given array of values.
884
-
validator.arrayNotContains(array, values); // Checks if array does not contain any of the given values.
885
-
validator.arrayNotEmpty(array); // Checks if given array is not empty.
886
-
validator.arrayMinSize(array, min); // Checks if array's length is at least `min` number.
887
-
validator.arrayMaxSize(array, max); // Checks if array's length is as most `max` number.
888
-
validator.arrayUnique(array); // Checks if all array's values are unique. Comparison for objects is reference-based.
889
-
890
-
// object validation methods
891
-
validator.isInstance(value, target); // Checks value is an instance of the target.
793
+
import {isEmpty, isBoolean} from "class-validator";
794
+
795
+
isEmpty(value);
796
+
isBoolean(value);
892
797
```
893
798
894
799
## Validationdecorators
@@ -943,7 +848,7 @@ validator.isInstance(value, target); // Checks value is an instance of the targe
943
848
| `@IsVariableWidth()` | Checks if the string contains a mixture of full and half-width chars. |
944
849
| `@IsHexColor()` | Checks if the string is a hexadecimal color. |
945
850
| `@IsHexadecimal()` | Checks if the string is a hexadecimal number. |
946
-
| `@IsMACAddress()` | Checks if the string is a MAC Address. |
851
+
| `@IsMACAddress(options?:IsMACAddressOptions)` | Checks if the string is a MAC Address. |
947
852
| `@IsIP(version?:"4"\|"6")` | Checks if the string is an IP (version 4 or 6). |
948
853
| `@IsPort()` | Check if the string is a valid port number. |
949
854
| `@IsISBN(version?:"10"\|"13")` | Checks if the string is an ISBN (version 10 or 13). |
0 commit comments