<commit_before>import {defaultTypeResolver, Deserializer} from './deserializer';
import {logError, logWarning, nameof, parseToJSObject} from './helpers';
import {createArrayType} from './json-array-member';
import {JsonObjectMetadata, TypeHintEmitter, TypeResolver} from './metadata';
import {extractOptionBase, OptionsBase} from './options-base';
import {defaultTypeEmitter, Serializer} from './serializer';
import {ensureTypeDescriptor, MapT, SetT} from './type-descriptor';
import {Constructor, IndexedObject, Serializable} from './types';

export type JsonTypes = Object | boolean | string | number | null | undefined;
export {defaultTypeResolver, defaultTypeEmitter};

export interface MappedTypeSerializer<T> {

    /**
     * Use this deserializer to convert a JSON value to the type.
     */
    deserializer: (json: any) => T | null | undefined;

    /**
     * Use this serializer to convert a type back to JSON.
     */
    serializer: (value: T | null | undefined) => any;
}

export interface ITypedJSONSettings extends OptionsBase {
    /**
     * Sets the handler callback to invoke on errors during serializing and deserializing.
     * Re-throwing errors in this function will halt serialization/deserialization.
     * The default behavior is to log errors to the console.
     */
    errorHandler?: ((e: Error) => void) | null;

    /**
     * Maps a type to their respective serializer. Prevents you from having to repeat serializers.
     * Register additional types with `TypedJSON.mapType`.
     */
    mappedTypes?: Map<any, MappedTypeSerializer<any>> | null;

    /**
     * Sets a callback that determines the constructor of the correct sub-type of polymorphic
     * objects while deserializing.
     * The default behavior is to read the type-name from the '__type' property of 'sourceObject',
     * and look it up in 'knownTypes'.
     * The constructor of the sub-type should be returned.
     */
    typeResolver?: TypeResolver | null;

    nameResolver?: ((ctor: Function) => string) | null;

    /**
     * Sets a callback that writes type-hints to serialized objects.
     * The default behavior is to write the type-name to the '__type' property, if a derived type
     * is present in place of a base type.
     */
    typeHintEmitter?: TypeHintEmitter | null;

    /**
     * Sets the amount of indentation to use in produced JSON strings.
     * Default value is 0, or no indentation.
     */
    indent?: number | null;
<commit_msg>Tighten mappedTypes type<commit_after>import {defaultTypeResolver, Deserializer} from './deserializer';
import {logError, logWarning, nameof, parseToJSObject} from './helpers';
import {createArrayType} from './json-array-member';
import {JsonObjectMetadata, TypeHintEmitter, TypeResolver} from './metadata';
import {extractOptionBase, OptionsBase} from './options-base';
import {defaultTypeEmitter, Serializer} from './serializer';
import {ensureTypeDescriptor, MapT, SetT} from './type-descriptor';
import {Constructor, IndexedObject, Serializable} from './types';

export type JsonTypes = Object | boolean | string | number | null | undefined;
export {defaultTypeResolver, defaultTypeEmitter};

export interface MappedTypeSerializer<T> {

    /**
     * Use this deserializer to convert a JSON value to the type.
     */
    deserializer: (json: any) => T | null | undefined;

    /**
     * Use this serializer to convert a type back to JSON.
     */
    serializer: (value: T | null | undefined) => any;
}

export interface ITypedJSONSettings extends OptionsBase {
    /**
     * Sets the handler callback to invoke on errors during serializing and deserializing.
     * Re-throwing errors in this function will halt serialization/deserialization.
     * The default behavior is to log errors to the console.
     */
    errorHandler?: ((e: Error) => void) | null;

    /**
     * Maps a type to their respective serializer. Prevents you from having to repeat serializers.
     * Register additional types with `TypedJSON.mapType`.
     */
    mappedTypes?: Map<Serializable<any>, MappedTypeSerializer<any>> | null;

    /**
     * Sets a callback that determines the constructor of the correct sub-type of polymorphic
     * objects while deserializing.
     * The default behavior is to read the type-name from the '__type' property of 'sourceObject',
     * and look it up in 'knownTypes'.
     * The constructor of the sub-type should be returned.
     */
    typeResolver?: TypeResolver | null;

    nameResolver?: ((ctor: Function) => string) | null;

    /**
     * Sets a callback that writes type-hints to serialized objects.
     * The default behavior is to write the type-name to the '__type' property, if a derived type
     * is present in place of a base type.
     */
    typeHintEmitter?: TypeHintEmitter | null;

    /**
     * Sets the amount of indentation to use in produced JSON strings.
     * Default value is 0, or no indentation.
     */
    indent?: number | null;

{'fraction_non_alphanumeric': 0.09704046708274612, 'fraction_numerical': 0.0004026575397624321, 'mean_word_length': 3.384819064430715, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 18, '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': '3545858', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1306, 'n_words': 530}