<commit_before>// import from npm
import { assignIn } from 'lodash';

// declare an interface for the object that is
// used to describe each link and stored in the
// map
interface LinkState {
    hasLoaded: boolean;
    wasRejected: boolean;
    error?: any;
    link: HTMLLinkElement;
}

/**
 * map for link names against utility objects
 * @type {Map<string, LinkState>}
 */
const loadedLinks = new Map<string, LinkState>();

/**
 * Get a style or other linked resource from a remote location.
 * @param name {string} - The name of the resource to be retrieved.
 * @param url {string} - The URL/location of the resource to be retrieved.
 */
export function getLink(url: string, name: string) {
    if (!loadedLinks.has(name)) {
        const link: HTMLLinkElement = document.createElement('link');
        const body = document.getElementsByTagName('body')[0];

        assignIn(link, {
            type: 'text/css',
            href: url,
        });

        body.appendChild(link);

        const linkObject: LinkState = {
            hasLoaded: false,
            wasRejected: false,
            link,
        };

        loadedLinks.set(name, linkObject);
    }

    return loadedLinks.get(name);
}

// make the 'getLink' method the default export
export default getLink;<commit_msg>Add the stylesheet rel to the generated links.<commit_after>// import from npm
import { assignIn } from 'lodash';

// declare an interface for the object that is
// used to describe each link and stored in the
// map
interface LinkState {
    hasLoaded: boolean;
    wasRejected: boolean;
    error?: any;
    link: HTMLLinkElement;
}

/**
 * map for link names against utility objects
 * @type {Map<string, LinkState>}
 */
const loadedLinks = new Map<string, LinkState>();

/**
 * Get a style or other linked resource from a remote location.
 * @param name {string} - The name of the resource to be retrieved.
 * @param url {string} - The URL/location of the resource to be retrieved.
 */
export function getLink(url: string, name: string) {
    if (!loadedLinks.has(name)) {
        const link: HTMLLinkElement = document.createElement('link');
        const body = document.getElementsByTagName('body')[0];

        assignIn(link, {
            type: 'text/css',
            href: url,
            rel: 'stylesheet',
        });

        body.appendChild(link);

        const linkObject: LinkState = {
            hasLoaded: false,
            wasRejected: false,
            link,
        };

        loadedLinks.set(name, linkObject);
    }

    return loadedLinks.get(name);
}

// make the 'getLink' method the default export
export default getLink;
{'fraction_non_alphanumeric': 0.10762839879154079, 'fraction_numerical': 0.0007552870090634441, 'mean_word_length': 2.6437414030261346, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3704136', 'n_tokens_mistral': 744, 'n_tokens_neox': 728, 'n_words': 262}