Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Replace _.isString(value) with typeof value === 'string' #7812

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/classes/PluginManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PluginManager {
let pluginProvider = null;
// check if plugin is provider agnostic
if (pluginInstance.provider) {
if (_.isString(pluginInstance.provider)) {
if (typeof pluginInstance.provider === 'string') {
pluginProvider = pluginInstance.provider;
} else if (_.isObject(pluginInstance.provider)) {
pluginProvider = pluginInstance.provider.constructor.getProviderName();
Expand Down Expand Up @@ -168,7 +168,7 @@ class PluginManager {
modules = servicePlugs;
} else if (servicePlugs) {
localPath =
servicePlugs.localPath && _.isString(servicePlugs.localPath)
servicePlugs.localPath && typeof servicePlugs.localPath === 'string'
? servicePlugs.localPath
: localPath;
if (Array.isArray(servicePlugs.modules)) {
Expand Down Expand Up @@ -503,7 +503,7 @@ class PluginManager {
*/
spawn(commandsArray, options) {
let commands = commandsArray;
if (_.isString(commandsArray)) {
if (typeof commandsArray === 'string') {
commands = _.split(commandsArray, ':');
}
return this.invoke(commands, true).then(() => {
Expand Down Expand Up @@ -568,7 +568,7 @@ class PluginManager {
if (
_.isPlainObject(value.customValidation) &&
value.customValidation.regularExpression instanceof RegExp &&
_.isString(value.customValidation.errorMessage) &&
typeof value.customValidation.errorMessage === 'string' &&
!value.customValidation.regularExpression.test(this.cliOptions[key])
) {
throw new this.serverless.classes.Error(value.customValidation.errorMessage);
Expand Down
6 changes: 3 additions & 3 deletions lib/classes/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class Utils {
// For HTTP events, see what authorizer types are enabled
if (_.has(event, 'http.authorizer')) {
if (
(_.isString(event.http.authorizer) &&
(typeof event.http.authorizer === 'string' &&
event.http.authorizer.toUpperCase() === 'AWS_IAM') ||
(event.http.authorizer.type &&
event.http.authorizer.type.toUpperCase() === 'AWS_IAM')
Expand All @@ -234,7 +234,7 @@ class Utils {
// 3) By listing a function's ARN in the arn property of the authorizer object.

if (
(_.isString(event.http.authorizer) &&
(typeof event.http.authorizer === 'string' &&
event.http.authorizer.toUpperCase() !== 'AWS_IAM' &&
!awsArnRegExs.cognitoIdpArnExpr.test(event.http.authorizer)) ||
event.http.authorizer.name ||
Expand All @@ -244,7 +244,7 @@ class Utils {
hasCustomAuthorizer = true;
}
if (
(_.isString(event.http.authorizer) &&
(typeof event.http.authorizer === 'string' &&
awsArnRegExs.cognitoIdpArnExpr.test(event.http.authorizer)) ||
(event.http.authorizer.arn &&
awsArnRegExs.cognitoIdpArnExpr.test(event.http.authorizer.arn))
Expand Down
12 changes: 6 additions & 6 deletions lib/classes/Variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class Variables {
*/
populateVariables(properties) {
const variables = properties.filter(
property => _.isString(property.value) && property.value.match(this.variableSyntax)
property => typeof property.value === 'string' && property.value.match(this.variableSyntax)
);
return _.map(variables, variable =>
this.populateValue(variable.value, false).then(populated =>
Expand Down Expand Up @@ -458,7 +458,7 @@ class Variables {
if (property === matchedString) {
// total replacement
property = valueToPopulate;
} else if (_.isString(valueToPopulate)) {
} else if (typeof valueToPopulate === 'string') {
// partial replacement, string
property = replaceall(matchedString, valueToPopulate, property);
} else if (_.isNumber(valueToPopulate)) {
Expand Down Expand Up @@ -548,7 +548,7 @@ class Variables {
let deepPropertyString = variableMatch;
let deepProperties = 0;
values.forEach((value, index) => {
if (_.isString(value) && value.match(this.variableSyntax)) {
if (typeof value === 'string' && value.match(this.variableSyntax)) {
deepProperties += 1;
const deepVariable = this.makeDeepVariable(value);
deepPropertyString = deepPropertyString.replace(
Expand Down Expand Up @@ -866,7 +866,7 @@ class Variables {

getValueStrToBool(variableString) {
return BbPromise.try(() => {
if (_.isString(variableString)) {
if (typeof variableString === 'string') {
const groups = variableString.match(this.strToBoolRefSyntax);
const param = groups[1].trim();
if (/^(true|false|0|1)$/.test(param)) {
Expand Down Expand Up @@ -901,7 +901,7 @@ class Variables {
if (deepRef.length) {
// if there is a deep reference remaining
ret = ret.then(result => {
if (_.isString(result) && result.match(this.variableSyntax)) {
if (typeof result === 'string' && result.match(this.variableSyntax)) {
const deepVariable = this.makeDeepVariable(result);
return BbPromise.resolve(this.appendDeepVariable(deepVariable, deepRef));
}
Expand Down Expand Up @@ -944,7 +944,7 @@ class Variables {
deepProperties,
(reducedValueParam, subProperty) => {
let reducedValue = reducedValueParam;
if (_.isString(reducedValue) && reducedValue.match(this.deepRefSyntax)) {
if (typeof reducedValue === 'string' && reducedValue.match(this.deepRefSyntax)) {
// build mode
reducedValue = this.appendDeepVariable(reducedValue, subProperty);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/deployFunction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class AwsDeployFunction {
throw new this.serverless.classes.Error(errorMessage);
}

if (!_.isString(params.Environment.Variables[key])) {
if (typeof params.Environment.Variables[key] !== 'string') {
params.Environment.Variables[key] = _.toString(params.Environment.Variables[key]);
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/info/getApiKeyValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
} else if (definition.name) {
apiKeyNames.push(definition.name);
}
} else if (_.isString(definition)) {
} else if (typeof definition === 'string') {
// plain strings are simple, non-nested API keys
apiKeyNames.push(definition);
}
Expand Down
13 changes: 7 additions & 6 deletions lib/plugins/aws/lib/naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
getStackName() {
if (
this.provider.serverless.service.provider.stackName &&
_.isString(this.provider.serverless.service.provider.stackName)
typeof this.provider.serverless.service.provider.stackName === 'string'
) {
return `${this.provider.serverless.service.provider.stackName}`;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ module.exports = {
getWebsocketsApiName() {
if (
this.provider.serverless.service.provider.websocketsApiName &&
_.isString(this.provider.serverless.service.provider.websocketsApiName)
typeof this.provider.serverless.service.provider.websocketsApiName === 'string'
) {
return `${this.provider.serverless.service.provider.websocketsApiName}`;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ module.exports = {
getApiGatewayName() {
if (
this.provider.serverless.service.provider.apiName &&
_.isString(this.provider.serverless.service.provider.apiName)
typeof this.provider.serverless.service.provider.apiName === 'string'
) {
return `${this.provider.serverless.service.provider.apiName}`;
}
Expand Down Expand Up @@ -575,9 +575,10 @@ module.exports = {
const originPath = originObj.OriginPath;

let originId = isS3Origin ? 's3' : 'custom';
const domainName = _.isString(domain)
? domain
: this.normalizeNameToAlphaNumericOnly(JSON.stringify(domain));
const domainName =
typeof domain === 'string'
? domain
: this.normalizeNameToAlphaNumericOnly(JSON.stringify(domain));

originId = `${originId}/${domainName}`;
if (originPath) {
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/aws/package/compile/events/alexaSkill/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class AwsCompileAlexaSkillEvents {
' Please refer to the documentation for additional information.',
].join('');
this.serverless.cli.log(warningMessage);
} else if (_.isString(event.alexaSkill)) {
} else if (typeof event.alexaSkill === 'string') {
appId = event.alexaSkill;
} else if (_.isPlainObject(event.alexaSkill)) {
if (!_.isString(event.alexaSkill.appId)) {
if (typeof event.alexaSkill.appId !== 'string') {
const errorMessage = [
`Missing "appId" property for alexaSkill event in function ${functionName}`,
' The correct syntax is: appId: amzn1.ask.skill.xx-xx-xx-xx-xx',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const _ = require('lodash');
const BbPromise = require('bluebird');

function createApiKeyResource(that, apiKey) {
const name = _.isString(apiKey) ? apiKey : apiKey.name;
const name = typeof apiKey === 'string' ? apiKey : apiKey.name;
const value = _.isObject(apiKey) && apiKey.value ? apiKey.value : undefined;
const description = _.isObject(apiKey) ? apiKey.description : undefined;
const customerId = _.isObject(apiKey) ? apiKey.customerId : undefined;
Expand Down Expand Up @@ -33,7 +33,7 @@ module.exports = {
validateApiKeyInput(apiKey) {
if (_.isObject(apiKey) && (!_.isNil(apiKey.name) || !_.isNil(apiKey.value))) {
return true;
} else if (!_.isString(apiKey)) {
} else if (typeof apiKey !== 'string') {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function handleTags() {
);
const currentTags = this.apiGatewayStageState.tags || {};
const tagKeysToBeRemoved = Object.keys(currentTags).filter(
currentKey => !_.isString(tagsMerged[currentKey])
currentKey => typeof tagsMerged[currentKey] !== 'string'
);

const restApiId = this.apiGatewayRestApiId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ module.exports = {
type = 'AWS_IAM';
} else if (authorizer.arn) {
arn = authorizer.arn;
if (_.isString(authorizer.name)) {
if (typeof authorizer.name === 'string') {
name = authorizer.name;
} else if (
authorizer.type &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
}

// authorizers
if (_.isString(event.websocket.authorizer)) {
if (typeof event.websocket.authorizer === 'string') {
if (event.websocket.authorizer.includes(':')) {
// arn
websocketObj.authorizer = {
Expand Down Expand Up @@ -140,7 +140,7 @@ module.exports = {
}
events.push(websocketObj);
// dealing with the simplified string representation
} else if (_.isString(event.websocket)) {
} else if (typeof event.websocket === 'string') {
events.push({
functionName,
route: event.websocket,
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/print/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Print {
}
// provider treatment and defaults
this.cache.serviceProvider = service.provider;
if (_.isString(this.cache.serviceProvider)) {
if (typeof this.cache.serviceProvider === 'string') {
service.provider = { name: this.cache.serviceProvider };
}
service.provider = _.merge(
Expand All @@ -65,7 +65,7 @@ class Print {
service.service = this.cache.serviceService;
delete service.serviceObject;
}
if (_.isString(this.cache.serviceProvider)) {
if (typeof this.cache.serviceProvider === 'string') {
service.provider = this.cache.serviceProvider;
} else {
// is object
Expand Down