Skip to content

Commit

Permalink
Extract copystr function to lib/util/string.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed Jul 12, 2022
1 parent fd3bf61 commit 51ebf55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
10 changes: 2 additions & 8 deletions lib/modules/datasource/cpan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ExternalHostError } from '../../../types/errors/external-host-error';
import { cache } from '../../../util/cache/package/decorator';
import { getElapsedMinutes } from '../../../util/date';
import { newlineRegex, regEx } from '../../../util/regex';
import { copystr } from '../../../util/string';
import * as perlVersioning from '../../versioning/perl';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';
Expand Down Expand Up @@ -57,13 +58,6 @@ export class CpanDatasource extends Datasource {
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> {
const url = 'https://www.cpan.org/modules/02packages.details.txt';
const options = {
Expand Down Expand Up @@ -109,7 +103,7 @@ export class CpanDatasource extends Datasource {
}
split = l.split(/\s+/);
[pkg, latestVersion, path] = split;
pkg = CpanDatasource.copystr(pkg);
pkg = copystr(pkg);
const distribution = path.replace(pathPattern, '$1');
packages[pkg] = {
release: {
Expand Down
12 changes: 3 additions & 9 deletions lib/modules/datasource/rubygems/get-rubygems-org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import { getElapsedMinutes } from '../../../util/date';
import { newlineRegex } from '../../../util/regex';
import { copystr } from '../../../util/string';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types';

Expand Down Expand Up @@ -37,13 +38,6 @@ export class RubyGemsOrgDatasource extends Datasource {
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> {
const url = 'https://rubygems.org/versions';
const options = {
Expand Down Expand Up @@ -88,7 +82,7 @@ export class RubyGemsOrgDatasource extends Datasource {
}
split = l.split(' ');
[pkg, versions] = split;
pkg = RubyGemsOrgDatasource.copystr(pkg);
pkg = copystr(pkg);
packageReleases[pkg] = packageReleases[pkg] || [];
const lineVersions = versions.split(',').map((version) => version.trim());
for (const lineVersion of lineVersions) {
Expand All @@ -99,7 +93,7 @@ export class RubyGemsOrgDatasource extends Datasource {
(version) => version !== deletedVersion
);
} else {
packageReleases[pkg].push(RubyGemsOrgDatasource.copystr(lineVersion));
packageReleases[pkg].push(copystr(lineVersion));
}
}
} catch (err) /* istanbul ignore next */ {
Expand Down
7 changes: 7 additions & 0 deletions lib/util/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ export function uniqueStrings(
): boolean {
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);
}

0 comments on commit 51ebf55

Please sign in to comment.