From 71c4abbfe557ac14ccd9e2a1f355d5f7e4602141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Po=C5=9Bpiech?= Date: Tue, 18 Jun 2024 16:10:38 +0200 Subject: [PATCH] formatted playground presets --- website/lib/presets.ts | 149 +++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 73 deletions(-) diff --git a/website/lib/presets.ts b/website/lib/presets.ts index 98c7cb6cb..45c8478b5 100644 --- a/website/lib/presets.ts +++ b/website/lib/presets.ts @@ -5,23 +5,23 @@ const presets = { 'Welcome!': preset` new SimpleSchema2Bridge({ schema: new SimpleSchema({ - date: { type: Date, defaultValue: new Date() }, - adult: Boolean, - size: { - type: String, - defaultValue: 'm', - allowedValues: ['xs', 's', 'm', 'l', 'xl'], - }, - rating: { - type: Number, - allowedValues: [1, 2, 3, 4, 5], - uniforms: { checkboxes: true }, - }, - friends: { type: Array, minCount: 1 }, - 'friends.$': Object, - 'friends.$.name': { type: String, min: 3 }, - 'friends.$.age': { type: Number, min: 0, max: 150 }, - }) + date: { type: Date, defaultValue: new Date() }, + adult: Boolean, + size: { + type: String, + defaultValue: 'm', + allowedValues: ['xs', 's', 'm', 'l', 'xl'], + }, + rating: { + type: Number, + allowedValues: [1, 2, 3, 4, 5], + uniforms: { checkboxes: true }, + }, + friends: { type: Array, minCount: 1 }, + 'friends.$': Object, + 'friends.$.name': { type: String, min: 3 }, + 'friends.$.age': { type: Number, min: 0, max: 150 }, + }), }) `, @@ -43,7 +43,7 @@ const presets = { function createValidator(schema) { const validator = ajv.compile(schema); - return (model) => { + return model => { validator(model); if (validator.errors && validator.errors.length) { @@ -61,81 +61,84 @@ const presets = { 'Address (SimpleSchema)': preset` new SimpleSchema2Bridge({ schema: new SimpleSchema({ - city: { - type: String, - optional: true, - max: 50, - }, - state: String, - street: { type: String, max: 100 }, - zip: { - type: String, - regEx: /^[0-9]{5}$/, - }, - }) + city: { + type: String, + optional: true, + max: 50, + }, + state: String, + street: { type: String, max: 100 }, + zip: { + type: String, + regEx: /^[0-9]{5}$/, + }, + }), }) `, 'Address (Zod)': preset` new ZodBridge({ schema: z.object({ - city: z.string().max(50).optional(), - state: z.string(), - street: z.string().max(100), - zip: z.string().regex(/^[0-9]{5}$/), - }) + city: z.string().max(50).optional(), + state: z.string(), + street: z.string().max(100), + zip: z.string().regex(/^[0-9]{5}$/), + }), }) `, 'All Fields (SimpleSchema)': preset` new SimpleSchema2Bridge({ schema: new SimpleSchema({ - text: { type: String }, - num: { type: Number }, - bool: { type: Boolean }, - nested: { type: Object }, - 'nested.text': { type: String }, - date: { type: Date }, - list: { type: Array }, - 'list.$': { - type: String, - uniforms: { label: 'List Text', placeholder: 'List Text Placeholder' }, - }, - select: { - type: String, - uniforms: { - options: [ - { label: 'Option A', value: 'a' }, - { label: 'Option B', value: 'b' }, - ], - }, + text: { type: String }, + num: { type: Number }, + bool: { type: Boolean }, + nested: { type: Object }, + 'nested.text': { type: String }, + date: { type: Date }, + list: { type: Array }, + 'list.$': { + type: String, + uniforms: { label: 'List Text', placeholder: 'List Text Placeholder' }, + }, + select: { + type: String, + uniforms: { + options: [ + { label: 'Option A', value: 'a' }, + { label: 'Option B', value: 'b' }, + ], }, - radio: { - type: String, - uniforms: { - checkboxes: true, - options: [ - { label: 'Option A', value: 'a' }, - { label: 'Option B', value: 'b' }, - ], - }, + }, + radio: { + type: String, + uniforms: { + checkboxes: true, + options: [ + { label: 'Option A', value: 'a' }, + { label: 'Option B', value: 'b' }, + ], }, - }) + }, + }), }) `, 'All Fields (Zod)': preset` new ZodBridge({ schema: z.object({ - text: z.string(), - num: z.number(), - bool: z.boolean(), - nested: z.object({ text: z.string() }), - date: z.date(), - list: z.array(z.string().uniforms({ label: 'List Text', placeholder: 'List Text Placeholder' })), - select: z.enum(['a', 'b']), - radio: z.enum(['a', 'b']).uniforms({ checkboxes: true }), - }) + text: z.string(), + num: z.number(), + bool: z.boolean(), + nested: z.object({ text: z.string() }), + date: z.date(), + list: z + .string() + .uniforms({ label: 'List Text', placeholder: 'List Text Placeholder' }) + .array(), + select: z.enum(['a', 'b']), + radio: z.enum(['a', 'b']).uniforms({ checkboxes: true }), + }), }) `, };