File size: 726 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
27
28
29
30
31
32
33
import { includes } from 'lodash';
import { getMimePrefix } from 'calypso/lib/media/utils';
import { Formats, MediaTypes } from './constants';

/**
 * Module variables
 */
const VALID_SHORTCODE_TYPES = [ 'closed', 'self-closing', 'single' ];

export default function ( node ) {
	if ( 'string' === typeof node ) {
		return Formats.STRING;
	}

	if ( 'object' === typeof node && 'string' === typeof node.nodeName ) {
		return Formats.DOM;
	}

	if ( node && node.tag && includes( VALID_SHORTCODE_TYPES, node.type ) ) {
		return Formats.SHORTCODE;
	}

	if ( node && node.type && includes( MediaTypes, node.type ) ) {
		return Formats.OBJECT;
	}

	if ( getMimePrefix( node ) ) {
		return Formats.API;
	}

	return Formats.UNKNOWN;
}