From 3601f63604741a310ec12eb21bcbe3259bb960f7 Mon Sep 17 00:00:00 2001 From: Juk - a search builder Date: Sat, 21 Oct 2023 13:42:18 +0700 Subject: [PATCH] fix: default export to expose to browser --- dist/assets/index-a505a960.js | 1 - dist/assets/index-aadd4a5c.css | 1 - dist/index.html | 141 --------------------------------- dist/validator.es.js | 13 +-- dist/validator.umd.js | 2 +- global.d.ts | 5 ++ lib/validator.js | 9 +++ 7 files changed, 22 insertions(+), 150 deletions(-) delete mode 100644 dist/assets/index-a505a960.js delete mode 100644 dist/assets/index-aadd4a5c.css delete mode 100644 dist/index.html create mode 100644 global.d.ts diff --git a/dist/assets/index-a505a960.js b/dist/assets/index-a505a960.js deleted file mode 100644 index 8d72a7d..0000000 --- a/dist/assets/index-a505a960.js +++ /dev/null @@ -1 +0,0 @@ -(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))n(e);new MutationObserver(e=>{for(const t of e)if(t.type==="childList")for(const u of t.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&n(u)}).observe(document,{childList:!0,subtree:!0});function c(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?t.credentials="include":e.crossOrigin==="anonymous"?t.credentials="omit":t.credentials="same-origin",t}function n(e){if(e.ep)return;e.ep=!0;const t=c(e);fetch(e.href,t)}})();function p(r){if(!/^\d{13}$/.test(r))return!1;let s=0;for(let n=0;n<12;n++)s+=Number(r[n])*(13-n);return(11-s%11)%10===Number(r[12])}document.addEventListener("DOMContentLoaded",()=>{const r=document.getElementById("citizenid"),s=document.getElementById("button"),c=document.getElementById("errorMessage"),n=document.getElementById("successMessage"),e=IMask(r,{mask:"0-0000-00000-00-0"});r.addEventListener("input",t),r.addEventListener("keypress",u),s.addEventListener("click",a);function t(){const i=e.unmaskedValue,l=13,m=/^[0-9]\d*$/,d=i.length===l,f=m.test(i),o=p(i);s.disabled=!(d&&f&&o),r.setAttribute("aria-invalid",String(!o)),c.setAttribute("aria-hidden",String(o)),n.setAttribute("aria-hidden",String(!o)),c.style.display=d?o?"none":"block":"none",n.style.display=d&&o?"block":"none"}function u(i){if(i.code==="Enter")return i.preventDefault(),!1}function a(i){i.preventDefault(),i.stopImmediatePropagation(),window.alert("Your citizen ID submit value is: "+e.unmaskedValue)}}); diff --git a/dist/assets/index-aadd4a5c.css b/dist/assets/index-aadd4a5c.css deleted file mode 100644 index d7a5978..0000000 --- a/dist/assets/index-aadd4a5c.css +++ /dev/null @@ -1 +0,0 @@ -*{box-sizing:border-box;margin:0;padding:0;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}body{max-height:100vh;font-family:-apple-system,BlinkMacSystemFont,Arial,sans-serif;font-size:1rem;color:#333;background:#ece9e6;background:-webkit-linear-gradient(to right,#ece9e6,#ffffff);background:linear-gradient(to right,#ece9e6,#ffffff)}input,select,textarea{appearance:none;border:none;box-sizing:border-box;display:block;outline:none;width:100%;-webkit-appearance:none;-moz-appearance:none}h1,h2,p{text-align:center}section{margin:6rem 0;padding:16px}form{margin:16px auto;max-width:700px}button{position:relative;background-color:#fff;border:1px solid #e4e4e4;border-radius:5px;display:block;font-size:1rem;margin:0 auto;color:#333;padding:12px 40px;box-shadow:0 1px 2px #0000001a;-webkit-transition:all .6s cubic-bezier(.165,.84,.44,1);transition:all .6s cubic-bezier(.165,.84,.44,1)}button:after:not([disabled]){content:"";border-radius:5px;position:absolute;z-index:-1;top:0;left:0;width:100%;height:100%;box-shadow:0 5px 15px #0000004d;opacity:0;-webkit-transition:all .6s cubic-bezier(.165,.84,.44,1);transition:all .6s cubic-bezier(.165,.84,.44,1)}button:hover:after{opacity:1}button:hover:not([disabled]){border:1px solid #e4e4e4;cursor:pointer;-webkit-transform:scale(1.1,1.1);transform:scale(1.1)}button:disabled{color:silver;background-color:#eee;cursor:not-allowed}.label{display:block;margin-bottom:1em;text-align:center}.input{padding:10px;border:1px solid #e4e4e4;border-radius:4px;background-color:#fff;font-size:1.25rem;text-align:center;margin-bottom:1rem}.input:focus{border-color:silver}.input::placeholder{color:#ddd}.text{max-width:700px;margin:2rem auto;padding:1.5rem;line-height:0}.error{color:#b22222;background-color:#fa000012}.success{color:green;background-color:#00c80017}#errorMessage,#successMessage{display:none} diff --git a/dist/index.html b/dist/index.html deleted file mode 100644 index f7f3440..0000000 --- a/dist/index.html +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - Thai Citizen ID Input Validation - - - - - - - - - - - - -
-

Thai Citizen ID Validation with WCAG Standard

- -

ตรวจสอบความถูกต้องเลขบัตรประชาชน

- -
- - - -
- - -
- - diff --git a/dist/validator.es.js b/dist/validator.es.js index 5931c5b..048e170 100644 --- a/dist/validator.es.js +++ b/dist/validator.es.js @@ -1,11 +1,12 @@ -function c(t) { - if (!/^\d{13}$/.test(t)) +function t(u) { + if (!/^\d{13}$/.test(u)) return !1; - let u = 0; + let i = 0; for (let e = 0; e < 12; e++) - u += Number(t[e]) * (13 - e); - return (11 - u % 11) % 10 === Number(t[12]); + i += Number(u[e]) * (13 - e); + return (11 - i % 11) % 10 === Number(u[12]); } +typeof module < "u" && typeof module.exports < "u" ? (module.exports = t, exports.default = t, exports.isValidThaiID = t) : window.isValidThaiID = t; export { - c as default + t as default }; diff --git a/dist/validator.umd.js b/dist/validator.umd.js index f9fbfe0..01cbe33 100644 --- a/dist/validator.umd.js +++ b/dist/validator.umd.js @@ -1 +1 @@ -(function(t,e){typeof exports=="object"&&typeof module<"u"?module.exports=e():typeof define=="function"&&define.amd?define(e):(t=typeof globalThis<"u"?globalThis:t||self,t.validateThaiID=e())})(this,function(){"use strict";function t(e){if(!/^\d{13}$/.test(e))return!1;let i=0;for(let n=0;n<12;n++)i+=Number(e[n])*(13-n);return(11-i%11)%10===Number(e[12])}return t}); +(function(e,i){typeof exports=="object"&&typeof module<"u"?module.exports=i():typeof define=="function"&&define.amd?define(i):(e=typeof globalThis<"u"?globalThis:e||self,e.validateThaiID=i())})(this,function(){"use strict";function e(i){if(!/^\d{13}$/.test(i))return!1;let n=0;for(let t=0;t<12;t++)n+=Number(i[t])*(13-t);return(11-n%11)%10===Number(i[12])}return typeof module<"u"&&typeof module.exports<"u"?(module.exports=e,exports.default=e,exports.isValidThaiID=e):window.isValidThaiID=e,e}); diff --git a/global.d.ts b/global.d.ts new file mode 100644 index 0000000..dd9b16c --- /dev/null +++ b/global.d.ts @@ -0,0 +1,5 @@ +declare global { + interface Window { + isValidThaiID: (id: string) => boolean; + } +} diff --git a/lib/validator.js b/lib/validator.js index 5934eb8..1f7c5f6 100644 --- a/lib/validator.js +++ b/lib/validator.js @@ -25,4 +25,13 @@ function isValidThaiID(id) { } // Export the function. +if (typeof module !== "undefined" && typeof module.exports !== "undefined") { + module.exports = isValidThaiID; + exports.default = isValidThaiID; + exports.isValidThaiID = isValidThaiID; +} else { + // @ts-ignore + window.isValidThaiID = isValidThaiID; +} + export default isValidThaiID;