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.

87 lines (86 loc) 4.09 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] = "b0749dfe-b235-483b-85b2-edb2eec8a0ac", e._sentryDebugIdIdentifier = "sentry-dbid-b0749dfe-b235-483b-85b2-edb2eec8a0ac"); } catch (e) {} import { useContext } from "preact/hooks"; import { createContext } from "preact"; //#region src/utils/entriesOf.ts var entriesOf = (object) => Object.entries(object); var valuesOf = (object) => Object.values(object); var keysOf = (object) => Object.keys(object); //#endregion //#region src/utils/genUtils.ts var keyIsInObject = (key, obj) => key in obj; /** * 'Destructures' properties from object - returns a new object only containing those properties that were asked for (including if those properties * have values that are falsy: null, undefined, false, ''). * * @param propertiesToKeep - property names to select: can be either 'regular' arguments (comma separated list) or an array * @returns - an object with a function 'from' that accepts a single argument - the object from which to choose properties. * This function returns a new object - a copy of the original but only including the desired properties * * @example const strippedObj = pick('cardType', 'securityCode').from(cardObject); * @example const strippedObj = pick(['cardType', 'securityCode']).from(cardObject); */ var pick = (...propertiesToKeep) => ({ from: (obj) => propertiesToKeep.map((k) => keyIsInObject(k, obj) ? { [k]: obj[k] } : {}).reduce((res, o) => ({ ...res, ...o }), {}) }); /** *'Destructures' properties from object, returning a new object containing all the original objects properties except those that were specifically rejected * * @param propertiesToDrop - property names to reject: can be either 'regular' arguments (comma separated list) or an array * @returns - an object with a function 'from' that accepts a single argument - the object from which to reject properties. * This function returns a new object - a copy of the original but excluding the selected properties * * @example const strippedObj = drop('permittedLengths', 'pattern', 'startingRules').from(cardObject); * @example const strippedObj = drop(['permittedLengths', 'pattern', 'startingRules']).from(cardObject); */ var drop = (...propertiesToDrop) => ({ from: (obj) => { return pick(...keysOf(obj).filter((k) => !propertiesToDrop.includes(k))).from(obj); } }); /** * Compares 2 arrays of (primitive) values to see if they are the same * re. https://sebhastian.com/javascript-compare-array/ */ var doArraysMatch = (arr1, arr2) => arr1.length === arr2.length && arr1.every((element) => arr2.includes(element)); /** * Recursively compare 2 objects */ var objectsDeepEqual = (x, y) => { if (x && y && typeof x === "object" && typeof y === "object") { if (Object.keys(x).length !== Object.keys(y).length) return false; return keysOf(x).every((key) => objectsDeepEqual(x[key], y[key])); } return x === y; }; function cloneObject(object) { return structuredClone(object); } function listify(array, { type = "conjunction", style = "long", stringify = (thing) => thing.toString() } = {}) { const stringified = array.map((item) => stringify(item)); return new Intl.ListFormat("en", { style, type }).format(stringified); } var noop = () => {}; var AnalyticsContext = createContext({ addEvent: noop, addJourneyEvent: noop, addTaskEvent: noop, addPageEvent: noop, addFieldEvent: noop, startEvent: noop, subscribe: noop, updateBaseTrackingPayload: noop, updateSharedEventProperties: noop, unsubscribe: noop }); //#endregion //#region src/context/AnalyticsContext/useAnalyticsContext.tsx var useAnalyticsContext = () => { return useContext(AnalyticsContext); }; //#endregion export { drop as a, objectsDeepEqual as c, keysOf as d, valuesOf as f, doArraysMatch as i, pick as l, AnalyticsContext as n, listify as o, cloneObject as r, noop as s, useAnalyticsContext as t, entriesOf as u };