<commit_before>const {extname} = require('path')

let sgf = require('./sgf')
let ngf = require('./ngf')
let gib = require('./gib')

let modules = {sgf, ngf, gib}

exports = module.exports = modules

let extensions = Object.keys(modules).map(key => modules[key].meta)
let combinedExtensions = extensions.map(x => x.extensions)
    .reduce((acc, x) => [...acc, ...x], [])

exports.meta = [
    {name: 'Game Records', extensions: combinedExtensions},
    ...extensions
]

exports.getModuleByExtension = function(extension) {
    return modules[Object.keys(modules).find(key =>
        modules[key].meta.extensions.includes(extension.toLowerCase())
    )] || sgf
}

exports.parseFile = function(filename, onProgress) {
    let extension = extname(filename).slice(1)
    let m = exports.getModuleByExtension(extension)

    return m.parseFile(filename, onProgress)<commit_msg>Use SGF loader if open file with unrecognized extension<commit_after>const {extname} = require('path')

let sgf = require('./sgf')
let ngf = require('./ngf')
let gib = require('./gib')

let modules = {sgf, ngf, gib}

exports = module.exports = Object.assign({}, modules)

let extensions = Object.keys(modules).map(key => modules[key].meta)
let combinedExtensions = extensions.map(x => x.extensions)
    .reduce((acc, x) => [...acc, ...x], [])

exports.meta = [
    {name: 'Game Records', extensions: combinedExtensions},
    ...extensions
]

exports.getModuleByExtension = function(extension) {
    return modules[Object.keys(modules).find(key =>
        modules[key].meta.extensions.includes(extension.toLowerCase())
    )] || sgf
}

exports.parseFile = function(filename, onProgress) {
    let extension = extname(filename).slice(1)
    let m = exports.getModuleByExtension(extension)

    return m.parseFile(filename, onProgress)
{'fraction_non_alphanumeric': 0.15973377703826955, 'fraction_numerical': 0.0011092623405435386, 'mean_word_length': 4.321533923303835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2625721', 'n_tokens_mistral': 552, 'n_tokens_neox': 543, 'n_words': 122}