Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
add env-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-takei committed Jul 6, 2019
1 parent 2ab1eca commit ce8577a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
BasicInterceptor: require('./util/basic-interceptor'),
pathUtils: require('./util/path-utils'),
envUtils: require('./util/env-utils'),
// plugin
customTagUtils: require('./plugin/util/custom-tag-utils'),
// service
Expand Down
23 changes: 23 additions & 0 deletions src/test/util/env-utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require('module-alias/register');

const envUtils = require('@src/util/env-utils');


describe('env-utils', () => {
describe('.toBoolean', () => {

test('should convert to true', () => {
expect(envUtils.toBoolean('true')).toBe(true);
expect(envUtils.toBoolean('True')).toBe(true);
expect(envUtils.toBoolean(1)).toBe(true);
});

test('should convert to false', () => {
expect(envUtils.toBoolean(undefined)).toBe(false);
expect(envUtils.toBoolean(null)).toBe(false);
expect(envUtils.toBoolean('false')).toBe(false);
expect(envUtils.toBoolean(0)).toBe(false);
});

});
});
17 changes: 17 additions & 0 deletions src/util/env-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* convert to boolean
*
* @param {string} value
* @returns {boolean}
* @memberof envUtils
*/
function toBoolean(value) {
return /^(true|1)$/i.test(value);
}

/**
* @namespace envUtils
*/
module.exports = {
toBoolean,
};

0 comments on commit ce8577a

Please sign in to comment.