All files / util/field/mapToFields mapToFields.js

81.82% Statements 9/11
70% Branches 7/10
100% Functions 1/1
81.82% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 34 35 36 37 38 39 40  6x                           11x                     11x 11x 11x 10x   10x 10x         11x    
import Field from '../Field';
const RESERVED = [
    'get',
    'set',
    'serialize'
];
 
// eslint-disable-next-line
/**
 * Converts a DefineMap to an array of Field objects using the property definitions
 * property or the keys
 * @param  {Constructor | DefineMap} defineMap The extended map/constructor to parse
 * @return {Array<util/field/Field>} The array of fields
 */
export default function mapToFields (defineMap) {
    Iif (!defineMap) {
        
        // eslint-disable-next-line
        //!steal-remove-start
        // eslint-disable-next-line
        console.warn('map is undefined, so no fields will be generated');
        // eslint-disable-next-line
        //!steal-remove-end
        return [];
    }
    
    const props = (defineMap._define || defineMap.prototype._define).definitions;
    const fields = [];
    for (const key in props) {
        Eif (key.substr(0, 1) !== '_' && RESERVED.indexOf(key) < 0) {
            
            const fType = typeof props[key].type === 'function' ? props[key].type.name : props[key].type;
            fields.push(new Field(Object.assign({name: key}, props[key], {type: fType})));
 
        }
    }
 
    return fields;
}