Skip to content

Commit 02be1c6

Browse files
authored
Merge pull request #34 from xpepermint/master
Add general validators
2 parents 3d71335 + bdafb17 commit 02be1c6

56 files changed

Lines changed: 4936 additions & 5 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,161 @@ try {
727727
| 'Date' | Date object.
728728
| Model | Nested model instance.
729729

730+
### Available Validators
731+
732+
**absenceValidator()**: Function
733+
734+
> Validates that the specified property is blank.
735+
736+
**arrayExclusionValidator(options)**: Function
737+
738+
> Validates that the specified property is not in an array of values.
739+
740+
| Option | Type | Required | Default | Description
741+
|--------|------|----------|---------|------------
742+
| options.values | Array | Yes | - | Array of restricted values.
743+
744+
**arrayInclusionValidator(options)**: Function
745+
746+
> Validates that the specified property is in an array of values.
747+
748+
| Option | Type | Required | Default | Description
749+
|--------|------|----------|---------|------------
750+
| options.values | Array | Yes | - | Array of allowed values.
751+
752+
**arrayLengthValidator(options)**: Function
753+
754+
> Validates the size of an array.
755+
756+
| Option | Type | Required | Default | Description
757+
|--------|------|----------|---------|------------
758+
| options.min | Number | No | - | Allowed minimum items count.
759+
| options.minOrEqual | Number | No | - | Allowed minimum items count (allowing equal).
760+
| options.max | Number | No | - | Allowed maximum items count.
761+
| options.maxOrEqual | Number | No | - | Allowed maximum items count (allowing equal).
762+
763+
**base64Validator()**: Function
764+
765+
> Validates that the specified property is base64 encoded string.
766+
767+
**bsonObjectIdValidator()**: Function
768+
769+
> Validates that the specified property is BSON ObjectId encoded string.
770+
771+
**dateValidator(options)**: Function
772+
773+
> Validates that the specified property is a date string.
774+
775+
| Option | Type | Required | Default | Description
776+
|--------|------|----------|----------|-----------
777+
| options.iso | Boolean | No | false | When `true` only ISO-8601 date format is accepted.
778+
779+
**downcaseStringValidator()**: Function
780+
781+
> Validates that the specified property is lowercase.
782+
783+
**emailValidator(options)**: Function
784+
785+
> Validates that the specified property is an email.
786+
787+
| Option | Type | Required | Default | Description
788+
|--------|------|----------|---------|------------
789+
| options.allowDisplayName | Boolean | No | false | When set to true, the validator will also match `name <address>`.
790+
| options.allowUtf8LocalPart | Boolean | No | false | When set to false, the validator will not allow any non-English UTF8 character in email address' local part.
791+
| options.requireTld | Boolean | No | true | When set to false, email addresses without having TLD in their domain will also be matched.
792+
793+
**ethAddressValidator()**: Function
794+
795+
> Checks if the string represents an ethereum address.
796+
797+
**fqdnValidator(options)**: Function
798+
799+
> Validates that the specified property is a fully qualified domain name (e.g. domain.com).
800+
801+
| Option | Type | Required | Default | Description
802+
|--------|------|----------|---------|------------
803+
| options.requireTld | Boolean | No | true | Require top-level domain name.
804+
| options.allowUnderscores | Boolean | No | false | Allow string to include underscores.
805+
| options.allowTrailingDot | Boolean | No | false | Allow string to include a trailing dot.
806+
807+
**hexColorValidator()**: Function
808+
809+
> Validates that the specified property is a hexadecimal color string.
810+
811+
**hexValidator()**: Function
812+
813+
> Validates that a specified property is a hexadecimal number.
814+
815+
**jsonStringValidator(options)**: Function
816+
817+
> Validates that the specified property is a JSON string.
818+
819+
**matchValidator(options)**: Function
820+
821+
> Validates that the specified property matches the pattern.
822+
823+
| Key | Type | Required | Default | Description
824+
|-----|------|----------|---------|------------
825+
| options.regexp | RegExp | Yes | - | Regular expression pattern.
826+
827+
**numberSizeValidator(options)**: Function
828+
829+
> Validates the size of a number.
830+
831+
| Option | Type | Required | Default | Description
832+
|--------|------|----------|---------|------------
833+
| options.min | Number | No | - | Allowed minimum value.
834+
| options.minOrEqual | Number | No | - | Allowed minimum value (allowing equal).
835+
| options.max | Number | No | - | Allowed maximum value.
836+
| options.maxOrEqual | Number | No | - | Allowed maximum value (allowing equal).
837+
838+
**presenceValidator()**: Function
839+
840+
> Validates that the specified property is not blank.
841+
842+
**stringExclusionValidator(options)**: Function
843+
844+
> Checks if the string does not contain the seed.
845+
846+
| Option | Type | Required | Default | Description
847+
|--------|------|----------|---------|------------
848+
| options.seed | String | Yes | - | The seed which should exist in the string.
849+
850+
**stringInclusionValidator()**: Function
851+
852+
> Checks if the string contains the seed.
853+
854+
| Option | Type | Required | Default | Description
855+
|--------|------|----------|---------|------------
856+
| options.seed | String | Yes | - | The seed which should exist in the string.
857+
858+
**stringLengthValidator(options)**: Function
859+
860+
> Validates the length of the specified property.
861+
862+
| Option | Type | Required | Default | Description
863+
|--------|------|----------|---------|------------
864+
| options.bytes | Boolean | No | false | When `true` the number of bytes is returned.
865+
| options.min | Number | No | - | Allowed minimum number of characters.
866+
| options.minOrEqual | Number | No | - | Allowed minimum value number of characters (allowing equal).
867+
| options.max | Number | No | - | Allowed maximum number of characters.
868+
| options.maxOrEqual | Number | No | - | Allowed maximum number of characters (allowing equal).
869+
870+
**upcaseStringValidator()**: Function
871+
872+
> Validates that the specified property is uppercase.
873+
874+
**uuidValidator(options)**: Function
875+
876+
> Validates that the specified property is a [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier).
877+
878+
| Option | Type | Required | Default | Description
879+
|--------|------|----------|---------|------------
880+
| options.version | Integer | No | - | UUID version (1, 2, 3, 4 or 5).
881+
730882
### Available Handlers
731883

732-
**mongoUniquenessHandler(options)**
884+
**mongoUniquenessHandler(options)**: Function
733885

734886
> Checks if the error represents a MongoDB unique constraint error.
735887
@@ -756,6 +908,7 @@ const recipe = { // make sure that this index name exists in your MongoDB collec
756908
| [@rawmodel/parser](https://github.com/rawmodel/framework/tree/master/packages/rawmodel-parser) | Parsing and type casting. | [![NPM Version](https://badge.fury.io/js/@rawmodel%2Fparser.svg)](https://badge.fury.io/js/%40rawmodel%2Fparser)
757909
| [@rawmodel/utils](https://github.com/rawmodel/framework/tree/master/packages/rawmodel-utils) | Framework helpers. | [![NPM Version](https://badge.fury.io/js/@rawmodel%2Futils.svg)](https://badge.fury.io/js/%40rawmodel%2Futils)
758910
| [@rawmodel/validator](https://github.com/rawmodel/framework/tree/master/packages/rawmodel-validator) | Property validator. | [![NPM Version](https://badge.fury.io/js/@rawmodel%2Fvalidator.svg)](https://badge.fury.io/js/%40rawmodel%2Fvalidator)
911+
| [@rawmodel/validators](https://github.com/rawmodel/framework/tree/master/packages/rawmodel-validators) | Collection of validators. | [![NPM Version](https://badge.fury.io/js/@rawmodel%2Fvalidators.svg)](https://badge.fury.io/js/%40rawmodel%2Fvalidators)
759912

760913
## Contributing
761914

packages/rawmodel-handlers/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,5 @@
7979
"ts-node": "^7.0.1",
8080
"tslint": "^5.11.0",
8181
"typescript": "^3.0.3"
82-
},
83-
"dependencies": {
84-
"@rawmodel/utils": "^2.0.3"
8582
}
8683
}

packages/rawmodel-handlers/src/handlers/mongo-uniqueness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ export function mongoUniquenessHandler(options?: {
2727
} else {
2828
return false;
2929
}
30-
}
30+
};
3131
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
.vscode
3+
.nyc_output
4+
dist
5+
node_modules
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.vscode
3+
.nyc_output
4+
node_modules
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ignore": ["dist/*"],
3+
"ext": "js,ts"
4+
}

0 commit comments

Comments
 (0)