<commit_before>/**
 * @license
 * Copyright color-coding studio. All Rights Reserved.
 *
 * Use of this source code is governed by an Apache License, Version 2.0
 * that can be found in the LICENSE file at http://www.apache.org/licenses/LICENSE-2.0
 */

import { ArrayList } from "../data/index";
import * as conf from "../configuration/index";
/**  */
export module requires {
    /** 模块间共享的类库名称，逗号分隔 */
    export const CONFIG_ITEM_SHARED_LIBRARIES: string = "sharedLibraries";
    /** 加载器名称模板 */
    export const CONTEXT_NAME_TEMPLATE_IBAS: string = "ibas.{0}";
    /** 命名 */
    export function naming(name: string): string {
        return CONTEXT_NAME_TEMPLATE_IBAS.replace("{0}", name);
    }
    /**
     * 创建require实例
     * @param config 配置
     * @param library 共享的类库，为null时不共享
     */
    export function create(config: RequireConfig, library: any): Require {
        if ((<any>window).require === undefined || (<any>window).require === null) {
            throw new Error("not found requirejs.");
        }
        let names: ArrayList<string> = new ArrayList<string>();
        // names.push("ibas");
        names.push("ibas/bobas");
        names.push("ibas/bsbas");
        names.push("ibas/index.js");
        if (library !== undefined && library !== null) {
            if (library instanceof Array) {
                // 定义了path
                for (let item of library) {
                    names.push(item);
                }
            } else if (typeof library === "string") {
                names.push(library);
            }
            // 加载共享类库配置项
            let libraries: any = conf.config.get(CONFIG_ITEM_SHARED_LIBRARIES);
            if (libraries !== undefined) {
                for (let item of libraries.toString().split(",")) {
                    if (item === undefined || item === null || item.length === 0) {
                        continue;
                    }
                    let name: string = item;
                    if (!names.contain(name)) {
                        names.push(name);
                    }
                }
            }
            config.paths = {};
            let scripts: NodeListOf<HTMLScriptElement> = document.getElementsByTagName("script");
            for (let index: number = 0; index < scripts.length; index++) {
                let script: HTMLScriptElement = scripts[index];
                if (script.src !== undefined && script.src !== null && script.src.length !== 0) {
                    let scriptUrl: string = script.src;
                    if (scriptUrl.indexOf("?")) {
                        // 去除参数部分<commit_msg>修复bug<commit_after>/**
 * @license
 * Copyright color-coding studio. All Rights Reserved.
 *
 * Use of this source code is governed by an Apache License, Version 2.0
 * that can be found in the LICENSE file at http://www.apache.org/licenses/LICENSE-2.0
 */

import { ArrayList } from "../data/index";
import * as conf from "../configuration/index";
/**  */
export module requires {
    /** 模块间共享的类库名称，逗号分隔 */
    export const CONFIG_ITEM_SHARED_LIBRARIES: string = "sharedLibraries";
    /** 加载器名称模板 */
    export const CONTEXT_NAME_TEMPLATE_IBAS: string = "ibas.{0}";
    /** 命名 */
    export function naming(name: string): string {
        return CONTEXT_NAME_TEMPLATE_IBAS.replace("{0}", name);
    }
    /**
     * 创建require实例
     * @param config 配置
     * @param library 共享的类库，为null时不共享
     */
    export function create(config: RequireConfig, library: any): Require {
        if ((<any>window).require === undefined || (<any>window).require === null) {
            throw new Error("not found requirejs.");
        }
        let names: ArrayList<string> = new ArrayList<string>();
        // names.push("ibas");
        names.push("ibas/bobas");
        names.push("ibas/bsbas");
        names.push("ibas/index.js");
        if (library !== undefined && library !== null) {
            if (library instanceof Array) {
                // 定义了path
                for (let item of library) {
                    names.push(item);
                }
            } else if (typeof library === "string") {
                names.push(library);
            }
            // 加载共享类库配置项
            let libraries: any = conf.config.get(CONFIG_ITEM_SHARED_LIBRARIES);
            if (libraries !== undefined) {
                for (let item of libraries.toString().split(",")) {
                    if (item === undefined || item === null || item.length === 0) {
                        continue;
                    }
                    let name: string = item;
                    if (!names.contain(name)) {
                        names.push(name);
                    }
                }
            }
            config.paths = {};
            let scripts: NodeListOf<HTMLScriptElement> = document.getElementsByTagName("script");
            for (let index: number = 0; index < scripts.length; index++) {
                let script: HTMLScriptElement = scripts[index];
                if (script.src !== undefined && script.src !== null && script.src.length !== 0) {
                    let scriptUrl: string = script.src;
                    if (scriptUrl.indexOf("?") > 0) {
                        // 去除参数部分
{'fraction_non_alphanumeric': 0.13298890164561805, 'fraction_numerical': 0.0036356678147722926, 'mean_word_length': 1.7295039164490862, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4860104', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1483, 'n_words': 356}