{"_id":"@audc/json-schema-instantiator","_rev":"1-38bc6d0772773c7a679f6c1c9d04642b","name":"@audc/json-schema-instantiator","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@audc/json-schema-instantiator","version":"1.0.0","keywords":["JSON","schema","instantiate","instantiator","JSON-Schema","Generator","Generate","Data Generation"],"license":"MIT","_id":"@audc/json-schema-instantiator@1.0.0","maintainers":[{"name":"bivas6","email":"yaakov.bivas@audiocodes.com"},{"name":"orgads","email":"orgads@gmail.com"}],"homepage":"https://github.com/tomarad/JSON-Schema-Instantiator#readme","bugs":{"url":"https://github.com/tomarad/JSON-Schema-Instantiator/issues"},"dist":{"shasum":"2d0c5785b78133a8402658eec11bc0855eb84366","tarball":"https://registry.npmjs.org/@audc/json-schema-instantiator/-/json-schema-instantiator-1.0.0.tgz","fileCount":6,"integrity":"sha512-++q8B8//pZ/G6sjMbGwT2ih+foWV2HQl92zAzwV/9M0DpDOgdAgAfEwXEm9xEP7lDybvu/lfzfBlHMGq4BijsA==","signatures":[{"sig":"MEQCIG2PCNHehPWZIdFpKP57ZSgKiyTNZ2vztHPQshgfGhS6AiBYasFXJmu8TQjd+3Mi5n7ppt9yKiAl5u+WwBU4kSe8OA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":19608},"main":"dist/cjs/instantiator.js","types":"dist/types/instantiator.d.ts","module":"dist/esm/instantiator.mjs","authors":["Tom Arad","Samuel Batista <sambatista@pm.me> (https://sambatista.com) "],"exports":{".":{"types":"./dist/types/instantiator.d.ts","import":"./dist/esm/instantiator.mjs","require":"./dist/cjs/instantiator.js"}},"gitHead":"6b98424c0e9a6bf91c3f2b7742cd3f4789de8cb8","scripts":{"test":"node --unhandled-rejections=strict infrastructure/package_scripts/test.mjs","build":"node --unhandled-rejections=strict infrastructure/package_scripts/build.mjs","clean":"node --unhandled-rejections=strict infrastructure/package_scripts/clean.mjs","format":"node --unhandled-rejections=strict infrastructure/package_scripts/format.mjs","prepack":"node --unhandled-rejections=strict infrastructure/package_scripts/prepack.mjs","build_infrastructure":"node --unhandled-rejections=strict infrastructure/package_scripts/build_infrastructure.mjs"},"_npmUser":{"name":"orgads","email":"orgads@gmail.com"},"repository":{"url":"git+https://github.com/tomarad/JSON-Schema-Instantiator.git","type":"git"},"_npmVersion":"10.2.3","description":"A simple instantiator for json schemas.","directories":{},"_nodeVersion":"20.9.0","_hasShrinkwrap":false,"devDependencies":{"chai":"^4.3.10","mocha":"^10.2.0","prettier":"^3.1.0","typescript":"^5.3.2"},"_npmOperationalInternal":{"tmp":"tmp/json-schema-instantiator_1.0.0_1701762233272_0.3850392474736497","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-12-05T07:43:53.134Z","modified":"2025-01-19T20:18:57.750Z","1.0.0":"2023-12-05T07:43:53.455Z"},"bugs":{"url":"https://github.com/tomarad/JSON-Schema-Instantiator/issues"},"license":"MIT","homepage":"https://github.com/tomarad/JSON-Schema-Instantiator#readme","keywords":["JSON","schema","instantiate","instantiator","JSON-Schema","Generator","Generate","Data Generation"],"repository":{"url":"git+https://github.com/tomarad/JSON-Schema-Instantiator.git","type":"git"},"description":"A simple instantiator for json schemas.","maintainers":[{"email":"orgads@gmail.com","name":"orgads"}],"readme":"# JSON-Schema-Instantiator\r\nA simple tool for instantiating JSON Schemas, with Angular support!\r\n\r\n## Installing\r\n\r\n### Node.js\r\n\r\n```\r\nnpm install json-schema-instantiator\r\n```\r\n\r\n### AngularJS\r\n\r\n```\r\nbower install angular-schema-instantiator\r\n```\r\n\r\n## Using\r\n\r\n### Node.js\r\n``` javascript\r\nvar instantiator = require('json-schema-instantiator');\r\n\r\n...\r\n\r\nvar schema = {\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n        \"title\": {\r\n            \"type\": \"string\",\r\n            \"default\": \"Example\"\r\n        },\r\n        \"description\": {\r\n            \"type\": \"string\"\r\n        },\r\n        \"quantity\": {\r\n            \"type\": \"number\"\r\n        },\r\n        \"endDate\": {\r\n            \"type\": \"string\",\r\n            \"format\": \"date\"\r\n        }\r\n    },\r\n    \"required\": [\"title\"]\r\n};\r\n\r\ninstance = instantiator.instantiate(schema);\r\n// instance === { title: \"Example\", description: \"\", quantity: 0, endDate: \"\" }\r\n\r\ninstance = instantiator.instantiate(schema, {requiredPropertiesOnly: false});\r\n// instance === { title: \"Example\", description: \"\", quantity: 0, endDate: \"\" }\r\n\r\ninstance = instantiator.instantiate(schema, {requiredPropertiesOnly: true});\r\n// instance === { title: \"Example\" }\r\n\r\n// Override default values for a given type with a static value\r\ninstance = instantiator.instantiate(schema, { defaults: { number: 42 } });\r\n// instance === { title: \"Example\", description: \"\", quantity: 42, endDate: \"\" }\r\n\r\n// Override default values for a given type function that returns a value\r\ninstance = instantiator.instantiate(schema, {\r\n  defaults: {\r\n    // Function that receives current property/val and returns a value\r\n    string: function (val) {\r\n      var format = val.format;\r\n\r\n      if (format && format === \"date\") {\r\n        return new Date(2021, 0, 1);\r\n      }\r\n\r\n      return \"\";\r\n    },\r\n  },\r\n});\r\n// instance === { title: \"Example\", description: \"\", quantity: 0, endDate: new Date(2021, 0, 1) }\r\n```\r\n\r\n### AngularJS\r\nAdd the sources to index.html:\r\n\r\n    <script src=\"json-schema-instanciator/src/instantiator.js\"></script>\r\n    <script src=\"json-schema-instanciator/src/angular-instantiator.js\"></script>\r\n\r\nInclude the module:\r\n``` javascript\r\nangular.module('myApp', ['schemaInstantiator'])\r\n\r\n...\r\n```\r\n\r\nInject the InstantiatorService and use it:\r\n``` javascript\r\n...\r\n\r\n.controller({\r\n    MyCtrl: ['InstantiatorService', function(Instantiator) {\r\n        var schema = {\r\n            type: \"string\",\r\n            default: \"Hello!\"\r\n        };\r\n        \r\n        console.log(Instantiator.instantiate(schema));\r\n        // Hello!\r\n    }]\r\n})\r\n\r\n...\r\n```\r\n\r\n### Note\r\nThis does not replace schema validation! Invalid schemas will yield unexpected results.\r\n","readmeFilename":"README.md"}