Skip to content

Commit

Permalink
remove trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrelogan committed Sep 28, 2016
1 parent 2ce17c9 commit a997a53
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions index.es6
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export let library = {
return library.regex(value, /^-?[0-9]+$/);
},
length: function(value, len) {
return library.exists(value) && library.exists(value.length) && (typeof(value) === 'string' ? value.trim() : value).length === len;
return library.exists(value) && library.exists(value.length) && value.length === len;
},
lessThan: function(value, baseline) {
return library.required(value) && Number(value) < baseline;
Expand All @@ -24,13 +24,13 @@ export let library = {
return library.required(value) && Number(value) <= baseline;
},
maxLength: function(value, len) {
return library.exists(value) && library.exists(value.length) && (typeof(value) === 'string' ? value.trim() : value).length <= len;
return library.exists(value) && library.exists(value.length) && value.length <= len;
},
min: function(value, baseline) {
return library.required(value) && Number(value) >= baseline;
},
minLength: function(value, len) {
return library.exists(value) && library.exists(value.length) && (typeof(value) === 'string' ? value.trim() : value).length >= len;
return library.exists(value) && library.exists(value.length) && value.length >= len;
},
number: function(value) {
return library.required(value) && !Number.isNaN(Number(value));
Expand All @@ -39,13 +39,13 @@ export let library = {
return library.regex(value, /^[0-9]+$/);
},
regex: function(value, pattern) {
return library.required(value) && pattern.test(value.trim());
return library.required(value) && pattern.test(value);
},
required: function(value) {
return typeof(value) === 'string' && value.trim() !== '';
},
startsWith: function(value, searchString) {
return library.required(value) && library.exists(searchString) && value.trim().substr(0, searchString.length) === searchString;
return library.required(value) && library.exists(searchString) && value.substr(0, searchString.length) === searchString;
},
url: function(value) {
// matches blank strings so you have a choice of pairing it with required
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var library = exports.library = {
return library.regex(value, /^-?[0-9]+$/);
},
length: function length(value, len) {
return library.exists(value) && library.exists(value.length) && (typeof value === 'string' ? value.trim() : value).length === len;
return library.exists(value) && library.exists(value.length) && value.length === len;
},
lessThan: function lessThan(value, baseline) {
return library.required(value) && Number(value) < baseline;
Expand All @@ -43,13 +43,13 @@ var library = exports.library = {
return library.required(value) && Number(value) <= baseline;
},
maxLength: function maxLength(value, len) {
return library.exists(value) && library.exists(value.length) && (typeof value === 'string' ? value.trim() : value).length <= len;
return library.exists(value) && library.exists(value.length) && value.length <= len;
},
min: function min(value, baseline) {
return library.required(value) && Number(value) >= baseline;
},
minLength: function minLength(value, len) {
return library.exists(value) && library.exists(value.length) && (typeof value === 'string' ? value.trim() : value).length >= len;
return library.exists(value) && library.exists(value.length) && value.length >= len;
},
number: function number(value) {
return library.required(value) && !Number.isNaN(Number(value));
Expand All @@ -58,13 +58,13 @@ var library = exports.library = {
return library.regex(value, /^[0-9]+$/);
},
regex: function regex(value, pattern) {
return library.required(value) && pattern.test(value.trim());
return library.required(value) && pattern.test(value);
},
required: function required(value) {
return typeof value === 'string' && value.trim() !== '';
},
startsWith: function startsWith(value, searchString) {
return library.required(value) && library.exists(searchString) && value.trim().substr(0, searchString.length) === searchString;
return library.required(value) && library.exists(searchString) && value.substr(0, searchString.length) === searchString;
},
url: function url(value) {
// matches blank strings so you have a choice of pairing it with required
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-formstate-validation",
"version": "0.2.1",
"version": "0.3.0",
"peerDependencies": {
"react-formstate": ">=0.3.0"
},
Expand Down
16 changes: 8 additions & 8 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('validation library', function() {
it('normal case', function() { assert.equal(true, lib.email('[email protected]')); });
it('requires @', function() { assert.equal(false, lib.email('ab.c')); });
it('requires .', function() { assert.equal(false, lib.email('a@bc')); });
it('trims', function() { assert.equal(true, lib.email(' [email protected] ')); });
it('does not trim', function() { assert.equal(false, lib.email(' [email protected] ')); });
it('spaces', function() { assert.equal(false, lib.email('a @b.c')); });
it('multiple dots', function() { assert.equal(true, lib.email('[email protected]')); });
it('multiple @s', function() { assert.equal(true, lib.email('a@[email protected]')); });
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('validation library', function() {
it('+4', function() { assert.equal(false, lib.integer('+4')); });
it('--4', function() { assert.equal(false, lib.integer('--4')); });
it('1.3', function() { assert.equal(false, lib.integer('1.3')); });
it(' 4 ', function() { assert.equal(true, lib.integer(' 4 ')); });
it(' 4 ', function() { assert.equal(false, lib.integer(' 4 ')); });
it(' 4 6 ', function() { assert.equal(false, lib.integer(' 4 6 ')); });
it('null', function() { assert.equal(false, lib.integer(null)); });
it('boolean', function() { assert.equal(false, lib.integer(true)); });
Expand All @@ -65,7 +65,7 @@ describe('validation library', function() {
it('arraylt', function() { assert.equal(false, lib.length([1,2], 3)); });
it('arrayeq', function() { assert.equal(true, lib.length([1,2], 2)); });
it('arraygt', function() { assert.equal(false, lib.length([1,2], 1)); });
it('trims', function() { assert.equal(true, lib.length(' hello ', 5)); });
it('does not trim', function() { assert.equal(false, lib.length(' hello ', 5)); });
});
describe('lessThan', function() {
it('lt', function() { assert.equal(true, lib.lessThan('5', 6)); });
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('validation library', function() {
it('arraylt', function() { assert.equal(true, lib.maxLength([1,2], 3)); });
it('arrayeq', function() { assert.equal(true, lib.maxLength([1,2], 2)); });
it('arraygt', function() { assert.equal(false, lib.maxLength([1,2], 1)); });
it('trims', function() { assert.equal(true, lib.maxLength(' hello ', 6)); });
it('does not trim', function() { assert.equal(false, lib.maxLength(' hello ', 6)); });
});
describe('min', function() {
it('lt', function() { assert.equal(false, lib.min('5', 6)); });
Expand All @@ -120,7 +120,7 @@ describe('validation library', function() {
it('arraylt', function() { assert.equal(false, lib.minLength([1,2], 3)); });
it('arrayeq', function() { assert.equal(true, lib.minLength([1,2], 2)); });
it('arraygt', function() { assert.equal(true, lib.minLength([1,2], 1)); });
it('trims', function() { assert.equal(false, lib.minLength(' hello ', 6)); });
it('does not trim', function() { assert.equal(true, lib.minLength(' hello ', 6)); });
});
describe('number', function() {
it('01234567899876543210', function() {
Expand All @@ -145,7 +145,7 @@ describe('validation library', function() {
it('+4', function() { assert.equal(false, lib.numeric('+4')); });
it('--4', function() { assert.equal(false, lib.numeric('--4')); });
it('1.3', function() { assert.equal(false, lib.numeric('1.3')); });
it(' 4 ', function() { assert.equal(true, lib.numeric(' 4 ')); });
it(' 4 ', function() { assert.equal(false, lib.numeric(' 4 ')); });
it(' 4 6 ', function() { assert.equal(false, lib.numeric(' 4 6 ')); });
it('null', function() { assert.equal(false, lib.numeric(null)); });
it('boolean', function() { assert.equal(false, lib.numeric(true)); });
Expand All @@ -167,9 +167,9 @@ describe('validation library', function() {
it('null', function() { assert.equal(false, lib.startsWith(null)); });
it('null searchString', function() { assert.equal(false, lib.startsWith('kilgore trout', null)); });
it('non-string searchString', function() { assert.equal(false, lib.startsWith('kilgore trout', 3)); });
it('trims value', function() { assert.equal(true, lib.startsWith(' kilgore trout','kilg')); });
it('does not trim', function() { assert.equal(false, lib.startsWith(' kilgore trout','kilg')); });
it('does not trim searchString', function() { assert.equal(false, lib.startsWith('kilgore trout',' kilg')); });
it('does not trim searchString2', function() { assert.equal(false, lib.startsWith(' kilgore trout',' kilg')); });
it('does not trim searchString2', function() { assert.equal(true, lib.startsWith(' kilgore trout',' kilg')); });
it('empty string', function() { assert.equal(false, lib.startsWith('','kilgore ')); });
});
describe('url', function() {
Expand Down

0 comments on commit a997a53

Please sign in to comment.