Line 1: |
Line 1: |
| // License: GPL | | // License: GPL |
| // | | // |
− |
| |
− | console.log('Wbprocessor loading');
| |
| function wbContainer( universe, location ) { | | function wbContainer( universe, location ) { |
| | | |
| this.main = interjson( get_Y_from_X( universe, location )); | | this.main = interjson( get_Y_from_X( universe, location )); |
| + | var container = this; |
| | | |
− | this.checkentity = function ( rel_id_list, inner_location, property ) { | + | this.checkentity = function ( rel_id_list, paths ) { |
− | var return_obj = {}; | + | var return_obj = [], |
− | Object.keys(rel_id_list).forEach( function(item){ | + | temporary_obj = [], |
− | if ( check( this.main, rel_id_list[item][0] ) != undefined ) { | + | baseRelation; |
− | var primary_part = get_Y_from_X( this.main, rel_id_list[item][0] ); | + | if ( Object.keys(rel_id_list).length > 0 ) { |
− | if ( check_Y_in_X ( primary_part, (property) ? inner_location + '.' + property : inner_location ) ) { | + | Object.keys(rel_id_list).forEach(item){ |
− | return_obj[item] = rel_id_list[item];
| + | temporary_obj = []; |
| + | baseRelation = checkdive( container.main, rel_id_list[item][0] ); |
| + | rise( temporary_obj, depthdive( baseRelation, paths )); |
| + | if ( Object.keys(temporary_obj).length > 0 ) { |
| + | Object.keys(temporary_obj).forEach(hit){ |
| + | if ( temporary_obj[hit] == rel_id_list[item][1] ) { |
| + | return_obj.push(rel_id_list[item]); |
| + | } |
| + | } |
| + | } else if ( temporary_obj == rel_id_list[item][1] ) { |
| + | return_obj.push(rel_id_list[item]); |
| } | | } |
| } | | } |
− | }); | + | } |
| return return_obj; | | return return_obj; |
| } | | } |
Line 26: |
Line 35: |
| // dive selects matrix.a.b.c.d from the array called matrix and 'a.b.c.d' as string | | // dive selects matrix.a.b.c.d from the array called matrix and 'a.b.c.d' as string |
| // if a.b.c.d does not exists, it returns the substructure until the substructure exists, if d does not exist, it returns matrix.a.b.c e.g. | | // if a.b.c.d does not exists, it returns the substructure until the substructure exists, if d does not exist, it returns matrix.a.b.c e.g. |
| + | |
| function dive(array, read){ | | function dive(array, read){ |
| return read.split('.').reduce(indexinterpolate, array); | | return read.split('.').reduce(indexinterpolate, array); |
| } | | } |
| + | |
| function check(array, read){ | | function check(array, read){ |
− | return read.split('.').reduce(indexcheck, array); | + | if ( array != undefined ) { |
| + | return read.split('.').reduce(indexcheck, array); |
| + | } |
| + | } |
| + | |
| + | function checkdive(array, read){ |
| + | if ( check(array, read) != undefined) { |
| + | return dive(array, read); |
| + | } else if ( Object.keys(array).length > 0 ) { |
| + | return complexcheck( array, read ); |
| + | } |
| } | | } |
− | function interjson( obj ) { | + | |
− | try { | + | function complexcheck(array, read){ |
− | return JSON.parse( obj )
| + | var ret_obj; |
− | } catch (e) {
| + | Object.keys(array).forEach(item){ |
− | // if not JSON, do silly things
| + | rise( ret_obj, checkdive(array[item], read)) ; |
− | console.log('not a json ¯\_(ツ)_/¯');
| + | } |
− | };
| + | return ret_obj; |
− | } | + | } |
− | // Get Y from X whether its a single object or an arrayish object
| + | |
− | function get_Y_from_X( obj, B ){ | + | function depthdive(array, read){ |
− | if ( check(obj, B) !== undefined ) { | + | var ret_obj, |
− | console.log( "entity is defined" ) | + | temp_obj = array; |
− | return dive(obj, B);
| + | if ( Object.keys(read).length > 0 ) { |
− | } else { | + | Object.keys(read).forEach(path) { |
− | for (var i = 0; i < obj.length; i++ ){
| + | temp_obj = checkdive(temp_obj, path); |
− | if ( check(obj[i], B) !== undefined ) {
| |
− | console.log( "entity is defined within index " + i );
| |
− | return dive(obj[i], B);
| |
− | };
| |
− | Object.keys(obj).forEach( function(item) {
| |
− | if ( check(obj[item], B) !== undefined ) {
| |
− | console.log( "entity is defined within associative element" + item )
| |
− | return dive(obj[item], B);
| |
− | };
| |
− | });
| |
| } | | } |
| + | rise(ret_obj, temp_obj); |
| + | return ret_obj; |
| + | } else { |
| + | return checkdive(array, read); |
| } | | } |
| } | | } |
| | | |
− | // Check if Y can be found in X whether X is a single value, an indexed array, or an associative array
| + | function rise(array, to_push){ |
− | function check_Y_in_X(obj, to_check){ | + | if ( to_push != undefined) { |
− | if (obj === to_check) { | + | if ( Object.keys(to_push).length > 0 ){ |
− | console.log( "entity is confirmed"); | + | Object.keys(to_push).forEach(item){ |
− | return true;
| + | if ( array != undefined ) { |
− | };
| + | array.push(to_push[item]); |
− | for (var i = 0; i < obj.length; i++ ){
| + | } |
− | if (obj[i] === to_check) {
| + | } |
− | console.log( "entity is confirmed within index " + i );
| + | } else { |
− | return true; | + | array.push(to_push); |
− | }; | + | } |
| } | | } |
− | Object.keys(obj).forEach( function(item) {
| |
− | if (obj[item] === to_check) {
| |
− | console.log( "entity is confirmed within associative element" + item )
| |
− | return true;
| |
− | };
| |
− | });
| |
− | return false;
| |
| } | | } |
| + | |
| + | function interjson( obj ) { |
| + | try { |
| + | return JSON.parse( obj ) |
| + | } catch (e) { |
| + | // if not JSON, do silly things |
| + | console.log('not a json ¯\_(ツ)_/¯'); |
| + | }; |
| + | } |
| + | |
| } | | } |