@fynlink/nochain
v0.1.1
Published
Fast short URL domain checker to prevent redirect chains
Downloads
24
Readme
@fynlink/nochain
Fast detection of known short URL domains for browser and Node.js runtimes.
Why this package
This package is designed for anti-chain-shortening enforcement (for example, blocking redirects to another known shortener).
- Very fast runtime checks using pre-generated in-memory map lookups
- Browser-safe and Node.js-safe (no runtime dependencies)
- Includes normalization utilities for domain/URL input
- Includes an updater script to regenerate the generated map from the canonical local source list
Installation
npm install @fynlink/nochainUsage
import { isKnownShortUrlDomain } from '@fynlink/nochain';
isKnownShortUrlDomain('bit.ly'); // true
isKnownShortUrlDomain('https://tinyurl.com/example'); // true
isKnownShortUrlDomain('example.com'); // falseRuntime manual domain list
If your application has extra short domains, create a matcher once with your manual list and reuse it:
import { createShortUrlDomainMatcher } from '@fynlink/nochain';
const isShortUrlDomain = createShortUrlDomainMatcher([
'manual-short-domain.example',
'custom.manual-link.test'
]);
isShortUrlDomain('https://manual-short-domain.example/abc'); // true
isShortUrlDomain('sub.custom.manual-link.test'); // true
isShortUrlDomain('https://bit.ly/abc123'); // true (built-in list still applies)
isShortUrlDomain('example.com'); // falsecreateShortUrlDomainMatcher is a one-time setup for the provided list. If the list changes, create a new matcher instance.
API
isKnownShortUrlDomain(domainOrUrl: string): booleancreateShortUrlDomainMatcher(additionalDomains: Iterable<string>): (domainOrUrl: string) => booleannormalizeDomain(input: string): string | nullSHORT_URL_DOMAINS: readonly string[]SHORT_URL_DOMAIN_COUNT: number
Data updates
Regenerate the dataset:
npm run update:domains --workspace @fynlink/nochainCurrent source inputs are documented in NOTICE and embedded in the generated source file header.
