Update is truthy fn

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-03-30 13:55:28 +02:00
parent 24000818f4
commit d60578c875
4 changed files with 12 additions and 19 deletions

View File

@ -1,4 +1,4 @@
const isTruthyEnvVar = require('../truthy-var');
const isTruthyEnvVar = require('../is-truthy');
describe('isTruthyEnvVar', () => {
test('Handles boolean strings', () => {

View File

@ -12,13 +12,13 @@ const ciEnv = require('ci-info');
const { scheduleJob } = require('node-schedule');
const createMiddleware = require('./middleware');
const isTruthyEnvVar = require('./truthy-var');
const isTruthy = require('./is-truthy');
const createTelemetryInstance = strapi => {
const uuid = strapi.config.uuid;
const deviceId = machineIdSync();
const isDisabled = !uuid || isTruthyEnvVar(process.env.STRAPI_TELEMETRY_DISABLED);
const isDisabled = !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED);
const anonymous_metadata = {
environment: strapi.config.environment,

View File

@ -0,0 +1,9 @@
'use strict';
const _ = require('lodash');
const isTruthy = val => {
return [1, true].includes(val) || ['true', '1'].includes(_.toLower(val));
};
module.exports = isTruthy;

View File

@ -1,16 +0,0 @@
'use strict';
const isTruthyEnvVar = val => {
if (val === null || val === undefined) return false;
if (val === true) return true;
if (val.toString().toLowerCase() === 'true') return true;
if (val.toString().toLowerCase() === 'false') return false;
if (val === 1) return true;
return false;
};
module.exports = isTruthyEnvVar;