Skip to main content

Javascript

You can export the data generated by schemas or any type of data to javascript format

const userSchema = chaca.schema({
id: schemas.id.uuid(),
username: schemas.internet.userName(),
image: { type: schemas.image.people(), posibleNull: 50 },
posts: {
type: schemas.id.uuid(),
isArray: {
min: 1,
max: 5,
},
},
})

await userSchema.generateAndExport({
filaName: 'data',
format: 'javascript',
location: 'folder',
})

For example, if we have this schema, we generate 5 documents and export them in javascript format, we will obtain the following result

const data = [
{
id: 'bac15e95-0cb0-4acb-86b4-b625216c4db9',
username: 'Eliana_',
image: 'https://images.unsplash.com/photo-1531547255897-f400dc1b7de2?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzNTM2NjZ8MHwxfHNlYXJjaHw2NHx8cGVvcGxlfGVufDB8fHx8MTY2Njk3MDgzMw&ixlib=rb-4.0.3&q=80',
posts: [
'2d47d1bb-a735-4e2a-9dc2-3aada6505c1d',
'd1d378c9-a467-4880-9790-55659ce400a0',
'13467e21-c442-4705-8569-4ca59ed48ba2',
],
},
{
id: '5513c967-5508-4c45-98c5-126e4cb86960',
username: 'Elijah_',
image: 'https://pixabay.com/get/g7e4afc8fc92a3f8b39bbd35c7c082b4fe037bab84b1d90e0411766a65abf6cf6d4cf39e446a5839612a9ea2680958156729645977b61c4cac73a1ba468fca934_1280.jpg',
posts: ['bea3bc21-d232-4901-ba92-b0e387440dd7'],
},
{
id: '13e83ce3-8dba-4b49-8293-33bc434deb1d',
username: 'Isla717',
image: 'https://pixabay.com/get/g5f41f8ffc6ee66ec76622448cfc25a59529d50f1eee79af48e8ca1ab974f9817c526c3a430d2e6ce99127b7a0f51aba82996eab2bab4f174ff774544fc3c9fb5_1280.jpg',
posts: [
'58c25292-bb0b-42d6-97a6-1bd55bc59343',
'aee1e750-54e3-4d64-a0b3-9d36652dc593',
'29d190a3-ac07-4532-92dc-59d71e384a40',
],
},
{
id: '9067d4ab-72b1-429b-909c-62572021a66e',
username: 'Ava282',
image: 'https://images.pexels.com/photos/1417255/pexels-photo-1417255.jpeg',
posts: [
'14386521-2e49-401c-a2dc-43a8a9ab9e11',
'ee3e130e-3d77-40d5-b95c-7ee82be44075',
],
},
{
id: '679aa7e3-0b26-4b75-a7ed-9a9862892b10',
username: 'Hazel589',
image: null,
posts: [
'8de9a3bc-8e6e-452a-bc6a-505702760e2c',
'922315b7-bdc6-4b98-bc0e-99de97017e5e',
'99392632-46e5-49ad-92c8-929a7c9d0706',
'1ec4a41c-745d-44db-a6ba-e8043cc3085e',
],
},
]