Switch _.isString usage to native versions

Change-type: patch
This commit is contained in:
Pagan Gazzard 2023-10-13 15:11:57 +01:00 committed by Felipe Lalanne
parent a3d70e3240
commit 3fe8a22fb0
6 changed files with 17 additions and 13 deletions

View File

@ -32,7 +32,7 @@ export class PortMap {
private ports: PortRange;
private constructor(portStrOrObj: string | PortRange) {
if (_.isString(portStrOrObj)) {
if (typeof portStrOrObj === 'string') {
this.parsePortString(portStrOrObj);
} else {
this.ports = portStrOrObj;

View File

@ -222,11 +222,11 @@ export class Service {
delete config.ulimits;
// string or array of strings - normalise to an array
if (_.isString(config.dns)) {
if (typeof config.dns === 'string') {
config.dns = [config.dns];
}
if (_.isString(config.dnsSearch)) {
if (typeof config.dnsSearch === 'string') {
config.dnsSearch = [config.dnsSearch];
}
@ -396,7 +396,7 @@ export class Service {
let tmpfs: string[] = [];
if (config.tmpfs != null) {
if (_.isString(config.tmpfs)) {
if (typeof config.tmpfs === 'string') {
tmpfs = [config.tmpfs];
} else {
tmpfs = config.tmpfs;

View File

@ -85,7 +85,7 @@ export function createRestartPolicy(name?: string): string {
// Ensure that name is a string, otherwise the below could
// throw
if (!_.isString(name)) {
if (typeof name !== 'string') {
log.warn(`Non-string argument for restart field: ${name} - ignoring.`);
return 'always';
}
@ -109,7 +109,7 @@ function processCommandString(command: string): string {
function processCommandParsedArrayElement(
arg: string | { [key: string]: string },
): string {
if (_.isString(arg)) {
if (typeof arg === 'string') {
return arg;
}
if (arg.op === 'glob') {
@ -119,7 +119,7 @@ function processCommandParsedArrayElement(
}
function commandAsArray(command: string | string[]): string[] {
if (_.isString(command)) {
if (typeof command === 'string') {
return _.map(
parseCommand(processCommandString(command)),
processCommandParsedArrayElement,
@ -158,7 +158,7 @@ export function getStopSignal(
imageInfo?: Dockerode.ImageInspectInfo,
): string {
if (composeStop != null) {
if (!_.isString(composeStop)) {
if (typeof composeStop !== 'string') {
return composeStop.toString();
}
return composeStop;
@ -197,7 +197,7 @@ export function dockerHealthcheckToServiceHealthcheck(
}
function buildHealthcheckTest(test: string | string[]): string[] {
if (_.isString(test)) {
if (typeof test === 'string') {
return ['CMD-SHELL', test];
}
return test;

View File

@ -169,7 +169,7 @@ export class ConfigTxt extends ConfigBackend {
private ensureDtoverlay(conf: ConfigOptions, field: string) {
if (conf.dtoverlay == null) {
conf.dtoverlay = [];
} else if (_.isString(conf.dtoverlay)) {
} else if (typeof conf.dtoverlay === 'string') {
conf.dtoverlay = [conf.dtoverlay];
}
if (!_.includes(conf.dtoverlay, field)) {

View File

@ -91,7 +91,7 @@ const actionExecutors: DeviceActionExecutors = {
},
setVPNEnabled: async (step, opts = {}) => {
const { initial = false } = opts;
if (!_.isString(step.target)) {
if (typeof step.target !== 'string') {
throw new Error('Non-string value passed to setVPNEnabled');
}
const logValue = { SUPERVISOR_VPN_CONTROL: step.target };

View File

@ -43,7 +43,11 @@ export function checkInt(
* Check that a string exists, and is not an empty string, 'null', or 'undefined'
*/
export function checkString(s: unknown): string | undefined {
if (s == null || !_.isString(s) || _.includes(['null', 'undefined', ''], s)) {
if (
s == null ||
typeof s !== 'string' ||
_.includes(['null', 'undefined', ''], s)
) {
return;
}
@ -96,7 +100,7 @@ export function isValidDeviceName(v: unknown): v is DeviceName {
* Ensure a string is either undefined, or a non-empty string
*/
export function validStringOrUndefined(s: string | undefined): boolean {
return _.isUndefined(s) || (_.isString(s) && !_.isEmpty(s));
return _.isUndefined(s) || (typeof s === 'string' && !_.isEmpty(s));
}
/**