Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
suragch committed Feb 23, 2023
1 parent e7f14a0 commit 0c3ef18
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 132 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changes

## 1.0.0

- Seems to have been stable for a long time so bumping to 1.0.0.
- Fixed analyzer warnings.
- Added type safety.

## 0.3.0

- Null safety stable bump
Expand Down
5 changes: 5 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: package:lints/recommended.yaml

analyzer:
strong-mode:
implicit-dynamic: false
15 changes: 7 additions & 8 deletions lib/src/helpers.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Helper functions for validator and sanitizer.

shift(List l) {
if (l.isNotEmpty) {
var first = l.first;
l.removeAt(0);
return first;
}
return null;
String? shift(List<String> elements) {
if (elements.isEmpty) return null;
return elements.removeAt(0);
}

Map<String, Object> merge(Map<String, Object>? obj, Map<String, Object> defaults) {
Map<String, Object> merge(
Map<String, Object>? obj,
Map<String, Object> defaults,
) {
if (obj == null) {
return defaults;
}
Expand Down
19 changes: 9 additions & 10 deletions lib/src/sanitizer.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'helpers.dart';
import 'validator.dart';

Map<String, Object> _default_normalize_email_options = {'lowercase': true};
Map<String, Object> _defaultNormalizeEmailOptions = {'lowercase': true};

/// convert the input to a string
String toString(input) {
String toString(Object? input) {
if (input == null || (input is List && input.isEmpty)) {
input = '';
}
Expand Down Expand Up @@ -82,25 +82,24 @@ String rtrim(String str, [String? chars]) {
/// The characters are used in a RegExp and so you will need to escape
/// some chars.
String whitelist(String str, String chars) {
return str.replaceAll(RegExp('[^' + chars + ']+'), '');
return str.replaceAll(RegExp('[^$chars]+'), '');
}

/// remove characters that appear in the blacklist.
///
/// The characters are used in a RegExp and so you will need to escape
/// some chars.
String blacklist(String str, String chars) {
return str.replaceAll(RegExp('[' + chars + ']+'), '');
return str.replaceAll(RegExp('[$chars]+'), '');
}

/// remove characters with a numerical value < 32 and 127.
///
/// If `keep_new_lines` is `true`, newline characters are preserved
/// `(\n and \r, hex 0xA and 0xD)`.
String stripLow(String str, [bool keep_new_lines = false]) {
String chars = keep_new_lines == true
? '\x00-\x09\x0B\x0C\x0E-\x1F\x7F'
: '\x00-\x1F\x7F';
String stripLow(String str, [bool keepNewLines = false]) {
String chars =
keepNewLines == true ? '\x00-\x09\x0B\x0C\x0E-\x1F\x7F' : '\x00-\x1F\x7F';
return blacklist(str, chars);
}

Expand All @@ -126,7 +125,7 @@ String escape(String str) {
/// tags (e.g. `[email protected]` becomes `[email protected]`) and all
/// `@googlemail.com` addresses are normalized to `@gmail.com`.
String normalizeEmail(String email, [Map<String, Object>? options]) {
options = merge(options, _default_normalize_email_options);
options = merge(options, _defaultNormalizeEmailOptions);
if (isEmail(email) == false) {
return '';
}
Expand All @@ -142,7 +141,7 @@ String normalizeEmail(String email, [Map<String, Object>? options]) {
if (options['lowercase'] == false) {
parts[0] = parts[0].toLowerCase();
}
parts[0] = parts[0].replaceAll('\.', '').split('+')[0];
parts[0] = parts[0].replaceAll('.', '').split('+')[0];
parts[1] = 'gmail.com';
}
return parts.join('@');
Expand Down
Loading

0 comments on commit 0c3ef18

Please sign in to comment.