<commit_before>var objectAssign = require('object-assign'),
    SchemaError = require('./errors/SchemaError.js');

var finalize = function(formalizedSchema, nonFormalizedSchema, fn, sync) {

	// Add the old non-formalized schema - for preventing
	// redundant formalization and for usage by the
	// validator when sending validation errors.
	//
	// Make the property unenumerable.
	Object.defineProperty(formalizedSchema, '_nonFormalizedSchema', {
		value: nonFormalizedSchema,
		enumerable: false,
	});

	// We seal the schema so no futher editing can take place.
	Object.seal(formalizedSchema);

	// Allow for I/O if running async.
	if (fn) {
		if (sync) return fn(formalizedSchema);
		else setImmediate(fn, formalizedSchema);
	}

};

var formalizeObject = function(formalizedSchema, nonFormalizedSchema, fn, sync) {

	// For backwards compatibility be before version 1.0.3
	// we change the allowUnknownKeys to unknownKeys
	if (typeof formalizedSchema.allowUnknownKeys === 'boolean') {
		if (!process.env['ISVALID_SILENCE']) {
			console.error('isvalid: DEPRECATED: Validator allowUnknownKeys has been deprecated in favour of unknownKeys as of version 1.0.4. See README for more info.')
		}
		formalizedSchema.unknownKeys = (formalizedSchema.allowUnknownKeys ? 'allow' : 'deny');
		formalizedSchema.wasAllowUnknownKeys = true;
		delete formalizedSchema.allowUnknownKeys;
	}

	// Set an empty sub-schema if schema is not present.
	formalizedSchema.schema = formalizedSchema.schema || {};

	// Build new formalized schema into this.
	var formalizedSubschema = {};

	var keys = Object.keys(formalizedSchema.schema);

	(function formalizeNextKey(idx) {

		// If idx equals keys length - we are done.
		if (idx == keys.length) {
			formalizedSchema.schema = formalizedSubschema;
			formalizedSchema = finalize(formalizedSchema, nonFormalizedSchema, fn, sync);
			return;
		}

		var key = keys[idx];

		formalizeAny(formalizedSchema.schema[key], function(formalizedKey) {

			// Apply implicit required if sub-schema is required.
			if (formalizedSchema.required === undefined || formalizedSchema.required == 'implicit') {
				if (formalizedKey.required === true) formalizedSchema.required = true;
			}

			formalizedSubschema[key] = formalizedKey;

			if (sync) return formalizeNextKey(idx + 1);
			else setImmediate(formalizeNextKey, idx + 1);

		}, sync);

	})(0);

	return formalizedSchema;

};

var formalizeArray = function(formalizedSchema, nonFormalizedSchema, fn, sync) {

	// formalizedSchema has been pre-processed by formalizeAny, so
	// we only need to formalize the sub-schema.

	return formalizeAny(formalizedSchema.schema, function(formalizedSubschema) {

		formalizedSchema.schema = formalizedSubschema;

		// Apply implicit required if sub-schema has required data.
		if (typeof(formalizedSchema.required) === 'undefined' || formalizedSchema.required === 'implicit') {
			if (formalizedSchema.schema.required === true) formalizedSchema.required = true;
		}
<commit_msg>Schemas are now optional on Array and Object.<commit_after>var objectAssign = require('object-assign'),
    SchemaError = require('./errors/SchemaError.js');

var finalize = function(formalizedSchema, nonFormalizedSchema, fn, sync) {

	// Add the old non-formalized schema - for preventing
	// redundant formalization and for usage by the
	// validator when sending validation errors.
	//
	// Make the property unenumerable.
	Object.defineProperty(formalizedSchema, '_nonFormalizedSchema', {
		value: nonFormalizedSchema,
		enumerable: false,
	});

	// We seal the schema so no futher editing can take place.
	Object.seal(formalizedSchema);

	// Allow for I/O if running async.
	if (fn) {
		if (sync) return fn(formalizedSchema);
		else setImmediate(fn, formalizedSchema);
	}

};

var formalizeObject = function(formalizedSchema, nonFormalizedSchema, fn, sync) {

	// For backwards compatibility be before version 1.0.3
	// we change the allowUnknownKeys to unknownKeys
	if (typeof formalizedSchema.allowUnknownKeys === 'boolean') {
		if (!process.env['ISVALID_SILENCE']) {
			console.error('isvalid: DEPRECATED: Validator allowUnknownKeys has been deprecated in favour of unknownKeys as of version 1.0.4. See README for more info.')
		}
		formalizedSchema.unknownKeys = (formalizedSchema.allowUnknownKeys ? 'allow' : 'deny');
		formalizedSchema.wasAllowUnknownKeys = true;
		delete formalizedSchema.allowUnknownKeys;
	}

	// If no sub-schema is provided we consider the schema final.
	if (typeof formalizedSchema.schema === 'undefined') return finalize(formalizedSchema, nonFormalizedSchema, fn, sync);

	// Build new formalized schema into this.
	var formalizedSubschema = {};

	var keys = Object.keys(formalizedSchema.schema);

	(function formalizeNextKey(idx) {

		// If idx equals keys length - we are done.
		if (idx == keys.length) {
			formalizedSchema.schema = formalizedSubschema;
			formalizedSchema = finalize(formalizedSchema, nonFormalizedSchema, fn, sync);
			return;
		}

		var key = keys[idx];

		formalizeAny(formalizedSchema.schema[key], function(formalizedKey) {

			// Apply implicit required if sub-schema is required.
			if (formalizedSchema.required === undefined || formalizedSchema.required == 'implicit') {
				if (formalizedKey.required === true) formalizedSchema.required = true;
			}

			formalizedSubschema[key] = formalizedKey;

			if (sync) return formalizeNextKey(idx + 1);
			else setImmediate(formalizeNextKey, idx + 1);

		}, sync);

	})(0);

	return formalizedSchema;

};

var formalizeArray = function(formalizedSchema, nonFormalizedSchema, fn, sync) {

	// formalizedSchema has been pre-processed by formalizeAny, so
	// we only need to formalize the sub-schema.

	// If no sub-schema is provided we consider the schema final.
	if (typeof formalizedSchema.schema === 'undefined') return finalize(formalizedSchema, nonFormalizedSchema, fn, sync);

	return formalizeAny(formalizedSchema.schema, function(formalizedSubschema) {

		formalizedSchema.schema = formalizedSubschema;

		// Apply implicit required if sub-schema has required data.
		if (typeof(formalizedSchema.required) === 'undefined' || formalizedSchema.required === 'implicit') {
			if (formalizedSchema.schema.required === true) formalizedSchema.required = true;
		}

{'fraction_non_alphanumeric': 0.1057092595554134, 'fraction_numerical': 0.002878618263233648, 'mean_word_length': 4.578947368421052, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '451386', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1792, 'n_words': 520}