@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.
81 lines (80 loc) • 2.73 kB
JavaScript
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] = "ffdd995a-7104-4d0a-bc33-35a8a818d69c", e._sentryDebugIdIdentifier = "sentry-dbid-ffdd995a-7104-4d0a-bc33-35a8a818d69c");
} catch (e) {}
function getProp(object, path) {
return path.split(".").reduce((xs, x) => xs && xs[x] !== void 0 ? xs[x] : void 0, object);
}
/**
* assigns the value provided to the key in targetObject.
* @param path - keys separated by a delimiter.
* @param obj - object to which value will be assigned
* @param val - value to be assigned
*
* @example
* ```
* targetObject = {};
* assignToProp('x.y.z', targetObject, 'foo');
* console.log(targetObject); => {x:{y:{z:'foo'}}}
* ```
*/
function assignToProp(path, obj, val) {
const splitPath = path.split(".");
const pathDepth = splitPath.length;
let currentObj = obj;
splitPath.forEach((key, index) => {
if (index === pathDepth - 1) currentObj[key] = val;
else {
if (!currentObj[key]) currentObj[key] = {};
currentObj = currentObj[key];
}
});
}
function deleteProp(path, obj) {
const splitPath = path.split(".");
const pathDepth = splitPath.length;
let currentObj = obj;
splitPath.forEach((key, index) => {
if (currentObj[key] === void 0) throw Error(`The given path does not exist on the object: ${key} (${path})`);
if (index === pathDepth - 1) delete currentObj[key];
else currentObj = currentObj[key];
});
}
/**
* @param obj - source object
* @param mapping - key mappings from source to target object structure
* @example
* ```
* let mapping={ 'a.b': 'x.y.z'}
* let obj = {x: {y: {z: 'foo'}}}
* formatObject(obj, mapping) => {a:{b:'foo'}}
* ```
*/
var formatObject = (obj, mapping) => {
const formattedObj = {};
Object.entries(mapping).forEach(([targetKey, sourceKey]) => {
const value = getProp(obj, sourceKey);
if (value !== void 0) assignToProp(targetKey, formattedObj, value);
});
return formattedObj;
};
/**
* @param obj - source object
* @param mapping - key mappings from target to source object structure
* @example
* ```
* let mapping={ 'a.b': 'x.y.z'}
* let obj = {x: {y: {z: 'foo'}}}
* formatObject(obj, mapping) => {a:{b:'foo'}}
* ```
*/
var mapWith = (obj, mapping) => {
const formattedObj = {};
for (const [sourceKey, targetKey] of Object.entries(mapping)) {
const value = getProp(obj, sourceKey);
if (value !== void 0) assignToProp(targetKey, formattedObj, value);
}
return formattedObj;
};
//#endregion
export { mapWith as a, getProp as i, deleteProp as n, formatObject as r, assignToProp as t };