Skip to content

Commit a997a53

Browse files
committed
remove trimming
1 parent 2ce17c9 commit a997a53

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

index.es6

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export let library = {
1515
return library.regex(value, /^-?[0-9]+$/);
1616
},
1717
length: function(value, len) {
18-
return library.exists(value) && library.exists(value.length) && (typeof(value) === 'string' ? value.trim() : value).length === len;
18+
return library.exists(value) && library.exists(value.length) && value.length === len;
1919
},
2020
lessThan: function(value, baseline) {
2121
return library.required(value) && Number(value) < baseline;
@@ -24,13 +24,13 @@ export let library = {
2424
return library.required(value) && Number(value) <= baseline;
2525
},
2626
maxLength: function(value, len) {
27-
return library.exists(value) && library.exists(value.length) && (typeof(value) === 'string' ? value.trim() : value).length <= len;
27+
return library.exists(value) && library.exists(value.length) && value.length <= len;
2828
},
2929
min: function(value, baseline) {
3030
return library.required(value) && Number(value) >= baseline;
3131
},
3232
minLength: function(value, len) {
33-
return library.exists(value) && library.exists(value.length) && (typeof(value) === 'string' ? value.trim() : value).length >= len;
33+
return library.exists(value) && library.exists(value.length) && value.length >= len;
3434
},
3535
number: function(value) {
3636
return library.required(value) && !Number.isNaN(Number(value));
@@ -39,13 +39,13 @@ export let library = {
3939
return library.regex(value, /^[0-9]+$/);
4040
},
4141
regex: function(value, pattern) {
42-
return library.required(value) && pattern.test(value.trim());
42+
return library.required(value) && pattern.test(value);
4343
},
4444
required: function(value) {
4545
return typeof(value) === 'string' && value.trim() !== '';
4646
},
4747
startsWith: function(value, searchString) {
48-
return library.required(value) && library.exists(searchString) && value.trim().substr(0, searchString.length) === searchString;
48+
return library.required(value) && library.exists(searchString) && value.substr(0, searchString.length) === searchString;
4949
},
5050
url: function(value) {
5151
// matches blank strings so you have a choice of pairing it with required

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var library = exports.library = {
3434
return library.regex(value, /^-?[0-9]+$/);
3535
},
3636
length: function length(value, len) {
37-
return library.exists(value) && library.exists(value.length) && (typeof value === 'string' ? value.trim() : value).length === len;
37+
return library.exists(value) && library.exists(value.length) && value.length === len;
3838
},
3939
lessThan: function lessThan(value, baseline) {
4040
return library.required(value) && Number(value) < baseline;
@@ -43,13 +43,13 @@ var library = exports.library = {
4343
return library.required(value) && Number(value) <= baseline;
4444
},
4545
maxLength: function maxLength(value, len) {
46-
return library.exists(value) && library.exists(value.length) && (typeof value === 'string' ? value.trim() : value).length <= len;
46+
return library.exists(value) && library.exists(value.length) && value.length <= len;
4747
},
4848
min: function min(value, baseline) {
4949
return library.required(value) && Number(value) >= baseline;
5050
},
5151
minLength: function minLength(value, len) {
52-
return library.exists(value) && library.exists(value.length) && (typeof value === 'string' ? value.trim() : value).length >= len;
52+
return library.exists(value) && library.exists(value.length) && value.length >= len;
5353
},
5454
number: function number(value) {
5555
return library.required(value) && !Number.isNaN(Number(value));
@@ -58,13 +58,13 @@ var library = exports.library = {
5858
return library.regex(value, /^[0-9]+$/);
5959
},
6060
regex: function regex(value, pattern) {
61-
return library.required(value) && pattern.test(value.trim());
61+
return library.required(value) && pattern.test(value);
6262
},
6363
required: function required(value) {
6464
return typeof value === 'string' && value.trim() !== '';
6565
},
6666
startsWith: function startsWith(value, searchString) {
67-
return library.required(value) && library.exists(searchString) && value.trim().substr(0, searchString.length) === searchString;
67+
return library.required(value) && library.exists(searchString) && value.substr(0, searchString.length) === searchString;
6868
},
6969
url: function url(value) {
7070
// matches blank strings so you have a choice of pairing it with required

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-formstate-validation",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"peerDependencies": {
55
"react-formstate": ">=0.3.0"
66
},

test/test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('validation library', function() {
1111
it('normal case', function() { assert.equal(true, lib.email('a@b.c')); });
1212
it('requires @', function() { assert.equal(false, lib.email('ab.c')); });
1313
it('requires .', function() { assert.equal(false, lib.email('a@bc')); });
14-
it('trims', function() { assert.equal(true, lib.email(' a@b.c ')); });
14+
it('does not trim', function() { assert.equal(false, lib.email(' a@b.c ')); });
1515
it('spaces', function() { assert.equal(false, lib.email('a @b.c')); });
1616
it('multiple dots', function() { assert.equal(true, lib.email('a@b..c')); });
1717
it('multiple @s', function() { assert.equal(true, lib.email('a@b@c.d')); });
@@ -49,7 +49,7 @@ describe('validation library', function() {
4949
it('+4', function() { assert.equal(false, lib.integer('+4')); });
5050
it('--4', function() { assert.equal(false, lib.integer('--4')); });
5151
it('1.3', function() { assert.equal(false, lib.integer('1.3')); });
52-
it(' 4 ', function() { assert.equal(true, lib.integer(' 4 ')); });
52+
it(' 4 ', function() { assert.equal(false, lib.integer(' 4 ')); });
5353
it(' 4 6 ', function() { assert.equal(false, lib.integer(' 4 6 ')); });
5454
it('null', function() { assert.equal(false, lib.integer(null)); });
5555
it('boolean', function() { assert.equal(false, lib.integer(true)); });
@@ -65,7 +65,7 @@ describe('validation library', function() {
6565
it('arraylt', function() { assert.equal(false, lib.length([1,2], 3)); });
6666
it('arrayeq', function() { assert.equal(true, lib.length([1,2], 2)); });
6767
it('arraygt', function() { assert.equal(false, lib.length([1,2], 1)); });
68-
it('trims', function() { assert.equal(true, lib.length(' hello ', 5)); });
68+
it('does not trim', function() { assert.equal(false, lib.length(' hello ', 5)); });
6969
});
7070
describe('lessThan', function() {
7171
it('lt', function() { assert.equal(true, lib.lessThan('5', 6)); });
@@ -98,7 +98,7 @@ describe('validation library', function() {
9898
it('arraylt', function() { assert.equal(true, lib.maxLength([1,2], 3)); });
9999
it('arrayeq', function() { assert.equal(true, lib.maxLength([1,2], 2)); });
100100
it('arraygt', function() { assert.equal(false, lib.maxLength([1,2], 1)); });
101-
it('trims', function() { assert.equal(true, lib.maxLength(' hello ', 6)); });
101+
it('does not trim', function() { assert.equal(false, lib.maxLength(' hello ', 6)); });
102102
});
103103
describe('min', function() {
104104
it('lt', function() { assert.equal(false, lib.min('5', 6)); });
@@ -120,7 +120,7 @@ describe('validation library', function() {
120120
it('arraylt', function() { assert.equal(false, lib.minLength([1,2], 3)); });
121121
it('arrayeq', function() { assert.equal(true, lib.minLength([1,2], 2)); });
122122
it('arraygt', function() { assert.equal(true, lib.minLength([1,2], 1)); });
123-
it('trims', function() { assert.equal(false, lib.minLength(' hello ', 6)); });
123+
it('does not trim', function() { assert.equal(true, lib.minLength(' hello ', 6)); });
124124
});
125125
describe('number', function() {
126126
it('01234567899876543210', function() {
@@ -145,7 +145,7 @@ describe('validation library', function() {
145145
it('+4', function() { assert.equal(false, lib.numeric('+4')); });
146146
it('--4', function() { assert.equal(false, lib.numeric('--4')); });
147147
it('1.3', function() { assert.equal(false, lib.numeric('1.3')); });
148-
it(' 4 ', function() { assert.equal(true, lib.numeric(' 4 ')); });
148+
it(' 4 ', function() { assert.equal(false, lib.numeric(' 4 ')); });
149149
it(' 4 6 ', function() { assert.equal(false, lib.numeric(' 4 6 ')); });
150150
it('null', function() { assert.equal(false, lib.numeric(null)); });
151151
it('boolean', function() { assert.equal(false, lib.numeric(true)); });
@@ -167,9 +167,9 @@ describe('validation library', function() {
167167
it('null', function() { assert.equal(false, lib.startsWith(null)); });
168168
it('null searchString', function() { assert.equal(false, lib.startsWith('kilgore trout', null)); });
169169
it('non-string searchString', function() { assert.equal(false, lib.startsWith('kilgore trout', 3)); });
170-
it('trims value', function() { assert.equal(true, lib.startsWith(' kilgore trout','kilg')); });
170+
it('does not trim', function() { assert.equal(false, lib.startsWith(' kilgore trout','kilg')); });
171171
it('does not trim searchString', function() { assert.equal(false, lib.startsWith('kilgore trout',' kilg')); });
172-
it('does not trim searchString2', function() { assert.equal(false, lib.startsWith(' kilgore trout',' kilg')); });
172+
it('does not trim searchString2', function() { assert.equal(true, lib.startsWith(' kilgore trout',' kilg')); });
173173
it('empty string', function() { assert.equal(false, lib.startsWith('','kilgore ')); });
174174
});
175175
describe('url', function() {

0 commit comments

Comments
 (0)