@fynd-design-engineering/fynd-one-v2 3.1.8 → 3.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{(function(){window.phoneValidator={},document.addEventListener("DOMContentLoaded",function(){setTimeout(function(){u()},100)});function u(){document.querySelectorAll("input[type='tel'], .phone-input").forEach(function(t){t.id||(t.id="phone-input-"+Math.floor(Math.random()*1e4));try{let o=window.intlTelInput(t,{utilsScript:"https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js",separateDialCode:!0,initialCountry:"auto",geoIpLookup:function(n){fetch("https://ipapi.co/json").then(i=>i.json()).then(i=>n(i.country_code)).catch(()=>n("in"))},nationalMode:!1,allowDropdown:!0,autoPlaceholder:"polite",formatOnDisplay:!0});t.iti=o,t.addEventListener("countrychange",function(){console.log("Country changed to:",o.getSelectedCountryData())}),console.log("Phone input initialized:",t.id)}catch(o){console.error("Failed to initialize phone input:",o)}}),window.validatePhone=(t,o)=>{let n=c(t);if(!n)return{isValid:!1,message:"No phone input found"};let i=n.iti;if(!i)return{isValid:!1,message:"Phone validator not initialized"};o!==void 0&&(n.value=o,i.setNumber(o));let a=n.value.trim();if(!a)return{isValid:!1,message:"No phone number provided"};let e=d(n,a,i);if(e.isValid)return e;try{if(i.isValidNumber&&i.isValidNumber()){let r=i.getNumber(),l=i.getSelectedCountryData(),s=l.dialCode;return{isValid:!0,message:"Valid number (standard validation)",fullNumber:r,countryCode:s,phoneNumber:r.substring(1+s.length),countryIso:l.iso2,countryName:l.name,validationMethod:"standard"}}}catch(r){console.warn("Standard validation failed:",r)}return e};function d(t,o,n){let i=n.getSelectedCountryData(),a=i.iso2?.toUpperCase(),e=o.replace(/\D/g,"");if(a==="US")return e.length===10&&/^[2-9]/.test(e)?{isValid:!0,message:"Valid US number",fullNumber:`+1${e}`,countryCode:"1",phoneNumber:e,countryIso:"us",countryName:"United States",formatInternational:`+1 ${e.slice(0,3)} ${e.slice(3,6)} ${e.slice(6)}`,formatNational:`(${e.slice(0,3)}) ${e.slice(3,6)}-${e.slice(6)}`,validationMethod:"custom"}:{isValid:!1,message:e.length!==10?`US numbers must be 10 digits (got ${e.length})`:"US numbers cannot start with 0 or 1"};if(a==="IN")return e.length===10&&/^[6-9]/.test(e)?{isValid:!0,message:"Valid Indian mobile number",fullNumber:`+91${e}`,countryCode:"91",phoneNumber:e,countryIso:"in",countryName:"India",formatInternational:`+91 ${e.slice(0,5)} ${e.slice(5)}`,formatNational:`${e.slice(0,5)} ${e.slice(5)}`,validationMethod:"custom"}:{isValid:!1,message:e.length!==10?`Indian mobile numbers must be 10 digits (got ${e.length})`:"Indian mobile numbers must start with 6, 7, 8, or 9"};if(a==="GB"){if(e.length===11&&e.startsWith("07"))return{isValid:!0,message:"Valid UK mobile number",fullNumber:`+44${e.slice(1)}`,countryCode:"44",phoneNumber:e.slice(1),countryIso:"gb",countryName:"United Kingdom",validationMethod:"custom"};if(e.length>=10&&e.length<=11&&/^0[12]/.test(e))return{isValid:!0,message:"Valid UK landline number",fullNumber:`+44${e.slice(1)}`,countryCode:"44",phoneNumber:e.slice(1),countryIso:"gb",countryName:"United Kingdom",validationMethod:"custom"}}return a==="AU"&&e.length===10&&e.startsWith("04")?{isValid:!0,message:"Valid Australian mobile number",fullNumber:`+61${e.slice(1)}`,countryCode:"61",phoneNumber:e.slice(1),countryIso:"au",countryName:"Australia",validationMethod:"custom"}:a==="CA"&&e.length===10&&/^[2-9]/.test(e)?{isValid:!0,message:"Valid Canadian number",fullNumber:`+1${e}`,countryCode:"1",phoneNumber:e,countryIso:"ca",countryName:"Canada",validationMethod:"custom"}:{isValid:!1,message:`No validation rules for ${i.name||"this country"}`}}function c(t){return typeof t=="string"?document.getElementById(t)||document.querySelector(t):t instanceof HTMLElement?t:document.querySelector("#phone-number")||document.querySelector("input[type='tel']")}window.validatePhoneAsync=async(t,o)=>{let n=0;for(;!window.intlTelInputUtils&&n<20;)await new Promise(i=>setTimeout(i,100)),n++;return window.validatePhone?window.validatePhone(t,o||""):{isValid:!1,message:"Validation not available"}},window.validatePhoneCustom=window.validatePhone,window.updateCountryCode=()=>{let t=document.querySelector("#phone-number"),o=document.querySelector("#country-code");if(!t||!o)return"91";try{if(t.iti){let n=t.iti.getSelectedCountryData();return o.value="+"+n.dialCode,n.dialCode}}catch(n){console.error("Error updating country code:",n)}return o.value="+91","91"},window.validatePhoneNumber=window.validatePhone,window.testPhoneNumber=window.validatePhone}})();})();
|
package/package.json
CHANGED