validators 1.0.0+1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 87

validators

Build Status

String validation and sanitization for Dart.

Port of chriso's library.

Usage

1. Add dependency to your package's pubspec.yaml file:

dependencies:
  validator: ">=0.0.4 <0.1.0"

2. Run from the command line:

$ pub get

Alternatively, your editor might support pub. Check the docs for your editor to learn more.

3. Import in your Dart code:

import 'package:validator/validator.dart';

Validators

  • equals(String str, comparison) - check if the string matches the comparison.
  • contains(String str, seed) - check if the string contains the seed.
  • matches(String str, pattern) - check if string matches the pattern. matches('foobar', 'foo').
  • isEmail(String str) - check if the string is an email.
  • isURL(String str [, options]) - check if the string is an URL. options is an object which defaults to { protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, allow_underscores: false, host_whitelist: false, host_blacklist: false }.
  • isFQDN(String str [, options]) - check if the string is a fully qualified domain name (e.g. domain.com). options is an object which defaults to { require_tld: true, allow_underscores: false }.
  • isIP(String str [, version]) - check if the string is an IP (version 4 or 6).
  • isAlpha(String str) - check if the string contains only letters (a-zA-Z).
  • isNumeric(String str) - check if the string contains only numbers.
  • isAlphanumeric(String str) - check if the string contains only letters and numbers.
  • isBase64(String str) - check if a string is base64 encoded.
  • isHexadecimal(String str) - check if the string is a hexadecimal number.
  • isHexColor(String str) - check if the string is a hexadecimal color.
  • isLowercase(String str) - check if the string is lowercase.
  • isUppercase(String str) - check if the string is uppercase.
  • isInt(String str) - check if the string is an integer.
  • isFloat(String str) - check if the string is a float.
  • isDivisibleBy(String str, number) - check if the string is a number that's divisible by another.
  • isNull(String str) - check if the string is null.
  • isLength(String str, min [, max]) - check if the string's length falls in a range. Note: this function takes into account surrogate pairs.
  • isByteLength(String str, min [, max]) - check if the string's length (in bytes) falls in a range.
  • isUUID(String str [, version]) - check if the string is a UUID (version 3, 4 or 5).
  • isDate(String str) - check if the string is a date.
  • isAfter(String str [, date]) - check if the string is a date that's after the specified date (defaults to now).
  • isBefore(String str [, date]) - check if the string is a date that's before the specified date.
  • isIn(String str, values) - check if the string is in a array of allowed values.
  • isCreditCard(String str) - check if the string is a credit card.
  • isISBN(String str [, version]) - check if the string is an ISBN (version 10 or 13).
  • isJSON(String str) - check if the string is valid JSON (note: uses JSON.parse).
  • isMultibyte(String str) - check if the string contains one or more multibyte chars.
  • isAscii(String str) - check if the string contains ASCII chars only.
  • isFullWidth(String str) - check if the string contains any full-width chars.
  • isHalfWidth(String str) - check if the string contains any half-width chars.
  • isVariableWidth(String str) - check if the string contains a mixture of full and half-width chars.
  • isSurrogatePair(String str) - check if the string contains any surrogate pairs chars.
  • isMongoId(String str) - check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].

Sanitizers

  • toString(String input) - convert the input to a string.
  • toDate(String input) - convert the input to a date, or null if the input is not a date.
  • toFloat(String input) - convert the input to a float, or NaN if the input is not a float.
  • toInt(String input [, radix]) - convert the input to an integer, or NaN if the input is not an integer.
  • toBoolean(String input [, strict]) - convert the input to a boolean. Everything except for '0', 'false' and '' returns true. In strict mode only '1' and 'true' return true.
  • trim(String input [, chars]) - trim characters (whitespace by default) from both sides of the input.
  • ltrim(String input [, chars]) - trim characters from the left-side of the input.
  • rtrim(String input [, chars]) - trim characters from the right-side of the input.
  • escape(String input) - replace <, >, &, ' and " with HTML entities.
  • stripLow(String input [, keep_new_lines]) - remove characters with a numerical value < 32 and 127, mostly control characters. If keep_new_lines is true, newline characters are preserved (\n and \r, hex 0xA and 0xD). Unicode-safe in JavaScript.
  • whitelist(String input, chars) - remove characters that do not appear in the whitelist. The characters are used in a RegExp and so you will need to escape some chars, e.g. whitelist(String input, '\[\]').
  • blacklist(String input, chars) - remove characters that appear in the blacklist. The characters are used in a RegExp and so you will need to escape some chars, e.g. blacklist(String input, '\[\]').
  • normalizeEmail(String email [, options]) - canonicalize an email address. options is an object which defaults to { lowercase: true }. With lowercase set to true, the local part of the email address is lowercased for all domains; the hostname is always lowercased and the local part of the email address is always lowercased for hosts that are known to be case-insensitive (currently only GMail). Normalization follows special rules for known providers: currently, GMail addresses have dots removed in the local part and are stripped of tags (e.g. some.one+tag@gmail.com becomes someone@gmail.com) and all @googlemail.com addresses are normalized to @gmail.com.

1.0.0

  • migrate to dart 2 and fix tests

example/main.dart

import 'package:validators/validators.dart';

main() {
  print(toString(1));
  print(trim('  hello '));
  print(toDouble('1.23'));

  print(isDate('1988-01-01'));
  print(isNumeric('123'));
  print(isAlphanumeric('abc123'));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  validators: ^1.0.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:validators/validators.dart';
  
Version Uploaded Documentation Archive
1.0.0+1 Sep 18, 2018 Go to the documentation of validators 1.0.0+1 Download validators 1.0.0+1 archive
1.0.0 Sep 18, 2018 Go to the documentation of validators 1.0.0 Download validators 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
81
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:validators/validators.dart.

Health suggestions

Format lib/src/sanitizer.dart.

Run dartfmt to format lib/src/sanitizer.dart.

Format lib/src/validator.dart.

Run dartfmt to format lib/src/validator.dart.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
test ^1.3.3 1.5.1+1
Transitive dependencies
analyzer 0.34.0
args 1.5.1
async 2.0.8
boolean_selector 1.0.4
charcode 1.1.2
collection 1.14.11
convert 2.0.2
crypto 2.0.6
csslib 0.14.6
front_end 0.1.7
glob 1.1.7
html 0.13.3+3
http 0.12.0
http_multi_server 2.0.5
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_rpc_2 2.0.9
kernel 0.3.7
logging 0.11.3+2
matcher 0.12.3+1 0.12.4
meta 1.1.6
mime 0.9.6+2
multi_server_socket 1.0.2
node_preamble 1.4.4
package_config 1.0.5
package_resolver 1.0.6
path 1.6.2
plugin 0.2.0+3
pool 1.3.6
pub_semver 1.4.2
shelf 0.7.3+3
shelf_packages_handler 1.0.4
shelf_static 0.2.8
shelf_web_socket 0.2.2+4
source_map_stack_trace 1.1.5
source_maps 0.10.8
source_span 1.4.1
stack_trace 1.9.3
stream_channel 1.6.8
string_scanner 1.0.4
term_glyph 1.0.1
test_api 0.2.1
test_core 0.2.0+1
typed_data 1.1.6
utf 0.9.0+5
vm_service_client 0.2.6
watcher 0.9.7+10
web_socket_channel 1.0.9
yaml 2.1.15