File size: 791 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import { domForHtml } from 'calypso/lib/post-normalizer/utils';
export const getStateKey = ( siteId, postId ) => `${ siteId }-${ postId }`;
export const deconstructStateKey = ( key ) => {
const [ siteId, postId ] = key.split( '-' );
return { siteId: +siteId, postId: +postId };
};
export const getErrorKey = ( siteId, commentId ) => `${ siteId }-${ commentId }`;
export const commentHasLink = ( commentContent, apiSuppliedValue ) => {
// In case API provides value for has_link, skip parsing and return it instead.
if ( typeof apiSuppliedValue !== 'undefined' ) {
return apiSuppliedValue;
}
try {
return !! domForHtml( commentContent ).getElementsByTagName( 'a' ).length;
} catch ( e ) {
return false;
}
};
export const getCommentDate = ( { date } ) => new Date( date );
|