dist/modules/to.js
function toMap(val, id, def) {
    if (is_1.isValue(id) && !is_1.isString(id)) {
        def = id;
        id = undefined;
    }
    if (is_1.isPlainObject(val))
        return val;
    if (!is_1.isValue(val) || (!is_1.isString(val) && !is_1.isArray(val)))
        return toDefault(null, def);
    // Default id key.
    id = id || '$id';
    var exp = /(\/|\.|,|;|\|)/g;
    var i = 0;
    var obj = {};
    if (is_1.isString(val)) {
        // simple string.
        if (!exp.test(val))
            return { 0: val };
        // split string into array, iterate.
        val = string_1.split(val);
        val.forEach(function (v, i) { return obj[i] = v; });
        return obj;
    }
    while (i < val.length) {
        if (is_1.isString(val[i])) {
            obj[i] = val[i];
        }
        else if (is_1.isPlainObject(val[i])) {
            var itm = Object.assign({}, val[i]);
            var key = itm[id] ? itm[id] : i;
            obj[key] = itm[id] ? object_1.del(itm, id) : itm;
        }
        i++;
    }
    return obj;
}
function toMap(val, id, def) {
    if (is_1.isValue(id) && !is_1.isString(id)) {
        def = id;
        id = undefined;
    }
    if (is_1.isPlainObject(val))
        return val;
    if (!is_1.isValue(val) || (!is_1.isString(val) && !is_1.isArray(val)))
        return toDefault(null, def);
    // Default id key.
    id = id || '$id';
    var exp = /(\/|\.|,|;|\|)/g;
    var i = 0;
    var obj = {};
    if (is_1.isString(val)) {
        // simple string.
        if (!exp.test(val))
            return { 0: val };
        // split string into array, iterate.
        val = string_1.split(val);
        val.forEach(function (v, i) { return obj[i] = v; });
        return obj;
    }
    while (i < val.length) {
        if (is_1.isString(val[i])) {
            obj[i] = val[i];
        }
        else if (is_1.isPlainObject(val[i])) {
            var itm = Object.assign({}, val[i]);
            var key = itm[id] ? itm[id] : i;
            obj[key] = itm[id] ? object_1.del(itm, id) : itm;
        }
        i++;
    }
    return obj;
}
function toMap ( val , id , def ) { if ( is_1 . isValue ( id ) && ! is_1 . isString ( id ) ) { def = id ; id = undefined ; } if ( is_1 . isPlainObject ( val ) ) return val ; if ( ! is_1 . isValue ( val ) || ( ! is_1 . isString ( val ) && ! is_1 . isArray ( val ) ) ) return toDefault ( null , def ) ; // Default id key. id = id || '$id' ; var exp = / (\/|\.|,|;|\|) / g ; var i = 0 ; var obj = { } ; if ( is_1 . isString ( val ) ) { // simple string. if ( ! exp . test ( val ) ) return { 0 : val } ; // split string into array, iterate. val = string_1 . split ( val ) ; val . forEach ( function ( v , i ) { return obj [ i ] = v ; } ) ; return obj ; } while ( i < val . length ) { if ( is_1 . isString ( val [ i ] ) ) { obj [ i ] = val [ i ] ; } else if ( is_1 . isPlainObject ( val [ i ] ) ) { var itm = Object . assign ( { } , val [ i ] ) ; var key = itm [ id ] ? itm [ id ] : i ; obj [ key ] = itm [ id ] ? object_1 . del ( itm , id ) : itm ; } i ++ ; } return obj ; }
To Map
Converts arrays, strings, to an object literal.

@example
Array: ['one', 'two', 'three'] Maps To: { 0: 'one', 1: 'two', 2: 'three' }
String: 'Star Wars' Maps To: { 0: 'Star Wars' }
String: 'Star Wars, Star Trek' Maps To { 0: 'Star Wars', 1: 'Star Trek' }
Array: [{ id: '123', name: 'Joe' }] Maps To: { 123: { name: 'Joe' }}
Array: [{ name: 'Joe' }, { name: 'Amy' }]
Maps To: { 0: { name: 'Joe' }, 2: { name: 'Amy' }}

NOTE: mixed content arrays not supported.

@param val the value to be mapped.
@param id optional id key when iterating array of objects.
@param def optional default value on null or error.
To Map Converts arrays strings to an object literal .