in src/Habitat.js [61:126]
static parseProps(ele) {
// Default props with reference to the initiating node
const props = {
proxy: ele, // Pass in a reference to the original node
};
// Populate custom props from reading any ele attributes that start with 'data-prop-'
for (let i = 0; i < ele.attributes.length; i++) {
const a = ele.attributes[i];
if (a.name.indexOf(HABITAT_PROP) === 0) {
// Convert prop name from hyphens to camel case
const name = getNameFor(HABITAT_PROP, a.name);
let value = a.value || '';
// Parse booleans
if (typeof value === 'string' && value.toLowerCase() === 'false') { value = false; }
if (typeof value === 'string' && value.toLowerCase() === 'true') { value = true; }
// Parse json strings
if (typeof value === 'string' && value.length >= 2 &&
((value[0] === '{' && value[value.length - 1] === '}') ||
(value[0] === '[' && value[value.length - 1] === ']'))) {
value = JSON.parse(value);
}
// Parse nulls
if (typeof value === 'string' && value.toLowerCase() === 'null') {
value = null;
}
props[name] = value;
} else
// JSON type props
if (a.name === HABITAT_PROP_JSON) {
// Parse all of the props as json
Object.assign(props, JSON.parse(a.value));
} else
// Number type props
if (a.name.indexOf('data-n-prop-') === 0) {
// Convert prop name from hyphens to camel case
const name = getNameFor(HABITAT_PROP_NUMBER, a.name);
// Parse the value as a float as it handles both floats and whole int's
// Might want to look at configuring the radix somehow in the future
props[name] = parseFloat(a.value);
} else
// Reference type props
if (window && a.name.indexOf(HABITAT_PROP_REF) === 0) {
// Convert prop name from hyphens to camel case
const name = getNameFor(HABITAT_PROP_REF, a.name);
// Set the reference to the global object
props[name] = window[a.value];
}
}
return props;
}