I have to write a javascript function which can validate data according to this kind of schema. How should i go about this? Can i use json schema for this. That does'nt work for fucnctions so how should i solve this? Is there any native js way to go about this?
const userSchema = {
    name: {
        fn: () => String,
        option: { default: 'Abhi', enum: ['John', 'Rick', 'Dan'] }
    },
    phone: {
        fn: () => Number,
        option: {}
    },
    cart: {
        fn: () => [
            {
                id: {
                    fn: () => String,
                    option: {}
                },
                count: {
                    fn: () => Number,
                    option: {}
                }
            }
        ],
        option: {}
    },
    address: {
        contactName: {
            fn: () => String,
            option: {}
        },
        detailAddress: {
            line1: {
                fn: () => String,
                option: {}
            },
            line2: {
                fn: () => String,
                option: {}
            },
            line3: {
                fn: () => String,
                option: {}
            }
        },
        pin: {
            fn: () => Number,
            option: {}
        },
        country: {
            fn: () => String,
            option: {}
        }
    }
};
const user = {
    name: 'Ric',
    phone: 6610592314,
    address: {
        contactName: 'Bitu',
        detailAddress: {
            line1: 'Colony: 2/A',
            line2: 'Q. No.: 3-018',
            line3: 'Near IT store'
        },
        pin: 770017,
        country: 'India'
    },
    cart: [
        {
            id: 'newId',
            count: 2
        }
    ]
};