File tree Expand file tree Collapse file tree 5 files changed +23
-8
lines changed
Expand file tree Collapse file tree 5 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 1+ ## 3.1.0 (11/12/17)
2+ * Update typings to correctly handle default values for numeric types.
3+ * Ensure an error is thrown when ` asArray ` does not detect at least a single non-empty value.
4+
15## 3.0.2 (19/10/17)
26* Restore support for use in browser based applications
37
Original file line number Diff line number Diff line change @@ -7,33 +7,33 @@ interface IPresentVariable {
77 /**
88 * Attempt to parse the variable to a float. Throws an exception if parsing fails.
99 */
10- asFloat : ( ) => number | undefined ;
10+ asFloat : ( ) => number ;
1111
1212 /**
1313 * Performs the same task as asFloat(), but also verifies that the number is positive (greater than zero).
1414 */
15- asFloatPositive : ( ) => number | undefined ;
15+ asFloatPositive : ( ) => number ;
1616
1717 /**
1818 * Performs the same task as asFloat(), but also verifies that the number is negative (less than zero).
1919 */
20- asFloatNegative : ( ) => number | undefined ;
20+ asFloatNegative : ( ) => number ;
2121
2222 /**
2323 * Attempt to parse the variable to an integer. Throws an exception if parsing fails.
2424 * This is a strict check, meaning that if the process.env value is 1.2, an exception will be raised rather than rounding up/down.
2525 */
26- asInt : ( ) => number | undefined ;
26+ asInt : ( ) => number ;
2727
2828 /**
2929 * Performs the same task as asInt(), but also verifies that the number is positive (greater than zero).
3030 */
31- asIntPositive : ( ) => number | undefined ;
31+ asIntPositive : ( ) => number ;
3232
3333 /**
3434 * Performs the same task as asInt(), but also verifies that the number is negative (less than zero).
3535 */
36- asIntNegative : ( ) => number | undefined ;
36+ asIntNegative : ( ) => number ;
3737
3838 /**
3939 * Return the variable value as a String. Throws an exception if value is not a String.
Original file line number Diff line number Diff line change @@ -5,5 +5,9 @@ const asString = require('./string')
55module . exports = function asArray ( raiseError , value , delimeter ) {
66 delimeter = delimeter || ','
77
8+ if ( ! value . includes ( delimeter ) ) {
9+ raiseError ( `should include values separated with the delimeter "${ delimeter } "` )
10+ }
11+
812 return asString ( raiseError , value ) . split ( delimeter )
913}
Original file line number Diff line number Diff line change 11{
22 "name" : " env-var" ,
3- "version" : " 3.0.2 " ,
3+ "version" : " 3.1.0 " ,
44 "description" : " Solution for loading and sanatizing environment variables in node.js with correct typings" ,
55 "main" : " env-var.js" ,
66 "typings" : " env-var.d.ts" ,
5555 },
5656 "dependencies" : {
5757 "@types/node" : " ~8.0.31" ,
58- "camelcase" : " ~4.1.0" ,
5958 "is-url" : " ~1.2.2"
6059 },
6160 "engines" : {
Original file line number Diff line number Diff line change @@ -384,6 +384,14 @@ describe('env-var', function () {
384384 expect ( mod . get ( '.NOPE.' ) . asArray ( ) ) . to . equal ( undefined )
385385 } )
386386
387+ it ( 'should raise an error if set incorrectly' , function ( ) {
388+ process . env . COMMA_ARRAY = ''
389+
390+ expect ( ( ) => {
391+ mod . get ( 'COMMA_ARRAY' ) . asArray ( )
392+ } ) . to . throw ( 'should include values separated with the delimeter ","' )
393+ } )
394+
387395 it ( 'should return an array that was split on commas' , function ( ) {
388396 expect ( mod . get ( 'COMMA_ARRAY' ) . asArray ( ) ) . to . deep . equal ( [ '1' , '2' , '3' ] )
389397 } )
You can’t perform that action at this time.
0 commit comments