renovate/lib/util/index.ts
Sergei Zharinov 31c7d8a8c6
refactor(build): Pre-compile files imported from data folder (#7896)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2020-12-08 14:07:29 +01:00

28 lines
813 B
TypeScript

import { RenovateConfig } from '../config/common';
import { setExecConfig } from './exec';
import { setFsConfig } from './fs';
export async function setUtilConfig(
config: Partial<RenovateConfig>
): Promise<void> {
await setExecConfig(config);
setFsConfig(config);
}
export function sampleSize(array: string[], n: number): string[] {
const length = array == null ? 0 : array.length;
if (!length || n < 1) {
return [];
}
// eslint-disable-next-line no-param-reassign
n = n > length ? length : n;
let index = 0;
const lastIndex = length - 1;
const result = [...array];
while (index < n) {
const rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
[result[rand], result[index]] = [result[index], result[rand]];
index += 1;
}
return result.slice(0, n);
}