mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-15 06:56:36 +00:00
Switch _.isString usage to native versions
Change-type: patch
This commit is contained in:
parent
a3d70e3240
commit
3fe8a22fb0
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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)) {
|
||||
|
@ -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 };
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user