Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

v8r

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

v8r - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

5

CHANGELOG.md
# Changelog
## 📦 [0.2.0](https://www.npmjs.com/package/v8r/v/0.2.0) - 2020-12-24
* Find schemas using paths and glob patterns
* Add `--ignore-errors` flag
## 📦 [0.1.1](https://www.npmjs.com/package/v8r/v/0.1.1) - 2020-11-08

@@ -4,0 +9,0 @@

11

index.js

@@ -7,4 +7,4 @@ #!/usr/bin/env node

const schemaHelp = `URL of schema to validate file against (optional)
If not supplied, we will attempt to find an appropriate schema on schemastore.org using the filename`;
const schemaHelp = `(optional) URL of schema to validate file against. If not supplied, we will attempt to find an appropriate schema on schemastore.org using the filename`;
const ignoreErrorsHelp = `(optional) Exit with code 0 even if an error was encountered. Passing this flag means a non-zero exit code is only issued if validation could be completed successfully and the file was invalid`;

@@ -23,2 +23,6 @@ const args = yargs(hideBin(process.argv))

describe: schemaHelp,
})
.option("ignore-errors", {
type: "boolean",
describe: ignoreErrorsHelp,
}).argv;

@@ -35,4 +39,7 @@

console.error(e.message);
if (args.ignoreErrors) {
process.exit(0);
}
process.exit(1);
}
})();

@@ -6,2 +6,3 @@ "use strict";

const got = require("got");
const minimatch = require("minimatch");
const path = require("path");

@@ -26,11 +27,30 @@ const yaml = require("js-yaml");

);
const matches = [];
schemas.forEach(function (schema) {
if ("fileMatch" in schema && schema.fileMatch.includes(filename)) {
matches.push(schema);
if ("fileMatch" in schema) {
if (schema.fileMatch.includes(path.basename(filename))) {
matches.push(schema);
return;
}
for (const glob of schema.fileMatch) {
if (minimatch(path.normalize(filename), glob)) {
matches.push(schema);
break;
}
}
}
});
if (matches.length == 1) {
return matches[0].url;
}
if (matches.length > 1) {
console.log(
`Found multiple possible schemas for ${filename}. Possible matches:`
);
matches.forEach(function (match) {
console.log(`${match.description}: ${match.url}`);
});
}
throw new Error(`❌ Could not find a schema to validate ${filename}`);

@@ -74,4 +94,3 @@ }

);
const schemaUrl =
args.schema || (await getSchemaUrlForFilename(path.basename(filename)));
const schemaUrl = args.schema || (await getSchemaUrlForFilename(filename));
const schema = await fetch(schemaUrl);

@@ -78,0 +97,0 @@ console.log(`Validating ${filename} against schema from ${schemaUrl} ...`);

7

package.json
{
"name": "v8r",
"version": "0.1.1",
"version": "0.2.0",
"description": "A command-line JSON and YAML validator that's on your wavelength",
"scripts": {
"test": "mocha tests.js",
"test": "nyc --reporter=text mocha tests.js",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov",
"prettier": "prettier --write \"**/*.js\"",

@@ -24,2 +25,3 @@ "prettier:check": "prettier --check \"**/*.js\""

"js-yaml": "^3.14.0",
"minimatch": "^3.0.4",
"yargs": "^16.1.0"

@@ -32,2 +34,3 @@ },

"nock": "^13.0.4",
"nyc": "^15.1.0",
"prettier": "^2.1.2"

@@ -34,0 +37,0 @@ },

# v8r
![Build status](https://github.com/chris48s/v8r/workflows/Run%20tests/badge.svg)
![Build status](https://github.com/chris48s/v8r/workflows/Run%20tests/badge.svg?branch=main)
[![codecov](https://codecov.io/gh/chris48s/v8r/branch/main/graph/badge.svg?token=KL998A5CJH)](https://codecov.io/gh/chris48s/v8r)
![NPM version](https://img.shields.io/npm/v/v8r.svg)

@@ -28,3 +29,3 @@ ![License](https://img.shields.io/npm/l/v8r.svg)

$ v8r package.json # v8r can validate JSON..
Validating package.json with schema 'package.json'...
Validating package.json against schema from https://json.schemastore.org/package ...

@@ -50,9 +51,9 @@ Errors:

# if v8r can't auto-detect a schema for your file..
$ v8r chart.yaml
❌ Could not find a schema to validate chart.yaml
$ v8r feature.geojson
❌ Could not find a schema to validate feature.geojson
# ..you can specify one
$ v8r chart.yaml -s https://json.schemastore.org/helmfile
Validating chart.yaml against schema from https://json.schemastore.org/helmfile ...
✅ chart.yaml is valid
$ v8r feature.geojson -s https://json.schemastore.org/geojson
Validating feature.geojson against schema from https://json.schemastore.org/geojson ...
✅ feature.geojson is valid
```

@@ -62,19 +63,18 @@

v8r exits with code `0` when:
* v8r always exits with code `0` when:
* The input file was validated against a schema and the input file was **valid**
* `v8r` was called with `--help` or `--version` flags
* The input file was validated against a schema and the input file was **valid**
* `v8r` was called with `--help` or `--version` flags
* By default v8r exits with code `1` when an error was encountered trying to validate the input file. For example:
* No suitable schema could be found
* An error was encountered during an HTTP request
* The input file did not exist
* The input file was not JSON or yaml
* etc
v8r exits with code `1` when an error was encountered trying to validate the input file. For example:
This behaviour can be modified using the `--ignore-errors` flag. When invoked with `--ignore-errors` v8r will exit with code `0` even if one of these errors was encountered while attempting validation. A non-zero exit code will only be issued if validation could be completed successfully and the file was invalid.
* No suitable schema could be found
* An error was encountered during an HTTP request
* The input file did not exist
* The input file was not JSON or yaml
* etc
* v8r always exits with code `99` when:
* The input file was validated against a schema and the input file was **invalid**
v8r exits with code `99` when:
* The input file was validated against a schema and the input file was **invalid**
## FAQ

@@ -81,0 +81,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc