<commit_before>import bSemver = require('balena-semver');
import includes = require('lodash/includes');
import isEmpty = require('lodash/isEmpty');
import { isProvisioned } from '.';
import * as BalenaSdk from '../../typings/balena-sdk';

export const normalizeDeviceOsVersion = (device: BalenaSdk.Device) => {
	if (
		device.os_version != null &&
		isEmpty(device.os_version) &&
		isProvisioned(device)
	) {
		device.os_version = 'Resin OS 1.0.0-pre';
	}
};

export const getDeviceOsSemverWithVariant = ({
	os_version,
	os_variant,
}: Pick<BalenaSdk.Device, 'os_version' | 'os_variant'>) => {
	if (!os_version) {
		return null;
	}

	const versionInfo = bSemver.parse(os_version);
	if (!versionInfo) {
		return null;
	}

	let { version } = versionInfo;
	const build = versionInfo.build.slice();
	if (
		os_variant &&
		!includes(build.concat(versionInfo.prerelease), os_variant)
	) {
		build.push(os_variant);
	}

	if (!isEmpty(build)) {
		version = `${version}+${build.join('.')}`;
	}

	return version;
};<commit_msg>util/device-os-version: Make compatible w/ newer typings<commit_after>import bSemver = require('balena-semver');
import includes = require('lodash/includes');
import isEmpty = require('lodash/isEmpty');
import { isProvisioned } from '.';
import * as BalenaSdk from '../../typings/balena-sdk';

export const normalizeDeviceOsVersion = (device: BalenaSdk.Device) => {
	if (
		device.os_version != null &&
		isEmpty(device.os_version) &&
		isProvisioned(device)
	) {
		device.os_version = 'Resin OS 1.0.0-pre';
	}
};

export const getDeviceOsSemverWithVariant = ({
	os_version,
	os_variant,
}: Pick<BalenaSdk.Device, 'os_version' | 'os_variant'>) => {
	if (!os_version) {
		return null;
	}

	const versionInfo = bSemver.parse(os_version);
	if (!versionInfo) {
		return null;
	}

	let { version } = versionInfo;
	const build = versionInfo.build.slice();
	if (
		os_variant &&
		!includes([...build, ...versionInfo.prerelease], os_variant)
	) {
		build.push(os_variant);
	}

	if (!isEmpty(build)) {
		version = `${version}+${build.join('.')}`;
	}

	return version;
};
{'fraction_non_alphanumeric': 0.16682692307692307, 'fraction_numerical': 0.0028846153846153848, 'mean_word_length': 4.505291005291006, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3803551', 'n_tokens_mistral': 769, 'n_tokens_neox': 738, 'n_words': 140}