diff --git a/docs/404.html b/docs/404.html index e887729..1900ff8 100644 --- a/docs/404.html +++ b/docs/404.html @@ -1 +1 @@ -
this is the +
this is the @magic-libraries json library. it returns errors instead of throwing them and catches (some) malformed objects when stringifying.
npm install @magic-libraries/json
in a page/component, just use the lib.json functions
lib.json.stringify({ some: { object: ['with', 'values'] } })
renders
{ "some": { "object": ["with", "values"] } }
this library is intended to handle incoming web traffic. we can never be sure that this incoming packets will not include faulty json.
to use this library without checking it's return value your input json MUST be wellformed.
in all (other) cases the following pattern should be employed -(and enhanced with custom error messages).
export const ViewStringify = unsafe => {
const result = lib.json.stringify(unsafe)
return div([result.message ? result.message : result])
}
export const ViewParse = unsafe => {
const result = lib.json.parse(unsafe)
// in this case we can not check for .message,
// since unsafe might have a .message key after parsing
div([result instanceof Error ? result.message : result])
}
the example/assets directory contains two modules that use the lib.json functions:
<JsonStringify state></JsonStringify>
renders
stringified JSON:
{
"state": {
"title": "@magic-libraries/json",
"description": "json client lib for @magic. returns errors instead of throwing them.",
"logotext": "@magic-libraries/json",
"menu": [
{
"to": "/#installation",
"text": "installation"
},
{
"to": "/#usage",
"text": "usage"
},
{
"to": "/#caveat",
"text": "caveat"
},
{
"to": "/#source",
"text": "source"
}
],
"theme": "dark",
"nospy": {
"show": false
},
"pageClass": {},
"url": "/json/",
"root": "/json/",
"pages": {
"/json/": {
"title": "@magic-libraries/json",
"description": "json client lib for @magic. returns errors instead of throwing them.",
"logotext": "@magic-libraries/json",
"menu": [
{
"to": "/#installation",
"text": "installation"
},
{
"to": "/#usage",
"text": "usage"
},
{
"to": "/#caveat",
"text": "caveat"
},
{
"to": "/#source",
"text": "source"
}
],
"url": "/json/",
"root": "/json/"
},
"/json/404/": {
"title": "404 - not found",
"description": "404 - not found."
}
}
}
}
<JsonParse>{ "valid": true }</JsonParse>
renders
parsed (and then stringified) JSON:
{
"valid": true
}
the source for this page is in the +(and enhanced with custom error messages).
export const ViewStringify = unsafe => {
const result = lib.json.stringify(unsafe)
return div([result.message ? result.message : result])
}
export const ViewParse = unsafe => {
const result = lib.json.parse(unsafe)
// in this case we can not check for .message,
// since unsafe might have a .message key after parsing
div([result instanceof Error ? result.message : result])
}
the example/assets directory contains two modules that use the lib.json functions:
<JsonStringify state></JsonStringify>
renders
stringified JSON:
{
"state": {
"title": "@magic-libraries/json",
"description": "json client lib for @magic. returns errors instead of throwing them.",
"logotext": "@magic-libraries/json",
"menu": [
{
"to": "/#installation",
"text": "installation"
},
{
"to": "/#usage",
"text": "usage"
},
{
"to": "/#caveat",
"text": "caveat"
},
{
"to": "/#source",
"text": "source"
}
],
"nospy": {
"show": false
},
"theme": "dark",
"pageClass": {},
"url": "/json/",
"root": "/json/",
"pages": {
"/json/": {
"title": "@magic-libraries/json",
"description": "json client lib for @magic. returns errors instead of throwing them.",
"logotext": "@magic-libraries/json",
"menu": [
{
"to": "/#installation",
"text": "installation"
},
{
"to": "/#usage",
"text": "usage"
},
{
"to": "/#caveat",
"text": "caveat"
},
{
"to": "/#source",
"text": "source"
}
],
"url": "/json/",
"root": "/json/"
},
"/json/404/": {
"title": "404 - not found",
"description": "404 - not found."
}
}
}
}
<JsonParse>{ "valid": true }</JsonParse>
renders
parsed (and then stringified) JSON:
{
"valid": true
}
the source for this page is in the example directory and gets built and published to github using -@magic/core