(function(i,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(i=typeof globalThis<"u"?globalThis:i||self,m(i.NHTSA={}))})(this,function(i){"use strict";const m=({name:e,value:t,required:n,types:r,errorMode:c="error"})=>{if(v(e)!=="string")throw Error("'name', is required and must be of type string");let a="";const o=v(t),s=`error validating argument named "${e}",`,h=`received value: ${t} - of type: <${o}>`;if(r&&(v(r)!=="array"||!r.length))throw Error(`${s} 'types' must be an array of strings`);const u=r?`<${r.join(" | ")}>`:"";if(n&&!r?t||(a=`${s} is required, ${h}`):r&&!n?t!==void 0&&!r.includes(o)&&(a=`${s} must be of type(s) ${u}, ${h}`):n&&r&&(!t||!r.includes(o))&&(a=`${s} is required and must be of type(s) ${u}, ${h}`),a.length){if(c==="boolean")return!1;throw Error(a)}return!0},l=({args:e,mode:t="default"})=>{if(v(e)!=="array"||!e.length)throw Error('catchInvalidArguments requires "args" that must be an array of IArgToValidate objects');if(t==="default")e.forEach(n=>m(n));else if(t==="atLeast"&&!e.find(r=>!!r.value))throw Error(`must provide at least one of the following arguments: ${e.map(r=>r.name).join(", ")}`);return!0},q=e=>v(e)==="error",N=e=>{let t="an unknown error occurred.";return q(e)?(e.message||(e.message=t),e):(v(e)==="string"&&(t=e),Error(t))},d=async e=>Promise.reject(N(e)),v=e=>{const t=Object.prototype.toString.call(e).toLowerCase();return t.slice(8,t.length-1)},j={A:1,B:2,C:3,D:4,E:5,F:6,G:7,H:8,J:1,K:2,L:3,M:4,N:5,P:7,R:9,S:2,T:3,U:4,V:5,W:6,X:7,Y:8,Z:9},I=[8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2];function $(e){if(typeof e!="string"||e.length!=17)return!1;e=e.toUpperCase();const t=e.split(""),n=t[8];if(isNaN(parseInt(n))&&n!=="X")return!1;const r=n==="X"?10:parseInt(n);return t.map((a,o)=>{let s;isNaN(parseInt(a))?s=j[a]:s=parseInt(a);const h=I[o];return s*h}).reduce((a,o)=>a+o,0)%11===r}const A="https://vpic.nhtsa.dot.gov/api/vehicles",G="json",V=e=>(m({name:"params",value:e,required:!0,types:["object"]}),Object.entries(e).filter(([n,r])=>m({name:n,types:["string","number","boolean"],value:r,errorMode:"boolean"})).reduce((n,[r,c])=>(n[r]=encodeURIComponent(c),n),{})),p=(e={},t=!1)=>{m({name:"params",value:e,types:["object"]});const n=V({...e,format:G});return"?"+Object.entries(n).map(([r,c],a,o)=>c.length||t&&c===""?`${r}=${c}${a{let e;const t=u=>e=u,n=()=>e,r=()=>e="",c=u=>{if(typeof u=="string")return t(u),u;const{endpointName:y,allowEmptyParams:b=!1,includeQueryString:f=!0,path:U="",params:M,saveUrl:T=!0}=u;if(!y)throw Error("Endpoint name is required to create a VPIC URL string");const k=f?p(M,b):"",C=encodeURI(`${A}/${y}/${U}${k}`);return T&&t(C),C},a=u=>c({...u,saveUrl:!1}),o=u=>encodeURI(`DATA=${u?u+"&":""}format=${G}`),s=async(u,y={saveUrl:!0,method:"GET"})=>(u&&v(u)==="object"&&(u=c({...u,saveUrl:y.saveUrl})),u=v(u)==="string"?u:n(),l({args:[{name:"url",value:u,required:!0,types:["string"]},{name:"options",value:y,types:["object"]}]}),y.saveUrl&&(e=u),await fetch(u,y).then(async f=>{if(!f)throw Error("APi responded with an error, no response object returned");const U=f.headers.get("content-type"),M=`content-type: ${U}, responseStatus: ${f.status}, responseUrl: ${f.url}`;if(!f.ok)throw Error(`APi response not ok, got ${M}`);if(!["application/json","text/json"].some(ne=>U==null?void 0:U.includes(ne))||typeof f.json!="function")throw Error(`API response not in JSON format, got ${M}`);const C=await f.json();if(C)return C;throw Error(`VPIC API returned no data, got ${M}`)}).catch(f=>(f.message=`There was an error fetching API data: ${f.message}`,d(f))));return{setCachedUrl:t,getCachedUrl:n,clearCachedUrl:r,createCachedUrl:c,createUrl:a,createPostBody:o,get:s,post:async(u,y={saveUrl:!0})=>(u&&v(u)==="object"&&(u=c({...u,saveUrl:y.saveUrl,includeQueryString:!1})),u=v(u)==="string"?u:n(),l({args:[{name:"url",value:u,required:!0,types:["string"]},{name:"options",value:y,types:["object"]},{name:"options.body",value:y.body,types:["string"]}]}),await s(u,{...y,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o(y.body)}))}};i.DecodeVin=E,i.DecodeVinExtended=S,i.DecodeVinValues=D,i.DecodeVinValuesBatch=Y,i.DecodeVinValuesExtended=F,i.DecodeWMI=w,i.GetAllMakes=P,i.GetAllManufacturers=L,i.GetCanadianVehicleSpecifications=R,i.GetEquipmentPlantCodes=O,i.GetMakeForManufacturer=_,i.GetMakesForManufacturerAndYear=W,i.GetMakesForVehicleType=B,i.GetManufacturerDetails=H,i.GetModelsForMake=Q,i.GetModelsForMakeId=J,i.GetModelsForMakeIdYear=X,i.GetModelsForMakeYear=K,i.GetParts=Z,i.GetVehicleTypesForMake=z,i.GetVehicleTypesForMakeId=x,i.GetVehicleVariableList=ee,i.GetVehicleVariableValuesList=te,i.GetWMIsForManufacturer=re,i.createQueryString=p,i.encodeQueryStringParams=V,i.isValidVin=$,i.useNHTSA=g,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}); //# sourceMappingURL=nhtsa-api-wrapper.umd.cjs.map