File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1
1
const Phone = require ( './phone' ) ;
2
+ const Postal = require ( './postal' ) ;
2
3
3
4
const Verifier = function ( ) { } ;
4
5
5
6
Verifier . prototype . Phone = Phone ;
7
+ Verifier . prototype . Postal = Postal ;
6
8
7
9
module . exports = new Verifier ( ) ;
Original file line number Diff line number Diff line change
1
+ const PostalCodeRegex = / ^ [ 1 3 - 9 ] { 10 } $ / ;
2
+
3
+ const Postal = function ( ) { } ;
4
+
5
+ /**
6
+ * Check if the entered postal code is valid.
7
+ * @param {string } postalCode
8
+ * @returns {boolean }
9
+ */
10
+ Postal . prototype . isPostalCodeValid = function ( postalCode ) {
11
+ return new RegExp ( PostalCodeRegex ) . test ( postalCode ) ;
12
+ } ;
13
+
14
+ module . exports = new Postal ( ) ;
Original file line number Diff line number Diff line change
1
+ const { describe, it } = require ( 'mocha' ) ;
2
+ const { expect } = require ( 'chai' ) ;
3
+ const { Postal } = require ( '../index' ) ;
4
+
5
+ describe ( 'Postal Tools' , ( ) => {
6
+ describe ( 'isPostalCodeValid' , ( ) => {
7
+ it ( 'should be valid postal codes' , ( ) => {
8
+ expect ( Postal . isPostalCodeValid ( '1834556784' ) ) . to . equal ( true ) ;
9
+ expect ( Postal . isPostalCodeValid ( '7634598734' ) ) . to . equal ( true ) ;
10
+ expect ( Postal . isPostalCodeValid ( '3813187764' ) ) . to . equal ( true ) ;
11
+ } ) ;
12
+ it ( 'should be not a valid postal code' , ( ) => {
13
+ expect ( Postal . isPostalCodeValid ( '76654543' ) ) . to . equal ( false ) ;
14
+ expect ( Postal . isPostalCodeValid ( '1898875423' ) ) . to . equal ( false ) ;
15
+ expect ( Postal . isPostalCodeValid ( '1890875413' ) ) . to . equal ( false ) ;
16
+ } ) ;
17
+ } ) ;
18
+ } ) ;
You can’t perform that action at this time.
0 commit comments