
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@timkit/url-lang
Advanced tools
URL replacement utilities for adding language codes to URLs. Supports both path-based and subdomain-based internationalization strategies.
npm install @timkit/url-lang
example.com → example.com/fr)example.com → fr.example.com)/api/*, *.pdf)import { replaceUrl } from '@timkit/url-lang';
const result = replaceUrl({
url: 'https://example.com/about',
langCodeToAdd: 'fr',
currentLangCodes: ['en', 'fr', 'es', 'de'],
mainDomain: 'example.com',
excludedLinkPatterns: [],
subdomainReplacement: false
});
console.log(result); // 'https://example.com/fr/about'
replaceUrl({
url: '/about',
langCodeToAdd: 'fr',
currentLangCodes: ['en', 'fr', 'es'],
mainDomain: 'example.com',
excludedLinkPatterns: [],
subdomainReplacement: false
});
// Returns: '/fr/about'
replaceUrl({
url: 'https://example.com/about',
langCodeToAdd: 'fr',
currentLangCodes: ['en', 'fr', 'es'],
mainDomain: 'example.com',
excludedLinkPatterns: [],
subdomainReplacement: true
});
// Returns: 'https://fr.example.com/about'
Exclude specific URLs from language code insertion using wildcard patterns:
replaceUrl({
url: '/api/users',
langCodeToAdd: 'fr',
currentLangCodes: ['en', 'fr'],
mainDomain: 'example.com',
excludedLinkPatterns: ['/api/*', '/wp-admin/*', '*.pdf'],
subdomainReplacement: false
});
// Returns: '/api/users' (unchanged)
/api/* - Matches any URL starting with /api/ (including /api/ itself)*.pdf - Matches any URL ending with .pdf/uploads/*.jpg - Matches /uploads/ + anything + .jpg# - Matches any URL containing # (anchor links)/wp-admin/ - Matches any URL containing /wp-admin/The wildcard * matches zero or more characters.
You can also use the pattern matching function independently:
import { matchesExclusionPattern } from '@timkit/url-lang';
matchesExclusionPattern('/api/users', '/api/*'); // true
matchesExclusionPattern('/api/', '/api/*'); // true
matchesExclusionPattern('document.pdf', '*.pdf'); // true
matchesExclusionPattern('#section', '#'); // true
replaceUrl(options: UrlReplacerOptions): stringReplaces or adds a language code to a URL based on the specified strategy.
url (string): The URL to process (absolute or relative)langCodeToAdd (string): Language code to add (e.g., 'fr', 'es', 'de')currentLangCodes (string[]): Array of all known language codes for detectionmainDomain (string): Main domain name without www (e.g., 'example.com')excludedLinkPatterns (string[]): Array of URL patterns to excludesubdomainReplacement (boolean): Use subdomain (true) or path (false) strategyThe URL with the language code added, or the original URL if excluded or invalid.
matchesExclusionPattern(url: string, pattern: string): booleanChecks if a URL matches an exclusion pattern.
url (string): The URL to testpattern (string): The pattern to match againsttrue if the URL matches the pattern, false otherwise.
const options = {
langCodeToAdd: 'es',
currentLangCodes: ['en', 'es', 'fr'],
mainDomain: 'myblog.com',
excludedLinkPatterns: [
'/wp-admin/*',
'/wp-content/*',
'/wp-includes/*',
'/feed/*'
],
subdomainReplacement: false
};
replaceUrl({ ...options, url: 'https://myblog.com/about' });
// 'https://myblog.com/es/about'
replaceUrl({ ...options, url: '/wp-admin/post.php' });
// '/wp-admin/post.php' (excluded)
replaceUrl({ ...options, url: '/wp-content/uploads/image.jpg' });
// '/wp-content/uploads/image.jpg' (excluded)
const options = {
langCodeToAdd: 'de',
currentLangCodes: ['en', 'de', 'fr', 'es'],
mainDomain: 'myapp.io',
excludedLinkPatterns: ['/api/*', '/auth/*', '*.json'],
subdomainReplacement: true
};
replaceUrl({ ...options, url: 'https://myapp.io/dashboard' });
// 'https://de.myapp.io/dashboard'
replaceUrl({ ...options, url: 'https://myapp.io/api/users' });
// 'https://myapp.io/api/users' (excluded)
Full TypeScript support with exported types:
import type { UrlReplacerOptions } from '@timkit/url-lang';
const options: UrlReplacerOptions = {
url: '/about',
langCodeToAdd: 'fr',
currentLangCodes: ['en', 'fr'],
mainDomain: 'example.com',
excludedLinkPatterns: [],
subdomainReplacement: false
};
# Install dependencies
npm install
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
# Build the package
npm run build
# Development mode (watch for changes)
npm run dev
MIT
FAQs
URL replacement utilities for adding language codes to URLs
We found that @timkit/url-lang demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.