Adds SFRA 6.0

This commit is contained in:
Isaac Vallee
2021-12-21 10:57:31 -08:00
parent d04eb5dd16
commit 823c7608c3
1257 changed files with 137087 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
var _ = require('lodash');
function jsonUtils() {}
/**
* Duplicate the source object and delete specified key(s) from the new object.
*
* @param {JSON} srcObj
* @param {String[]} keys
* @returns {Object} - A new object with key(s) removed
*/
jsonUtils.deleteProperties = function (srcObj, keys) {
var newObj = _.cloneDeep(srcObj);
jsonUtils.removeProps(newObj, keys);
return newObj;
};
/**
* Delete specified key(s) from the object.
*
* @param {JSON} obj
* @param {String[]} keys
*/
jsonUtils.removeProps = function (obj, keys) {
if (obj instanceof Array && obj[0] !== null) {
obj.forEach(function (item) {
jsonUtils.removeProps(item, keys);
});
} else if (typeof obj === 'object') {
Object.getOwnPropertyNames(obj).forEach(function (key) {
if (keys.indexOf(key) !== -1) {
delete obj[key]; // eslint-disable-line no-param-reassign
} else if (obj[key] != null) {
jsonUtils.removeProps(obj[key], keys);
}
});
}
};
/**
* Return pretty-print JSON string
*
* @param {JSON} obj
*/
jsonUtils.toPrettyString = function (obj) {
var prettyString;
if (obj) {
prettyString = JSON.stringify(obj, null, '\t');
}
return prettyString;
};
module.exports = jsonUtils;

View File

@@ -0,0 +1,18 @@
function urlUtils() {}
/**
* Strips auth basic authentication parameters - if set - and returns the url
*
* @param {String} url - Url string
* @returns {String}
*/
urlUtils.stripBasicAuth = function (url) {
var sfIndex = url.indexOf('storefront');
var atIndex = url.indexOf('@');
if (sfIndex > -1 && atIndex > -1) {
return url.slice(0, sfIndex) + url.slice(atIndex + 1, url.length);
}
return url;
};
module.exports = urlUtils;