{"id":27222224,"url":"https://github.com/paazmaya/yaml-validator","last_synced_at":"2025-04-10T08:57:38.510Z","repository":{"id":4191024,"uuid":"52278258","full_name":"paazmaya/yaml-validator","owner":"paazmaya","description":"Validate Yaml files and enforce a given structure","archived":false,"fork":false,"pushed_at":"2024-10-29T18:01:08.000Z","size":990,"stargazers_count":56,"open_issues_count":19,"forks_count":17,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-29T20:09:52.972Z","etag":null,"topics":["hacktoberfest","nodejs","validator","yaml"],"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/paazmaya.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-02-22T14:16:39.000Z","updated_at":"2024-09-12T23:11:59.000Z","dependencies_parsed_at":"2023-07-05T20:31:16.435Z","dependency_job_id":"df2e0e78-6167-4a58-aebc-503628710b13","html_url":"https://github.com/paazmaya/yaml-validator","commit_stats":{"total_commits":577,"total_committers":14,"mean_commits":"41.214285714285715","dds":0.3292894280762565,"last_synced_commit":"6b3adb3de22a669f1683c0cc238fbf32e0a7f7d2"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paazmaya%2Fyaml-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paazmaya%2Fyaml-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paazmaya%2Fyaml-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paazmaya%2Fyaml-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paazmaya","download_url":"https://codeload.github.com/paazmaya/yaml-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248190439,"owners_count":21062278,"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":["hacktoberfest","nodejs","validator","yaml"],"created_at":"2025-04-10T08:57:37.942Z","updated_at":"2025-04-10T08:57:38.482Z","avatar_url":"https://github.com/paazmaya.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yaml-validator\n\n\u003e Validate Yaml files and enforce a given structure\n\n[![Ubuntu Build Status](https://paazmaya.semaphoreci.com/badges/yaml-validator/branches/master.svg)](https://paazmaya.semaphoreci.com/projects/yaml-validator)\n[![Windows build status](https://ci.appveyor.com/api/projects/status/rxt9kv7geq8vyny7/branch/master?svg=true)](https://ci.appveyor.com/project/paazmaya/yaml-validator)\n[![code coverage](https://codecov.io/gh/paazmaya/yaml-validator/branch/master/graph/badge.svg)](https://codecov.io/gh/paazmaya/yaml-validator)\n[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=paazmaya_yaml-validator\u0026metric=code_smells)](https://sonarcloud.io/dashboard?id=paazmaya_yaml-validator)\n\n[Yaml](http://yaml.org/) files are parsed via [`js-yaml`](https://github.com/nodeca/js-yaml)\nand the structure defined in the configuration options is enforced with\n[`check-type`](https://github.com/alistairjcbrown/check-type).\n\n## Getting Started\n\nPlease note that the minimum supported version of [Node.js](https://nodejs.org/en/) is `22.11.0`, which is [the active Long Term Support (LTS) version](https://github.com/nodejs/Release#release-schedule).\n\nThis tool can be used in two ways, either via Node.js script, or as a command line tool.\nNote that when used via command line, custom structure cannot be validated.\n\nInstallation when used via Node.js script:\n\n```sh\nnpm install yaml-validator --save-dev\n```\n\nInstallation when used as a command line tool:\n\n```sh\nnpm install --global yaml-validator\n```\n\nUsage as a part of a Node.js script:\n\n```js\nconst YamlValidator = require('yaml-validator');\n\n// Default options\nconst options = {\n  log: false,\n  structure: false,\n  onWarning: null,\n  writeJson: false\n};\n\nconst files = [\n  'file paths',\n  'that exists',\n  'somewhere',\n  'and are Yaml files'\n];\n\nconst validator = new YamlValidator(options);\nvalidator.validate(files);\nvalidator.report();\n```\n\nUsing via command line tool, the only argument would be the Yaml file which should be validated:\n\n```sh\nyaml-validator random_file.yml\n```\n\nThe available options for command line use, can be seen with the help command `yaml-validator -h`, which results in output similar to:\n\n```sh\nyaml-validator [options] \u003cfiles\u003e\n\n  -h, --help             Help and usage instructions\n  -V, --version          Version number\n  -w, --write-json       Write the contents of the Yaml file to a JSON file next to it\n  -l, --log-file String  Log file where errors are written\n\nVersion 5.0.0\n```\n\nWhen used from the command line, the process exits with the number of invalid files.\n\n## Configuration options\n\nAll options are `false` by default which disables their use.\n\n### options.log\n\nType: `string`\n\nDefault value: `false`\n\nIn case the value is not `false`, the given string will be used as log file where all the\ntask output is written.\n\n\n### options.structure\n\nType: `object`\n\nDefault value: `false`\n\nThe most complex style of checking validity.\n\n\n### options.onWarning\n\nType: `function`\n\nDefault value: `null`\n\nOne of the options passed to [`load` method of `js-yaml`](https://github.com/nodeca/js-yaml#load-string---options-).\n\nPlease note that the `onWarning` callback is being used by this library and any method written for it,\nwill be run after the one implemented in this library.\nThe callback get called with two parameters, of which the first is the error in question,\nwhile the second is the file path of the given Yaml file.\n\n\n### options.writeJson\n\nType: `boolean`\n\nDefault: `false`\n\nWrite the given Yaml file as pretty printed JSON in the same path, just by changing the file extension to `json`.\n\nPlease note that any existing JSON files will be cruelly overwritten.\n\n## Typescript Support\n\n`YamlValidator` ships with its own typing definition in the library, no need to use `@types`.\n\n## Examples\n\n### Structure validation options\n\nIn case an array is found, all its members are assumed to have the given structure.\nThis can be seen in the `classRooms` property, which according to the configuration below,\nshould be an array, for which all items are objects, which all should have a `name` and `id`\nproperties, with the given types.\n\nThe `teachers` array is made of strings, thus all items in that array must be a string.\n\n\n```js\nconst options = {\n  structure: {\n    school: {\n      'description?': 'string', //Optional, won't show in invalid array\n      code: 'number',\n      principal: {\n        name: 'string'\n      },\n      classRooms: [\n        {\n          name: 'string',\n          id: 'number',\n          'location?':{\n            floor: \"string\",\n            building: \"string\",\n          }\n        }\n      ],\n      teachers: [\n        'string'\n      ]\n    }\n  }\n};\n```\n\n### Warning callback in Yaml parsing options\n\nUsing the `options.onWarning` callback, the possible parsing errors can be retrieved.\n\n```js\nconst options = {\n  onWarning: function (error, filepath) {\n    console.log(filepath + ' has error: ' + error);\n  }\n};\n```\n\n### Write a JSON file option\n\nIt is possible to use the `options.writeJson` to have all the files processed,\nto be saved in JSON format, in the same file path as the original Yaml files.\n\n```js\nconst options = {\n  writeJson: true\n};\n```\n\n## Contributing\n\n[\"A Beginner's Guide to Open Source: The Best Advice for Making your First Contribution\"](http://www.erikaheidi.com/blog/a-beginners-guide-to-open-source-the-best-advice-for-making-your-first-contribution/).\n\n[Also there is a blog post about \"45 Github Issues Dos and Don’ts\"](https://davidwalsh.name/45-github-issues-dos-donts).\n\nLinting is done with [ESLint](http://eslint.org) and can be executed with `npm run lint`.\nThere should be no errors appearing after any JavaScript file changes.\n\nPlease note that any features or changed will not be merged without working unit tests.\n\nUnit tests are written with [`tape`](https://github.com/substack/tape) and can be executed with `npm test`.\nCode coverage is inspected with [`nyc`](https://github.com/istanbuljs/nyc) and\ncan be executed with `npm run coverage` after running `npm test`.\nPlease make sure it is over 90% at all times.\n\n## Version History\n\n[Changes happening across different versions and upcoming changes are tracked in the `CHANGELOG.md` file.](CHANGELOG.md)\n\n## License\n\nCopyright (c) [Juga Paazmaya](https://paazmaya.fi) \u003cpaazmaya@yahoo.com\u003e\n\nLicensed under [the MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaazmaya%2Fyaml-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaazmaya%2Fyaml-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaazmaya%2Fyaml-validator/lists"}