diff --git a/src/logger.js b/src/logger.js index c9964235..3a6de361 100644 --- a/src/logger.js +++ b/src/logger.js @@ -1,5 +1,5 @@ /* istanbul ignore else: coverage tools always in testing environment */ -if (process.env.MOCHA === '1') { +if (process.env.TEST_MOCHA === 'true') { // If testing from CLI, use noop logger, to not interfere with the mocha reporter // (see issues mochajs/mocha#1998, mochajs/mocha#2107, etc.) diff --git a/src/parse/interface/index.js b/src/parse/interface/index.js index 61f14b63..bb48ab12 100644 --- a/src/parse/interface/index.js +++ b/src/parse/interface/index.js @@ -1,3 +1,9 @@ +import * as dataType from './dataType' +import * as graph from './graph' +import * as parser from './parser' + +export const util = {...dataType, ...graph, ...parser} + export * from './register' export * from './chain' diff --git a/src/parse/interface/parser.js b/src/parse/interface/parser.js index 6552833a..63eab0d9 100644 --- a/src/parse/interface/parser.js +++ b/src/parse/interface/parser.js @@ -3,7 +3,7 @@ import {type, typeMatcher} from './type' export class TypeParser { validDataTypes = ['String', 'Array', 'SimpleObject', 'ComplexObject', 'Primitive'] - constructor (data = {}) { + constructor (data) { this.data = data } @@ -47,6 +47,9 @@ export class TypeParser { } validate () { + if (this.data !== null && typeof this.data !== 'object') { + throw new TypeError(`typeParser was ${typeof this.data}; expected object`) + } this.validateDataType() this.validateParseType() this.validatePropertyConstraint() @@ -61,7 +64,7 @@ export class TypeParser { parsePropertyConstraint () { let constraints = [].concat(this.data.propertyConstraint || []) - return constraints.map(({props = [], match = 'every', value = () => true}) => { + return constraints.map(({props, match = 'every', value = () => true}) => { props = [].concat(props) return input => props[match](prop => prop in input && value(input[prop])) @@ -129,7 +132,7 @@ export class TypeParser { } export class DataParser { - constructor (parser = {}, {async} = {}) { + constructor (parser, {async} = {}) { this.parser = parser this.async = async } @@ -140,7 +143,7 @@ export class DataParser { validate () { const parser = this.parser - if (parser && typeof parser !== 'function') { + if (typeof parser !== 'function') { throw new TypeError(`parser was ${typeof parser}; expected function`) } } diff --git a/src/parse/interface/register.js b/src/parse/interface/register.js index e7988013..2b775ae2 100644 --- a/src/parse/interface/register.js +++ b/src/parse/interface/register.js @@ -145,7 +145,7 @@ export const hasFormat = (format) => format in formats export const listFormat = () => Object.keys(formats) // BEGIN compat -export const add = (...args) => { +export const add = /* istanbul ignore next: deprecated */ (...args) => { logger.warn('This method is deprecated; use addFormat') return addFormat(...args) } diff --git a/src/parse/interface/type.js b/src/parse/interface/type.js index 3fa4e366..f04663a6 100644 --- a/src/parse/interface/type.js +++ b/src/parse/interface/type.js @@ -65,12 +65,6 @@ const matchType = (typeList = [], data) => { export const type = (input) => { const dataType = dataTypeOf(input) - if (!dataTypes.hasOwnProperty(dataType)) { - // TODO if no parsers registered, this warning is always thrown - logger.warn('[set]', 'Data type has no formats listed') - return parseNativeTypes(input, dataType) - } - // Empty array should be @csl/list+object too if (dataType === 'Array' && input.length === 0) { // Off-load to parseNativeTypes() to not repeat the name @@ -174,7 +168,7 @@ export const listTypeParser = () => Object.keys(types) * * @return {Object} tree structure */ -export const treeTypeParser = () => { +export const treeTypeParser = /* istanbul ignore next: debugging */ () => { const attachNode = name => ({name, children: types[name].extensions.map(attachNode)}) return { name: 'Type tree',