Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

commons-validator-es

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commons-validator-es - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

dist/index.es.js

87

dist/index.d.ts

@@ -1,4 +0,83 @@

export { default as isDomain } from './isDomain';
export { default as isEmail } from './isEmail';
export { default as isTld } from './isTld';
export { default as isIpAddress } from './isIpAddress';
/**
* Returns true if the specified domain parses as a valid domain
* name with a recognised top-level domain.
* The parsing is case-insensitive.
* @param domain - the parameter to check for domain name syntax
* @param allowLocal - should local addresses be considered valid?
* @returns true if the parameter is a valid domain name
*/
declare const isDomain: (domain: string, allowLocal?: boolean) => boolean;
/**
* Checks if the value is a valid email address.
* @param email - The value validation is being performed on.
* @param allowLocal - Should local addresses be considered valid?
* @param allowTld - Should TLDs be allowed?
* @returns true if the email address is valid.
*/
declare const isEmail: (email: string, allowLocal?: boolean, allowTld?: boolean) => boolean;
/**
* Returns true if ccTld matches any IANA-defined country code top-level domain.
* Leading dots are ignored if present.
* The search is case-insensitive
* @param ccTld - the parameter to check for country codeTLD status, not null
* @returns true if the parameter is an country codeTLD
*/
declare const isCountryCodeTld: (ccTld: string) => boolean;
/**
* Returns true if gTld matches any IANA-defined generic top-level domain.
* Leading dots are ignored if present.
* The search is case-insensitive
* @param gTld - the parameter to check for generic TLD status, not null
* @returns true if the parameter is an generic TLD
*/
declare const isGenericTld: (gTld: string) => boolean;
/**
* Returns true if iTld matches any IANA-defined infrastructure top-level domain.
* Leading dots are ignored if present.
* The search is case-insensitive
* @param iTld - the parameter to check for infrastructure TLD status, not null
* @returns true if the parameter is an infrastructure TLD
*/
declare const isInfrastructureTld: (iTld: string) => boolean;
/**
* Returns true if lTld matches any widely used "local" domains (localhost or localdomain)
* Leading dots are ignored if present.
* The search is case-insensitive
* @param lTld - the parameter to check for local TLD status, not null
* @returns true if the parameter is an local TLD
*/
declare const isLocalTld: (lTld: string) => boolean;
/**
* Returns true if tld matches any IANA-defined top-level domain.
* Leading dots are ignored if present.
* The search is case-insentive.
* If allowLocal is true, the TLD is checked using {@link isLocalTld}.
* The TLD is then checked against {@link isCountryCodeTld}, {@link isGenericTld} and {@link isInfrastructureTld}.
* @param tld - tld to check
* @param allowLocal - whether local TLDs like ".localdomain" are allowed
* @returns true if tld is a valid TLD, otherwise false
*/
declare const isTld: (tld: string, allowLocal?: boolean) => boolean;
/**
* Validates an IPv4 address. Returns true if valid.
* @param address - address to check
* @returns true if the argument contains a valid IPv4 address
*/
declare const isIpv4Address: (address: string) => boolean;
/**
* Validates an IPv6 address. Returns true if valid.
* @param address - address to check
* @returns true if the argument contains a valid IPv6 address
*/
declare const isIpv6Address: (address: string) => boolean;
/**
* Checks if the specified string is a valid IP address.
* @param address - the string to validate
* @returns true if the string vaidates as an IP address
*/
declare const isIpAddress: (address: string) => boolean;
export { isCountryCodeTld, isDomain, isEmail, isGenericTld, isInfrastructureTld, isIpAddress, isIpv4Address, isIpv6Address, isLocalTld, isTld };

@@ -1,4 +0,1867 @@

export { default as isDomain } from './isDomain';
export { default as isEmail } from './isEmail';
export { default as isTld } from './isTld';
export { default as isIpAddress } from './isIpAddress';
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _ = require('punycode/');
/**
* Ported from org.apache.commons.validator.routines.DomainValidator
* https://github.com/apache/commons-validator/blob/master/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
*/
// WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search
const infrastructureTlds = [
'arpa', // internet infrastructure
];
// WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search
const genericTlds = [
// Taken from Version 2020073100, Last Updated Fri Jul 31 07:07:01 2020 UTC
'aaa',
'aarp',
'abarth',
'abb',
'abbott',
'abbvie',
'abc',
'able',
'abogado',
'abudhabi',
'academy',
'accenture',
'accountant',
'accountants',
'aco',
// "active", // active The Active Network, Inc
'actor',
'adac',
'ads',
'adult',
'aeg',
'aero',
'aetna',
'afamilycompany',
'afl',
'africa',
'agakhan',
'agency',
'aig',
// "aigo", // aigo aigo Digital Technology Co,Ltd. [Not assigned as of Jul 25]
'airbus',
'airforce',
'airtel',
'akdn',
'alfaromeo',
'alibaba',
'alipay',
'allfinanz',
'allstate',
'ally',
'alsace',
'alstom',
'amazon',
'americanexpress',
'americanfamily',
'amex',
'amfam',
'amica',
'amsterdam',
'analytics',
'android',
'anquan',
'anz',
'aol',
'apartments',
'app',
'apple',
'aquarelle',
'arab',
'aramco',
'archi',
'army',
'art',
'arte',
'asda',
'asia',
'associates',
'athleta',
'attorney',
'auction',
'audi',
'audible',
'audio',
'auspost',
'author',
'auto',
'autos',
'avianca',
'aws',
'axa',
'azure',
'baby',
'baidu',
'banamex',
'bananarepublic',
'band',
'bank',
'bar',
'barcelona',
'barclaycard',
'barclays',
'barefoot',
'bargains',
'baseball',
'basketball',
'bauhaus',
'bayern',
'bbc',
'bbt',
'bbva',
'bcg',
'bcn',
'beats',
'beauty',
'beer',
'bentley',
'berlin',
'best',
'bestbuy',
'bet',
'bharti',
'bible',
'bid',
'bike',
'bing',
'bingo',
'bio',
'biz',
'black',
'blackfriday',
// "blanco", // blanco BLANCO GmbH + Co KG
'blockbuster',
'blog',
'bloomberg',
'blue',
'bms',
'bmw',
// "bnl", // bnl Banca Nazionale del Lavoro
'bnpparibas',
'boats',
'boehringer',
'bofa',
'bom',
'bond',
'boo',
'book',
'booking',
// "boots", // boots THE BOOTS COMPANY PLC
'bosch',
'bostik',
'boston',
'bot',
'boutique',
'box',
'bradesco',
'bridgestone',
'broadway',
'broker',
'brother',
'brussels',
'budapest',
'bugatti',
'build',
'builders',
'business',
'buy',
'buzz',
'bzh',
'cab',
'cafe',
'cal',
'call',
'calvinklein',
'cam',
'camera',
'camp',
'cancerresearch',
'canon',
'capetown',
'capital',
'capitalone',
'car',
'caravan',
'cards',
'care',
'career',
'careers',
'cars',
// "cartier", // cartier Richemont DNS Inc.
'casa',
'case',
'caseih',
'cash',
'casino',
'cat',
'catering',
'catholic',
'cba',
'cbn',
'cbre',
'cbs',
'ceb',
'center',
'ceo',
'cern',
'cfa',
'cfd',
'chanel',
'channel',
'charity',
'chase',
'chat',
'cheap',
'chintai',
// "chloe", // chloe Richemont DNS Inc. (Not assigned)
'christmas',
'chrome',
// "chrysler", // chrysler FCA US LLC.
'church',
'cipriani',
'circle',
'cisco',
'citadel',
'citi',
'citic',
'city',
'cityeats',
'claims',
'cleaning',
'click',
'clinic',
'clinique',
'clothing',
'cloud',
'club',
'clubmed',
'coach',
'codes',
'coffee',
'college',
'cologne',
'com',
'comcast',
'commbank',
'community',
'company',
'compare',
'computer',
'comsec',
'condos',
'construction',
'consulting',
'contact',
'contractors',
'cooking',
'cookingchannel',
'cool',
'coop',
'corsica',
'country',
'coupon',
'coupons',
'courses',
'cpa',
'credit',
'creditcard',
'creditunion',
'cricket',
'crown',
'crs',
'cruise',
'cruises',
'csc',
'cuisinella',
'cymru',
'cyou',
'dabur',
'dad',
'dance',
'data',
'date',
'dating',
'datsun',
'day',
'dclk',
'dds',
'deal',
'dealer',
'deals',
'degree',
'delivery',
'dell',
'deloitte',
'delta',
'democrat',
'dental',
'dentist',
'desi',
'design',
'dev',
'dhl',
'diamonds',
'diet',
'digital',
'direct',
'directory',
'discount',
'discover',
'dish',
'diy',
'dnp',
'docs',
'doctor',
// "dodge", // dodge FCA US LLC.
'dog',
// "doha", // doha Communications Regulatory Authority (CRA)
'domains',
// "doosan", // doosan Doosan Corporation (retired)
'dot',
'download',
'drive',
'dtv',
'dubai',
'duck',
'dunlop',
// "duns", // duns The Dun & Bradstreet Corporation
'dupont',
'durban',
'dvag',
'dvr',
'earth',
'eat',
'eco',
'edeka',
'edu',
'education',
'email',
'emerck',
'energy',
'engineer',
'engineering',
'enterprises',
// "epost", // epost Deutsche Post AG
'epson',
'equipment',
'ericsson',
'erni',
'esq',
'estate',
// "esurance", // esurance Esurance Insurance Company (not assigned as at Version 2020062100)
'etisalat',
'eurovision',
'eus',
'events',
// "everbank", // everbank EverBank
'exchange',
'expert',
'exposed',
'express',
'extraspace',
'fage',
'fail',
'fairwinds',
'faith',
'family',
'fan',
'fans',
'farm',
'farmers',
'fashion',
'fast',
'fedex',
'feedback',
'ferrari',
'ferrero',
'fiat',
'fidelity',
'fido',
'film',
'final',
'finance',
'financial',
'fire',
'firestone',
'firmdale',
'fish',
'fishing',
'fit',
'fitness',
'flickr',
'flights',
'flir',
'florist',
'flowers',
// "flsmidth", // flsmidth FLSmidth A/S retired 2016-07-22
'fly',
'foo',
'food',
'foodnetwork',
'football',
'ford',
'forex',
'forsale',
'forum',
'foundation',
'fox',
'free',
'fresenius',
'frl',
'frogans',
'frontdoor',
'frontier',
'ftr',
'fujitsu',
'fujixerox',
'fun',
'fund',
'furniture',
'futbol',
'fyi',
'gal',
'gallery',
'gallo',
'gallup',
'game',
'games',
'gap',
'garden',
'gay',
'gbiz',
'gdn',
'gea',
'gent',
'genting',
'george',
'ggee',
'gift',
'gifts',
'gives',
'giving',
'glade',
'glass',
'gle',
'global',
'globo',
'gmail',
'gmbh',
'gmo',
'gmx',
'godaddy',
'gold',
'goldpoint',
'golf',
'goo',
// "goodhands", // goodhands Allstate Fire and Casualty Insurance Company
'goodyear',
'goog',
'google',
'gop',
'got',
'gov',
'grainger',
'graphics',
'gratis',
'green',
'gripe',
'grocery',
'group',
'guardian',
'gucci',
'guge',
'guide',
'guitars',
'guru',
'hair',
'hamburg',
'hangout',
'haus',
'hbo',
'hdfc',
'hdfcbank',
'health',
'healthcare',
'help',
'helsinki',
'here',
'hermes',
'hgtv',
'hiphop',
'hisamitsu',
'hitachi',
'hiv',
'hkt',
'hockey',
'holdings',
'holiday',
'homedepot',
'homegoods',
'homes',
'homesense',
'honda',
// "honeywell", // honeywell Honeywell GTLD LLC
'horse',
'hospital',
'host',
'hosting',
'hot',
'hoteles',
'hotels',
'hotmail',
'house',
'how',
'hsbc',
// "htc", // htc HTC corporation (Not assigned)
'hughes',
'hyatt',
'hyundai',
'ibm',
'icbc',
'ice',
'icu',
'ieee',
'ifm',
// "iinet", // iinet Connect West Pty. Ltd. (Retired)
'ikano',
'imamat',
'imdb',
'immo',
'immobilien',
'inc',
'industries',
'infiniti',
'info',
'ing',
'ink',
'institute',
'insurance',
'insure',
'int',
'intel',
'international',
'intuit',
'investments',
'ipiranga',
'irish',
// "iselect", // iselect iSelect Ltd
'ismaili',
'ist',
'istanbul',
'itau',
'itv',
'iveco',
// "iwc", // iwc Richemont DNS Inc.
'jaguar',
'java',
'jcb',
'jcp',
'jeep',
'jetzt',
'jewelry',
'jio',
// "jlc", // jlc Richemont DNS Inc.
'jll',
'jmp',
'jnj',
'jobs',
'joburg',
'jot',
'joy',
'jpmorgan',
'jprs',
'juegos',
'juniper',
'kaufen',
'kddi',
'kerryhotels',
'kerrylogistics',
'kerryproperties',
'kfh',
'kia',
'kim',
'kinder',
'kindle',
'kitchen',
'kiwi',
'koeln',
'komatsu',
'kosher',
'kpmg',
'kpn',
'krd',
'kred',
'kuokgroup',
'kyoto',
'lacaixa',
// "ladbrokes", // ladbrokes LADBROKES INTERNATIONAL PLC
'lamborghini',
'lamer',
'lancaster',
'lancia',
// "lancome", // lancome L'Oréal
'land',
'landrover',
'lanxess',
'lasalle',
'lat',
'latino',
'latrobe',
'law',
'lawyer',
'lds',
'lease',
'leclerc',
'lefrak',
'legal',
'lego',
'lexus',
'lgbt',
// "liaison", // liaison Liaison Technologies, Incorporated
'lidl',
'life',
'lifeinsurance',
'lifestyle',
'lighting',
'like',
'lilly',
'limited',
'limo',
'lincoln',
'linde',
'link',
'lipsy',
'live',
'living',
'lixil',
'llc',
'llp',
'loan',
'loans',
'locker',
'locus',
'loft',
'lol',
'london',
'lotte',
'lotto',
'love',
'lpl',
'lplfinancial',
'ltd',
'ltda',
'lundbeck',
'lupin',
'luxe',
'luxury',
'macys',
'madrid',
'maif',
'maison',
'makeup',
'man',
'management',
'mango',
'map',
'market',
'marketing',
'markets',
'marriott',
'marshalls',
'maserati',
'mattel',
'mba',
// "mcd", // mcd McDonald’s Corporation (Not assigned)
// "mcdonalds", // mcdonalds McDonald’s Corporation (Not assigned)
'mckinsey',
'med',
'media',
'meet',
'melbourne',
'meme',
'memorial',
'men',
'menu',
// "meo", // meo PT Comunicacoes S.A.
'merckmsd',
'metlife',
'miami',
'microsoft',
'mil',
'mini',
'mint',
'mit',
'mitsubishi',
'mlb',
'mls',
'mma',
'mobi',
'mobile',
// "mobily", // mobily GreenTech Consultancy Company W.L.L.
'moda',
'moe',
'moi',
'mom',
'monash',
'money',
'monster',
// "montblanc", // montblanc Richemont DNS Inc. (Not assigned)
// "mopar", // mopar FCA US LLC.
'mormon',
'mortgage',
'moscow',
'moto',
'motorcycles',
'mov',
'movie',
// "movistar", // movistar Telefónica S.A.
'msd',
'mtn',
// "mtpc", // mtpc Mitsubishi Tanabe Pharma Corporation (Retired)
'mtr',
'museum',
'mutual',
// "mutuelle", // mutuelle Fédération Nationale de la Mutualité Française (Retired)
'nab',
// "nadex", // nadex Nadex Domains, Inc
'nagoya',
'name',
'nationwide',
'natura',
'navy',
'nba',
'nec',
'net',
'netbank',
'netflix',
'network',
'neustar',
'new',
'newholland',
'news',
'next',
'nextdirect',
'nexus',
'nfl',
'ngo',
'nhk',
'nico',
'nike',
'nikon',
'ninja',
'nissan',
'nissay',
'nokia',
'northwesternmutual',
'norton',
'now',
'nowruz',
'nowtv',
'nra',
'nrw',
'ntt',
'nyc',
'obi',
'observer',
'off',
'office',
'okinawa',
'olayan',
'olayangroup',
'oldnavy',
'ollo',
'omega',
'one',
'ong',
'onl',
'online',
'onyourside',
'ooo',
'open',
'oracle',
'orange',
'org',
'organic',
// "orientexpress", // orientexpress Orient Express (retired 2017-04-11)
'origins',
'osaka',
'otsuka',
'ott',
'ovh',
'page',
// "pamperedchef", // pamperedchef The Pampered Chef, Ltd. (Not assigned)
'panasonic',
// "panerai", // panerai Richemont DNS Inc.
'paris',
'pars',
'partners',
'parts',
'party',
'passagens',
'pay',
'pccw',
'pet',
'pfizer',
'pharmacy',
'phd',
'philips',
'phone',
'photo',
'photography',
'photos',
'physio',
// "piaget", // piaget Richemont DNS Inc.
'pics',
'pictet',
'pictures',
'pid',
'pin',
'ping',
'pink',
'pioneer',
'pizza',
'place',
'play',
'playstation',
'plumbing',
'plus',
'pnc',
'pohl',
'poker',
'politie',
'porn',
'post',
'pramerica',
'praxi',
'press',
'prime',
'pro',
'prod',
'productions',
'prof',
'progressive',
'promo',
'properties',
'property',
'protection',
'pru',
'prudential',
'pub',
'pwc',
'qpon',
'quebec',
'quest',
'qvc',
'racing',
'radio',
'raid',
'read',
'realestate',
'realtor',
'realty',
'recipes',
'red',
'redstone',
'redumbrella',
'rehab',
'reise',
'reisen',
'reit',
'reliance',
'ren',
'rent',
'rentals',
'repair',
'report',
'republican',
'rest',
'restaurant',
'review',
'reviews',
'rexroth',
'rich',
'richardli',
'ricoh',
// "rightathome", // rightathome Johnson Shareholdings, Inc. (retired 2020-07-31)
'ril',
'rio',
'rip',
'rmit',
'rocher',
'rocks',
'rodeo',
'rogers',
'room',
'rsvp',
'rugby',
'ruhr',
'run',
'rwe',
'ryukyu',
'saarland',
'safe',
'safety',
'sakura',
'sale',
'salon',
'samsclub',
'samsung',
'sandvik',
'sandvikcoromant',
'sanofi',
'sap',
// "sapo", // sapo PT Comunicacoes S.A.
'sarl',
'sas',
'save',
'saxo',
'sbi',
'sbs',
'sca',
'scb',
'schaeffler',
'schmidt',
'scholarships',
'school',
'schule',
'schwarz',
'science',
'scjohnson',
// "scor", // scor SCOR SE (not assigned as at Version 2020062100)
'scot',
'search',
'seat',
'secure',
'security',
'seek',
'select',
'sener',
'services',
'ses',
'seven',
'sew',
'sex',
'sexy',
'sfr',
'shangrila',
'sharp',
'shaw',
'shell',
'shia',
'shiksha',
'shoes',
'shop',
'shopping',
'shouji',
'show',
'showtime',
'shriram',
'silk',
'sina',
'singles',
'site',
'ski',
'skin',
'sky',
'skype',
'sling',
'smart',
'smile',
'sncf',
'soccer',
'social',
'softbank',
'software',
'sohu',
'solar',
'solutions',
'song',
'sony',
'soy',
'space',
// "spiegel", // spiegel SPIEGEL-Verlag Rudolf Augstein GmbH & Co. KG
'sport',
'spot',
'spreadbetting',
'srl',
// "srt", // srt FCA US LLC.
'stada',
'staples',
'star',
// "starhub", // starhub StarHub Limited
'statebank',
'statefarm',
// "statoil", // statoil Statoil ASA
'stc',
'stcgroup',
'stockholm',
'storage',
'store',
'stream',
'studio',
'study',
'style',
'sucks',
'supplies',
'supply',
'support',
'surf',
'surgery',
'suzuki',
'swatch',
'swiftcover',
'swiss',
'sydney',
// "symantec", // symantec Symantec Corporation [Not assigned as of Jul 25]
'systems',
'tab',
'taipei',
'talk',
'taobao',
'target',
'tatamotors',
'tatar',
'tattoo',
'tax',
'taxi',
'tci',
'tdk',
'team',
'tech',
'technology',
'tel',
// "telecity", // telecity TelecityGroup International Limited
// "telefonica", // telefonica Telefónica S.A.
'temasek',
'tennis',
'teva',
'thd',
'theater',
'theatre',
'tiaa',
'tickets',
'tienda',
'tiffany',
'tips',
'tires',
'tirol',
'tjmaxx',
'tjx',
'tkmaxx',
'tmall',
'today',
'tokyo',
'tools',
'top',
'toray',
'toshiba',
'total',
'tours',
'town',
'toyota',
'toys',
'trade',
'trading',
'training',
'travel',
'travelchannel',
'travelers',
'travelersinsurance',
'trust',
'trv',
'tube',
'tui',
'tunes',
'tushu',
'tvs',
'ubank',
'ubs',
// "uconnect", // uconnect FCA US LLC.
'unicom',
'university',
'uno',
'uol',
'ups',
'vacations',
'vana',
'vanguard',
'vegas',
'ventures',
'verisign',
'versicherung',
'vet',
'viajes',
'video',
'vig',
'viking',
'villas',
'vin',
'vip',
'virgin',
'visa',
'vision',
// "vista", // vista Vistaprint Limited
// "vistaprint", // vistaprint Vistaprint Limited
'viva',
'vivo',
'vlaanderen',
'vodka',
'volkswagen',
'volvo',
'vote',
'voting',
'voto',
'voyage',
'vuelos',
'wales',
'walmart',
'walter',
'wang',
'wanggou',
// "warman", // warman Weir Group IP Limited
'watch',
'watches',
'weather',
'weatherchannel',
'webcam',
'weber',
'website',
'wed',
'wedding',
'weibo',
'weir',
'whoswho',
'wien',
'wiki',
'williamhill',
'win',
'windows',
'wine',
'winners',
'wme',
'wolterskluwer',
'woodside',
'work',
'works',
'world',
'wow',
'wtc',
'wtf',
'xbox',
'xerox',
'xfinity',
'xihuan',
'xin',
'xn--11b4c3d',
'xn--1ck2e1b',
'xn--1qqw23a',
'xn--30rr7y',
'xn--3bst00m',
'xn--3ds443g',
'xn--3oq18vl8pn36a',
'xn--3pxu8k',
'xn--42c2d9a',
'xn--45q11c',
'xn--4gbrim',
'xn--55qw42g',
'xn--55qx5d',
'xn--5su34j936bgsg',
'xn--5tzm5g',
'xn--6frz82g',
'xn--6qq986b3xl',
'xn--80adxhks',
'xn--80aqecdr1a',
'xn--80asehdb',
'xn--80aswg',
'xn--8y0a063a',
'xn--90ae',
'xn--9dbq2a',
'xn--9et52u',
'xn--9krt00a',
'xn--b4w605ferd',
'xn--bck1b9a5dre4c',
'xn--c1avg',
'xn--c2br7g',
'xn--cck2b3b',
'xn--cckwcxetd',
'xn--cg4bki',
'xn--czr694b',
'xn--czrs0t',
'xn--czru2d',
'xn--d1acj3b',
'xn--eckvdtc9d',
'xn--efvy88h',
// "xn--estv75g", // 工行 Industrial and Commercial Bank of China Limited
'xn--fct429k',
'xn--fhbei',
'xn--fiq228c5hs',
'xn--fiq64b',
'xn--fjq720a',
'xn--flw351e',
'xn--fzys8d69uvgm',
'xn--g2xx48c',
'xn--gckr3f0f',
'xn--gk3at1e',
'xn--hxt814e',
'xn--i1b6b1a6a2e',
'xn--imr513n',
'xn--io0a7i',
'xn--j1aef',
'xn--jlq480n2rg',
'xn--jlq61u9w7b',
'xn--jvr189m',
'xn--kcrx77d1x4a',
// "xn--kpu716f", // 手表 Richemont DNS Inc. [Not assigned as of Jul 25]
'xn--kput3i',
'xn--mgba3a3ejt',
'xn--mgba7c0bbn0a',
'xn--mgbaakc7dvf',
'xn--mgbab2bd',
// "xn--mgbb9fbpob", // موبايلي GreenTech Consultancy Company W.L.L.
'xn--mgbca7dzdo',
'xn--mgbi4ecexp',
'xn--mgbt3dhd',
'xn--mk1bu44c',
'xn--mxtq1m',
'xn--ngbc5azd',
'xn--ngbe9e0a',
'xn--ngbrx',
'xn--nqv7f',
'xn--nqv7fs00ema',
'xn--nyqy26a',
'xn--otu796d',
'xn--p1acf',
// "xn--pbt977c", // 珠宝 Richemont DNS Inc. [Not assigned as of Jul 25]
'xn--pssy2u',
'xn--q9jyb4c',
'xn--qcka1pmc',
'xn--rhqv96g',
'xn--rovu88b',
'xn--ses554g',
'xn--t60b56a',
'xn--tckwe',
'xn--tiq49xqyj',
'xn--unup4y',
'xn--vermgensberater-ctb',
'xn--vermgensberatung-pwb',
'xn--vhquv',
'xn--vuq861b',
'xn--w4r85el8fhu5dnra',
'xn--w4rs40l',
'xn--xhq521b',
'xn--zfr164b',
// "xperia", // xperia Sony Mobile Communications AB
'xxx',
'xyz',
'yachts',
'yahoo',
'yamaxun',
'yandex',
'yodobashi',
'yoga',
'yokohama',
'you',
'youtube',
'yun',
'zappos',
'zara',
'zero',
'zip',
// "zippo", // zippo Zadco Company
'zone',
'zuerich', // zuerich Kanton Zürich (Canton of Zurich)
];
// WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search
const countryCodeTlds = [
// Taken from Version 2020051000, Last Updated Sun May 10 07:07:01 2020 UTC
'ac',
'ad',
'ae',
'af',
'ag',
'ai',
'al',
'am',
// "an", // Netherlands Antilles (retired)
'ao',
'aq',
'ar',
'as',
'at',
'au',
'aw',
'ax',
'az',
'ba',
'bb',
'bd',
'be',
'bf',
'bg',
'bh',
'bi',
'bj',
'bm',
'bn',
'bo',
'br',
'bs',
'bt',
'bv',
'bw',
'by',
'bz',
'ca',
'cc',
'cd',
'cf',
'cg',
'ch',
'ci',
'ck',
'cl',
'cm',
'cn',
'co',
'cr',
'cu',
'cv',
'cw',
'cx',
'cy',
'cz',
'de',
'dj',
'dk',
'dm',
'do',
'dz',
'ec',
'ee',
'eg',
'er',
'es',
'et',
'eu',
'fi',
'fj',
'fk',
'fm',
'fo',
'fr',
'ga',
'gb',
'gd',
'ge',
'gf',
'gg',
'gh',
'gi',
'gl',
'gm',
'gn',
'gp',
'gq',
'gr',
'gs',
'gt',
'gu',
'gw',
'gy',
'hk',
'hm',
'hn',
'hr',
'ht',
'hu',
'id',
'ie',
'il',
'im',
'in',
'io',
'iq',
'ir',
'is',
'it',
'je',
'jm',
'jo',
'jp',
'ke',
'kg',
'kh',
'ki',
'km',
'kn',
'kp',
'kr',
'kw',
'ky',
'kz',
'la',
'lb',
'lc',
'li',
'lk',
'lr',
'ls',
'lt',
'lu',
'lv',
'ly',
'ma',
'mc',
'md',
'me',
'mg',
'mh',
'mk',
'ml',
'mm',
'mn',
'mo',
'mp',
'mq',
'mr',
'ms',
'mt',
'mu',
'mv',
'mw',
'mx',
'my',
'mz',
'na',
'nc',
'ne',
'nf',
'ng',
'ni',
'nl',
'no',
'np',
'nr',
'nu',
'nz',
'om',
'pa',
'pe',
'pf',
'pg',
'ph',
'pk',
'pl',
'pm',
'pn',
'pr',
'ps',
'pt',
'pw',
'py',
'qa',
're',
'ro',
'rs',
'ru',
'rw',
'sa',
'sb',
'sc',
'sd',
'se',
'sg',
'sh',
'si',
'sj',
'sk',
'sl',
'sm',
'sn',
'so',
'sr',
'ss',
'st',
'su',
'sv',
'sx',
'sy',
'sz',
'tc',
'td',
'tf',
'tg',
'th',
'tj',
'tk',
'tl',
'tm',
'tn',
'to',
// "tp", // East Timor (Retired)
'tr',
'tt',
'tv',
'tw',
'tz',
'ua',
'ug',
'uk',
'us',
'uy',
'uz',
'va',
'vc',
've',
'vg',
'vi',
'vn',
'vu',
'wf',
'ws',
'xn--2scrj9c',
'xn--3e0b707e',
'xn--3hcrj9c',
'xn--45br5cyl',
'xn--45brj9c',
'xn--54b7fta0cc',
'xn--80ao21a',
'xn--90a3ac',
'xn--90ais',
'xn--clchc0ea0b2g2a9gcd',
'xn--d1alf',
'xn--e1a4c',
'xn--fiqs8s',
'xn--fiqz9s',
'xn--fpcrj9c3d',
'xn--fzc2c9e2c',
'xn--gecrj9c',
'xn--h2breg3eve',
'xn--h2brj9c',
'xn--h2brj9c8c',
'xn--j1amh',
'xn--j6w193g',
'xn--kprw13d',
'xn--kpry57d',
'xn--l1acc',
'xn--lgbbat1ad8j',
'xn--mgb9awbf',
'xn--mgba3a4f16a',
'xn--mgbaam7a8h',
'xn--mgbah1a3hjkrd',
'xn--mgbai9azgqp6j',
'xn--mgbayh7gpa',
'xn--mgbbh1a',
'xn--mgbbh1a71e',
'xn--mgbc0a9azcg',
'xn--mgbcpq6gpa1a',
'xn--mgberp4a5d4ar',
'xn--mgbgu82a',
'xn--mgbpl2fh',
'xn--mgbtx2b',
'xn--mgbx4cd0ab',
'xn--mix891f',
'xn--node',
'xn--o3cw4h',
'xn--ogbpf8fl',
'xn--p1ai',
'xn--pgbs0dh',
'xn--q7ce6a',
'xn--qxa6a',
'xn--qxam',
'xn--rvc1e0am3e',
'xn--s9brj9c',
'xn--wgbh1c',
'xn--wgbl6a',
'xn--xkc2al3hye2a',
'xn--xkc2dl3a5ee0h',
'xn--y9a3aq',
'xn--yfro4i67o',
'xn--ygbi2ammx',
'ye',
'yt',
'za',
'zm',
'zw', // Zimbabwe
];
// WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search
const localTlds = [
'localdomain',
'localhost', // RFC2606 defined
];
/**
* Removes leading dot from string
* @private
* @param str - the string to modify
* @returns string without leading dot
*/
const chompLeadingDot = (str) => {
if (str[0] === '.') {
return str.substring(1);
}
return str;
};
/**
* Returns true if ccTld matches any IANA-defined country code top-level domain.
* Leading dots are ignored if present.
* The search is case-insensitive
* @param ccTld - the parameter to check for country codeTLD status, not null
* @returns true if the parameter is an country codeTLD
*/
const isCountryCodeTld = (ccTld) => {
const key = chompLeadingDot(ccTld.toLowerCase());
return countryCodeTlds.includes(key);
};
/**
* Returns true if gTld matches any IANA-defined generic top-level domain.
* Leading dots are ignored if present.
* The search is case-insensitive
* @param gTld - the parameter to check for generic TLD status, not null
* @returns true if the parameter is an generic TLD
*/
const isGenericTld = (gTld) => {
const key = chompLeadingDot(gTld.toLowerCase());
return genericTlds.includes(key);
};
/**
* Returns true if iTld matches any IANA-defined infrastructure top-level domain.
* Leading dots are ignored if present.
* The search is case-insensitive
* @param iTld - the parameter to check for infrastructure TLD status, not null
* @returns true if the parameter is an infrastructure TLD
*/
const isInfrastructureTld = (iTld) => {
const key = chompLeadingDot(iTld.toLowerCase());
return infrastructureTlds.includes(key);
};
/**
* Returns true if lTld matches any widely used "local" domains (localhost or localdomain)
* Leading dots are ignored if present.
* The search is case-insensitive
* @param lTld - the parameter to check for local TLD status, not null
* @returns true if the parameter is an local TLD
*/
const isLocalTld = (lTld) => {
const key = chompLeadingDot(lTld.toLowerCase());
return localTlds.includes(key);
};
/**
* Returns true if tld matches any IANA-defined top-level domain.
* Leading dots are ignored if present.
* The search is case-insentive.
* If allowLocal is true, the TLD is checked using {@link isLocalTld}.
* The TLD is then checked against {@link isCountryCodeTld}, {@link isGenericTld} and {@link isInfrastructureTld}.
* @param tld - tld to check
* @param allowLocal - whether local TLDs like ".localdomain" are allowed
* @returns true if tld is a valid TLD, otherwise false
*/
const isTld = (tld, allowLocal = false) => {
if (!tld) {
return false;
}
tld = _.toASCII(tld);
if (allowLocal && isLocalTld(tld)) {
return true;
}
return isInfrastructureTld(tld) || isGenericTld(tld) || isCountryCodeTld(tld);
};
const domainLabelRegex = '[a-zA-Z0-9](?:[a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?';
const topLabelRegex = '[a-zA-Z](?:[a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?';
const domainRegex = new RegExp('^(?:' + domainLabelRegex + '\\.)*(' + topLabelRegex + ')\\.?$');
/**
* Returns true if the specified domain parses as a valid domain
* name with a recognised top-level domain.
* The parsing is case-insensitive.
* @param domain - the parameter to check for domain name syntax
* @param allowLocal - should local addresses be considered valid?
* @returns true if the parameter is a valid domain name
*/
const isDomain = (domain, allowLocal = false) => {
if (!domain) {
return false;
}
domain = _.toASCII(domain);
if (domain.length > 253) {
return false;
}
const groups = domain.match(domainRegex);
if (groups && groups.length > 1 && groups[0] !== groups[1]) {
return isTld(groups[1], allowLocal);
}
return allowLocal && new RegExp(`^${domainLabelRegex}$`).test(domain);
};
const ipv4Regex = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/;
/**
* Validates an IPv4 address. Returns true if valid.
* @param address - address to check
* @returns true if the argument contains a valid IPv4 address
*/
const isIpv4Address = (address) => {
return ipv4Regex.test(address);
};
/**
* Validates an IPv6 address. Returns true if valid.
* @param address - address to check
* @returns true if the argument contains a valid IPv6 address
*/
const isIpv6Address = (address) => {
const splitPrefix = address.split('/');
if (splitPrefix.length > 2) {
return false;
}
else if (splitPrefix.length === 2) {
if (!splitPrefix[1].match(/^\d{1,3}$/)) {
return false;
}
const bits = parseInt(splitPrefix[1]); // cannot fail because regex check)
if (bits < 0 || bits > 128) {
return false;
}
}
const splitZoneId = splitPrefix[0].split('%');
if (splitZoneId.length > 2) {
return false;
}
else if (splitZoneId.length === 2 && !splitZoneId[1].match(/^[^\s/%]+$/)) {
// no whitespace, '/' or '%' allowed
return false;
}
const ipv6Address = splitZoneId[0];
const containsCompressedZeros = ipv6Address.includes('::');
if (containsCompressedZeros &&
ipv6Address.indexOf('::') !== ipv6Address.lastIndexOf('::')) {
return false;
}
if ((ipv6Address.startsWith(':') && !ipv6Address.startsWith('::')) ||
(ipv6Address.endsWith(':') && !ipv6Address.endsWith('::'))) {
return false;
}
const octets = ipv6Address.split(':');
if (containsCompressedZeros) {
if (ipv6Address.endsWith('::')) {
while (octets[octets.length - 1] === '') {
octets.pop();
}
octets.push('');
}
else if (ipv6Address.startsWith('::') && octets.length) {
octets.shift();
}
}
if (octets.length > 8) {
return false;
}
let validOctets = 0;
for (let index = 0; index < octets.length; index++) {
const octet = octets[index];
if (octet) {
if (index === octets.length - 1 && octet.includes('.')) {
if (!isIpv4Address(octet)) {
return false;
}
validOctets += 2;
continue;
}
if (!/^[\dA-Fa-f]{1,4}$/.test(octet)) {
return false;
}
}
validOctets++;
}
if (validOctets > 8 || (validOctets < 8 && !containsCompressedZeros)) {
return false;
}
return true;
};
/**
* Checks if the specified string is a valid IP address.
* @param address - the string to validate
* @returns true if the string vaidates as an IP address
*/
const isIpAddress = (address) => {
return isIpv4Address(address) || isIpv6Address(address);
};
const specialChars = '\x00-\x1F\x7F\\(\\)<>@,;:\'\\\\\\"\\.\\[\\]';
const validChars = '(\\\\.)|[^\\s' + specialChars + ']';
const quotedUser = '("(\\\\"|[^"])*")';
const word = '((' + validChars + "|')+|" + quotedUser + ')';
const userRegex = new RegExp('^' + word + '(\\.' + word + ')*$');
const emailRegex = /^\s*?(.+)@(.+)\s*$/;
const ipAddressRegex = /^\[(.*)\]$/;
/**
* Returns true if the domain component of an email address is valid.
* @private
* @param domain - domain being validated
* @param allowLocal - should local addresses be considered valid?
* @param allowTld - should TLDs be allowed?
* @returns true if the email address's domain is valid.
*/
const isValidDomain = (domain, allowLocal, allowTld) => {
const ipAddressGroups = domain.match(ipAddressRegex);
if (ipAddressGroups) {
return isIpAddress(ipAddressGroups[1]);
}
if (allowTld) {
return (isDomain(domain, allowLocal) || (!domain.startsWith('.') && isTld(domain)));
}
return isDomain(domain, allowLocal);
};
/**
* Returns true if the user component of an email address is valid.
* @private
* @param user - user being validated
* @returns true if the username is valid
*/
const isValidUser = (user) => {
if (!user || user.length > 64) {
return false;
}
return userRegex.test(user);
};
/**
* Checks if the value is a valid email address.
* @param email - The value validation is being performed on.
* @param allowLocal - Should local addresses be considered valid?
* @param allowTld - Should TLDs be allowed?
* @returns true if the email address is valid.
*/
const isEmail = (email, allowLocal = false, allowTld = false) => {
if (!email) {
return false;
}
if (email.endsWith('.')) {
return false;
}
const groups = email.match(emailRegex);
if (!groups) {
return false;
}
if (!isValidUser(groups[1])) {
return false;
}
if (!isValidDomain(groups[2], allowLocal, allowTld)) {
return false;
}
return true;
};
exports.isCountryCodeTld = isCountryCodeTld;
exports.isDomain = isDomain;
exports.isEmail = isEmail;
exports.isGenericTld = isGenericTld;
exports.isInfrastructureTld = isInfrastructureTld;
exports.isIpAddress = isIpAddress;
exports.isIpv4Address = isIpv4Address;
exports.isIpv6Address = isIpv6Address;
exports.isLocalTld = isLocalTld;
exports.isTld = isTld;

20

package.json
{
"name": "commons-validator-es",
"version": "1.0.1",
"version": "1.0.2",
"description": "Apache Commons Validator ported to TypeScript",

@@ -20,5 +20,5 @@ "keywords": [

"repository": "github:iandrewt/commons-validator-es",
"main": "./dist/index.js",
"main": "./dist/index.min.js",
"module": "./dist/index.es.min.js",
"types": "./dist/index.d.ts",
"type": "module",
"files": [

@@ -28,6 +28,7 @@ "/dist"

"scripts": {
"clean": "rm -rf dist",
"test": "jest",
"build": "tsc",
"eslint": "eslint 'src/**/*.ts'",
"eslint:fix": "eslint --fix 'src/**/*.ts'",
"build": "npm run clean && tsc && rollup -c",
"eslint": "eslint '**/*.ts'",
"eslint:fix": "eslint --fix '**/*.ts'",
"prepare": "husky install",

@@ -41,2 +42,3 @@ "prepublish": "npm run build"

"@commitlint/config-conventional": "^12.1.4",
"@rollup/plugin-typescript": "^8.2.1",
"@types/jest": "^26.0.23",

@@ -56,3 +58,7 @@ "@types/punycode": "^2.1.0",

"prettier": "2.3.2",
"rollup": "^2.52.7",
"rollup-plugin-dts": "^3.0.2",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^27.0.3",
"tslib": "^1.14.1",
"typescript": "^4.3.5"

@@ -64,3 +70,3 @@ },

"lint-staged": {
"src/**/*.ts": "eslint --fix"
"**/*.ts": "eslint --fix"
},

@@ -67,0 +73,0 @@ "jest": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc