From 1ace394ed4a7d0e69fd397165df04fa72d46efab Mon Sep 17 00:00:00 2001 From: delvedor Date: Fri, 7 Apr 2017 09:54:48 +0200 Subject: [PATCH 1/3] Updated README.md --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f068cb89..bf0ae191 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -# fast-json-stringify  [![Build Status](https://travis-ci.org/fastify/fast-json-stringify.svg?branch=master)](https://travis-ci.org/fastify/fast-json-stringify) +# fast-json-stringify + +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) + [![Build Status](https://travis-ci.org/fastify/fast-json-stringify.svg?branch=master)](https://travis-ci.org/fastify/fast-json-stringify) __fast-json-stringify__ is x1-4 times faster than `JSON.stringify()`. It is particularly suited if you are sending small JSON payloads, the @@ -297,7 +300,9 @@ const stringify = fastJson(schema, { schema: externalSchema }) ## Acknowledgements -This project was kindly sponsored by [nearForm](http://nearform.com). +This project is kindly sponsored by: +- [nearForm](http://nearform.com) +- [LetzDoIt](http://www.letzdoitapp.com/) ## License From 6550e84965b0234365655525bf8882757c9f8a4c Mon Sep 17 00:00:00 2001 From: delvedor Date: Fri, 7 Apr 2017 09:55:03 +0200 Subject: [PATCH 2/3] Better errors --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 65d627a6..962c149e 100644 --- a/index.js +++ b/index.js @@ -45,7 +45,7 @@ function build (schema, options) { code = buildArray(schema, code, main, options.schema, schema) break default: - throw new Error(`${schema.type} unsupported`) + throw new Error(`${schema.type} unsupported in schema:\n${JSON.stringify(schema, null, 2)}`) } code += ` @@ -391,7 +391,7 @@ function nested (laterCode, name, key, schema, externalSchema, fullSchema) { ` break default: - throw new Error(`${type} unsupported`) + throw new Error(`${type} unsupported in schema:\n${JSON.stringify(fullSchema, null, 2)}`) } return { From a34146dc71c1ba3d12119f7e63307724821609fa Mon Sep 17 00:00:00 2001 From: delvedor Date: Fri, 7 Apr 2017 09:55:16 +0200 Subject: [PATCH 3/3] Updated test --- test/type-not-supported.test.js | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/type-not-supported.test.js diff --git a/test/type-not-supported.test.js b/test/type-not-supported.test.js new file mode 100644 index 00000000..351cceef --- /dev/null +++ b/test/type-not-supported.test.js @@ -0,0 +1,45 @@ +'use strict' + +const test = require('tap').test +const build = require('..') + +test('type not supported', (t) => { + t.plan(1) + + const schema = { + title: 'object with RegExp', + type: 'object', + properties: { + reg: 'string' + } + } + + try { + build(schema) + } catch (err) { + t.equal(err.message, `undefined unsupported in schema:\n${JSON.stringify(schema, null, 2)}`) + } +}) + +test('type not supported - nested', (t) => { + t.plan(1) + + const schema = { + title: 'object with RegExp', + type: 'object', + properties: { + key: { + type: 'object', + properties: { + key: 'number' + } + } + } + } + + try { + build(schema) + } catch (err) { + t.equal(err.message, `undefined unsupported in schema:\n${JSON.stringify(schema, null, 2)}`) + } +})