Skip to content

Instantly share code, notes, and snippets.

@ankitarora05
ankitarora05 / gist:0c962035f533743e5c83e5cfac2ba04b
Last active October 22, 2024 06:29
JavaScript Program to Convert a Json Object to a Typescript Interface
/**
* Function to convert a JSON object to a TypeScript interface with nested interfaces.
* @param {Object} obj - The JSON object to convert.
* @param {string} interfaceName - The name of the TypeScript interface.
* @returns {string} - The TypeScript interface as a string.
*/
function jsonToTypeScriptInterface(obj, interfaceName = 'RootObject') {
let result = `interface ${interfaceName} {\n`;
const nestedInterfaces = [];
@ankitarora05
ankitarora05 / gist:85bf734d1b5785329b4dfaff4c40c624
Last active August 23, 2024 08:24
Generate mongoose schema for your MongoDB database model from dynamic JSON objects with mixed types
const mongoose = require('mongoose');
// Example JSON object with mixed types in arrays
const json = {
"name": "John Doe",
"age": 30,
"email": "[email protected]",
"isActive": true,
"roles": [
{"role": "admin", "level": 1},
@ankitarora05
ankitarora05 / nuxt.config.js
Last active July 30, 2022 23:28
Automatically detect and update new PWA Workbox builds in nuxt.js
plugins: [{src: '@/plugins/pwa-update.js', mode: 'client'}]
pwa: {
workbox: {
cachingExtensions: "@/plugins/workbox-range-request.js",
skipWaiting: true
},
}