This commit is contained in:
thosakwe 2017-04-26 08:49:26 -04:00
parent fc1e04304c
commit 7fb9e27e28
4 changed files with 28 additions and 4 deletions

View file

@ -1,5 +1,5 @@
# validate # validate
[![version 1.0.2+1](https://img.shields.io/badge/pub-v1.0.2+1-brightgreen.svg)](https://pub.dartlang.org/packages/angel_validate) [![version 1.0.2+2](https://img.shields.io/badge/pub-v1.0.2+2-brightgreen.svg)](https://pub.dartlang.org/packages/angel_validate)
[![build status](https://travis-ci.org/angel-dart/validate.svg)](https://travis-ci.org/angel-dart/validate) [![build status](https://travis-ci.org/angel-dart/validate.svg)](https://travis-ci.org/angel-dart/validate)
[Live Example](https://angel-dart.github.io/validate) [Live Example](https://angel-dart.github.io/validate)
@ -38,9 +38,14 @@ import 'package:angel_validate/angel_validate.dart';
main() { main() {
var validator = new Validator({ var validator = new Validator({
'username': isAlphaNum, 'username': isAlphaNum,
'multiple,keys,with,same,rules': [isString, isNotEmpty],
'balance': [ 'balance': [
greaterThanOrEqualTo(0), greaterThanOrEqualTo(0),
lessThan(1000000) lessThan(1000000)
],
'nested': [
foo,
[bar, baz]
] ]
}); });
} }
@ -225,6 +230,7 @@ including:
* `isInt`: Asserts that a value is an `int`. * `isInt`: Asserts that a value is an `int`.
* `isNum`: Asserts that a value is a `num`. * `isNum`: Asserts that a value is a `num`.
* `isString`: Asserts that a value is a `String`. * `isString`: Asserts that a value is a `String`.
* `isNonEmptyString`: Asserts that a value is a non-empty `String`.
* `isUrl`: Asserts that a `String` is an HTTPS or HTTP URL. * `isUrl`: Asserts that a `String` is an HTTPS or HTTP URL.
The remaining functionality is The remaining functionality is

View file

@ -32,12 +32,20 @@ final Matcher isNum = predicate((value) => value is num, 'a number');
/// Asserts that a value is a `String`. /// Asserts that a value is a `String`.
final Matcher isString = predicate((value) => value is String, 'a String'); final Matcher isString = predicate((value) => value is String, 'a String');
/// Asserts that a value is a non-empty `String`.
final Matcher isNonEmptyString = predicate(
(value) => value is String && value.isNotEmpty, 'a non-empty String');
/// Asserts that a `String` is an `http://` or `https://` URL. /// Asserts that a `String` is an `http://` or `https://` URL.
/// ///
/// The regular expression used: /// The regular expression used:
/// ``` /// ```
/// https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*) /// https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)
/// ``` /// ```
final Matcher isurl = predicate( final Matcher isUrl = predicate(
(value) => value is String && _url.hasMatch(value), (value) => value is String && _url.hasMatch(value),
'a valid url, starting with http:// or https://'); 'a valid url, starting with http:// or https://');
/// Use [isUrl] instead.
@deprecated
final Matcher isurl = isUrl;

View file

@ -76,8 +76,18 @@ class Validator extends Matcher {
requiredFields.add(fieldName); requiredFields.add(fieldName);
} }
Iterable iterable = Iterable _iterable =
schema[keys] is Iterable ? schema[keys] : [schema[keys]]; schema[keys] is Iterable ? schema[keys] : [schema[keys]];
var iterable = [];
_addTo(x) {
if (x is Iterable)
x.map(_addTo);
else
iterable.add(x);
}
_iterable.map(_addTo);
for (var rule in iterable) { for (var rule in iterable) {
if (rule is Matcher) { if (rule is Matcher) {

View file

@ -1,6 +1,6 @@
name: angel_validate name: angel_validate
description: Cross-platform validation library based on `matcher`. description: Cross-platform validation library based on `matcher`.
version: 1.0.2+1 version: 1.0.2+2
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/validate homepage: https://github.com/angel-dart/validate
environment: environment: