UNPKG

@adyen/kyc-components

Version:

This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.

67 lines (66 loc) 2.47 kB
try { let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack; n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "51198327-b8a2-43af-8ec4-cd269289d49a", e._sentryDebugIdIdentifier = "sentry-dbid-51198327-b8a2-43af-8ec4-cd269289d49a"); } catch (e) {} function mapApiScriptLocalizationToSchemaFields(localization) { const schema = {}; const scriptNameInSchema = localization.script.replace("-", ""); for (const [field, value] of Object.entries(localization.fields)) schema[scriptNameInSchema + field[0].toUpperCase() + field.slice(1)] = value; return schema; } /** * Given a schema and a script, takes the fields prefixed with that script and produces a {@link ScriptLocalization}. * * E.g. * ```ts * const schema = { * firstName: 'Alex', * lastName: 'Tompkins', * jaKanaFirstName: 'アレキサンダー', * jaKanaLastName: 'パトリック', * jaHaniFirstName: 'pretend this is hiragana', * jaHaniLastName: 'this too', * }; * * const localization = mapSchemaFieldsToApiScriptLocalization(schema, 'jaKana'); * console.log(localization); * // { * // script: 'ja-Kana', * // fields: { firstName: 'アレキサンダー', lastName: 'パトリック' }, * // }; * ``` */ function mapSchemaFieldsToApiScriptLocalization(data, script) { const fields = {}; for (const [schemaField, value] of Object.entries(data)) if (schemaField.startsWith(script)) { let fieldName = schemaField.replace(script, ""); fieldName = fieldName[0].toLowerCase() + fieldName.slice(1); fields[fieldName] = value; } return { script: `${script.slice(0, 2)}-${script.slice(2)}`, fields }; } //#endregion //#region src/components/Shared/forms/Address/localized/jp/mapAddressLocalizationToJpAddressSchema.ts var mapAddressLocalizationToJpAddressSchema = (localization) => { if (!localization) return {}; let jpAddress = {}; for (const { script, fields } of localization) { const schemaFieldsFromLocalization = mapApiScriptLocalizationToSchemaFields({ script, fields: { city: fields.city, address: fields.street } }); jpAddress = { ...jpAddress, ...schemaFieldsFromLocalization }; } return jpAddress; }; //#endregion export { mapApiScriptLocalizationToSchemaFields as n, mapSchemaFieldsToApiScriptLocalization as r, mapAddressLocalizationToJpAddressSchema as t };