Extract copystr function to lib/util/string.ts

This commit is contained in:
IKEDA Sho 2022-07-12 23:26:54 +09:00
parent fd3bf61046
commit 51ebf55c90
3 changed files with 12 additions and 17 deletions

View file

@ -3,6 +3,7 @@ import { ExternalHostError } from '../../../types/errors/external-host-error';
import { cache } from '../../../util/cache/package/decorator'; import { cache } from '../../../util/cache/package/decorator';
import { getElapsedMinutes } from '../../../util/date'; import { getElapsedMinutes } from '../../../util/date';
import { newlineRegex, regEx } from '../../../util/regex'; import { newlineRegex, regEx } from '../../../util/regex';
import { copystr } from '../../../util/string';
import * as perlVersioning from '../../versioning/perl'; import * as perlVersioning from '../../versioning/perl';
import { Datasource } from '../datasource'; import { Datasource } from '../datasource';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types'; import type { GetReleasesConfig, Release, ReleaseResult } from '../types';
@ -57,13 +58,6 @@ export class CpanDatasource extends Datasource {
return dep; return dep;
} }
/**
* https://bugs.chromium.org/p/v8/issues/detail?id=2869
*/
private static copystr(x: string): string {
return (' ' + x).slice(1);
}
async updateCpanVersions(): Promise<void> { async updateCpanVersions(): Promise<void> {
const url = 'https://www.cpan.org/modules/02packages.details.txt'; const url = 'https://www.cpan.org/modules/02packages.details.txt';
const options = { const options = {
@ -109,7 +103,7 @@ export class CpanDatasource extends Datasource {
} }
split = l.split(/\s+/); split = l.split(/\s+/);
[pkg, latestVersion, path] = split; [pkg, latestVersion, path] = split;
pkg = CpanDatasource.copystr(pkg); pkg = copystr(pkg);
const distribution = path.replace(pathPattern, '$1'); const distribution = path.replace(pathPattern, '$1');
packages[pkg] = { packages[pkg] = {
release: { release: {

View file

@ -2,6 +2,7 @@ import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error'; import { ExternalHostError } from '../../../types/errors/external-host-error';
import { getElapsedMinutes } from '../../../util/date'; import { getElapsedMinutes } from '../../../util/date';
import { newlineRegex } from '../../../util/regex'; import { newlineRegex } from '../../../util/regex';
import { copystr } from '../../../util/string';
import { Datasource } from '../datasource'; import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types'; import type { GetReleasesConfig, ReleaseResult } from '../types';
@ -37,13 +38,6 @@ export class RubyGemsOrgDatasource extends Datasource {
return dep; return dep;
} }
/**
* https://bugs.chromium.org/p/v8/issues/detail?id=2869
*/
private static copystr(x: string): string {
return (' ' + x).slice(1);
}
async updateRubyGemsVersions(): Promise<void> { async updateRubyGemsVersions(): Promise<void> {
const url = 'https://rubygems.org/versions'; const url = 'https://rubygems.org/versions';
const options = { const options = {
@ -88,7 +82,7 @@ export class RubyGemsOrgDatasource extends Datasource {
} }
split = l.split(' '); split = l.split(' ');
[pkg, versions] = split; [pkg, versions] = split;
pkg = RubyGemsOrgDatasource.copystr(pkg); pkg = copystr(pkg);
packageReleases[pkg] = packageReleases[pkg] || []; packageReleases[pkg] = packageReleases[pkg] || [];
const lineVersions = versions.split(',').map((version) => version.trim()); const lineVersions = versions.split(',').map((version) => version.trim());
for (const lineVersion of lineVersions) { for (const lineVersion of lineVersions) {
@ -99,7 +93,7 @@ export class RubyGemsOrgDatasource extends Datasource {
(version) => version !== deletedVersion (version) => version !== deletedVersion
); );
} else { } else {
packageReleases[pkg].push(RubyGemsOrgDatasource.copystr(lineVersion)); packageReleases[pkg].push(copystr(lineVersion));
} }
} }
} catch (err) /* istanbul ignore next */ { } catch (err) /* istanbul ignore next */ {

View file

@ -45,3 +45,10 @@ export function uniqueStrings(
): boolean { ): boolean {
return elements.indexOf(element) === index; return elements.indexOf(element) === index;
} }
/**
* https://bugs.chromium.org/p/v8/issues/detail?id=2869
*/
export function copystr(x: string): string {
return (' ' + x).slice(1);
}