<commit_before>"use strict";
import {separate as separate} from "../separate/separate.js";
import {deSeparate as deSeparate} from "../separate/separate.js";
import identify from "./identify.js";
import url2tag from "./url2tag.js";


export default function(str,options){
	var arr = separate(str);
	arr = identify(arr,options).map((fragment)=>{
		if(typeof fragment === "string") return fragment;
		url2tag(fragment.url,options);
		return url2tag(fragment.protocol+fragment.url,options);
	});
	return deSeparate(arr);
}

function url2tag (fragment,options){
	var href = fragment.protocol + removeNotationEnds(fragment.encoded);
	var original = fragment.raw;
	original = (options.truncate > 0 && original.length > options.truncate) ?  original.substring(0,options.truncate) + "..." : original;
	return `<a href="${href}" ${options.attributes.map((attribute)=>{
		if(typeof attribute === 'function') {
			var name = attribute(fragment).name;
			var value = attribute(fragment).value;
			if(name && !value) return " name ";
			if(name && value) return ` ${name}="${value}" `;
		}
		else return ` ${attribute.name}="${attribute.value}" `;
	}).join("")}>${original}</a>`;
}<commit_msg>attributes and options can now be functions<commit_after>"use strict";
import {separate as separate} from "../separate/separate.js";
import {deSeparate as deSeparate} from "../separate/separate.js";
import {removeNotationEnds as removeNotationEnds} from "../util.js";
import identify from "./identify.js";

export default function(str,options){

	var arr = separate(str);
	arr = identify(arr,options);

	// return the current list (with words being filtered out)
	if(options.list) return arr.filter((fragment)=>typeof fragment !== "string");

	// transform objects to HTML tags
	arr = arr.map((fragment)=>{
		if(typeof fragment === "string") return fragment;
		return url2tag(fragment,options);
	});

	// join and return
	return deSeparate(arr);
}

function url2tag (fragment,options){
	var href = fragment.protocol + removeNotationEnds(fragment.encoded);
	var original = fragment.raw;
	original = (options.truncate > 0 && original.length > options.truncate) ?  original.substring(0,options.truncate) + "..." : original;
	return `<a href="${href}" ${options.attributes.map((attribute)=>{
		if(typeof attribute === 'function') {
			var name = attribute(fragment).name;
			var value = attribute(fragment).value;
			if(name && !value) return " name ";
			if(name && value) return ` ${name}="${value}" `;
		}
		else return ` ${attribute.name}="${attribute.value}" `;
	}).join("")}>${original}</a>`;
}
{'fraction_non_alphanumeric': 0.17514563106796116, 'fraction_numerical': 0.004271844660194175, 'mean_word_length': 5.08983451536643, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, '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': '7456938', 'n_tokens_mistral': 827, 'n_tokens_neox': 773, 'n_words': 195}