Socket
Socket
Sign inDemoInstall

@stencila/configa

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stencila/configa - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [0.3.0](https://github.com/stencila/configa/compare/v0.2.1...v0.3.0) (2019-12-04)
### Features
* **Run time:** Coerce comma separated items into array ([601ffe3](https://github.com/stencila/configa/commit/601ffe36394ee2874107f84697c8a2ff103d3b3a))
## [0.2.1](https://github.com/stencila/configa/compare/v0.2.0...v0.2.1) (2019-12-02)

@@ -2,0 +9,0 @@

2

dist/config.schema.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "Configa 0.2.0",
"description": "Configa 0.2.1",
"$comment": "",

@@ -6,0 +6,0 @@ "properties": {

@@ -8,2 +8,3 @@ /**

import { Logger } from '@stencila/logga';
import { JSONSchema7 } from 'json-schema';
/**

@@ -20,1 +21,19 @@ * Collect configuration options.

};
/**
* Coerce options to a JSON Schema.
*
* This function only does coercions that Ajv does not.
*
* @param value The value to coerce
* @param schema The schema to coerce to
* @param log A logger to emit messages to
*/
export declare function coerceOptions(value: any, schema?: JSONSchema7): object;
/**
* Validate (and coerce where necessary) options against a JSON Schema
*
* @param options The options to validate
* @param schema The schema to validate against
* @param log A logger to emit messages to
*/
export declare function validateOptions(options: object, schema: JSONSchema7, log: Logger): [object, boolean];

@@ -40,3 +40,41 @@ "use strict";

const args = _.length > 0 ? _ : undefined;
// Validate and coerce options against schema
const coerced = coerceOptions(options, schema);
const [validated, valid] = validateOptions(coerced, schema, log);
const config = validated;
return { args, config, valid, log };
}
exports.collectOptions = collectOptions;
/**
* Coerce options to a JSON Schema.
*
* This function only does coercions that Ajv does not.
*
* @param value The value to coerce
* @param schema The schema to coerce to
* @param log A logger to emit messages to
*/
function coerceOptions(value, schema) {
if (schema === undefined)
return value;
const { type, properties } = schema;
if (typeof value === 'string' && type === 'array')
return value.split(/\s*,\s*/);
if (value === null || typeof value !== 'object' || Array.isArray(value))
return value;
if (properties === undefined)
return value;
return Object.entries(value).reduce((prev, [key, child]) => {
const value = coerceOptions(child, properties[key]);
return { ...prev, ...{ [key]: value } };
}, {});
}
exports.coerceOptions = coerceOptions;
/**
* Validate (and coerce where necessary) options against a JSON Schema
*
* @param options The options to validate
* @param schema The schema to validate against
* @param log A logger to emit messages to
*/
function validateOptions(options, schema, log) {
const validate = ajv.compile(schema);

@@ -59,5 +97,4 @@ const valid = validate(options);

}
const config = options;
return { args, config, valid, log };
return [options, valid];
}
exports.collectOptions = collectOptions;
exports.validateOptions = validateOptions;
{
"name": "@stencila/configa",
"version": "0.2.1",
"version": "0.3.0",
"description": "Application configuration: DRY, flexible and type-safe",

@@ -5,0 +5,0 @@ "bin": "dist/cli.js",

@@ -70,3 +70,2 @@ # Configa

### 4. Generate configuration documentation

@@ -73,0 +72,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