2018-11-29 15:57:49 +00:00
|
|
|
/** @format */
|
2018-12-04 03:01:23 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { isObject } from 'lodash';
|
2018-11-29 15:57:49 +00:00
|
|
|
|
|
|
|
export function getResourceName( prefix, identifier ) {
|
2018-12-04 03:01:23 +00:00
|
|
|
const keyList = [];
|
|
|
|
Object.keys( identifier ).forEach( key => {
|
|
|
|
keyList.push( key );
|
|
|
|
|
|
|
|
// whitelist nested object keys
|
|
|
|
if ( isObject( identifier[ key ] ) ) {
|
|
|
|
Array.prototype.push.apply( keyList, Object.keys( identifier[ key ] ) );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
const identifierString = JSON.stringify( identifier, keyList.sort() );
|
2018-11-29 15:57:49 +00:00
|
|
|
return `${ prefix }:${ identifierString }`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isResourcePrefix( resourceName, prefix ) {
|
|
|
|
const resourcePrefix = resourceName.substring( 0, resourceName.indexOf( ':' ) );
|
|
|
|
return resourcePrefix === prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getResourceIdentifier( resourceName ) {
|
|
|
|
const identifierString = resourceName.substring( resourceName.indexOf( ':' ) + 1 );
|
|
|
|
return JSON.parse( identifierString );
|
|
|
|
}
|