<commit_before>/*
absolute-json
version 0.8
author: <NAME>
https://github.com/lean/absolute-json
Licensed under the MIT license.
*/

(function () {
	"use strict";
	// defaults
	var options = {
		source: null,
		sourceUrl: "",
		localeObject: {}
	};
	var abjson = {};

	// helpers
	function abjError ( name, message ) {
		this.name = name;
		this.message = message || "error";
	}

	abjError.prototype = new Error();
	abjError.prototype.constructor = abjError;

	function forEach (obj, iterator, context) {
		if (!obj){
			return;
		}
		if (Array.prototype.forEach && obj.forEach === Array.prototype.forEach) {
			obj.forEach(iterator, context);
		} else if (obj.length === +obj.length) {
			for (var i = 0, l = obj.length; i < l; i++) {
				if (iterator.call(context, obj[i], i, obj) === {}){
					return;
				}
			}
		} else {
			for (var key in obj) {
				if ( obj.hasOwnProperty(key) ) {
					if (iterator.call(context, obj[key], key, obj) === {}) {
						return;
					}
				}
			}
		}

	}

	function setSource ( source ) {
		options.source = source;
	}

	function get ( key ) {
		return options.source[key] ?
						wildcardReplace(options.source[key], Array.prototype.slice.call(arguments, 1)) :
						undefined;
	}

	function updateElements ( el ) {

		var elKey = el.attributes["data-abjson"].value,
				elReplaceAttr = el.attributes["data-abjson-r"],
				updateElementsText = options.source[elKey];

		if ( typeof updateElementsText !== "undefined" ) {

			if ( updateElementsText === Object(updateElementsText) ) {

				forEach( updateElementsText, function ( val, key ) {

					if ( key === "text" ){
						if ( elReplaceAttr ) {
							el.innerHTML = wildcardReplace( updateElementsText, elReplaceAttr.value.split("|") ) ;
						} else {
							el.innerHTML = val;
						}
					} else {
						el.attributes[key].value = val;
					}
				});

			} else {

				if ( elReplaceAttr ) {
					el.innerHTML =  wildcardReplace( updateElementsText, elReplaceAttr.value.split("|") ) ;
				} else {
					el.innerHTML =  updateElementsText ;
				}

			}

		} else {
			//key not found
			el.innerHTML = elKey + " NOT FOUND";
		}

	}

	function wildcardReplace ( text, replaceElements ) {

		var i,
			replacedText = text,
			replaceElementsLength = replaceElements.length;

		for( i=0; i < replaceElementsLength; i++ ) {
			replacedText = replacedText.replace( new RegExp("%" + (i+1), "ig"), replaceElements[i] );
		}

		return replacedText;

	}
<commit_msg>Agregado data-abjson-attr, permite setear el valor del key a un atributo en vez de directamente al valor, funciona con data-abjson-r<commit_after>/*
absolute-json
version 0.8
author: <NAME>
https://github.com/lean/absolute-json
Licensed under the MIT license.
*/

(function () {
	"use strict";
	// defaults
	var options = {
		source: null,
		sourceUrl: "",
		localeObject: {}
	};
	var abjson = {};

	// helpers
	function abjError ( name, message ) {
		this.name = name;
		this.message = message || "error";
	}

	abjError.prototype = new Error();
	abjError.prototype.constructor = abjError;

	function forEach (obj, iterator, context) {
		if (!obj){
			return;
		}
		if (Array.prototype.forEach && obj.forEach === Array.prototype.forEach) {
			obj.forEach(iterator, context);
		} else if (obj.length === +obj.length) {
			for (var i = 0, l = obj.length; i < l; i++) {
				if (iterator.call(context, obj[i], i, obj) === {}){
					return;
				}
			}
		} else {
			for (var key in obj) {
				if ( obj.hasOwnProperty(key) ) {
					if (iterator.call(context, obj[key], key, obj) === {}) {
						return;
					}
				}
			}
		}

	}

	function setSource ( source ) {
		options.source = source;
	}

	function get ( key ) {
		return options.source[key] ?
						wildcardReplace(options.source[key], Array.prototype.slice.call(arguments, 1)) :
						undefined;
	}

	function updateElements ( el ) {

		var elKey = el.attributes["data-abjson"].value,
				elReplaceAttr = el.attributes["data-abjson-r"],
				elAttrSelector = el.attributes["data-abjson-attr"],
				updateElementsText = options.source[elKey];

		if ( typeof updateElementsText !== "undefined" ) {

			if ( updateElementsText === Object(updateElementsText) ) {

				forEach( updateElementsText, function ( val, key ) {

					if ( key === "text" ){
						if ( elReplaceAttr ) {
							if ( elAttrSelector ) {
								el.setAttribute( elAttrSelector, wildcardReplace( updateElementsText, elReplaceAttr.value.split("|") ) ) ;
							} else {
								el.innerHTML = wildcardReplace( updateElementsText, elReplaceAttr.value.split("|") ) ;
							}
						} else {
							if ( elAttrSelector ) {
								el.setAttribute( elAttrSelector, val );
							} else {
								el.innerHTML = val;
							}
						}
					} else {
						el.attributes[key].value = val;
					}
				});

			} else {

				if ( elReplaceAttr ) {
					if ( elAttrSelector ) {
						el.setAttribute (elAttrSelector, wildcardReplace( updateElementsText, elReplaceAttr.value.split("|") ) ) ;
					} else {
						el.innerHTML = wildcardReplace( updateElementsText, elReplaceAttr.value.split("|") ) ;
					}
				} else {
					if ( elAttrSelector ) {
						el.setAttribute( elAttrSelector, updateElementsText) ;
					} else {
						el.innerHTML = updateElementsText ;
					}
				}

			}

		} else {
			//key not found
			el.innerHTML = elKey + " NOT FOUND";
		}

	}

	function wildcardReplace ( text, replaceElements ) {

		var i,
			replacedText = text,
			replaceElementsLength = replaceElements.length;

		for( i=0; i < replaceElementsLength; i++ ) {
			replacedText = replacedText.replace( new RegExp("%" + (i+1), "ig"), replaceElements[i] );
		}

		return replacedText;

	}

{'fraction_non_alphanumeric': 0.14643237486687966, 'fraction_numerical': 0.002129925452609159, 'mean_word_length': 2.8022941970310393, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '6572040', 'n_tokens_mistral': 2287, 'n_tokens_neox': 1825, 'n_words': 407}