Adds SFRA 6.0
This commit is contained in:
@@ -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;
|
@@ -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;
|
Reference in New Issue
Block a user