function normalize(recordTypes, recordTypeName, record, lang, validationSets) {

	// check that we have the record
	if ((record === null) || ((typeof record) !== 'object'))
		throw new common.X2UsageError('Record object was not provided.');

	// get the record type descriptor (or throw error if invalid record type)
	const recordTypeDesc = recordTypes.getRecordTypeDesc(recordTypeName);

	// extract validation sets
	var sets = new Set(
		(validationSets ? validationSets.trim() + ',*' : '*').split(/\s*,\s*/));

	// create validation context
	const ctx = new ValidationContext(
		recordTypes, recordTypeDesc, new MessageResolver(lang || '*'), sets);

	// run recursive validation/normalization of the record properties
	normalizeChildren(ctx, recordTypeDesc, null, record, sets);

	// validate/normalize the record as a whole
	const recordValidators = getValidators(recordTypeDesc, false, sets);
	if (recordValidators)
		for (let validator of recordValidators)
			validator(ctx, record);

	// return the result
	return ctx.getResult();
}
/**
 * Validate and normalize the specified record.
 *
 * @function module:x2node-validators.normalizeRecord
 * @param {module:x2node-records~RecordTypesLibrary} recordType Record types
 * library.
 * @param {string} recordTypeName Record type name.
 * @param {Object} record The record to validate. May not be <code>null</code> or
 * <code>undefined</code>.
 * @param {string} [lang] Language for the error messages in the same format as
 * used by the HTTP's "Accept-Language" request header. If not provided, "*" is
 * assumed.
 * @param {string} [validationSets] Comma-separated validation set names. If not
 * provided, the default validation set is used.
 * @returns {module:x2node-validators~ValidationErrors} Errors if the record is
 * invalid, or <code>null</code> if it has been successfully validated and
 * normalized.
 * @throws {module:x2node-common.X2UsageError} If unknown record type, record was
 * not provided or invalid language or validation set specification.
 */
Validate and normalize the specified record.
@function module:x2node-validators.normalizeRecord
@param {module:x2node-records~RecordTypesLibrary} recordType Record types
library.
@param {string} recordTypeName Record type name.
@param {Object} record The record to validate. May not be null or
undefined.
@param {string} [lang] Language for the error messages in the same format as
used by the HTTP's "Accept-Language" request header. If not provided, "*" is
assumed.
@param {string} [validationSets] Comma-separated validation set names. If not
provided, the default validation set is used.
@returns {module:x2node-validators~ValidationErrors} Errors if the record is
invalid, or null if it has been successfully validated and
normalized.
@throws {module:x2node-common.X2UsageError} If unknown record type, record was
not provided or invalid language or validation set specification.
Validate and normalize the specified record . @function module : x2node - validators . normalizeRecord @param { module : x2node - records~RecordTypesLibrary } recordType Record types library . @param { string } recordTypeName Record type name . @param { Object } record The record to validate . May not be null or undefined . @param { string } [ lang ] Language for the error messages in the same format as used by the HTTP ' s " Accept - Language " request header . If not provided " * " is assumed . @param { string } [ validationSets ] Comma - separated validation set names . If not provided the default validation set is used . @returns { module : x2node - validators~ValidationErrors } Errors if the record is invalid or null if it has been successfully validated and normalized . @throws { module : x2node - common . X2UsageError } If unknown record type record was not provided or invalid language or validation set specification .
function normalize(recordTypes, recordTypeName, record, lang, validationSets) {
	if ((record === null) || ((typeof record) !== 'object'))
		throw new common.X2UsageError('Record object was not provided.');
	const recordTypeDesc = recordTypes.getRecordTypeDesc(recordTypeName);
	var sets = new Set(
		(validationSets ? validationSets.trim() + ',*' : '*').split(/\s*,\s*/));
	const ctx = new ValidationContext(
		recordTypes, recordTypeDesc, new MessageResolver(lang || '*'), sets);
	normalizeChildren(ctx, recordTypeDesc, null, record, sets);
	const recordValidators = getValidators(recordTypeDesc, false, sets);
	if (recordValidators)
		for (let validator of recordValidators)
			validator(ctx, record);
	return ctx.getResult();
}
function normalize ( recordTypes , recordTypeName , record , lang , validationSets ) { if ( ( record === null ) || ( ( typeof record ) !== 'object' ) ) throw new common . X2UsageError ( 'Record object was not provided.' ) ; const recordTypeDesc = recordTypes . getRecordTypeDesc ( recordTypeName ) ; var sets = new Set ( ( validationSets ? validationSets . trim ( ) + ',*' : '*' ) . split ( / \s*,\s* / ) ) ; const ctx = new ValidationContext ( recordTypes , recordTypeDesc , new MessageResolver ( lang || '*' ) , sets ) ; normalizeChildren ( ctx , recordTypeDesc , null , record , sets ) ; const recordValidators = getValidators ( recordTypeDesc , false , sets ) ; if ( recordValidators ) for ( let validator of recordValidators ) validator ( ctx , record ) ; return ctx . getResult ( ) ; }
Validate and normalize the specified record.
Validate and normalize the specified record .
// check that we have the record // get the record type descriptor (or throw error if invalid record type) // extract validation sets // create validation context // run recursive validation/normalization of the record properties // validate/normalize the record as a whole // return the result