import { toFormatDateTime, toPrettyFormat, toUnix } from '@angular-ru/cdk/date';
import { coerceBoolean } from '@angular-ru/cdk/coercion';
import { typeofType } from '@angular-ru/cdk/function';
import { isNil, checkValueIsEmpty } from '@angular-ru/cdk/utils';
import { isString, toStringVal, trim } from '@angular-ru/cdk/string';

function transformAsPrepareFieldsFromClass(classRef) {
    return ({ value }) => (Object.assign(Object.assign({}, new classRef()), value));
}

function transformDateToFormat(options) {
    return ({ value }) => toFormatDateTime(value, options);
}

const ONLY_TO_CLASS = { toClassOnly: true };
const ONLY_TO_PLAIN = { toPlainOnly: true };

function transformParseFloat({ value }) {
    return parseFloat(value);
}

function transformParseInt({ value }) {
    return parseInt(value);
}

function transformToBoolean({ value }) {
    return coerceBoolean(value);
}

function transformToClass(classType) {
    if (isNil(Reflect)) {
        throw new Error(`You are forgot add: import 'reflect-metadata';`);
    }
    return typeofType(classType);
}

function transformToFormatDateTime({ value }) {
    return toFormatDateTime(value);
}

function transformToNullableBoolean({ value }) {
    return isNil(value) ? null : coerceBoolean(value);
}

function transformToNumber({ value }) {
    if (isString(value)) {
        const strValue = value.trim().replace(/\s/g, '');
        return strValue ? Number(strValue) : null;
    }
    return checkValueIsEmpty(value) ? null : Number(value);
}

function transformToPrettyFormat({ value }) {
    return toPrettyFormat(value);
}

function transformToStringVal({ value }) {
    return toStringVal(value);
}

function transformToTrim({ value }) {
    return trim(value);
}

function transformToUnix({ value }) {
    return toUnix(value);
}

/**
 * Generated bundle index. Do not edit.
 */

export { ONLY_TO_CLASS, ONLY_TO_PLAIN, transformAsPrepareFieldsFromClass, transformDateToFormat, transformParseFloat, transformParseInt, transformToBoolean, transformToClass, transformToFormatDateTime, transformToNullableBoolean, transformToNumber, transformToPrettyFormat, transformToStringVal, transformToTrim, transformToUnix };
//# sourceMappingURL=angular-ru-cdk-class-transformer.js.map
