<commit_before>'use strict';

var objects = require('./objects.js');


function type(val) {
    // does an end-around on primitives by converting them to objects
    // tries to find subtype for objects
    if ( val === undefined ) {
        return {'type': 'undefined', 'prototypes': [],
                'subtype': null, 'isPrimitive': true};
    } else if ( val === null ) {
        return {'type': 'null', 'prototypes': [],
                'subtype': null, 'isPrimitive': true};
    }
    var ps = objects.prototypes(val);
    return {
        'type': 'object', 
        'prototypes': ps, 
        'subtype': (ps.length > 0) ? ps[0].constructor.name : null,
        'isPrimitive': !(val instanceof Object)
    };
}

function isArray(val) {
    return val instanceof Array;
}

function isArguments(val) {
    return Object.prototype.toString.call(obj) === '[object Arguments]';
}


module.exports = {
    'type':  type,
    'isArray': isArray,
    'isArguments': isArguments
};
<commit_msg>simplify interface into type inspection by getting rid of magic<commit_after>'use strict';

var objects = require('./objects.js');


function isProto(obj, possible_prototype) {
    return possible_prototype.isPrototypeOf(obj);
}

function getPrototypes(obj) {
    var protos = [],
        parent;
    while ( true ) { // seems to eventually get to null
        parent = Object.getPrototypeOf(parent);
        if ( parent === null ) {
            break;
        }
        protos.push(parent);
    }
    return protos;
}

function getTypeData(val) {
    if ( val instanceof Object ) {
        var protos = getPrototypes(val);
        return {
            'type'       : 'object', // that's right -- even for functions
            'prototypes' : protos,
            'subtype'    : (protos.length > 0) ? protos[0].constructor.name : null,
            'isPrimitive': false,
            'toString'   : Object.prototype.toString.call(val)
        };
    }
    // else: it's a primitive
    return {
        'type'       : ( val === null ) ? "null" : typeof val,
        'prototypes' : null,
        'subtype'    : null,
        'isPrimitive': true,
        'toString'   : Object.prototype.toString.call(val)
    };
}


module.exports = {
    'getTypeData':  getTypeData,
    'getPrototypes': getPrototypes,
    'isProto': isProto
};
{'fraction_non_alphanumeric': 0.14113077255071213, 'fraction_numerical': 0.0017263703064307294, 'mean_word_length': 2.316165951359084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3162489', 'n_tokens_mistral': 702, 'n_tokens_neox': 687, 'n_words': 177}