{"id":24251404,"url":"https://github.com/zweifisch/kontur","last_synced_at":"2025-09-23T16:31:14.922Z","repository":{"id":66141017,"uuid":"76361237","full_name":"zweifisch/kontur","owner":"zweifisch","description":"a little DSL that outputs JSON schema","archived":false,"fork":false,"pushed_at":"2016-12-16T23:42:15.000Z","size":32,"stargazers_count":78,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-11T00:05:34.115Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zweifisch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-13T13:30:15.000Z","updated_at":"2024-04-09T05:41:55.000Z","dependencies_parsed_at":"2023-03-14T12:30:41.980Z","dependency_job_id":null,"html_url":"https://github.com/zweifisch/kontur","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"a104987de9c4a4327848351572ecca0d0e59aeea"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fkontur","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fkontur/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fkontur/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fkontur/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zweifisch","download_url":"https://codeload.github.com/zweifisch/kontur/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233811754,"owners_count":18734169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-15T02:50:53.842Z","updated_at":"2025-09-23T16:31:09.642Z","avatar_url":"https://github.com/zweifisch.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kontur\n\n[![NPM Version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Node.js Version][node-version-image]][node-version-url]\n\na little DSL that outputs JSON schema\n\n[instruction](koa.md) on validating request body in koa using ajv and kontur\n\n## overview\n\n```js\nimport { compile, bool, int, str } from 'kontur'\n\ncompile({\n  gender: str,\n  age: int,\n  nickname: str,\n  verified: bool\n})\n```\n\nwill generate\n\n```js\n{\n  type: 'object',\n  properties: {\n     gender: { type: 'string' },\n     age: { type: 'integer' },\n     nickname: { type: 'string' },\n     verified: { type: 'boolean' }\n  },\n  required: [ 'gender', 'age', 'nickname', 'verified' ]\n}\n```\n\n```js\ncompile({\n  gender: str.in('male', 'female').optional,\n  age: int.between(0, 200),\n  nickname: str.minlen(3).match(/^[a-zA-Z]/),\n  verified: bool.optional.default(false)\n})\n```\n\nwill generate\n\n```js\n{\n  type: 'object',\n  properties: {\n    gender: {\n      enum: ['male', 'female'],\n      type: 'string'\n    },\n    age: {\n      minimum: 0,\n      maximum: 200,\n      type: 'integer'\n    },\n    nickname: {\n      minLength: 3,\n      pattern: '^[a-zA-Z]',\n      type: 'string'\n    },\n    verified: {\n      default: false,\n      type: 'boolean'\n    }\n  },\n  required: [ 'age', 'nickname' ]\n}\n```\n\nnested schema\n\n```js\ncompile({\n  assignment: {\n    assignees: array.len(3).uniq.items(str.len(16)),\n    assigner: object.strict.properties({\n      id: str.len(16)\n    }),\n    assigned_at: str.datetime\n  }\n})\n```\n\nthe output can be found [here](lib/compile.test.js)\n\n## types\n\n### object\n\n`strict`, no extra properties should be included\n\n`size(num)`, `maxsize(num)`, `minsize(num)`, limit the number of properties\n\n`properties(schema)`, specify schema of children\n\n### array\n\n`strict`, no extra items should be included\n\n`len(num)`, `minlen(num)`, `maxlen(num)`, limit the length of the array\n\n`items(schema)`, all element should match\n\n`uniq`\n\n`contains(schema)`, at least one element should match\n\n### string\n\n`match(regexp)`, match a regular expression\n\n`email`, `ipv4`, `ipv6`, `uri`, `datetime`, built-in formats\n\n### number/int\n\n`min(num)`, `max(num)`, `between(num, num)`,\n\n`min(num).exclusive`, `max(num).exclusive`\n\n### null\n\n`nil` just null\n\n### boolean\n\n`bool`\n\n### tuple(direived from array)\n\nuse plain array\n\n```\n[str, int.between(1,5)]\n```\n\n### enum\n\n```\nstr.in('created', 'suspended', 'deleted')\n```\n\n```\nany('male', 'female')\n```\n\n## miscs\n\n`optional` used in context of object, by default all keys are required\n\n`depends(keys)` used in context of object\n\n`default(value)` add default value\n\n`desc(text)` add description\n\n`title(text)` add title\n\n## combining schemas\n\n### all\n\n```\nall(int.min(0), int.max(1))\n```\n\n### any\n\n```\nany(int.min(1).exclusive, int.max(0).exclusive)\n```\n\n### one\n\n```\none(int.min(0), int.max(1))\n```\n\n### not\n\n```\nnot.nil\n```\n\n```\nnot.object.array\n```\n\n[npm-image]: https://img.shields.io/npm/v/kontur.svg?style=flat\n[npm-url]: https://npmjs.org/package/kontur\n[travis-image]: https://img.shields.io/travis/zweifisch/kontur.svg?style=flat\n[travis-url]: https://travis-ci.org/zweifisch/kontur\n[node-version-image]: https://img.shields.io/node/v/kontur.svg\n[node-version-url]: https://nodejs.org/en/download/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweifisch%2Fkontur","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzweifisch%2Fkontur","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweifisch%2Fkontur/lists"}