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

@ikas/localized-address

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ikas/localized-address - npm Package Compare versions

Comparing version 1.0.0-beta.1 to 1.0.0-beta.2

4

build/models/address/index.d.ts

@@ -27,3 +27,3 @@ import { AddressFormItem, BillingFormItem, AddressForm, IkasAddressFormFields } from "./model";

private _customAddressFormSettings?;
private _isFormSubmit;
private _isErrorsVisible;
private _message;

@@ -36,3 +36,3 @@ private _localizedAddressModel;

get address(): AddressForm;
get isFormSubmit(): boolean;
get isErrorsVisible(): boolean;
get currentCountry(): string;

@@ -39,0 +39,0 @@ get addressFormat(): AddressFormItem[][];

@@ -1,1 +0,1 @@

import{__awaiter as e,__spreadArray as i,__generator as t}from"../../_virtual/_tslib.js";import{makeAutoObservable as r}from"mobx";import*as s from"lodash";import{AddressFormItem as n,BillingFormItem as o,LocalizedAddressModel as d}from"./model.js";var l=function(){function l(e){this._initialized=!1,this._isFormSubmit=!1,this._currentLocale=e.currentLocale||"tr",this._currentCountry=e.currentCountry||"TR",this._invisibleAddressFields=e.invisibleAddressFields,this._invisibleBillingFields=e.invisibleBillingFields,this._address={firstName:"",lastName:"",identityNumber:"",addressLine1:"",addressLine2:"",postalCode:"",country:"",state:"",city:"",district:"",phone:"",company:"",taxOffice:"",taxNumber:""},this._validateAddressForm=void 0===e.validateAddressForm||e.validateAddressForm,this._validateBillingForm=void 0===e.validateBillingForm||e.validateBillingForm,this._customAddressFormSettings=e.customAddressFormSettings||{},this._message=e.message,this._localizedAddressModel=new d({currentLocale:this._currentLocale}),this.init(),r(this)}return l.prototype.waitUntilInitialized=function(){var e=this;return new Promise((function(i){var t=setInterval((function(){e.initialized&&(clearInterval(t),i(null))}),100)}))},l.prototype.init=function(){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,this._localizedAddressModel.waitUntilInitialized()];case 1:return e.sent(),this._initialized=!0,[2]}}))}))},Object.defineProperty(l.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"address",{get:function(){return this._address},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isFormSubmit",{get:function(){return this._isFormSubmit},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"currentCountry",{get:function(){return this._currentCountry},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"addressFormat",{get:function(){return this._localizedAddressModel.getAddressFormat(this.currentCountry,this._invisibleAddressFields)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"addressFormatIgnoreCountry",{get:function(){return this._localizedAddressModel.getAddressFormatIgnoreCountry(this.currentCountry,this._invisibleAddressFields)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"billingFormat",{get:function(){return this._localizedAddressModel.getBillingFormat(this.currentCountry,this._invisibleBillingFields)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"fieldSettings",{get:function(){return this._localizedAddressModel.getFieldSettings(this.currentCountry,this._invisibleAddressFields,this._invisibleBillingFields,this._validateAddressForm,this._validateBillingForm,this._customAddressFormSettings)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"fieldLabels",{get:function(){return this._localizedAddressModel.getFieldLabels(this.currentCountry)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isFreeTextCity",{get:function(){return this._localizedAddressModel.isFreeTextCity(this.currentCountry)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isFreeTextDistrict",{get:function(){return this._localizedAddressModel.isFreeTextDistrict(this.currentCountry)},enumerable:!1,configurable:!0}),l.prototype.changeCountry=function(e){this._currentCountry=e},l.prototype.changeAddress=function(e){this._address=e},l.prototype.changeValidateAddressForm=function(e){this._validateAddressForm=e},l.prototype.changeValidateBillingForm=function(e){this._validateBillingForm=e},l.prototype.changeInvisibleAddressFields=function(e){this._invisibleAddressFields=e},l.prototype.changeInvisibleBillingFields=function(e){this._invisibleBillingFields=e},l.prototype.changeCustomAddressFormSettings=function(e){this._customAddressFormSettings=e},l.prototype.validate=function(){this._isFormSubmit=!0},l.prototype.resetValidate=function(){this._isFormSubmit=!1},l.prototype.getPostalAddressFormat=function(e){var t=e.countryCode,r=e.address,s=e.isBillingAddress,d=void 0!==s&&s,l=e.identityNumberFormat;if(t){var a=this._localizedAddressModel.getAddressFormat(t,[n.COUNTRY,n.PHONE]),u=this._localizedAddressModel.getBillingFormat(t),c=[],m=[];return i(i([],a,!0),[[n.COUNTRY]],!1).map((function(e){var i=e.map((function(e){return e===n.FIRSTNAME?r.firstName:e===n.LASTNAME?r.lastName:e===n.IDENTITY_NUMBER?l&&r.identityNumber?l(r.identityNumber||""):r.identityNumber:e===n.ADDRESS_LINE_1?r.addressLine1:e===n.ADDRESS_LINE_2?r.addressLine2:e===n.POSTAL_CODE?r.postalCode:e===n.COUNTRY?r.country:e===n.STATE?r.state:e===n.CITY?r.city:e===n.DISTRICT?r.district:null})).join(" ");i&&c.push(i)})),d&&u.map((function(e){var i=e.map((function(e){return e===o.COMPANY?r.company:e===o.TAX_NUMBER?r.taxNumber:e===o.TAX_OFFICE?r.taxOffice:null})).join(" ");i&&m.push(i)})),m.map((function(e,i){c.splice(1+i,0,e)})),c}},Object.defineProperty(l.prototype,"validationResult",{get:function(){var e=this,i=this._localizedAddressModel.getValidationResult(this.currentCountry,this.address,this._invisibleAddressFields,this._invisibleBillingFields,this._validateAddressForm,this._validateBillingForm,this._customAddressFormSettings);if(i)return s.mapValues(i,(function(i,t){return{hasError:e._isFormSubmit&&i.hasError,message:e._isFormSubmit&&i.hasError?t===n.PHONE?e._message.phoneRule?"string"==typeof e._message.phoneRule?e._message.phoneRule:e._message.phoneRule(t,e.address):"":i.isEmpty?"string"==typeof e._message.requiredRule?e._message.requiredRule:e._message.requiredRule(t,e.address):"string"==typeof e._message.invalidRule?e._message.invalidRule:e._message.invalidRule(t,e.address):""}}))},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isValidAddress",{get:function(){return this._localizedAddressModel.isValidAddress(this.currentCountry,this.address,this._invisibleAddressFields,this._invisibleBillingFields,this._validateAddressForm,this._validateBillingForm,this._customAddressFormSettings)},enumerable:!1,configurable:!0}),l}();export{l as LocalizedAddress};
import{__awaiter as e,__spreadArray as i,__generator as t}from"../../_virtual/_tslib.js";import{makeAutoObservable as s}from"mobx";import*as r from"lodash";import{AddressFormItem as n,BillingFormItem as d,LocalizedAddressModel as o}from"./model.js";var l=function(){function l(e){this._initialized=!1,this._isErrorsVisible=!1,this._currentLocale=e.currentLocale||"tr",this._currentCountry=e.currentCountry||"TR",this._invisibleAddressFields=e.invisibleAddressFields,this._invisibleBillingFields=e.invisibleBillingFields,this._address={firstName:"",lastName:"",identityNumber:"",addressLine1:"",addressLine2:"",postalCode:"",country:"",state:"",city:"",district:"",phone:"",company:"",taxOffice:"",taxNumber:""},this._validateAddressForm=void 0===e.validateAddressForm||e.validateAddressForm,this._validateBillingForm=void 0!==e.validateBillingForm&&e.validateBillingForm,this._customAddressFormSettings=e.customAddressFormSettings||{},this._message=e.message,this._localizedAddressModel=new o({currentLocale:this._currentLocale}),this.init(),s(this)}return l.prototype.waitUntilInitialized=function(){var e=this;return new Promise((function(i){var t=setInterval((function(){e.initialized&&(clearInterval(t),i(null))}),100)}))},l.prototype.init=function(){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,this._localizedAddressModel.waitUntilInitialized()];case 1:return e.sent(),this._initialized=!0,[2]}}))}))},Object.defineProperty(l.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"address",{get:function(){return this._address},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isErrorsVisible",{get:function(){return this._isErrorsVisible},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"currentCountry",{get:function(){return this._currentCountry},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"addressFormat",{get:function(){return this._localizedAddressModel.getAddressFormat(this.currentCountry,this._invisibleAddressFields)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"addressFormatIgnoreCountry",{get:function(){return this._localizedAddressModel.getAddressFormatIgnoreCountry(this.currentCountry,this._invisibleAddressFields)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"billingFormat",{get:function(){return this._localizedAddressModel.getBillingFormat(this.currentCountry,this._invisibleBillingFields)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"fieldSettings",{get:function(){return this._localizedAddressModel.getFieldSettings({country:this.currentCountry,invisibleAddressFields:this._invisibleAddressFields,invisibleBillingFields:this._invisibleBillingFields,validateAddressForm:this._validateAddressForm,validateBillingForm:this._validateBillingForm,customAddressFormSettings:this._customAddressFormSettings})},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"fieldLabels",{get:function(){return this._localizedAddressModel.getFieldLabels(this.currentCountry)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isFreeTextCity",{get:function(){return this._localizedAddressModel.isFreeTextCity(this.currentCountry)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isFreeTextDistrict",{get:function(){return this._localizedAddressModel.isFreeTextDistrict(this.currentCountry)},enumerable:!1,configurable:!0}),l.prototype.changeCountry=function(e){this._currentCountry=e},l.prototype.changeAddress=function(e){this._address=e},l.prototype.changeValidateAddressForm=function(e){this._validateAddressForm=e},l.prototype.changeValidateBillingForm=function(e){this._validateBillingForm=e},l.prototype.changeInvisibleAddressFields=function(e){this._invisibleAddressFields=e},l.prototype.changeInvisibleBillingFields=function(e){this._invisibleBillingFields=e},l.prototype.changeCustomAddressFormSettings=function(e){this._customAddressFormSettings=e},l.prototype.validate=function(){this._isErrorsVisible=!0},l.prototype.resetValidate=function(){this._isErrorsVisible=!1},l.prototype.getPostalAddressFormat=function(e){var t=e.countryCode,s=e.address,r=e.isBillingAddress,o=void 0!==r&&r,l=e.identityNumberFormat;if(t){var a=this._localizedAddressModel.getAddressFormat(t,[n.COUNTRY,n.PHONE]),u=this._localizedAddressModel.getBillingFormat(t),c=[],m=[];return i(i([],a,!0),[[n.COUNTRY]],!1).map((function(e){var i=e.map((function(e){return e===n.FIRSTNAME?s.firstName:e===n.LASTNAME?s.lastName:e===n.IDENTITY_NUMBER?l&&s.identityNumber?l(s.identityNumber||""):s.identityNumber:e===n.ADDRESS_LINE_1?s.addressLine1:e===n.ADDRESS_LINE_2?s.addressLine2:e===n.POSTAL_CODE?s.postalCode:e===n.COUNTRY?s.country:e===n.STATE?s.state:e===n.CITY?s.city:e===n.DISTRICT?s.district:null})).join(" ");i&&c.push(i)})),o&&u.map((function(e){var i=e.map((function(e){return e===d.COMPANY?s.company:e===d.TAX_NUMBER?s.taxNumber:e===d.TAX_OFFICE?s.taxOffice:null})).join(" ");i&&m.push(i)})),m.map((function(e,i){c.splice(1+i,0,e)})),c}},Object.defineProperty(l.prototype,"validationResult",{get:function(){var e=this,i=this._localizedAddressModel.getValidationResult({country:this.currentCountry,address:this.address,invisibleAddressFields:this._invisibleAddressFields,invisibleBillingFields:this._invisibleBillingFields,validateAddressForm:this._validateAddressForm,validateBillingForm:this._validateBillingForm,customAddressFormSettings:this._customAddressFormSettings});if(i)return r.mapValues(i,(function(i,t){return{hasError:e._isErrorsVisible&&i.hasError,message:e._isErrorsVisible&&i.hasError?t===n.PHONE?e._message.phoneRule?"string"==typeof e._message.phoneRule?e._message.phoneRule:e._message.phoneRule(t,e.address):"":i.isEmpty?"string"==typeof e._message.requiredRule?e._message.requiredRule:e._message.requiredRule(t,e.address):"string"==typeof e._message.invalidRule?e._message.invalidRule:e._message.invalidRule(t,e.address):""}}))},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isValidAddress",{get:function(){return this._localizedAddressModel.isValidAddress({country:this.currentCountry,address:this.address,invisibleAddressFields:this._invisibleAddressFields,invisibleBillingFields:this._invisibleBillingFields,validateAddressForm:this._validateAddressForm,validateBillingForm:this._validateBillingForm,customAddressFormSettings:this._customAddressFormSettings})},enumerable:!1,configurable:!0}),l}();export{l as LocalizedAddress};

@@ -14,3 +14,3 @@ export declare const COUNTRY_FORMS_LOCALES: string[];

waitUntilInitialized(): Promise<unknown>;
getFieldSettings(country: string, _invisibleAddressFields?: AddressFormItem[], _invisibleBillingFields?: BillingFormItem[], _validateAddressForm?: boolean, _validateBillingForm?: boolean, _customAddressFormSettings?: CustomAddressFormSettings): {
getFieldSettings(fieldSettingsParams: FieldSettingsParams): {
firstName: AddressFormField;

@@ -35,3 +35,3 @@ lastName: AddressFormField;

getAddressFormatIgnoreCountry(country: string, invisibleFields?: AddressFormItem[]): AddressFormItem[][];
getValidationResult(country: string, address: AddressForm, _invisibleAddressFields?: AddressFormItem[], _invisibleBillingFields?: BillingFormItem[], _validateAddressForm?: boolean, _validateBillingForm?: boolean, _customAddressFormSettings?: CustomAddressFormSettings): {
getValidationResult(validationResultParams: ValidationResultParams): {
firstName: ErrorType;

@@ -52,3 +52,3 @@ lastName: ErrorType;

} | undefined;
isValidAddress(country: string, address: AddressForm, _invisibleAddressFields?: AddressFormItem[], _invisibleBillingFields?: BillingFormItem[], _validateAddressForm?: boolean, _validateBillingForm?: boolean, _customAddressFormSettings?: CustomAddressFormSettings): boolean;
isValidAddress(validationResultParams: ValidationResultParams): boolean;
isValidField(value: string, fieldSettings: AddressFormField): ErrorType;

@@ -68,2 +68,13 @@ isFreeTextCity(country: string): boolean | undefined;

}
type FieldSettingsParams = {
country: string;
invisibleAddressFields?: AddressFormItem[];
invisibleBillingFields?: BillingFormItem[];
validateAddressForm?: boolean;
validateBillingForm?: boolean;
customAddressFormSettings?: CustomAddressFormSettings;
};
type ValidationResultParams = {
address: AddressForm;
} & FieldSettingsParams;
export type CustomAddressFormSettings = {

@@ -188,1 +199,2 @@ firstName?: AddressFormFieldSettings;

}
export {};

@@ -1,1 +0,1 @@

import{__awaiter as e,__spreadArray as t,__generator as i}from"../../_virtual/_tslib.js";import{makeAutoObservable as o}from"mobx";import*as r from"lodash";var d,n,l,s=["tr","de","en","it","es","fr","ru"],a=function(){function a(e){this._initialized=!1,this._currentLocale=e.currentLocale,this.init(),o(this)}return a.prototype.init=function(){return e(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.getAddressFormCountrySettings()];case 1:return e.sent(),[4,this.getAddressFormCountryLabels()];case 2:return e.sent(),this._initialized=!0,[2]}}))}))},Object.defineProperty(a.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),a.prototype.waitUntilInitialized=function(){var e=this;return new Promise((function(t){var i=setInterval((function(){e.initialized&&(clearInterval(i),t(null))}),100)}))},a.prototype.getFieldSettings=function(e,t,i,o,r,d){var s,a,u,v,c,g,m,p,h,y,f,F,b,N,L,A,x,S,C,T,E,_,O,I,R,V,q,D,B,w,M,P,Y,j,U,X,z,k,H=this.getCountrySettings(e);if(H){var W=H.fields,$=this.getAddressFormat(e),G=this.getBillingFormat(e);return{firstName:this.getAddressFormSetting(!0,null===(s=W.firstName)||void 0===s?void 0:s.type,null===(a=W.firstName)||void 0===a?void 0:a.regex,n.FIRSTNAME,$,t,o,null==d?void 0:d.firstName),lastName:this.getAddressFormSetting(!0,null===(u=W.lastName)||void 0===u?void 0:u.type,null===(v=W.lastName)||void 0===v?void 0:v.regex,n.LASTNAME,$,t,o,null==d?void 0:d.lastName),identityNumber:this.getAddressFormSetting(null===(c=W.identityNumber)||void 0===c?void 0:c.required,null===(g=W.identityNumber)||void 0===g?void 0:g.type,null===(m=W.identityNumber)||void 0===m?void 0:m.regex,n.IDENTITY_NUMBER,$,t,o,null==d?void 0:d.identityNumber),addressLine1:this.getAddressFormSetting(!0,null===(p=W.addressLine1)||void 0===p?void 0:p.type,null===(h=W.addressLine1)||void 0===h?void 0:h.regex,n.ADDRESS_LINE_1,$,t,o,null==d?void 0:d.addressLine1),addressLine2:this.getAddressFormSetting(null===(y=W.addressLine2)||void 0===y?void 0:y.required,null===(f=W.addressLine2)||void 0===f?void 0:f.type,null===(F=W.addressLine2)||void 0===F?void 0:F.regex,n.ADDRESS_LINE_2,$,t,o,null==d?void 0:d.addressLine2),postalCode:this.getAddressFormSetting(null===(b=W.postalCode)||void 0===b?void 0:b.required,null===(N=W.postalCode)||void 0===N?void 0:N.type,null===(L=W.postalCode)||void 0===L?void 0:L.regex,n.POSTAL_CODE,$,t,o,null==d?void 0:d.postalCode),country:this.getAddressFormSetting(!0,null===(A=W.country)||void 0===A?void 0:A.type,null===(x=W.country)||void 0===x?void 0:x.regex,n.COUNTRY,$,t,o,null==d?void 0:d.country),state:this.getAddressFormSetting(null===(S=W.state)||void 0===S?void 0:S.required,null===(C=W.state)||void 0===C?void 0:C.type,null===(T=W.state)||void 0===T?void 0:T.regex,n.STATE,$,t,o,null==d?void 0:d.state),city:this.getAddressFormSetting(null===(E=W.city)||void 0===E?void 0:E.required,null===(_=W.city)||void 0===_?void 0:_.type,null===(O=W.city)||void 0===O?void 0:O.regex,n.CITY,$,t,o,null==d?void 0:d.city),district:this.getAddressFormSetting(null===(I=W.district)||void 0===I?void 0:I.required,null===(R=W.district)||void 0===R?void 0:R.type,null===(V=W.district)||void 0===V?void 0:V.regex,n.DISTRICT,$,t,o,null==d?void 0:d.district),phone:this.getAddressFormSetting(null===(q=W.phone)||void 0===q?void 0:q.required,null===(D=W.phone)||void 0===D?void 0:D.type,(null===(B=W.phone)||void 0===B?void 0:B.regex)||/^\+?\d{10,}$/,n.PHONE,$,t,o,null==d?void 0:d.phone),company:this.getBillingFormSetting(null===(w=W.company)||void 0===w?void 0:w.required,null===(M=W.company)||void 0===M?void 0:M.type,null===(P=W.company)||void 0===P?void 0:P.regex,l.COMPANY,G,i,r,null==d?void 0:d.company),taxOffice:this.getBillingFormSetting(null===(Y=W.taxOffice)||void 0===Y?void 0:Y.required,null===(j=W.taxOffice)||void 0===j?void 0:j.type,null===(U=W.taxOffice)||void 0===U?void 0:U.regex,l.TAX_OFFICE,G,i,r,null==d?void 0:d.taxOffice),taxNumber:this.getBillingFormSetting(null===(X=W.taxNumber)||void 0===X?void 0:X.required,null===(z=W.taxNumber)||void 0===z?void 0:z.type,null===(k=W.taxNumber)||void 0===k?void 0:k.regex,l.TAX_NUMBER,G,i,r,null==d?void 0:d.taxNumber)}}},a.prototype.getFieldLabels=function(e){var t,i,o,r,d,n,l,s,a,u,v,c,g,m,p,h,y,f,F,b,N,L,A,x,S,C,T,E,_=this.getCountryLabels(e);if(_){var O=_.fields;return{firstName:this.getAddressFormLabel(null===(t=O.firstName)||void 0===t?void 0:t.label,null===(i=O.firstName)||void 0===i?void 0:i.placeholder),lastName:this.getAddressFormLabel(null===(o=O.lastName)||void 0===o?void 0:o.label,null===(r=O.lastName)||void 0===r?void 0:r.placeholder),identityNumber:this.getAddressFormLabel(null===(d=O.identityNumber)||void 0===d?void 0:d.label,null===(n=O.identityNumber)||void 0===n?void 0:n.placeholder),addressLine1:this.getAddressFormLabel(null===(l=O.addressLine1)||void 0===l?void 0:l.label,null===(s=O.addressLine1)||void 0===s?void 0:s.placeholder),addressLine2:this.getAddressFormLabel(null===(a=O.addressLine2)||void 0===a?void 0:a.label,null===(u=O.addressLine2)||void 0===u?void 0:u.placeholder),postalCode:this.getAddressFormLabel(null===(v=O.postalCode)||void 0===v?void 0:v.label,null===(c=O.postalCode)||void 0===c?void 0:c.placeholder),country:this.getAddressFormLabel(null===(g=O.country)||void 0===g?void 0:g.label,null===(m=O.country)||void 0===m?void 0:m.placeholder),state:this.getAddressFormLabel(null===(p=O.state)||void 0===p?void 0:p.label,null===(h=O.state)||void 0===h?void 0:h.placeholder),city:this.getAddressFormLabel(null===(y=O.city)||void 0===y?void 0:y.label,null===(f=O.city)||void 0===f?void 0:f.placeholder),district:this.getAddressFormLabel(null===(F=O.district)||void 0===F?void 0:F.label,null===(b=O.district)||void 0===b?void 0:b.placeholder),phone:this.getAddressFormLabel(null===(N=O.phone)||void 0===N?void 0:N.label,null===(L=O.phone)||void 0===L?void 0:L.placeholder),company:this.getAddressFormLabel(null===(A=O.company)||void 0===A?void 0:A.label,null===(x=O.company)||void 0===x?void 0:x.placeholder),taxOffice:this.getAddressFormLabel(null===(S=O.taxOffice)||void 0===S?void 0:S.label,null===(C=O.taxOffice)||void 0===C?void 0:C.placeholder),taxNumber:this.getAddressFormLabel(null===(T=O.taxNumber)||void 0===T?void 0:T.label,null===(E=O.taxNumber)||void 0===E?void 0:E.placeholder)}}},a.prototype.getAddressFormat=function(e,t){var i=this.getCountrySettings(e),o=this.getAddressFormatView(i.addressFormat),d=[];return o&&t&&t.length&&o.map((function(e){return r.difference(e,t)})).map((function(e){e.length>0&&d.push(e)})),t&&t.length?d:o},a.prototype.getBillingFormat=function(e,t){var i=this.getCountrySettings(e),o=this.getBillingFormatView(i.billingFormat),d=[];return o&&t&&t.length&&o.map((function(e){return r.difference(e,t)})).map((function(e){e.length>0&&d.push(e)})),t&&t.length?d:o},a.prototype.getAddressFormatIgnoreCountry=function(e,i){return this.getAddressFormat(e,t(t([],i||[],!0),[n.COUNTRY],!1))},a.prototype.getValidationResult=function(e,t,i,o,r,d,n){var l=this.getFieldSettings(e,i,o,r,d,n);if(l)return{firstName:this.isValidField(t.firstName||"",l.firstName),lastName:this.isValidField(t.lastName||"",l.lastName),identityNumber:this.isValidField(t.identityNumber||"",l.identityNumber),addressLine1:this.isValidField(t.addressLine1||"",l.addressLine1),addressLine2:this.isValidField(t.addressLine2||"",l.addressLine2),postalCode:this.isValidField(t.postalCode||"",l.postalCode),country:this.isValidField(t.country||"",l.country),state:this.isValidField(t.state||"",l.state),city:this.isValidField(t.city||"",l.city),district:this.isValidField(t.district||"",l.district),phone:this.isValidField(t.phone||"",l.phone),company:this.isValidField(t.company||"",l.company),taxOffice:this.isValidField(t.taxOffice||"",l.taxOffice),taxNumber:this.isValidField(t.taxNumber||"",l.taxNumber)}},a.prototype.isValidAddress=function(e,t,i,o,r,d,n){var l=this.getValidationResult(e,t,i,o,r,d,n);return!!l&&Object.values(l).every((function(e){return!e.hasError}))},a.prototype.isValidField=function(e,t){var i=!1,o=!1,r=t.required||!1,d=t.regex||!1;return r&&!d&&(o=!e),r&&d&&(o=!e,i=!this.validateByRegexString(e,t.regex)),!r&&d&&e&&(i=!this.validateByRegexString(e,t.regex)),{hasError:i||o,isInvalid:i,isEmpty:o}},a.prototype.isFreeTextCity=function(e){var t=this.getFieldSettings(e);return t&&t.city&&t.city.type===d.TEXT},a.prototype.isFreeTextDistrict=function(e){var t=this.getFieldSettings(e);return t&&t.district&&t.district.type===d.TEXT},a.prototype.getCountrySettings=function(e){return this._addressFormCountrySettings.countrySettings[e]},a.prototype.getCountryLabels=function(e){return this._addressFormCountryLabels.countryLabels[e]},a.prototype.getAddressFormatView=function(e){return this._addressFormCountrySettings.addressFormats[e]},a.prototype.getBillingFormatView=function(e){return this._addressFormCountrySettings.billingFormats[e]},a.prototype.getAddressFormCountrySettings=function(){return e(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return"https://cdn.myikas.com/sf/static/location/settings.json",[4,fetch("https://cdn.myikas.com/sf/static/location/settings.json")];case 1:return[4,t.sent().json()];case 2:return e=t.sent(),this._addressFormCountrySettings=e,[2]}}))}))},a.prototype.getAddressFormCountryLabels=function(){return e(this,void 0,void 0,(function(){var e,t,o=this;return i(this,(function(i){switch(i.label){case 0:return s.find((function(e){return e===o._currentLocale}))||(this._currentLocale="en"),e="https://cdn.myikas.com/sf/static/location/".concat(this._currentLocale,".json"),[4,fetch(e)];case 1:return[4,i.sent().json()];case 2:return t=i.sent(),this._addressFormCountryLabels=t,[2]}}))}))},a.prototype.getAddressFormSetting=function(e,t,i,o,r,d,n,l){var s=(d||[]).some((function(e){return e===o}))||!(r||[]).some((function(e){return e.some((function(e){return e===o}))}));return{required:!!n&&(!s&&(void 0===(null==l?void 0:l.required)?e||!1:null==l?void 0:l.required)),type:void 0===(null==l?void 0:l.type)?t:null==l?void 0:l.type,regex:n?s?void 0:void 0===(null==l?void 0:l.regex)?i:null==l?void 0:l.regex:void 0}},a.prototype.getBillingFormSetting=function(e,t,i,o,r,d,n,l){var s=(d||[]).some((function(e){return e===o}))||!(r||[]).some((function(e){return e.some((function(e){return e===o}))}));return{required:!!n&&(!s&&(void 0===(null==l?void 0:l.required)?e||!1:null==l?void 0:l.required)),type:void 0===(null==l?void 0:l.type)?t:null==l?void 0:l.type,regex:n?s?void 0:void 0===(null==l?void 0:l.regex)?i:null==l?void 0:l.regex:void 0}},a.prototype.getAddressFormLabel=function(e,t){return{label:e,placeholder:t}},a.prototype.validateByRegexString=function(e,t){return new RegExp(t).test(e)},a}();!function(e){e.TEXT="text",e.DROPDOWN="dropdown"}(d||(d={})),function(e){e.FIRSTNAME="firstName",e.LASTNAME="lastName",e.IDENTITY_NUMBER="identityNumber",e.ADDRESS_LINE_1="addressLine1",e.ADDRESS_LINE_2="addressLine2",e.POSTAL_CODE="postalCode",e.COUNTRY="country",e.STATE="state",e.CITY="city",e.DISTRICT="district",e.PHONE="phone"}(n||(n={})),function(e){e.COMPANY="company",e.TAX_OFFICE="taxOffice",e.TAX_NUMBER="taxNumber"}(l||(l={}));export{n as AddressFormItem,l as BillingFormItem,s as COUNTRY_FORMS_LOCALES,d as IkasAddressFormInputType,a as LocalizedAddressModel};
import{__awaiter as e,__spreadArray as i,__generator as t}from"../../_virtual/_tslib.js";import{makeAutoObservable as o}from"mobx";import*as d from"lodash";var r,n,s,l=["tr","de","en","it","es","fr","ru"],a=function(){function a(e){this._initialized=!1,this._currentLocale=e.currentLocale,this.init(),o(this)}return a.prototype.init=function(){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,this.getAddressFormCountrySettings()];case 1:return e.sent(),[4,this.getAddressFormCountryLabels()];case 2:return e.sent(),this._initialized=!0,[2]}}))}))},Object.defineProperty(a.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),a.prototype.waitUntilInitialized=function(){var e=this;return new Promise((function(i){var t=setInterval((function(){e.initialized&&(clearInterval(t),i(null))}),100)}))},a.prototype.getFieldSettings=function(e){var i,t,o,d,r,l,a,u,v,c,m,g,p,y,h,f,F,b,N,A,L,x,S,C,T,E,_,O,I,R,V,B,q,D,w,M,P,Y,j=e.country,U=e.invisibleAddressFields,X=void 0===U?[]:U,z=e.invisibleBillingFields,k=void 0===z?[]:z,H=e.validateAddressForm,W=void 0===H||H,$=e.validateBillingForm,G=void 0!==$&&$,J=e.customAddressFormSettings,K=void 0===J?{}:J,Q=this.getCountrySettings(j);if(Q){var Z=Q.fields,ee=this.getAddressFormat(j),ie=this.getBillingFormat(j);return{firstName:this.getAddressFormSetting(!0,null===(i=Z.firstName)||void 0===i?void 0:i.type,null===(t=Z.firstName)||void 0===t?void 0:t.regex,n.FIRSTNAME,ee,X,W,null==K?void 0:K.firstName),lastName:this.getAddressFormSetting(!0,null===(o=Z.lastName)||void 0===o?void 0:o.type,null===(d=Z.lastName)||void 0===d?void 0:d.regex,n.LASTNAME,ee,X,W,null==K?void 0:K.lastName),identityNumber:this.getAddressFormSetting(null===(r=Z.identityNumber)||void 0===r?void 0:r.required,null===(l=Z.identityNumber)||void 0===l?void 0:l.type,null===(a=Z.identityNumber)||void 0===a?void 0:a.regex,n.IDENTITY_NUMBER,ee,X,W,null==K?void 0:K.identityNumber),addressLine1:this.getAddressFormSetting(!0,null===(u=Z.addressLine1)||void 0===u?void 0:u.type,null===(v=Z.addressLine1)||void 0===v?void 0:v.regex,n.ADDRESS_LINE_1,ee,X,W,null==K?void 0:K.addressLine1),addressLine2:this.getAddressFormSetting(null===(c=Z.addressLine2)||void 0===c?void 0:c.required,null===(m=Z.addressLine2)||void 0===m?void 0:m.type,null===(g=Z.addressLine2)||void 0===g?void 0:g.regex,n.ADDRESS_LINE_2,ee,X,W,null==K?void 0:K.addressLine2),postalCode:this.getAddressFormSetting(null===(p=Z.postalCode)||void 0===p?void 0:p.required,null===(y=Z.postalCode)||void 0===y?void 0:y.type,null===(h=Z.postalCode)||void 0===h?void 0:h.regex,n.POSTAL_CODE,ee,X,W,null==K?void 0:K.postalCode),country:this.getAddressFormSetting(!0,null===(f=Z.country)||void 0===f?void 0:f.type,null===(F=Z.country)||void 0===F?void 0:F.regex,n.COUNTRY,ee,X,W,null==K?void 0:K.country),state:this.getAddressFormSetting(null===(b=Z.state)||void 0===b?void 0:b.required,null===(N=Z.state)||void 0===N?void 0:N.type,null===(A=Z.state)||void 0===A?void 0:A.regex,n.STATE,ee,X,W,null==K?void 0:K.state),city:this.getAddressFormSetting(null===(L=Z.city)||void 0===L?void 0:L.required,null===(x=Z.city)||void 0===x?void 0:x.type,null===(S=Z.city)||void 0===S?void 0:S.regex,n.CITY,ee,X,W,null==K?void 0:K.city),district:this.getAddressFormSetting(null===(C=Z.district)||void 0===C?void 0:C.required,null===(T=Z.district)||void 0===T?void 0:T.type,null===(E=Z.district)||void 0===E?void 0:E.regex,n.DISTRICT,ee,X,W,null==K?void 0:K.district),phone:this.getAddressFormSetting(null===(_=Z.phone)||void 0===_?void 0:_.required,null===(O=Z.phone)||void 0===O?void 0:O.type,(null===(I=Z.phone)||void 0===I?void 0:I.regex)||/^\+?\d{10,}$/,n.PHONE,ee,X,W,null==K?void 0:K.phone),company:this.getBillingFormSetting(null===(R=Z.company)||void 0===R?void 0:R.required,null===(V=Z.company)||void 0===V?void 0:V.type,null===(B=Z.company)||void 0===B?void 0:B.regex,s.COMPANY,ie,k,G,null==K?void 0:K.company),taxOffice:this.getBillingFormSetting(null===(q=Z.taxOffice)||void 0===q?void 0:q.required,null===(D=Z.taxOffice)||void 0===D?void 0:D.type,null===(w=Z.taxOffice)||void 0===w?void 0:w.regex,s.TAX_OFFICE,ie,k,G,null==K?void 0:K.taxOffice),taxNumber:this.getBillingFormSetting(null===(M=Z.taxNumber)||void 0===M?void 0:M.required,null===(P=Z.taxNumber)||void 0===P?void 0:P.type,null===(Y=Z.taxNumber)||void 0===Y?void 0:Y.regex,s.TAX_NUMBER,ie,k,G,null==K?void 0:K.taxNumber)}}},a.prototype.getFieldLabels=function(e){var i,t,o,d,r,n,s,l,a,u,v,c,m,g,p,y,h,f,F,b,N,A,L,x,S,C,T,E,_=this.getCountryLabels(e);if(_){var O=_.fields;return{firstName:this.getAddressFormLabel(null===(i=O.firstName)||void 0===i?void 0:i.label,null===(t=O.firstName)||void 0===t?void 0:t.placeholder),lastName:this.getAddressFormLabel(null===(o=O.lastName)||void 0===o?void 0:o.label,null===(d=O.lastName)||void 0===d?void 0:d.placeholder),identityNumber:this.getAddressFormLabel(null===(r=O.identityNumber)||void 0===r?void 0:r.label,null===(n=O.identityNumber)||void 0===n?void 0:n.placeholder),addressLine1:this.getAddressFormLabel(null===(s=O.addressLine1)||void 0===s?void 0:s.label,null===(l=O.addressLine1)||void 0===l?void 0:l.placeholder),addressLine2:this.getAddressFormLabel(null===(a=O.addressLine2)||void 0===a?void 0:a.label,null===(u=O.addressLine2)||void 0===u?void 0:u.placeholder),postalCode:this.getAddressFormLabel(null===(v=O.postalCode)||void 0===v?void 0:v.label,null===(c=O.postalCode)||void 0===c?void 0:c.placeholder),country:this.getAddressFormLabel(null===(m=O.country)||void 0===m?void 0:m.label,null===(g=O.country)||void 0===g?void 0:g.placeholder),state:this.getAddressFormLabel(null===(p=O.state)||void 0===p?void 0:p.label,null===(y=O.state)||void 0===y?void 0:y.placeholder),city:this.getAddressFormLabel(null===(h=O.city)||void 0===h?void 0:h.label,null===(f=O.city)||void 0===f?void 0:f.placeholder),district:this.getAddressFormLabel(null===(F=O.district)||void 0===F?void 0:F.label,null===(b=O.district)||void 0===b?void 0:b.placeholder),phone:this.getAddressFormLabel(null===(N=O.phone)||void 0===N?void 0:N.label,null===(A=O.phone)||void 0===A?void 0:A.placeholder),company:this.getAddressFormLabel(null===(L=O.company)||void 0===L?void 0:L.label,null===(x=O.company)||void 0===x?void 0:x.placeholder),taxOffice:this.getAddressFormLabel(null===(S=O.taxOffice)||void 0===S?void 0:S.label,null===(C=O.taxOffice)||void 0===C?void 0:C.placeholder),taxNumber:this.getAddressFormLabel(null===(T=O.taxNumber)||void 0===T?void 0:T.label,null===(E=O.taxNumber)||void 0===E?void 0:E.placeholder)}}},a.prototype.getAddressFormat=function(e,i){var t=this.getCountrySettings(e),o=this.getAddressFormatView(t.addressFormat),r=[];return o&&i&&i.length&&o.map((function(e){return d.difference(e,i)})).map((function(e){e.length>0&&r.push(e)})),i&&i.length?r:o},a.prototype.getBillingFormat=function(e,i){var t=this.getCountrySettings(e),o=this.getBillingFormatView(t.billingFormat),r=[];return o&&i&&i.length&&o.map((function(e){return d.difference(e,i)})).map((function(e){e.length>0&&r.push(e)})),i&&i.length?r:o},a.prototype.getAddressFormatIgnoreCountry=function(e,t){return this.getAddressFormat(e,i(i([],t||[],!0),[n.COUNTRY],!1))},a.prototype.getValidationResult=function(e){var i=e.address,t=e.country,o=e.invisibleAddressFields,d=e.invisibleBillingFields,r=e.validateAddressForm,n=e.validateBillingForm,s=e.customAddressFormSettings,l=this.getFieldSettings({country:t,invisibleAddressFields:o,invisibleBillingFields:d,validateAddressForm:r,validateBillingForm:n,customAddressFormSettings:s});if(l)return{firstName:this.isValidField(i.firstName||"",l.firstName),lastName:this.isValidField(i.lastName||"",l.lastName),identityNumber:this.isValidField(i.identityNumber||"",l.identityNumber),addressLine1:this.isValidField(i.addressLine1||"",l.addressLine1),addressLine2:this.isValidField(i.addressLine2||"",l.addressLine2),postalCode:this.isValidField(i.postalCode||"",l.postalCode),country:this.isValidField(i.country||"",l.country),state:this.isValidField(i.state||"",l.state),city:this.isValidField(i.city||"",l.city),district:this.isValidField(i.district||"",l.district),phone:this.isValidField(i.phone||"",l.phone),company:this.isValidField(i.company||"",l.company),taxOffice:this.isValidField(i.taxOffice||"",l.taxOffice),taxNumber:this.isValidField(i.taxNumber||"",l.taxNumber)}},a.prototype.isValidAddress=function(e){var i=this.getValidationResult(e);return!!i&&Object.values(i).every((function(e){return!e.hasError}))},a.prototype.isValidField=function(e,i){var t=!1,o=!1,d=i.required||!1,r=i.regex||!1;return d&&!r&&(o=!e),d&&r&&(o=!e,t=!this.validateByRegexString(e,i.regex)),!d&&r&&e&&(t=!this.validateByRegexString(e,i.regex)),{hasError:t||o,isInvalid:t,isEmpty:o}},a.prototype.isFreeTextCity=function(e){var i=this.getFieldSettings({country:e});return i&&i.city&&i.city.type===r.TEXT},a.prototype.isFreeTextDistrict=function(e){var i=this.getFieldSettings({country:e});return i&&i.district&&i.district.type===r.TEXT},a.prototype.getCountrySettings=function(e){return this._addressFormCountrySettings.countrySettings[e]},a.prototype.getCountryLabels=function(e){return this._addressFormCountryLabels.countryLabels[e]},a.prototype.getAddressFormatView=function(e){return this._addressFormCountrySettings.addressFormats[e]},a.prototype.getBillingFormatView=function(e){return this._addressFormCountrySettings.billingFormats[e]},a.prototype.getAddressFormCountrySettings=function(){return e(this,void 0,void 0,(function(){var e;return t(this,(function(i){switch(i.label){case 0:return"https://cdn.myikas.com/sf/static/location/settings.json",[4,fetch("https://cdn.myikas.com/sf/static/location/settings.json")];case 1:return[4,i.sent().json()];case 2:return e=i.sent(),this._addressFormCountrySettings=e,[2]}}))}))},a.prototype.getAddressFormCountryLabels=function(){return e(this,void 0,void 0,(function(){var e,i,o=this;return t(this,(function(t){switch(t.label){case 0:return l.find((function(e){return e===o._currentLocale}))||(this._currentLocale="en"),e="https://cdn.myikas.com/sf/static/location/".concat(this._currentLocale,".json"),[4,fetch(e)];case 1:return[4,t.sent().json()];case 2:return i=t.sent(),this._addressFormCountryLabels=i,[2]}}))}))},a.prototype.getAddressFormSetting=function(e,i,t,o,d,r,n,s){var l=(r||[]).some((function(e){return e===o}))||!(d||[]).some((function(e){return e.some((function(e){return e===o}))}));return{required:!!n&&(!l&&(void 0===(null==s?void 0:s.required)?e||!1:null==s?void 0:s.required)),type:void 0===(null==s?void 0:s.type)?i:null==s?void 0:s.type,regex:n?l?void 0:void 0===(null==s?void 0:s.regex)?t:null==s?void 0:s.regex:void 0}},a.prototype.getBillingFormSetting=function(e,i,t,o,d,r,n,s){var l=(r||[]).some((function(e){return e===o}))||!(d||[]).some((function(e){return e.some((function(e){return e===o}))}));return{required:!!n&&(!l&&(void 0===(null==s?void 0:s.required)?e||!1:null==s?void 0:s.required)),type:void 0===(null==s?void 0:s.type)?i:null==s?void 0:s.type,regex:n?l?void 0:void 0===(null==s?void 0:s.regex)?t:null==s?void 0:s.regex:void 0}},a.prototype.getAddressFormLabel=function(e,i){return{label:e,placeholder:i}},a.prototype.validateByRegexString=function(e,i){return new RegExp(i).test(e)},a}();!function(e){e.TEXT="text",e.DROPDOWN="dropdown"}(r||(r={})),function(e){e.FIRSTNAME="firstName",e.LASTNAME="lastName",e.IDENTITY_NUMBER="identityNumber",e.ADDRESS_LINE_1="addressLine1",e.ADDRESS_LINE_2="addressLine2",e.POSTAL_CODE="postalCode",e.COUNTRY="country",e.STATE="state",e.CITY="city",e.DISTRICT="district",e.PHONE="phone"}(n||(n={})),function(e){e.COMPANY="company",e.TAX_OFFICE="taxOffice",e.TAX_NUMBER="taxNumber"}(s||(s={}));export{n as AddressFormItem,s as BillingFormItem,l as COUNTRY_FORMS_LOCALES,r as IkasAddressFormInputType,a as LocalizedAddressModel};
{
"name": "@ikas/localized-address",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"author": "ikas",

@@ -5,0 +5,0 @@ "license": "ISC",

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