You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							83 lines
						
					
					
						
							1.4 KiB
						
					
					
				
			
		
		
	
	
							83 lines
						
					
					
						
							1.4 KiB
						
					
					
				const moment = require('moment')
 | 
						|
const fastJson = require('fast-json-stringify')
 | 
						|
const stringify = fastJson({
 | 
						|
  title: 'Example Schema',
 | 
						|
  type: 'object',
 | 
						|
  properties: {
 | 
						|
    firstName: {
 | 
						|
      type: 'string'
 | 
						|
    },
 | 
						|
    lastName: {
 | 
						|
      type: 'string'
 | 
						|
    },
 | 
						|
    age: {
 | 
						|
      description: 'Age in years',
 | 
						|
      type: 'integer'
 | 
						|
    },
 | 
						|
    now: {
 | 
						|
      type: 'string'
 | 
						|
    },
 | 
						|
    birthdate: {
 | 
						|
      type: ['string'],
 | 
						|
      format: 'date-time'
 | 
						|
    },
 | 
						|
    reg: {
 | 
						|
      type: 'string'
 | 
						|
    },
 | 
						|
    obj: {
 | 
						|
      type: 'object',
 | 
						|
      properties: {
 | 
						|
        bool: {
 | 
						|
          type: 'boolean'
 | 
						|
        }
 | 
						|
      }
 | 
						|
    },
 | 
						|
    arr: {
 | 
						|
      type: 'array',
 | 
						|
      items: {
 | 
						|
        type: 'object',
 | 
						|
        properties: {
 | 
						|
          str: {
 | 
						|
            type: 'string'
 | 
						|
          }
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
  },
 | 
						|
  required: ['now'],
 | 
						|
  patternProperties: {
 | 
						|
    '.*foo$': {
 | 
						|
      type: 'string'
 | 
						|
    },
 | 
						|
    test: {
 | 
						|
      type: 'number'
 | 
						|
    },
 | 
						|
    date: {
 | 
						|
      type: 'string',
 | 
						|
      format: 'date-time'
 | 
						|
    }
 | 
						|
  },
 | 
						|
  additionalProperties: {
 | 
						|
    type: 'string'
 | 
						|
  }
 | 
						|
})
 | 
						|
 | 
						|
console.log(stringify({
 | 
						|
  firstName: 'Matteo',
 | 
						|
  lastName: 'Collina',
 | 
						|
  age: 32,
 | 
						|
  now: new Date(),
 | 
						|
  birthdate: moment(),
 | 
						|
  reg: /"([^"]|\\")*"/,
 | 
						|
  foo: 'hello',
 | 
						|
  numfoo: 42,
 | 
						|
  test: 42,
 | 
						|
  date: moment(),
 | 
						|
  strtest: '23',
 | 
						|
  arr: [{ str: 'stark' }, { str: 'lannister' }],
 | 
						|
  obj: { bool: true },
 | 
						|
  notmatch: 'valar morghulis',
 | 
						|
  notmatchobj: { a: true },
 | 
						|
  notmatchnum: 42
 | 
						|
}))
 |