dist/@ajsf/core/bundles/ajsf-core.umd.js
/**
     * 'buildSchemaFromData' function
     *
     * Build a JSON Schema from a data object
     *
     * //   data - The data object
     * //  { boolean = false } requireAllFields - Require all fields?
     * //  { boolean = true } isRoot - is root
     * //  - The new JSON Schema
     */
'buildSchemaFromData' function
Build a JSON Schema from a data object

The data object
{ boolean = false } requireAllFields - Require all fields.
{ boolean = true } isRoot - is root
- The new JSON Schema
' buildSchemaFromData ' function Build a JSON Schema from a data object The data object { boolean = false } requireAllFields - Require all fields . { boolean = true } isRoot - is root - The new JSON Schema
function buildSchemaFromData(data, requireAllFields, isRoot) {
        var e_1, _a;
        if (requireAllFields === void 0) { requireAllFields = false; }
        if (isRoot === void 0) { isRoot = true; }
        var newSchema = {};
        var getFieldType = function (value) {
            var fieldType = getType(value, 'strict');
            return { integer: 'number', null: 'string' }[fieldType] || fieldType;
        };
        var buildSubSchema = function (value) { return buildSchemaFromData(value, requireAllFields, false); };
        if (isRoot) {
            newSchema.$schema = 'http://json-schema.org/draft-06/schema#';
        }
        newSchema.type = getFieldType(data);
        if (newSchema.type === 'object') {
            newSchema.properties = {};
            if (requireAllFields) {
                newSchema.required = [];
            }
            try {
                for (var _b = __values(Object.keys(data)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var key = _c.value;
                    newSchema.properties[key] = buildSubSchema(data[key]);
                    if (requireAllFields) {
                        newSchema.required.push(key);
                    }
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_1) throw e_1.error; }
            }
        }
        else if (newSchema.type === 'array') {
            newSchema.items = data.map(buildSubSchema);
            if ((new Set(data.map(getFieldType))).size === 1) {
                newSchema.items = newSchema.items.reduce(function (a, b) { return (Object.assign(Object.assign({}, a), b)); }, {});
            }
            if (requireAllFields) {
                newSchema.minItems = 1;
            }
        }
        return newSchema;
    }
function buildSchemaFromData ( data , requireAllFields , isRoot ) { var e_1 , _a ; if ( requireAllFields === void 0 ) { requireAllFields = false ; } if ( isRoot === void 0 ) { isRoot = true ; } var newSchema = { } ; var getFieldType = function ( value ) { var fieldType = getType ( value , 'strict' ) ; return { integer : 'number' , null : 'string' } [ fieldType ] || fieldType ; } ; var buildSubSchema = function ( value ) { return buildSchemaFromData ( value , requireAllFields , false ) ; } ; if ( isRoot ) { newSchema . $schema = 'http://json-schema.org/draft-06/schema#' ; } newSchema . type = getFieldType ( data ) ; if ( newSchema . type === 'object' ) { newSchema . properties = { } ; if ( requireAllFields ) { newSchema . required = [ ] ; } try { for ( var _b = __values ( Object . keys ( data ) ) , _c = _b . next ( ) ; ! _c . done ; _c = _b . next ( ) ) { var key = _c . value ; newSchema . properties [ key ] = buildSubSchema ( data [ key ] ) ; if ( requireAllFields ) { newSchema . required . push ( key ) ; } } } catch ( e_1_1 ) { e_1 = { error : e_1_1 } ; } finally { try { if ( _c && ! _c . done && ( _a = _b . return ) ) _a . call ( _b ) ; } finally { if ( e_1 ) throw e_1 . error ; } } } else if ( newSchema . type === 'array' ) { newSchema . items = data . map ( buildSubSchema ) ; if ( ( new Set ( data . map ( getFieldType ) ) ) . size === 1 ) { newSchema . items = newSchema . items . reduce ( function ( a , b ) { return ( Object . assign ( Object . assign ( { } , a ) , b ) ) ; } , { } ) ; } if ( requireAllFields ) { newSchema . minItems = 1 ; } } return newSchema ; }
'buildSchemaFromData' function
 Build a JSON Schema from a data object
' buildSchemaFromData ' function Build a JSON Schema from a data object
// If all items are the same type, use an object for items instead of an array