Module: xblocks-core/dom/attrs

Members

(inner, constant) attrsBoolean :Array.<string>

A set of boolean attributes.

Type:
  • Array.<string>
Source:

Methods

(static) get(element, attrs) → {Object}

To obtain the specified attributes.

Parameters:
Name Type Description
element HTMLElement
attrs Object

the set of derived attributes (+default values)

Source:
Returns:
Type
Object
Example
import { get } from 'xblocks-core/dom/attrs';

var node = document.createElement('div');
node.setAttribute('attr1', '');
node.setAttribute('attr2', 'test1');
node.setAttribute('attr3', 'test2');

get(node, {
    'attr1': false,
    'attr2': undefined
});
// { 'attr1': true, 'attr2': 'test1' }

(static) toObject(element) → {Object}

Retrieve object attributes.

Parameters:
Name Type Description
element HTMLElement
Source:
Returns:
Type
Object
Example
import { toObject } from 'xblocks-core/dom/attrs';

var node = document.createElement('div');
node.setAttribute('attr1', '');
node.setAttribute('attr2', 'test');

toObject(node);
// { 'attr1': '', 'attr2': 'test' }

(static) typeConversion(props, propTypesopt) → {Object}

Collective conversion of attribute types.

Parameters:
Name Type Attributes Description
props Object

the set of attributes

propTypes Object <optional>

the set of attribute types

Source:
Returns:
Type
Object
Example
import { typeConversion } from 'xblocks-core/dom/attrs';

typeConversion({
    'attr1': '123',
    'attr2': ''
}, {
    'attr1': PropTypes.number,
    'attr2': PropTypes.bool
});
// { 'attr1': 123, 'attr2': true }

(static) valueConversion(prop, value, typeopt) → {*}

Convert the attribute value to the specified type.

Parameters:
Name Type Attributes Description
prop string

attribute name

value *

attribute value

type function <optional>

attribute type

Source:
Returns:
Type
*
Example
import { valueConversion } from 'xblocks-core/dom/attrs';

valueConversion('attr1', 'true');
// true
valueConversion('attr1', 'true', PropTypes.string);
// 'true'
valueConversion('attr1', '123', PropTypes.number);
// 123