protodef-yaml
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -41,2 +41,3 @@ # protodef-yaml | ||
score: li32 | ||
optional?: bool | ||
_: type? | ||
@@ -99,2 +100,9 @@ if remove: | ||
{ | ||
"name": "optional", | ||
"type": [ | ||
"option", | ||
"bool" | ||
] | ||
}, | ||
{ | ||
"anon": true, | ||
@@ -101,0 +109,0 @@ "type": [ |
@@ -27,3 +27,3 @@ const showdown = require('showdown') | ||
if (isStatement(key) && (parent?.includes('%switch'))) return `<span class='fake'>${key.replace('if', 'is').replace(/_/g, ' ')}</span>` | ||
return key.startsWith('_') ? key : key.replace(/_/g, ' ').replace('$', '') | ||
return key.startsWith('_') ? key : key.replace(/_/g, ' ').replace('$', '').replace('?', '') | ||
} | ||
@@ -44,6 +44,10 @@ | ||
let extraTag = '' | ||
const aname = key.startsWith('%') ? key.split(',')[1] : key | ||
if (aname.endsWith('?')) extraTag += `<div class='tag tag-optional'>optional</div>` | ||
if (typeof val === 'object') { | ||
if (key.startsWith('%switch')) { | ||
const [_, what, condition] = key.split(',') | ||
rows += pad(`<tr><td><b class='name'>${what.startsWith('_') ? '🔁' : tfName(what)}</b><br/><br/> <i><div class='tag tag-switch'>if <span class='name'>${tfName(condition)}</span></div></i></td><td colspan=2><table>`) | ||
rows += pad(`<tr><td><b class='name'>${what.startsWith('_') ? '🔁' : tfName(what)}</b><br/><br/>${extraTag}<i><div class='tag tag-switch'>if <span class='name'>${tfName(condition)}</span></div></i></td><td colspan=2><table>`) | ||
for (let k in val) { | ||
@@ -59,3 +63,3 @@ let condition = k.startsWith('%') ? k.split(',')[1] : k | ||
const name = key.startsWith('%') ? key.split(',')[1] : key | ||
rows += pad(`<tr><td class='name'>${tfName(name, parent)} </td><td colspan=2 class='bordered'><table>`) | ||
rows += pad(`<tr><td class='name'>${tfName(name, parent)} ${extraTag}</td><td colspan=2 class='bordered'><table>`) | ||
for (const k in val) { | ||
@@ -68,3 +72,3 @@ let v = val[k] | ||
const [_, what, type] = key.split(',') | ||
rows += pad(`<tr><td class='name field-name'>${tfName(what, parent)}</td><td colspan=2>${type} <span class='tag tag-enum'>enum</span><hr/> <table style='width:100%'>`) | ||
rows += pad(`<tr><td class='name field-name'>${tfName(what, parent)} ${extraTag}</td><td colspan=2>${type} <span class='tag tag-enum'>enum</span><hr/> <table style='width:100%'>`) | ||
for (const k in val) { | ||
@@ -102,3 +106,3 @@ let v = val[k] | ||
} else if (typeof val === 'string') { | ||
rows += pad(`<tr><td class='field-name name'>${tfName(key, parent)}</td><td>${tfType(val)}</td><td>${nextComment()}</td></tr>`) | ||
rows += pad(`<tr><td class='field-name name'>${tfName(key, parent)} ${extraTag}</td><td>${tfType(val)}</td><td>${nextComment()}</td></tr>`) | ||
} | ||
@@ -220,2 +224,5 @@ } | ||
} | ||
.tag-optional { | ||
background-color: gold; border: 1px solid #A0A0A0; color: black; padding: 6px; | ||
} | ||
.tag-array { | ||
@@ -222,0 +229,0 @@ background-color: navy; |
@@ -235,2 +235,12 @@ const fs = globalThis.window ? null : require('fs') | ||
ctx = ctx || [] | ||
function ctxPush (data) { | ||
if (data.name && data.name.endsWith('?')) { | ||
data.name = | ||
ctx.push({ ...data, name: data.name.slice(0, -1), type: ["option", data.type] }) | ||
} else { | ||
ctx.push(data) | ||
} | ||
} | ||
for (const key in obj) { | ||
@@ -253,3 +263,3 @@ let val = obj[key] | ||
} | ||
ctx.push({ | ||
ctxPush({ | ||
name, | ||
@@ -324,3 +334,3 @@ type: [ | ||
ctx.push({ | ||
ctxPush({ | ||
name, | ||
@@ -350,4 +360,5 @@ anon, | ||
if (!name) anon = true | ||
ctx.push({ name, anon, type: ['container', []] }) | ||
trans(val, ctx[ctx.length - 1].type[1]) | ||
const o = { name, anon, type: ['container', []] } | ||
trans(val, o.type[1]) | ||
ctxPush(o) | ||
} | ||
@@ -363,3 +374,3 @@ } else { | ||
} | ||
ctx.push({ name: key, type: val }) | ||
ctxPush({ name: key, type: val }) | ||
} | ||
@@ -366,0 +377,0 @@ log(key, typeof val) |
@@ -0,1 +1,6 @@ | ||
## 1.4.0 | ||
* [Add builtin syntax for protodef options (#12)](https://github.com/extremeheat/protodef-yaml/commit/5d5fb3d9a293218806e92005c986da103f2a65ce) (thanks @extremeheat) | ||
* [Update web bundle](https://github.com/extremeheat/protodef-yaml/commit/975213e7f46cde0a81ddec9c44dff26592ea773c) (thanks @extremeheat) | ||
* [Add repo commands workflow](https://github.com/extremeheat/protodef-yaml/commit/8b1e963f463173114674bc81e3d4067b1f5bc5df) (thanks @extremeheat) | ||
## 1.2 | ||
@@ -2,0 +7,0 @@ * Add a HTML generator |
{ | ||
"name": "protodef-yaml", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Transforms YAML-like syntax to ProtoDef JSON schema", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -31,2 +31,9 @@ const { parse, compile, genHTML } = require('../index') | ||
it('transforms optionals to ProtoDef', function() { | ||
compile(f`opts.yml`, f`opts.json`) | ||
const hash = sha1(f`opts.json`) | ||
console.info('sha1 of optionals', hash) | ||
assert.strictEqual(hash, '3c24211c3b0ed22371104a0485277e607dc7b58b') | ||
}) | ||
it('works inline', function () { | ||
@@ -33,0 +40,0 @@ const json = compile({ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
783182
28
11134
203
0